Skip to content

Commit

Permalink
RCAL-919: Formalize the patches (sky cells) file (e.g., add a data mo…
Browse files Browse the repository at this point in the history
…del to support it as a reference fiel) (#441)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Nadia Dencheva <[email protected]>
  • Loading branch information
3 people authored Feb 13, 2025
1 parent 9314ff3 commit c93046e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/441.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for skycell reference file
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies = [
"gwcs >=0.19.0",
"numpy >=1.24",
"astropy >=5.3.0",
# "rad >=0.23.0, <0.24.0",
"rad @ git+https://github.com/spacetelescope/rad.git",
"asdf-standard >=1.1.0",
]
Expand Down
4 changes: 4 additions & 0 deletions src/roman_datamodels/datamodels/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ class ReadnoiseRefModel(_DataModel):
_node_type = stnode.ReadnoiseRef


class SkycellsRefModel(_DataModel):
_node_type = stnode.SkycellsRef


class SuperbiasRefModel(_DataModel):
_node_type = stnode.SuperbiasRef

Expand Down
19 changes: 19 additions & 0 deletions src/roman_datamodels/maker_utils/_common_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,25 @@ def mk_ref_readnoise_meta(**kwargs):
return meta


def mk_ref_skycells_meta(**kwargs):
"""
Create dummy metadata for skycells reference file instances.
Returns
-------
dict (follows reference_file/ref_common-1.0.0 schema + skycell reference file meta data)
"""
meta = mk_ref_common("SKYCELLS", **kwargs)
if "instrument" in meta:
meta["instrument"].pop("detector", None)
meta["instrument"].pop("optical_element", None)
meta["nxy_skycell"] = kwargs.get("nxy_skycell", 5000)
meta["skycell_border_pixels"] = kwargs.get("skycell_border_pixels", 100)
meta["plate_scale"] = kwargs.get("plate_scale", 0.055)

return meta


def mk_mosaic_basic(**kwargs):
"""
Create a dummy mosaic basic instance with valid values for attributes
Expand Down
50 changes: 50 additions & 0 deletions src/roman_datamodels/maker_utils/_ref_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
mk_ref_epsf_meta,
mk_ref_pixelarea_meta,
mk_ref_readnoise_meta,
mk_ref_skycells_meta,
mk_ref_units_dn_meta,
)

Expand All @@ -32,6 +33,7 @@
"mk_readnoise",
"mk_refpix",
"mk_saturation",
"mk_skycells",
"mk_superbias",
"mk_wfi_img_photom",
]
Expand Down Expand Up @@ -560,6 +562,54 @@ def mk_saturation(*, shape=(4096, 4096), filepath=None, **kwargs):
return save_node(saturationref, filepath=filepath)


def mk_skycells(*, shape_pr=(100,), shape_sc=(1000,), filepath=None, **kwargs):
skycellref = stnode.SkycellsRef()
skycellref["meta"] = mk_ref_skycells_meta(**kwargs.get("meta", {}))
proj_dtype = np.dtype(
[
("index", "<i4"),
("ra_tangent", "<f8"),
("dec_tangent", "<f8"),
("ra_min", "<f8"),
("ra_max", "<f8"),
("dec_min", "<f8"),
("dec_max", "<f8"),
("orientat", "<f4"),
("x_tangent", "<f8"),
("y_tangent", "<f8"),
("nx", "<i4"),
("ny", "<i4"),
("skycell_start", "<i4"),
("skycell_end", "<i4"),
]
)
skycell_dtype = np.dtype(
[
("name", "<U16"),
("ra_center", "<f8"),
("dec_center", "<f8"),
("orientat", "<f4"),
("x_tangent", "<f8"),
("y_tangent", "<f8"),
("ra_corn1", "<f8"),
("dec_corn1", "<f8"),
("ra_corn2", "<f8"),
("dec_corn2", "<f8"),
("ra_corn3", "<f8"),
("dec_corn3", "<f8"),
("ra_corn4", "<f8"),
("dec_corn4", "<f8"),
]
)
proj_tab = kwargs.get("projection_regions", np.zeros(shape_pr, dtype=proj_dtype))
proj_tab[:]["index"] = np.arange(len(proj_tab))
skycell_tab = kwargs.get("skycells", np.zeros(shape_sc, dtype=skycell_dtype))
skycellref["projection_regions"] = proj_tab
skycellref["skycells"] = skycell_tab

return save_node(skycellref, filepath=filepath)


def mk_superbias(*, shape=(4096, 4096), filepath=None, **kwargs):
"""
Create a dummy Superbias instance (or file) with arrays and valid values for
Expand Down
6 changes: 6 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ def test_make_refpix():
assert refpix.alpha.shape == (8, 8)


# Skycells tests
def test_make_skycells():
skycells_ref = utils.mk_skycells()
assert skycells_ref.projection_regions["index"][2] == 2


# WFI Photom tests
def test_make_wfi_img_photom():
wfi_img_photom = utils.mk_wfi_img_photom()
Expand Down
6 changes: 5 additions & 1 deletion tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ def test_opening_model(tmp_path, node_class):
elif node_class in (stnode.MosaicSegmentationMap, stnode.MosaicSourceCatalog):
assert hasattr(model.meta, "basic")
else:
assert model.meta.instrument.optical_element == "F158"
# roman_skycells reference file does not contain optical_element. Skip this case
if hasattr(model.meta, "reftype") and model.meta.reftype == "SKYCELLS":
pass
else:
assert model.meta.instrument.optical_element == "F158"

# Check that the model is the correct type
assert isinstance(model, datamodels.MODEL_REGISTRY[node_class])
Expand Down

0 comments on commit c93046e

Please sign in to comment.