diff --git a/Makefile b/Makefile index 3029f02..8f7420d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 7b0c9e3..4710e4f 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +- 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 \ No newline at end of file diff --git a/liger_iris_pipeline/merge_subarrays/merge_subarrays.py b/liger_iris_pipeline/merge_subarrays/merge_subarrays.py index e0fa979..e7e11e4 100644 --- a/liger_iris_pipeline/merge_subarrays/merge_subarrays.py +++ b/liger_iris_pipeline/merge_subarrays/merge_subarrays.py @@ -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 @@ -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 diff --git a/liger_iris_pipeline/tests/test_merge_subarrays.py b/liger_iris_pipeline/tests/test_merge_subarrays.py new file mode 100644 index 0000000..f4caa02 --- /dev/null +++ b/liger_iris_pipeline/tests/test_merge_subarrays.py @@ -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))) \ No newline at end of file