Skip to content

Commit

Permalink
Fix bug when setting meta.background in SkyMatchStep.
Browse files Browse the repository at this point in the history
  • Loading branch information
mairanteodoro committed Jun 5, 2024
1 parent f593a51 commit 119b117
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
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 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"]:
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

0 comments on commit 119b117

Please sign in to comment.