Skip to content

ASDF and datamodel #2045

@Russell-Ryan

Description

@Russell-Ryan

If I have an asdf file and I know that can be read as a given datamodel, then it's easy to load it with the appropriate datamodel. For example, if it's a roman file, then I can readily read it:

import roman_datamodels as rdm

with rdm.open(filename) as dm:
      pass

Is there a way, before calling the with context to know which datamodel I should use to do the opening? For example, something like:

import asdf
import roman_datamodels as rdm
import stdatamodels.jwst.datamodels as jdm

with asdf.open(filename) as tree:
     datamodel = tree['datamodel']

if datamodel == 'JWST':
     with jdm.open(filename) as dm:
            pass
elif datamodel == 'Roman':
     with rdm.open(filename) as dm:
           pass
else:
     raise NotImplementedError("unsupported datamodel")

or something similar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions