Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 13, 2024
1 parent dc6fb11 commit 3ffd496
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 66 deletions.
2 changes: 1 addition & 1 deletion changes/441.feature.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added support for skycell reference file
Added support for skycell reference file
2 changes: 2 additions & 0 deletions src/roman_datamodels/maker_utils/_common_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ def mk_ref_readnoise_meta(**kwargs):

return meta


def mk_ref_skycells_meta(**kwargs):
"""
Create dummy metadata for skycells reference file instances.
Expand All @@ -770,6 +771,7 @@ def mk_ref_skycells_meta(**kwargs):

return meta


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

__all__ = [
Expand All @@ -33,10 +33,10 @@
"mk_pixelarea",
"mk_readnoise",
"mk_refpix",
"mk_roman_skycells",
"mk_saturation",
"mk_superbias",
"mk_wfi_img_photom",
"mk_roman_skycells",
]

OPT_ELEM = ("F062", "F087", "F106", "F129", "F146", "F158", "F184", "F213", "GRISM", "PRISM", "DARK")
Expand Down Expand Up @@ -566,61 +566,170 @@ def mk_saturation(*, shape=(4096, 4096), filepath=None, **kwargs):

return save_node(saturationref, filepath=filepath)


def mk_roman_skycells(*, filepath=None, **kwargs):
skycellref = stnode.RomanSkycellsRef()
skycellref["meta"] = mk_ref_skycells_meta(**kwargs)
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'),
('nxy_skycell', '<i4'),
('skycell_border_pixels', '<i4'),
('pixel_scale', '<f4')])
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_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"),
("nxy_skycell", "<i4"),
("skycell_border_pixels", "<i4"),
("pixel_scale", "<f4"),
]
)
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 = np.array(
[( 0, 225., 90. , 0. , 360. , 88.20062575, 90. , 0.,
117776.5, 117776.5, 235554, 235554, 0, 1985, 5000, 100, 1.5277777e-05),
( 1, 0., 86.40080763, -22.5, 22.5, 84.60010081, 88.20062575, 0.,
138592.5, 117834.5, 277186, 235670, 1985, 3986, 5000, 100, 1.5277777e-05),
( 2, 45., 86.40080763, 22.5, 67.5, 84.60010081, 88.20062575, 0.,
138592.5, 117834.5, 277186, 235670, 3986, 5987, 5000, 100, 1.5277777e-05),
], dtype=proj_dtype)
[
(
0,
225.0,
90.0,
0.0,
360.0,
88.20062575,
90.0,
0.0,
117776.5,
117776.5,
235554,
235554,
0,
1985,
5000,
100,
1.5277777e-05,
),
(
1,
0.0,
86.40080763,
-22.5,
22.5,
84.60010081,
88.20062575,
0.0,
138592.5,
117834.5,
277186,
235670,
1985,
3986,
5000,
100,
1.5277777e-05,
),
(
2,
45.0,
86.40080763,
22.5,
67.5,
84.60010081,
88.20062575,
0.0,
138592.5,
117834.5,
277186,
235670,
3986,
5987,
5000,
100,
1.5277777e-05,
),
],
dtype=proj_dtype,
)
skycell_tab = np.array(
[('a225dp90xm25yp01', 317.2901524 , 88.16584325, -92.29015 , 122499.5, 7299.5, 318.40988935, 88.12583697,
318.55462778, 88.20200659, 316.1209133 , 88.20512017, 316.07517233, 88.12882346),
('a225dp90xm25yp00', 314.99952253, 88.16730723, -89.99952 , 122499.5, 2499.5, 316.16868134, 88.1287637,
316.2183982 , 88.20505786, 313.78062699, 88.20505721, 313.8303836 , 88.12876307),
('a225dp90xm25yp01', 312.70889418, 88.16584203, -87.70889 , 122499.5, -2300.5, 313.92389255, 88.12882289,
313.87811182, 88.20511958, 311.44440071, 88.2020047 , 311.58917851, 88.12583515),
], dtype=skycell_dtype)
[
(
"a225dp90xm25yp01",
317.2901524,
88.16584325,
-92.29015,
122499.5,
7299.5,
318.40988935,
88.12583697,
318.55462778,
88.20200659,
316.1209133,
88.20512017,
316.07517233,
88.12882346,
),
(
"a225dp90xm25yp00",
314.99952253,
88.16730723,
-89.99952,
122499.5,
2499.5,
316.16868134,
88.1287637,
316.2183982,
88.20505786,
313.78062699,
88.20505721,
313.8303836,
88.12876307,
),
(
"a225dp90xm25yp01",
312.70889418,
88.16584203,
-87.70889,
122499.5,
-2300.5,
313.92389255,
88.12882289,
313.87811182,
88.20511958,
311.44440071,
88.2020047,
311.58917851,
88.12583515,
),
],
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
26 changes: 10 additions & 16 deletions src/roman_datamodels/maker_utils/mk_skycell_ref.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import asdf
import numpy as np
from astropy.time import Time
import asdf

import roman_datamodels.stnode as stnode

def mk_skycell(output_filename,
projection_regions,
skycells,
author,
useafter,
plate_scale,
border_pixels):

def mk_skycell(output_filename, projection_regions, skycells, author, useafter, plate_scale, border_pixels):
"""
Create a skycell reference file.
Expand Down Expand Up @@ -41,21 +37,19 @@ def mk_skycell(output_filename,
"useafter": Time("2024-01-01T01:00:00.000"),
"telescope": "ROMAN",
"origin": "STSCI",
"instrument": {
"name": "WFI"
},
"instrument": {"name": "WFI"},
"nxy_skycell": 5000,
"skycell_border_pixels": border_pixels,
"plate_scale": plate_scale,
}
projection_regions = np.array(projection_regions)
skycells = np.array(skycells)
skycellref = stnode.RomanSkycellsRef()
skycellref['meta'] = meta
skycellref['projection_regions'] = projection_regions
skycellref['skycells'] = skycells
skycellref['datamodel_name'] = "RomanSkycellsRefModel"
skycellref["meta"] = meta
skycellref["projection_regions"] = projection_regions
skycellref["skycells"] = skycells
skycellref["datamodel_name"] = "RomanSkycellsRefModel"
with asdf.AsdfFile() as afout:
afout = asdf.AsdfFile()
afout.tree['roman'] = skycellref
afout.tree["roman"] = skycellref
afout.write_to(output_filename)
1 change: 1 addition & 0 deletions tests/test_maker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def test_override_data(node_class):
# Skip the test if it is a RomanSkycellsRef class
if node_class.__name__ == "RomanSkycellsRef":
return

Check warning on line 149 in tests/test_maker_utils.py

View check run for this annotation

Codecov / codecov/patch

tests/test_maker_utils.py#L148-L149

Added lines #L148 - L149 were not covered by tests

def mutate_value(value):
"""
Generate a mutated value for a given value.
Expand Down
6 changes: 4 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_reference_file_model_base(tmp_path):
tags = [t for t in stnode.NODE_EXTENSIONS[0].tags if "/reference_files/" in t.tag_uri]
for tag in tags:
# roman_skycells doesn't use EXPECTED_COMMON_REFERENCE
if repr(tag).find('roman_skycells') > 0:
if repr(tag).find("roman_skycells") > 0:
return

Check warning on line 333 in tests/test_models.py

View check run for this annotation

Codecov / codecov/patch

tests/test_models.py#L332-L333

Added lines #L332 - L333 were not covered by tests
schema = asdf.schema.load_schema(tag.schema_uris[0])
# Check that schema references common reference schema
Expand Down Expand Up @@ -614,11 +614,13 @@ def test_make_refpix():
assert refpix.meta.input_units == u.DN
assert refpix.meta.output_units == u.DN


# Skycells tests
def test_make_roman_skycells():
skycells_ref = utils.mk_roman_skycells()
assert skycells_ref.projection_regions["index"][2] == 2
assert skycells_ref.skycells['dec_corn2'][0] > 88
assert skycells_ref.skycells["dec_corn2"][0] > 88

Check warning on line 622 in tests/test_models.py

View check run for this annotation

Codecov / codecov/patch

tests/test_models.py#L619-L622

Added lines #L619 - L622 were not covered by tests


# WFI Photom tests
def test_make_wfi_img_photom():
Expand Down

0 comments on commit 3ffd496

Please sign in to comment.