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

Clean up romancal to take advantage of the lazy datamodels changes #1603

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions docs/roman/datamodels/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ is called, when the data model is saved or when a file is read.
.. code-block:: python

>>> from roman_datamodels import datamodels as rdm
>>> from roman_datamodels.maker_utils import mk_datamodel

>>> model = mk_datamodel(rdm.ImageModel)
>>> model = rdm.ImageModel()
>>> model.meta.pointing.target_ra = "foo"
>>> model.validate() # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
Expand Down Expand Up @@ -59,7 +58,7 @@ model.

.. code-block:: python

>>> raw_science = mk_datamodel(rdm.ScienceRawModel) # Create a model of the desired type
>>> raw_science = rdm.ScienceRawModel() # Create a model of the desired type
>>> print(raw_science.schema_uri) # find the associated Schema
asdf://stsci.edu/datamodels/roman/schemas/wfi_science_raw-1.0.0

Expand Down
39 changes: 21 additions & 18 deletions docs/roman/datamodels/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ using python.

.. testsetup::
>>> from roman_datamodels import datamodels as rdm
>>> from roman_datamodels.maker_utils import mk_datamodel
>>> fn = 'r0019106003005004023_0034_wfi01_cal.asdf'
>>> image_model = mk_datamodel(rdm.ImageModel)
>>> image_model = rdm.ImageModel()

# set some metadata for the below tests
>>> image_model.meta.filename = fn
Expand All @@ -62,9 +61,8 @@ To create a new `ImageModel`, you can just
.. code-block:: python

>>> from roman_datamodels import datamodels as rdm
>>> from roman_datamodels.maker_utils import mk_datamodel

>>> new_model = mk_datamodel(rdm.ImageModel)
>>> new_model = rdm.ImageModel()
>>> type(new_model)
<class 'roman_datamodels.datamodels._datamodels.ImageModel'>

Expand Down Expand Up @@ -141,28 +139,33 @@ 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_name RomanCAL
meta.calibration_software_version 9.9.0
meta.product_type l2
meta.filename r0019106003005004023_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
>>> print("\n".join("{: >20}\t{}".format(k, v) for k, v in image_model.flat_items(flush="all")), "\n") # doctest: +ELLIPSIS
meta.calibration_software_name RomanCAL
meta.calibration_software_version 9.9.0
meta.coordinates.reference_frame ICRS
meta.ephemeris.earth_angle -999999.0
meta.ephemeris.moon_angle -999999.0
meta.ephemeris.sun_angle -999999.0
meta.ephemeris.type DEFINITIVE
meta.ephemeris.time -999999.0
meta.ephemeris.ephemeris_reference_frame ?
meta.ephemeris.spatial_x -999999.0
meta.ephemeris.spatial_y -999999.0
meta.ephemeris.spatial_z -999999.0
meta.ephemeris.velocity_x -999999.0
meta.ephemeris.velocity_y -999999.0
meta.ephemeris.velocity_z -999999.0
meta.exposure.type WFI_IMAGE
...

or you can print specifics

.. code-block:: python

>>> print("\n".join("{: >20}\t{}".format(k, v) for k, v in image_model.meta.instrument.items()))
name WFI
>>> print("\n".join("{: >20}\t{}".format(k, v) for k, v in image_model.meta.instrument.flat_items(flush="all")))
detector WFI01
optical_element F158
name WFI

.. note::

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ dependencies = [
"photutils >=1.13.0",
"pyparsing >=2.4.7",
"requests >=2.26",
"roman_datamodels>=0.23.0,<0.24.0",
# "roman_datamodels>=0.23.0,<0.24.0",
#"roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git",
"roman_datamodels @ git+https://github.com/WilliamJamieson/roman_datamodels.git@lazy_datamodels",
"scipy >=1.14.1",
# "stcal>=1.10.0,<1.11.0",
"stcal @ git+https://github.com/spacetelescope/stcal.git@main",
Expand Down
20 changes: 9 additions & 11 deletions romancal/assign_wcs/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@
from gwcs.wcstools import grid_from_bounding_box
from numpy.testing import assert_allclose
from roman_datamodels import datamodels as rdm
from roman_datamodels import maker_utils

from romancal.assign_wcs.assign_wcs_step import AssignWcsStep, load_wcs
from romancal.assign_wcs.utils import wcs_bbox_from_shape


def create_image():
l2 = maker_utils.mk_level2_image()
l2im = rdm.ImageModel(_array_shape=(2, 100, 100))

l2.meta.wcsinfo.v2_ref = -503
l2.meta.wcsinfo.v3_ref = -318
l2.meta.wcsinfo.ra_ref = 156
l2.meta.wcsinfo.dec_ref = 54.2
l2.meta.wcsinfo.vparity = -1
l2.meta.wcsinfo.roll_ref = 0.15
l2im.meta.wcsinfo.v2_ref = -503
l2im.meta.wcsinfo.v3_ref = -318
l2im.meta.wcsinfo.ra_ref = 156
l2im.meta.wcsinfo.dec_ref = 54.2
l2im.meta.wcsinfo.vparity = -1
l2im.meta.wcsinfo.roll_ref = 0.15

l2im = rdm.ImageModel(l2)
return l2im


def create_distortion():
distortions = [maker_utils.mk_distortion()]
distortions = [rdm.DistortionRefModel()]

model = create_image()
dist = maker_utils.mk_distortion()
dist = rdm.DistortionRefModel()
dist.coordinate_distortion_transform.bounding_box = wcs_bbox_from_shape(
model.data.shape
)
Expand Down
4 changes: 1 addition & 3 deletions romancal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from gwcs import coordinate_frames as cf
from gwcs import wcs
from roman_datamodels import datamodels as rdm
from roman_datamodels import maker_utils

from romancal.assign_wcs import pointing

Expand Down Expand Up @@ -237,8 +236,7 @@ def base_image():
"""

def _base_image(shift_1=0, shift_2=0):
l2 = maker_utils.mk_level2_image(shape=(100, 100))
l2_im = rdm.ImageModel(l2)
l2_im = rdm.ImageModel(_array_shape=(2, 100, 100))
_create_wcs(l2_im)
l2_im.meta.wcsinfo.vparity = -1
return l2_im
Expand Down
14 changes: 4 additions & 10 deletions romancal/dark_current/tests/test_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pytest
import roman_datamodels as rdm
from roman_datamodels import maker_utils
from roman_datamodels.datamodels import DarkRefModel, RampModel

from romancal.dark_current import DarkCurrentStep
Expand Down Expand Up @@ -142,16 +141,11 @@ def create_ramp_and_dark(shape, instrument, exptype):
"""Helper function to create test ramp and dark models"""

# Create test ramp model
ramp = maker_utils.mk_ramp(shape=shape)
ramp.meta.instrument.name = instrument
ramp.meta.instrument.detector = "WFI01"
ramp.meta.instrument.optical_element = "F158"
ramp.meta.exposure.type = exptype
ramp.data = np.ones(shape, dtype=np.float32)
ramp_model = RampModel(ramp)
ramp_model = RampModel(_array_shape=shape)
ramp_model.meta.instrument.name = instrument
ramp_model.meta.exposure.type = exptype

# Create dark model
darkref = maker_utils.mk_dark(shape=shape)
darkref_model = DarkRefModel(darkref)
darkref_model = DarkRefModel(_array_shape=shape)

return ramp_model, darkref_model
3 changes: 1 addition & 2 deletions romancal/datamodels/tests/test_filetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def test_filetype():
with open(DATA_DIRECTORY / "fake.json") as file_h:
file_8 = filetype.check(file_h)
file_9 = filetype.check(str(DATA_DIRECTORY / "pluto.asdf"))
image_node = rdm.maker_utils.mk_level2_image(shape=(20, 20))
im1 = rdm.datamodels.ImageModel(image_node)
im1 = rdm.datamodels.ImageModel(_array_shape=(2, 20, 20))
file_11 = filetype.check(im1)
model_library = ModelLibrary([im1])
file_10 = filetype.check(model_library)
Expand Down
9 changes: 1 addition & 8 deletions romancal/datamodels/tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
import roman_datamodels.datamodels as dm
from roman_datamodels.maker_utils import mk_level2_image

from romancal.associations import load_asn
from romancal.associations.asn_from_list import asn_from_list
Expand All @@ -25,14 +24,8 @@ 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 = 1
m = dm.ImageModel(_array_shape=(2, 2, 2))
m.meta.observation.observation = _OBSERVATION_NUMBERS[i]
m.meta.observation.visit = 1
m.meta.observation.visit_file_group = 1
m.meta.observation.visit_file_sequence = 1
m.meta.observation.visit_file_activity = "01"
m.meta.observation.exposure = 1
base_fn = f"{i}.asdf"
m.meta.filename = base_fn
m.save(str(tmp_path / base_fn))
Expand Down
Loading
Loading