Skip to content

Commit

Permalink
Add some support for opening SSC models (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Jan 10, 2025
1 parent 8dd30a5 commit 506b979
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/448.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for opening SSC models using ``rdm_open``.
11 changes: 11 additions & 0 deletions src/roman_datamodels/datamodels/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,16 @@ def rdm_open(init, memmap=False, **kwargs):
if (model_type := type(asdf_file.tree["roman"])) in MODEL_REGISTRY:
return MODEL_REGISTRY[model_type](asdf_file, **kwargs)

# Check if the datamodel is a GDPS datamodel
try:
import roman_gdps # noqa: F401
except ImportError as err:
asdf_file.close()
raise ImportError("Please install roman-gdps to allow opening GDPS datamodels") from err

# We assume at this point that an asdf file with `roman` key is a GDPS datamodel
if "roman" in asdf_file.tree:
return asdf_file.tree["roman"]

asdf_file.close()
raise TypeError(f"Unknown datamodel type: {model_type}")
1 change: 1 addition & 0 deletions tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def test_read_pattern_properties():
rdm_open(Path(__file__).parent / "data" / "photmjsm.asdf")


@pytest.mark.xfail(reason="We currently do not have a way to identify if a datamodel is a GDPS datamodel")
def test_rdm_open_non_datamodel():
from roman_datamodels.datamodels import open as rdm_open

Expand Down

0 comments on commit 506b979

Please sign in to comment.