From eb6851f376aad843a90dbf9d79efcd26b0bb9a39 Mon Sep 17 00:00:00 2001 From: "M. Teodoro" Date: Fri, 10 May 2024 10:02:56 -0400 Subject: [PATCH 1/3] Fix bug when setting meta.background in SkyMatchStep. --- romancal/skymatch/skymatch_step.py | 13 +++---------- romancal/skymatch/tests/test_skymatch.py | 10 +++++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/romancal/skymatch/skymatch_step.py b/romancal/skymatch/skymatch_step.py index c0d46f1fa..1c9a30a5e 100644 --- a/romancal/skymatch/skymatch_step.py +++ b/romancal/skymatch/skymatch_step.py @@ -197,16 +197,9 @@ def _set_sky_background(self, sky_image, step_status): dm = image if step_status == "COMPLETE": - # TODO: remove this block when ``rad`` has a background schema: - # https://github.com/spacetelescope/rad/issues/247 - # This is a temporary workaround to access a 'background' - # entry into metadata as a Python dict, which we'll later define with - # a schema in ``rad``: - dm.meta["background"]["method"] = str(self.skymethod) - dm.meta["background"]["level"] = sky - dm.meta["background"]["subtracted"] = ( - self.subtract or dm.meta["background"]["subtracted"] - ) + dm.meta.background.method = str(self.skymethod) + dm.meta.background.level = sky + dm.meta.background.subtracted = self.subtract if self.subtract: dm.data[...] = sky_image.image[...] diff --git a/romancal/skymatch/tests/test_skymatch.py b/romancal/skymatch/tests/test_skymatch.py index 7dc3c4349..f28bde01b 100644 --- a/romancal/skymatch/tests/test_skymatch.py +++ b/romancal/skymatch/tests/test_skymatch.py @@ -333,16 +333,16 @@ def test_skymatch_2x(wfi_rate, skymethod, subtract): result = step.run([im1, im2, im3]) result = ModelContainer(result) - assert result[0].meta["background"]["subtracted"] == subtract - assert result[0].meta["background"]["level"] is not None + assert result[0].meta.background.subtracted is subtract + assert result[0].meta.background.level is not None # 2nd run. step.subtract = False result2 = step.run(result) result2 = ModelContainer(result2) - assert result2[0].meta["background"]["subtracted"] == subtract - assert result2[0].meta["background"]["level"] is not None + assert result2[0].meta.background.subtracted == step.subtract + assert result2[0].meta.background.level is not None # compute expected levels if skymethod in ["local", "global+match"]: @@ -360,7 +360,7 @@ def test_skymatch_2x(wfi_rate, skymethod, subtract): for im, lev, rlev, slev in zip(result2, levels, ref_levels, sub_levels): # check that meta was set correctly: assert im.meta.background.method == skymethod - assert im.meta.background.subtracted == subtract + assert im.meta.background.subtracted == step.subtract # test computed/measured sky values: if not np.isclose(im.meta.background.level.value, 0, atol=1e-6): From bf5fdb24108c92b080464e16a10170cf85148f5f Mon Sep 17 00:00:00 2001 From: "M. Teodoro" Date: Fri, 10 May 2024 10:11:04 -0400 Subject: [PATCH 2/3] Add changelog entry. --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 659fd5266..22f1c2c96 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -31,6 +31,8 @@ skymatch -------- - Update step to always return a ``ModelContainer``. [#1208] +- Fix bug that prevented ``meta.background.subtracted`` from being set with the proper datatype. [#1233] + patch_match ----------- From a8015c024390459e3d55fe726d01cd06ba2e0e88 Mon Sep 17 00:00:00 2001 From: "M. Teodoro" Date: Thu, 6 Jun 2024 16:15:26 -0400 Subject: [PATCH 3/3] Fix assertion operator. --- romancal/skymatch/tests/test_skymatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/romancal/skymatch/tests/test_skymatch.py b/romancal/skymatch/tests/test_skymatch.py index f28bde01b..ffde92343 100644 --- a/romancal/skymatch/tests/test_skymatch.py +++ b/romancal/skymatch/tests/test_skymatch.py @@ -333,7 +333,7 @@ def test_skymatch_2x(wfi_rate, skymethod, subtract): result = step.run([im1, im2, im3]) result = ModelContainer(result) - assert result[0].meta.background.subtracted is subtract + assert result[0].meta.background.subtracted == subtract assert result[0].meta.background.level is not None # 2nd run.