Skip to content

Commit

Permalink
test cal_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro committed Oct 4, 2024
1 parent 217d660 commit 826b3a5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions jwst/stpipe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from functools import wraps
import logging
import time

from stdatamodels.jwst.datamodels import JwstDataModel
from stdatamodels.jwst import datamodels
Expand All @@ -13,6 +14,12 @@
from .. import __version_commit__, __version__
from ..lib.suffix import remove_suffix

_LOG_FORMATTER = logging.Formatter(
"%(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
)
_LOG_FORMATTER.converter = time.gmtime


log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
Expand All @@ -24,6 +31,8 @@ class JwstStep(Step):
output_ext = string(default='.fits') # Output file type
"""

_log_records_formatter = _LOG_FORMATTER

@classmethod
def _datamodels_open(cls, init, **kwargs):
return datamodels.open(init, **kwargs)
Expand Down Expand Up @@ -91,6 +100,10 @@ def finalize_result(self, result, reference_files_used):
if self.parent is None:
log.info(f"Results used CRDS context: {result.meta.ref_file.crds.context_used}")

if hasattr(result, 'cal_logs'):
tmpdict = result.cal_logs.instance
tmpdict[self.class_alias] = '\n'.join(self._log_records)
result.cal_logs = tmpdict

def remove_suffix(self, name):
return remove_suffix(name)
Expand All @@ -110,3 +123,12 @@ class JwstPipeline(Pipeline, JwstStep):
def finalize_result(self, result, reference_files_used):
if isinstance(result, JwstDataModel):
log.info(f"Results used CRDS context: {crds_client.get_context_used(result.crds_observatory)}")

if hasattr(result, 'cal_logs'):
tmpdict = result.cal_logs.instance
tmpdict[self.class_alias] = '\n'.join(self._log_records)

for _, step in self.step_defs.items():
if step.class_alias in tmpdict.keys():
del tmpdict[step.class_alias]
result.cal_logs = tmpdict

0 comments on commit 826b3a5

Please sign in to comment.