From 5cc07eeb124953cd262540463ad7b6f25f85a6d5 Mon Sep 17 00:00:00 2001 From: D Davis <49163225+ddavis-stsci@users.noreply.github.com> Date: Fri, 10 Nov 2023 15:51:14 -0500 Subject: [PATCH] RCAL-707 Update elp to replace list as input to tweakreg (#985) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGES.rst | 2 + romancal/lib/suffix.py | 2 +- romancal/pipeline/exposure_pipeline.py | 3 +- romancal/pipeline/highlevel_pipeline.py | 80 +++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 romancal/pipeline/highlevel_pipeline.py diff --git a/CHANGES.rst b/CHANGES.rst index d92674d01..4e3628670 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,8 @@ dark general ------- +- Update elp pipeline code to capture a list from tweakreg [#985] + - Update pipeline code to correct cal_step and suffixes [#971] - Update pipeline code to run through tweakreg with single files and associations [#960] diff --git a/romancal/lib/suffix.py b/romancal/lib/suffix.py index 9be896fd6..9a17b53b1 100644 --- a/romancal/lib/suffix.py +++ b/romancal/lib/suffix.py @@ -63,7 +63,7 @@ # Suffixes that are discovered but should not be considered. # Used by `find_suffixes` to remove undesired values it has found. -SUFFIXES_TO_DISCARD = ["pipeline", "step"] +SUFFIXES_TO_DISCARD = ["highlevelpipeline", "pipeline", "step"] # Calculated suffixes. diff --git a/romancal/pipeline/exposure_pipeline.py b/romancal/pipeline/exposure_pipeline.py index 12566b15b..f6c1402dd 100644 --- a/romancal/pipeline/exposure_pipeline.py +++ b/romancal/pipeline/exposure_pipeline.py @@ -191,8 +191,7 @@ def process(self, input): if result.meta.exposure.type == "WFI_IMAGE": if file_type == "asdf": result.meta.cal_step.tweakreg = "SKIPPED" - # mc_result = ModelContainer(result) - mc_result = self.tweakreg([result]) + mc_result = ModelContainer(result) if hasattr(ModelContainer(result), "_models") and mc_result._models: result = mc_result._models.pop() else: diff --git a/romancal/pipeline/highlevel_pipeline.py b/romancal/pipeline/highlevel_pipeline.py new file mode 100644 index 000000000..f42bb596d --- /dev/null +++ b/romancal/pipeline/highlevel_pipeline.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +import logging +from os.path import basename + +import romancal.datamodels.filetype as filetype +from romancal.datamodels import ModelContainer +from romancal.outlier_detection import OutlierDetectionStep +from romancal.resample import ResampleStep + +# step imports +from romancal.skymatch import SkyMatchStep + +from ..stpipe import RomanPipeline + +__all__ = ["HighLevelPipeline"] + +# Define logging +log = logging.getLogger() +log.setLevel(logging.DEBUG) + + +class HighLevelPipeline(RomanPipeline): + """ + HighLevelPipeline: Apply all calibration steps to the roman data + to produce level 3 products. Included steps are: + skymatch, Outlierdetectionn and resample. + """ + + class_alias = "roman_hlp" + + spec = """ + save_results = boolean(default=False) + """ + + # Define aliases to steps + step_defs = { + "skymatch": SkyMatchStep, + "outlierdet": OutlierDetectionStep, + "resample": ResampleStep, + } + + # start the actual processing + def process(self, input): + """Process the Roman WFI data from Level 2 to Level 3""" + + log.info("Starting Roman high level calibration pipeline ...") + if isinstance(input, str): + input_filename = basename(input) + else: + input_filename = None + + # open the input file + file_type = filetype.check(input) + asn = None + if file_type == "asdf": + log.info("The level three pipeline input needs to be an association") + return + + if file_type == "asn": + asn = ModelContainer.read_asn(input) + self.skymatch.suffix = "skymatch" + result = self.skymatch(input) + self.skymatch.suffix = "outlierdetection" + result = self.outlierdetection(asn) + self.skymatch.suffix = "i2d" + result = self.resample(result) + if input_filename: + result.meta.filename = input_filename + + return result + + def setup_output(self, input): + """Determine the proper file name suffix to use later""" + if input.meta.cal_step.ramp_fit == "COMPLETE": + self.suffix = "cal" + input.meta.filename = input.meta.filename.replace("uncal", self.suffix) + input["output_file"] = input.meta.filename + self.output_file = input.meta.filename + else: + self.suffix = "cal"