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

Fix bug when setting meta.background in SkyMatchStep. #1233

Merged
merged 3 commits into from
Jun 6, 2024
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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------

Expand Down
13 changes: 3 additions & 10 deletions romancal/skymatch/skymatch_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[...]
Expand Down
10 changes: 5 additions & 5 deletions romancal/skymatch/tests/test_skymatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 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"]:
Expand All @@ -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):
Expand Down
Loading