From b080c1747fa4114819c61043d3fe3b1fe9b0dbc4 Mon Sep 17 00:00:00 2001 From: Bryson Cale Date: Sat, 31 Aug 2024 10:21:22 -0700 Subject: [PATCH 1/2] Added subarray files to figshare. Added tmp_path for asn. --- Makefile | 2 +- README.md | 16 +++++- .../merge_subarrays/merge_subarrays.py | 7 ++- .../tests/test_merge_subarrays.py | 54 +++++++++++++++++++ 4 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 liger_iris_pipeline/tests/test_merge_subarrays.py 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..f256f39 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,22 @@ Testing Data - Raw science frame of a few stars - https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48191524 -#### raw_background_20240829.fits +#### raw_background_20240829.fitsg - Raw (sky) background frame - https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48903439 #### 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 From 4f5f9d775e4e6b986cc1b74a0c9456e165935c92 Mon Sep 17 00:00:00 2001 From: Bryson Cale Date: Sat, 31 Aug 2024 15:11:52 -0700 Subject: [PATCH 2/2] typo in README filename --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f256f39..4710e4f 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Testing Data - Raw science frame of a few stars - https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48191524 -#### raw_background_20240829.fitsg +#### raw_background_20240829.fits - Raw (sky) background frame - https://figshare.com/articles/dataset/IRIS_Liger_DRS_Test_Data/26492029?file=48903439