Skip to content

Commit

Permalink
RAD-155: Add 'basic' schema to 'wfi_mosaic' (#328)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
nden and pre-commit-ci[bot] committed Mar 12, 2024
1 parent e91ba14 commit 26c0b37
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

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

- Add attributes under the ``basic`` schema to ``WfiMosaic.meta``. [#328]

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

Expand Down
5 changes: 1 addition & 4 deletions src/roman_datamodels/datamodels/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ def __init__(self, init=None, **kwargs):
super().__init__(init, **kwargs)

if init is not None:
if self._node_type == stnode.WfiMosaic:
self.meta.basic.model_type = self.__class__.__name__
else:
self.meta.model_type = self.__class__.__name__
self.meta.model_type = self.__class__.__name__


class MosaicModel(_RomanDataModel):
Expand Down
7 changes: 2 additions & 5 deletions src/roman_datamodels/maker_utils/_common_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ def mk_mosaic_meta(**kwargs):
dict (defined by the wfi_mosaic-1.0.0 schema)
"""

meta = {}
meta["asn"] = mk_mosaic_associations(**kwargs.get("asn", {}))
meta = mk_basic_meta(**kwargs)
meta["basic"] = mk_mosaic_basic(**kwargs.get("basic", {}))
meta["asn"] = mk_mosaic_associations(**kwargs.get("asn", {}))
meta["cal_step"] = mk_cal_step(**kwargs.get("cal_step", {}))
meta["coordinates"] = mk_coordinates(**kwargs.get("coordinates", {}))
meta["individual_image_meta"] = mk_individual_image_meta(**kwargs.get("individual_image_meta", {}))
Expand Down Expand Up @@ -723,18 +723,15 @@ def mk_mosaic_basic(**kwargs):
mosbasic["time_mean_mjd"] = kwargs.get("time_mean_mjd", NONUM)
mosbasic["max_exposure_time"] = kwargs.get("max_exposure_time", NONUM)
mosbasic["mean_exposure_time"] = kwargs.get("mean_exposure_time", NONUM)
mosbasic["model_type"] = kwargs.get("model_type", NOSTR)
mosbasic["visit"] = kwargs.get("visit", NONUM)
mosbasic["segment"] = kwargs.get("segment", NONUM)
mosbasic["pass"] = kwargs.get("pass", NONUM)
mosbasic["program"] = kwargs.get("program", NOSTR)
mosbasic["survey"] = kwargs.get("survey", NOSTR)
mosbasic["optical_element"] = kwargs.get("optical_element", "F158")
mosbasic["instrument"] = kwargs.get("instrument", "WFI")
mosbasic["telescope"] = kwargs.get("telescope", "ROMAN")
mosbasic["location_name"] = kwargs.get("location_name", NOSTR)
mosbasic["product_type"] = kwargs.get("product_type", NOSTR)
mosbasic["filename"] = kwargs.get("filename", NOSTR)

return mosbasic

Expand Down
1 change: 0 additions & 1 deletion src/roman_datamodels/maker_utils/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def mk_level3_mosaic(*, shape=(4088, 4088), n_images=2, filepath=None, **kwargs)

wfi_mosaic = stnode.WfiMosaic()
wfi_mosaic["meta"] = mk_mosaic_meta(**kwargs.get("meta", {}))

wfi_mosaic["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.MJy / u.sr, dtype=np.float32))
wfi_mosaic["err"] = kwargs.get("err", u.Quantity(np.zeros(shape, dtype=np.float32), u.MJy / u.sr, dtype=np.float32))
wfi_mosaic["context"] = kwargs.get("context", np.zeros((n_images,) + shape, dtype=np.uint32))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_maker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def test_datamodel_maker(model_class):
model.validate()

if issubclass(model_class, _RomanDataModel):
if isinstance(model, datamodels.MosaicModel):
assert model.meta.basic.model_type == model_class.__name__
else:
assert model.meta.model_type == model_class.__name__
# if isinstance(model, datamodels.MosaicModel):
# assert model.meta.basic.model_type == model_class.__name__
# else:
assert model.meta.model_type == model_class.__name__


@pytest.mark.parametrize("node_class", [node for node in datamodels.MODEL_REGISTRY])
Expand Down
9 changes: 6 additions & 3 deletions tests/test_stnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,23 @@ def test_node_representation(model):
"time_mean_mjd": -999999,
"max_exposure_time": -999999,
"mean_exposure_time": -999999,
"model_type": "MosaicModel",
# "model_type": "MosaicModel",
"visit": -999999,
"segment": -999999,
"pass": -999999,
"program": "dummy value",
"survey": "dummy value",
"optical_element": "F158",
"instrument": "WFI",
"telescope": "ROMAN",
# "telescope": "ROMAN",
"location_name": "dummy value",
"product_type": "dummy value",
"filename": "dummy value",
# "filename": "dummy value",
}
)
assert mdl.meta.model_type == "MosaicModel"
assert mdl.meta.telescope == "ROMAN"
assert mdl.meta.filename == "dummy value"
else:
assert repr(mdl.meta.instrument) == repr(
{
Expand Down

0 comments on commit 26c0b37

Please sign in to comment.