Skip to content

Commit

Permalink
Merge pull request #76 from oirlab/port_merge_subarrays_step2
Browse files Browse the repository at this point in the history
Refactored merge_subarrays_step
  • Loading branch information
zonca authored Aug 31, 2024
2 parents a9d83db + 4f5f9d7 commit 46c8784
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
pytest -v liger_iris_pipeline/tests/test_datamodels.py liger_iris_pipeline/tests/test_dark.py liger_iris_pipeline/tests/test_rop.py liger_iris_pipeline/tests/test_utils.py liger_iris_pipeline/tests/test_normalize.py liger_iris_pipeline/tests/test_assign_wcs.py liger_iris_pipeline/tests/test_asdf_schema.py liger_iris_pipeline/tests/test_preprocess_flatfield.py liger_iris_pipeline/tests/test_image2.py
pytest -v liger_iris_pipeline/tests/test_datamodels.py liger_iris_pipeline/tests/test_dark.py liger_iris_pipeline/tests/test_rop.py liger_iris_pipeline/tests/test_utils.py liger_iris_pipeline/tests/test_normalize.py liger_iris_pipeline/tests/test_assign_wcs.py liger_iris_pipeline/tests/test_asdf_schema.py liger_iris_pipeline/tests/test_preprocess_flatfield.py liger_iris_pipeline/tests/test_image2.py liger_iris_pipeline/tests/test_merge_subarrays.py
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ Testing Data

#### test_iris_subtract_bg_flat_cal_20240822.fits
- Processed Level 2 image data
- https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48737014
- https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48737014

#### reduced_science_frame_sci_subarray_1_20240831.fits
- Subarray image
- https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48911917

#### reduced_science_frame_sci_subarray_2_20240831.fits
- Subarray image
- https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48911914

#### reduced_science_frame_sci_with_subarrays_20240831.fits
- Starting point for merging subarrays 1 & 2 above with nans where subarrays are
- https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48911932
7 changes: 3 additions & 4 deletions liger_iris_pipeline/merge_subarrays/merge_subarrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class MergeSubarraysStep(Step):
"""
ParseSubarrayMapStep: Parse a subarray map
extension, if available, and create header metadata
and data quality flag accordingly
and data quality flag accordingly.
"""

def process(self, input):

input = datamodels.open(input)

# If single input, wrap in a ModelContainer
# If single input, just return it
if not isinstance(input, datamodels.ModelContainer):
self.log.info("No subarray files provided, return the original model")
return input
Expand All @@ -31,14 +31,13 @@ def process(self, input):
else:
raise ValueError("Cannot identify the full frame, it should have SUBARRID=0")


# Assume subarrays are in order
for model in input_models:

i_sub = model.meta.subarray.id

# Skip the full frame
if i_sub == 0:
# skip the full frame
continue

subarray_mask = result.subarr_map == i_sub
Expand Down
54 changes: 54 additions & 0 deletions liger_iris_pipeline/tests/test_merge_subarrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Imports
import liger_iris_pipeline
liger_iris_pipeline.monkeypatch_jwst_datamodels()
import numpy as np

import json

# See README.md for notes on testing data
from liger_iris_pipeline.tests.test_utils import get_data_from_url


def test_merge_subarrays(tmp_path):

# Download the test data
reduced_science_frame_filename = get_data_from_url("48911932")
reduced_subarray1_filename = get_data_from_url("48911917")
reduced_subarray2_filename = get_data_from_url("48911914")

# Create an ASN for this test
asn = {
"asn_rule": "Asn_Image",
"asn_pool": "pool",
"asn_type": "image3",
"products": [
{
"name": "test_merge_subarrays_asn",
"members": [
{
"expname": reduced_science_frame_filename,
"exptype": "science"
},
{
"expname": reduced_subarray1_filename,
"exptype": "science"
},
{
"expname": reduced_subarray2_filename,
"exptype": "science"
}
]
}
]
}

# Save to file
asn_temp_filename = tmp_path / "test_asn.json"
with open(asn_temp_filename, "w+") as f:
json.dump(asn, f)

# Run the merge subarray pipeline
result = liger_iris_pipeline.MergeSubarraysStep().call(asn_temp_filename)

# Check that the image is valid
assert np.all(np.logical_not(np.isnan(result.data)))

0 comments on commit 46c8784

Please sign in to comment.