Skip to content

Commit

Permalink
Add some support for opening SSC models
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Jan 10, 2025
1 parent 8dd30a5 commit d859b59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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 d859b59

Please sign in to comment.