Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rcal-697 Update exposure pipeline to add tweakreg step #960

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dark
general
-------

- Update pipeline code to run through tweakreg with single files and associations [#960]

- Update regression tests with new data and update ramp fitting tests to use ols_cas22 [#911]

- Fix bug with ``ModelContainer.get_crds_parameters`` being a property not a method [#846]
Expand Down Expand Up @@ -42,7 +44,6 @@ ramp_fitting

- Make uneven ramp fitting the default [#877]


- Update Ramp fitting code to support the ``stcal`` changes to the ramp fitting
interface which were necessary to support jump detection on uneven ramps [#933]

Expand Down
50 changes: 34 additions & 16 deletions romancal/pipeline/exposure_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

# step imports
from romancal.assign_wcs import AssignWcsStep
from romancal.associations.exceptions import AssociationNotValidError
from romancal.associations.load_as_asn import LoadAsLevel2Asn

# from romancal.associations.exceptions import AssociationNotValidError
# from romancal.associations.load_as_asn import LoadAsLevel2Asn
from romancal.dark_current import DarkCurrentStep
from romancal.datamodels import ModelContainer
from romancal.dq_init import dq_init_step
from romancal.flatfield import FlatFieldStep
from romancal.jump import jump_step
Expand All @@ -23,6 +25,7 @@
from romancal.refpix import RefPixStep
from romancal.saturation import SaturationStep
from romancal.source_detection import SourceDetectionStep
from romancal.tweakreg import TweakRegStep

from ..stpipe import RomanPipeline

Expand Down Expand Up @@ -62,6 +65,7 @@
"flatfield": FlatFieldStep,
"photom": PhotomStep,
"source_detection": SourceDetectionStep,
"tweakreg": TweakRegStep,
}

# start the actual processing
Expand All @@ -85,22 +89,21 @@
return

if file_type == "asn":
try:
asn = LoadAsLevel2Asn.load(input, basename=self.output_file)
except AssociationNotValidError:
log.debug("Error opening file:")
return
asn = ModelContainer.read_asn(input)

Check warning on line 92 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L92

Added line #L92 was not covered by tests

# Build a list of observations to process
expos_file = []
n_members = 0

Check warning on line 96 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L96

Added line #L96 was not covered by tests
if file_type == "asdf":
expos_file = [input]
elif file_type == "asn":
for product in asn["products"]:
n_members = len(product["members"])

Check warning on line 101 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L101

Added line #L101 was not covered by tests
for member in product["members"]:
expos_file.append(member["expname"])

results = []
tweakreg_input = ModelContainer()

Check warning on line 106 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L106

Added line #L106 was not covered by tests
for in_file in expos_file:
if isinstance(in_file, str):
input_filename = basename(in_file)
Expand All @@ -117,7 +120,6 @@
if input_filename:
result.meta.filename = input_filename
result = self.saturation(result)
# pdb.set_trace()

# Test for fully saturated data
if is_fully_saturated(result):
Expand Down Expand Up @@ -149,29 +151,45 @@
result = self.dark_current(result)
result = self.jump(result)
result = self.rampfit(result)

result = self.assign_wcs(result)
if result.meta.exposure.type == "WFI_IMAGE":
result = self.flatfield(result)
else:
log.info("Flat Field step is being SKIPPED")
result.meta.cal_step.flat_field = "SKIPPED"

if result.meta.exposure.type == "WFI_IMAGE":
result = self.flatfield(result)

Check warning on line 157 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L157

Added line #L157 was not covered by tests
result = self.photom(result)
result = self.source_detection(result)
if file_type == "asn":
tweakreg_input.append(result)
log.info(

Check warning on line 162 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L160-L162

Added lines #L160 - L162 were not covered by tests
f"Number of models to tweakreg: {len(tweakreg_input._models), n_members}"
)
else:
log.info("Photom and source detection steps are being SKIPPED")
log.info("Flat Field step is being SKIPPED")
log.info("Photom step is being SKIPPED")
log.info("Source Detection step is being SKIPPED")
log.info("Tweakreg step is being SKIPPED")
result.meta.cal_step.flat_field = "SKIPPED"

Check warning on line 170 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L166-L170

Added lines #L166 - L170 were not covered by tests
result.meta.cal_step.photom = "SKIPPED"
result.meta.cal_step.source_detection = "SKIPPED"
result.meta.cal_step.tweakreg = "SKIPPED"

Check warning on line 173 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L173

Added line #L173 was not covered by tests

# setup output_file for saving
self.setup_output(result)
log.info("Roman exposure calibration pipeline ending...")

self.output_use_model = True
results.append(result)

# Now that all the exposures are collated, run tweakreg
# Note: this does not cover the case where the asn mixes imaging and spectral
# observations. This should not occur on-prem
if result.meta.exposure.type == "WFI_IMAGE":
if file_type == "asdf":
mc_result = self.tweakreg([result])
result = mc_result._models.pop()
if file_type == "asn":
result = self.tweakreg(tweakreg_input)

Check warning on line 189 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L184-L189

Added lines #L184 - L189 were not covered by tests

log.info("Roman exposure calibration pipeline ending...")

Check warning on line 191 in romancal/pipeline/exposure_pipeline.py

View check run for this annotation

Codecov / codecov/patch

romancal/pipeline/exposure_pipeline.py#L191

Added line #L191 was not covered by tests

return results

def setup_output(self, input):
Expand Down
31 changes: 29 additions & 2 deletions romancal/regtest/test_wfi_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def test_level2_image_processing_pipeline(rtdata, ignore_asdf_paths):

@pytest.mark.bigdata
@pytest.mark.soctests
@metrics_logger("DMS90", "DMS91", "DMS9")
@metrics_logger("DMS278", "DMS90", "DMS91", "DMS9")
def test_level2_grism_processing_pipeline(rtdata, ignore_asdf_paths):
"""Tests for flat field grism processing requirements DMS90 & DMS 91"""
"""Tests for flat field grism processing requirements DMS90, DMS91 & DMS 278"""
input_data = "r0000201001001001002_01101_0001_WFI01_uncal.asdf"
rtdata.get_data(f"WFI/grism/{input_data}")
rtdata.input = input_data
Expand Down Expand Up @@ -356,6 +356,33 @@ def test_level2_grism_processing_pipeline(rtdata, ignore_asdf_paths):
)
assert model.meta.cal_step.saturation == "COMPLETE"

pipeline.log.info(
"DMS278 MSG: Testing WFI Level 2 Data Generation - Spectroscopy in Level 2 spectroscopic"
" output......."
+ passfail(model.meta.cal_step.dq_init == "COMPLETE")
+ passfail(model.meta.cal_step.saturation == "COMPLETE")
+ passfail(model.meta.cal_step.refpix == "COMPLETE")
+ passfail(model.meta.cal_step.linearity == "COMPLETE")
+ passfail(model.meta.cal_step.jump == "COMPLETE")
+ passfail(model.meta.cal_step.ramp_fit == "COMPLETE")
+ passfail(model.meta.cal_step.assign_wcs == "COMPLETE")
+ passfail(model.meta.cal_step.flat_field == "SKIPPED")
+ passfail(model.meta.cal_step.photom == "SKIPPED")
+ passfail(model.meta.cal_step.source_detection == "SKIPPED")
+ passfail(model.meta.cal_step.tweakreg == "SKIPPED")
)
assert model.meta.cal_step.dq_init == "COMPLETE"
assert model.meta.cal_step.saturation == "COMPLETE"
assert model.meta.cal_step.refpix == "COMPLETE"
assert model.meta.cal_step.linearity == "COMPLETE"
assert model.meta.cal_step.jump == "COMPLETE"
assert model.meta.cal_step.ramp_fit == "COMPLETE"
assert model.meta.cal_step.assign_wcs == "COMPLETE"
assert model.meta.cal_step.flat_field == "SKIPPED"
assert model.meta.cal_step.photom == "SKIPPED"
assert model.meta.cal_step.source_detection == "SKIPPED"
assert model.meta.cal_step.tweakreg == "SKIPPED"

# DMS91 data quality tests
pipeline.log.info(
"DMS91 MSG: Testing existence of data quality array (dq) in Level 2"
Expand Down