Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCAL-941: Update romancal to use new L1/L2 schema. #1473

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d5444af
Initial updates.
mairanteodoro Oct 23, 2024
b4c9108
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
6f6d75b
Fix style checks.
mairanteodoro Oct 23, 2024
13e8403
Set doctest to skip code in docs.
mairanteodoro Oct 24, 2024
c6a225c
Merge branch 'main' into RCAL-941-update-romancal-to-use-new-l1-l2-sc…
mairanteodoro Oct 24, 2024
0d4d07a
Rename obs_id to observation_id.
mairanteodoro Oct 24, 2024
9299696
More obs_id fixes.
mairanteodoro Oct 24, 2024
4c83db0
Fix tweakreg unit test.
mairanteodoro Oct 24, 2024
1f0fa6b
Fix code block in models.rst.
mairanteodoro Oct 24, 2024
f27ab1d
Restore changes.
mairanteodoro Oct 24, 2024
014b0ea
Add sr to arcsec2conversion factor as a global variable.
mairanteodoro Oct 24, 2024
180409d
Updates to regtests and make_regtestdata.sh for the L1/L2 schema chan…
mairanteodoro Oct 25, 2024
10cde96
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2024
2a6b2e5
Mark flatfield test for grism as xfail.
mairanteodoro Oct 28, 2024
f2b25ab
Ignore changes in cal_logs when comparing output and truth files.
mairanteodoro Oct 28, 2024
6f52d5a
Fix missing import.
mairanteodoro Oct 28, 2024
d9ea650
Fix ignore cal logs for individual images.
mairanteodoro Oct 28, 2024
65d9409
Lowercase WFI in regtest filenames.
mairanteodoro Oct 28, 2024
36d742b
Fix call_logs issue.
mairanteodoro Oct 29, 2024
d8f5ae3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
adc9fe0
Remove testing code.
mairanteodoro Oct 29, 2024
6c987da
Fix bug with cal_logs.
mairanteodoro Oct 29, 2024
f7dae3a
Check style fixes.
mairanteodoro Oct 29, 2024
c84a744
Lowercase missed WFI in regtest filenames.
mairanteodoro Oct 29, 2024
e7ae5dc
Add changelog entry.
mairanteodoro Oct 29, 2024
c732d3b
Back to dot notation for cal_step.flat_field.
mairanteodoro Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1473.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updates to support L1/L2 schema changes.
33 changes: 19 additions & 14 deletions docs/roman/datamodels/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@ string will raise an exception.
>>> from roman_datamodels.maker_utils import mk_datamodel

>>> model = mk_datamodel(rdm.ImageModel)
>>> model.meta.target.ra = "foo" # doctest: +IGNORE_EXCEPTION_DETAIL
>>> model.meta.pointing.target_ra = "foo" # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ddavis/miniconda3/envs/rcal_dev/lib/python3.9/site-packages/roman_datamodels/stnode.py", line 183, in __setattr__
if schema is None or _validate(key, value, schema, self.ctx):
File "/Users/ddavis/miniconda3/envs/rcal_dev/lib/python3.9/site-packages/roman_datamodels/stnode.py", line 97, in _validate
return _value_change(attr, tagged_tree, schema, False, strict_validation, ctx)
File "/Users/ddavis/miniconda3/envs/rcal_dev/lib/python3.9/site-packages/roman_datamodels/stnode.py", line 68, in _value_change
raise jsonschema.ValidationError(errmsg)
jsonschema.exceptions.ValidationError: While validating ra the following error occurred:
File "/path/to/python/lib/python3.12/site-packages/roman_datamodels/stnode/_node.py", line 251, in __setattr__
_validate(key, value, schema, self.ctx)
File "/path/to/python/lib/python3.12/site-packages/roman_datamodels/stnode/_node.py", line 78, in _validate
return _value_change(attr, tagged_tree, schema, False, will_strict_validate(), ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/python/lib/python3.12/site-packages/roman_datamodels/stnode/_node.py", line 47, in _value_change
raise ValidationError(errmsg)
asdf._jsonschema.exceptions.ValidationError: While validating target_ra the following error occurred:
'foo' is not of type 'number'

Failed validating 'type' in schema:
{'$schema': 'http://stsci.edu/schemas/asdf-schema/0.1.0/asdf-schema',
'archive_catalog': {'datatype': 'float',
'destination': ['ScienceCommon.ra']},
'sdf': {'source': {'origin': 'PSS:fixed_target.ra_computed'},
'special_processing': 'VALUE_REQUIRED'},
'title': 'Target RA at mid time of exposure',
'type': 'number'}
'archive_catalog': {'datatype': 'float',
'destination': ['WFIExposure.target_ra',
'GuideWindow.target_ra']},
'description': 'Right ascension in units of degrees at the location '
'of\n'
'the target aperture.\n',
'sdf': {'source': {'origin': 'TBD'},
'special_processing': 'VALUE_REQUIRED'},
'title': 'Right Ascension of the Target Aperture (deg)',
'type': 'number'}

On instance:
'foo'
Expand Down
21 changes: 11 additions & 10 deletions docs/roman/datamodels/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ You can examine the contents of your model from within python using
.. code-block:: python

>>> print("\n".join("{: >20}\t{}".format(k, v) for k, v in image_model.items()), "\n") # doctest: +ELLIPSIS
meta.calibration_software_version 9.9.0
meta.sdf_software_version 7.7.7
meta.filename r0019106003005004023_03203_0034_WFI01_cal.asdf
meta.file_date 2020-01-01T00:00:00.000
meta.model_type ImageModel
meta.origin STSCI
meta.prd_software_version 8.8.8
meta.telescope ROMAN
meta.aperture.name WFI_06_FULL
meta.aperture.position_angle 30.0
meta.calibration_software_name RomanCAL
meta.calibration_software_version 9.9.0
meta.product_type l2
meta.filename r0019106003005004023_03203_0034_WFI01_cal.asdf
meta.file_date 2020-01-01T00:00:00.000
meta.model_type ImageModel
meta.origin STSCI/SOC
meta.prd_version 8.8.8
meta.sdf_software_version 7.7.7
meta.telescope ROMAN
meta.coordinates.reference_frame ICRS
...

or you can print specifics
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ dependencies = [
"pyparsing >=2.4.7",
"requests >=2.26",
# "rad>=0.21.0,<0.22.0",
"rad @ git+https://github.com/spacetelescope/rad.git",
# "rad @ git+https://github.com/spacetelescope/rad.git",
# "roman_datamodels>=0.21.0,<0.22.0",
"roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git",
# "roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git",
"rad @ git+https://github.com/PaulHuwe/rad.git@RAD-184_IMMandL1L2Updates",
"roman_datamodels @ git+https://github.com/PaulHuwe/roman_datamodels.git@RCAL-934_L1L2Update",
"scipy >=1.11",
# "stcal>=1.8.0,<1.9.0",
"stcal @ git+https://github.com/spacetelescope/stcal.git@main",
Expand Down
10 changes: 2 additions & 8 deletions romancal/dark_current/dark_current_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ def process(self, input):
with rdm.open(self.dark_name) as dark_model:
# Temporary patch to utilize stcal dark step until MA table support
# is fully implemented
if "ngroups" not in dark_model.meta.exposure:
dark_model.meta.exposure["ngroups"] = dark_model.data.shape[0]
if "nframes" not in dark_model.meta.exposure:
dark_model.meta.exposure["nframes"] = input_model.meta.exposure.nframes
if "groupgap" not in dark_model.meta.exposure:
dark_model.meta.exposure["groupgap"] = (
input_model.meta.exposure.groupgap
)
if "nresultants" not in dark_model.meta.exposure:
dark_model.meta.exposure["nresultants"] = dark_model.data.shape[0]

# Do the dark correction
out_model = input_model
Expand Down
2 changes: 1 addition & 1 deletion romancal/datamodels/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ def _mapping_to_group_id(mapping):
"""
Combine a number of file metadata values into a ``group_id`` string
"""
return "{obs_id}".format_map(mapping)
return "{observation_id}".format_map(mapping)
2 changes: 1 addition & 1 deletion romancal/datamodels/tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def example_asn_path(tmp_path):
fns = []
for i in range(_N_MODELS):
m = dm.ImageModel(mk_level2_image(shape=(2, 2)))
m.meta.observation.program = "0001"
m.meta.observation.program = 1
m.meta.observation.observation = _OBSERVATION_NUMBERS[i]
m.meta.observation.visit = 1
m.meta.observation.visit_file_group = 1
Expand Down
4 changes: 2 additions & 2 deletions romancal/dq_init/dq_init_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def process(self, input):
output_model = RampModel.from_science_raw(input_model)

# guide window range information
x_start = input_model.meta.guidestar.gw_window_xstart
x_end = input_model.meta.guidestar.gw_window_xsize + x_start
x_start = input_model.meta.guide_star.window_xstart
x_end = input_model.meta.guide_star.window_xsize + x_start
# set pixeldq array to GW_AFFECTED_DATA (2**4) for the given range
output_model.pixeldq[int(x_start) : int(x_end), :] = pixel.GW_AFFECTED_DATA
self.log.info(
Expand Down
40 changes: 20 additions & 20 deletions romancal/dq_init/tests/test_dq_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
RNG = np.random.default_rng(83)

# Set parameters for multiple runs of data
args = "xstart, ystart, xsize, ysize, ngroups, instrument, exp_type"
args = "xstart, ystart, xsize, ysize, nresultants, instrument, exp_type"
test_data = [(1, 1, 2048, 2048, 2, "WFI", "WFI_IMAGE")]
ids = ["RampModel"]


@pytest.mark.parametrize(args, test_data, ids=ids)
def test_dq_im(xstart, ystart, xsize, ysize, ngroups, instrument, exp_type):
def test_dq_im(xstart, ystart, xsize, ysize, nresultants, instrument, exp_type):
"""Check that PIXELDQ is initialized with the information from the reference file.
test that a flagged value in the reference file flags the PIXELDQ array"""

csize = (ngroups, ysize, xsize)
csize = (nresultants, ysize, xsize)

# create raw input data for step
dm_ramp = maker_utils.mk_ramp(shape=csize)
Expand Down Expand Up @@ -75,10 +75,10 @@ def test_groupdq():

# size of integration
instrument = "WFI"
ngroups = 5
nresultants = 5
xsize = 1032
ysize = 1024
csize = (ngroups, ysize, xsize)
csize = (nresultants, ysize, xsize)

# create raw input data for step
dm_ramp = maker_utils.mk_ramp(shape=csize)
Expand All @@ -95,7 +95,7 @@ def test_groupdq():
groupdq = outfile.groupdq

np.testing.assert_array_equal(
np.full((ngroups, ysize, xsize), 0, dtype=int),
np.full((nresultants, ysize, xsize), 0, dtype=int),
groupdq,
err_msg="groupdq not initialized to zero",
)
Expand All @@ -106,13 +106,13 @@ def test_err():

# size of integration
instrument = "WFI"
ngroups = 5
nresultants = 5
xsize = 1032
ysize = 1024
csize = (ngroups, ysize, xsize)
csize = (nresultants, ysize, xsize)

# create raw input data for step
dm_ramp = maker_utils.mk_ramp(shape=(ngroups, ysize, xsize))
dm_ramp = maker_utils.mk_ramp(shape=(nresultants, ysize, xsize))
dm_ramp.meta.instrument.name = instrument

# create a MaskModel elements for the dq input mask
Expand All @@ -138,13 +138,13 @@ def test_dq_add1_groupdq():

# size of integration
instrument = "WFI"
ngroups = 5
nresultants = 5
xsize = 1032
ysize = 1024
csize = (ngroups, ysize, xsize)
csize = (nresultants, ysize, xsize)

# create raw input data for step
dm_ramp = maker_utils.mk_ramp(shape=(ngroups, ysize, xsize))
dm_ramp = maker_utils.mk_ramp(shape=(nresultants, ysize, xsize))
dm_ramp.meta.instrument.name = instrument

# create a MaskModel elements for the dq input mask
Expand Down Expand Up @@ -195,8 +195,8 @@ def test_dqinit_step_interface(instrument, exptype):
wfi_sci_raw.meta.instrument.name = instrument
wfi_sci_raw.meta.instrument.detector = "WFI01"
wfi_sci_raw.meta.instrument.optical_element = "F158"
wfi_sci_raw.meta["guidestar"]["gw_window_xstart"] = 1012
wfi_sci_raw.meta["guidestar"]["gw_window_xsize"] = 16
wfi_sci_raw.meta["guide_star"]["window_xstart"] = 1012
wfi_sci_raw.meta["guide_star"]["window_xsize"] = 16
wfi_sci_raw.meta.exposure.type = exptype
wfi_sci_raw.data = np.ones(shape, dtype=np.uint16)
wfi_sci_raw[extra_key] = extra_value
Expand Down Expand Up @@ -245,8 +245,8 @@ def test_dqinit_refpix(instrument, exptype):
wfi_sci_raw.meta.instrument.name = instrument
wfi_sci_raw.meta.instrument.detector = "WFI01"
wfi_sci_raw.meta.instrument.optical_element = "F158"
wfi_sci_raw.meta["guidestar"]["gw_window_xstart"] = 1012
wfi_sci_raw.meta["guidestar"]["gw_window_xsize"] = 16
wfi_sci_raw.meta["guide_star"]["window_xstart"] = 1012
wfi_sci_raw.meta["guide_star"]["window_xsize"] = 16
wfi_sci_raw.meta.exposure.type = exptype
wfi_sci_raw.data = np.ones(shape, dtype=np.uint16)
wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw)
Expand Down Expand Up @@ -295,8 +295,8 @@ def test_dqinit_resultantdq(instrument, exptype):
wfi_sci_raw.meta.instrument.name = instrument
wfi_sci_raw.meta.instrument.detector = "WFI01"
wfi_sci_raw.meta.instrument.optical_element = "F158"
wfi_sci_raw.meta["guidestar"]["gw_window_xstart"] = 1012
wfi_sci_raw.meta["guidestar"]["gw_window_xsize"] = 16
wfi_sci_raw.meta["guide_star"]["window_xstart"] = 1012
wfi_sci_raw.meta["guide_star"]["window_xsize"] = 16
wfi_sci_raw.meta.exposure.type = exptype
wfi_sci_raw.resultantdq[1, 12, 12] = pixel["DROPOUT"]
wfi_sci_raw.data = np.ones(shape, dtype=np.uint16)
Expand Down Expand Up @@ -344,8 +344,8 @@ def test_dqinit_getbestref(instrument, exptype):
wfi_sci_raw.meta.instrument.name = instrument
wfi_sci_raw.meta.instrument.detector = "WFI01"
wfi_sci_raw.meta.instrument.optical_element = "F158"
wfi_sci_raw.meta["guidestar"]["gw_window_xstart"] = 1012
wfi_sci_raw.meta["guidestar"]["gw_window_xsize"] = 16
wfi_sci_raw.meta["guide_star"]["window_xstart"] = 1012
wfi_sci_raw.meta["guide_star"]["window_xsize"] = 16
wfi_sci_raw.meta.exposure.type = exptype
wfi_sci_raw.data = np.ones(shape, dtype=np.uint16)
wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw)
Expand Down
13 changes: 7 additions & 6 deletions romancal/jump/jump_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
input_model = rdd.open(input)

# Extract the needed info from the Roman Data Model
meta = input_model.meta
r_data = input_model.data
r_gdq = input_model.groupdq
r_pdq = input_model.pixeldq
Expand All @@ -64,7 +63,9 @@
result.meta.cal_step.jump = "SKIPPED"
return result

frames_per_group = meta.exposure.nframes
# FIXME: since frames_per_group => meta.exposure.nframes has been removed,
# we need to fix stcal.jump.jump to remove it from there too
frames_per_group = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we don't actually use this jump mode any longer; we should probably just open a ticket to remove this step. I'll do that now.

But for this ticket this is fine.


# Modify the arrays for input into the 'common' jump (4D)
data = np.copy(r_data[np.newaxis, :])
Expand All @@ -74,11 +75,11 @@

tstart = time.time()

# Check for an input model with NGROUPS<=2
ngroups = data.shape[1]
# Check for an input model with nresultants<=2
nresultants = data.shape[1]

if ngroups <= 2:
self.log.warning("Cannot apply jump detection as NGROUPS<=2;")
if nresultants <= 2:
self.log.warning("Cannot apply jump detection as nresultants<=2;")

Check warning on line 82 in romancal/jump/jump_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/jump/jump_step.py#L82

Added line #L82 was not covered by tests
self.log.warning("Jump step will be skipped")

result = input_model
Expand Down
Loading