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?
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:
Is there a way, before calling the
withcontext to know which datamodel I should use to do the opening? For example, something like:or something similar?