Skip to content

Commit

Permalink
RCAL-782: Changed image units. (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHuwe authored Mar 11, 2024
1 parent ef56c9a commit e91ba14
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- Make datamodels follow the same subscription pattern as the ``stnode`` based
objects. [#322]

- Changed image units from e/s to DN/s (and added support for MJy/sr). [#327]

0.19.0 (2024-02-09)
===================

Expand Down
10 changes: 5 additions & 5 deletions src/roman_datamodels/maker_utils/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ def mk_level2_image(*, shape=(4088, 4088), n_groups=8, filepath=None, **kwargs):
# add amp 33 ref pixel array
amp33_size = (n_groups, 4096, 128)
wfi_image["amp33"] = kwargs.get("amp33", u.Quantity(np.zeros(amp33_size, dtype=np.uint16), u.DN, dtype=np.uint16))
wfi_image["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.electron / u.s, dtype=np.float32))
wfi_image["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN / u.s, dtype=np.float32))
wfi_image["dq"] = kwargs.get("dq", np.zeros(shape, dtype=np.uint32))
wfi_image["err"] = kwargs.get("err", u.Quantity(np.zeros(shape, dtype=np.float32), u.electron / u.s, dtype=np.float32))
wfi_image["err"] = kwargs.get("err", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN / u.s, dtype=np.float32))

wfi_image["var_poisson"] = kwargs.get(
"var_poisson", u.Quantity(np.zeros(shape, dtype=np.float32), u.electron**2 / u.s**2, dtype=np.float32)
"var_poisson", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN**2 / u.s**2, dtype=np.float32)
)
wfi_image["var_rnoise"] = kwargs.get(
"var_rnoise", u.Quantity(np.zeros(shape, dtype=np.float32), u.electron**2 / u.s**2, dtype=np.float32)
"var_rnoise", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN**2 / u.s**2, dtype=np.float32)
)
wfi_image["var_flat"] = kwargs.get(
"var_flat", u.Quantity(np.zeros(shape, dtype=np.float32), u.electron**2 / u.s**2, dtype=np.float32)
"var_flat", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN**2 / u.s**2, dtype=np.float32)
)
wfi_image["cal_logs"] = mk_cal_logs(**kwargs)

Expand Down
19 changes: 15 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,21 +618,32 @@ def test_make_level2_image():
wfi_image = utils.mk_level2_image(shape=(8, 8))

assert wfi_image.data.dtype == np.float32
assert wfi_image.data.unit == u.electron / u.s
assert wfi_image.data.unit == u.DN / u.s
assert wfi_image.dq.dtype == np.uint32
assert wfi_image.err.dtype == np.float32
assert wfi_image.err.unit == u.electron / u.s
assert wfi_image.err.unit == u.DN / u.s
assert wfi_image.var_poisson.dtype == np.float32
assert wfi_image.var_poisson.unit == u.electron**2 / u.s**2
assert wfi_image.var_poisson.unit == u.DN**2 / u.s**2
assert wfi_image.var_rnoise.dtype == np.float32
assert wfi_image.var_rnoise.unit == u.electron**2 / u.s**2
assert wfi_image.var_rnoise.unit == u.DN**2 / u.s**2
assert wfi_image.var_flat.dtype == np.float32
assert wfi_image.var_flat.unit == u.DN**2 / u.s**2
assert isinstance(wfi_image.cal_logs[0], str)

# Test validation
wfi_image_model = datamodels.ImageModel(wfi_image)
assert wfi_image_model.validate() is None

# Test Physical units
wfi_image_model.data = wfi_image_model.data.value * (u.MJy / u.sr)
wfi_image_model.err = wfi_image_model.err.value * (u.MJy / u.sr)
wfi_image_model.var_poisson = wfi_image_model.var_poisson.value * (u.MJy**2 / u.sr**2)
wfi_image_model.var_rnoise = wfi_image_model.var_rnoise.value * (u.MJy**2 / u.sr**2)
wfi_image_model.var_flat = wfi_image_model.var_flat.value * (u.MJy**2 / u.sr**2)

# Test validation
assert wfi_image_model.validate() is None


# Test that attributes can be assigned object instances without raising exceptions
# unless they don't match the corresponding tag
Expand Down
10 changes: 5 additions & 5 deletions tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_path_input(tmp_path):
def test_model_input(tmp_path):
file_path = tmp_path / "test.asdf"

data = u.Quantity(np.random.default_rng(42).uniform(size=(4, 4)).astype(np.float32), u.electron / u.s, dtype=np.float32)
data = u.Quantity(np.random.default_rng(42).uniform(size=(4, 4)).astype(np.float32), u.DN / u.s, dtype=np.float32)

with asdf.AsdfFile() as af:
af.tree = {"roman": utils.mk_level2_image(shape=(8, 8))}
Expand Down Expand Up @@ -120,10 +120,10 @@ def test_memmap(tmp_path):
),
dtype=np.float32,
),
u.electron / u.s,
u.DN / u.s,
dtype=np.float32,
)
new_value = u.Quantity(1.0, u.electron / u.s, dtype=np.float32)
new_value = u.Quantity(1.0, u.DN / u.s, dtype=np.float32)
new_data = data.copy()
new_data[6, 19] = new_value

Expand Down Expand Up @@ -173,10 +173,10 @@ def test_no_memmap(tmp_path, kwargs):
),
dtype=np.float32,
),
u.electron / u.s,
u.DN / u.s,
dtype=np.float32,
)
new_value = u.Quantity(1.0, u.electron / u.s, dtype=np.float32)
new_value = u.Quantity(1.0, u.DN / u.s, dtype=np.float32)
new_data = data.copy()
new_data[6, 19] = new_value

Expand Down

0 comments on commit e91ba14

Please sign in to comment.