spacetelescope / stdatamodels

https://stdatamodels.readthedocs.io
Other
5 stars 24 forks source link

is_association fails to identify an association #209

Open izkgao opened 11 months ago

izkgao commented 11 months ago

I found that the is_association function of stdatamodels.jwst.datamodels.util checks if an object is an association based on the fact that it is a dict. However, the association created by jwst.associations.asn_from_list.asn_from_list by default is not a dict but jwst.associations.lib.rules_level3_base.DMS_Level3_Base. This would cause a problem when creating a ModelContainer from a DMS_Level3_Base association.

https://github.com/spacetelescope/stdatamodels/blob/49955c01d2e353edd16b95f3cb465e582a6b7b37/src/stdatamodels/jwst/datamodels/util.py#L387

Here is the code to reproduce this problem.

from jwst.associations.asn_from_list import asn_from_list
from jwst.datamodels import ModelContainer
import glob
files = glob.glob('*.fits')
asn = asn_from_list(files, product_name='test')
images = ModelContainer(asn)

But it works if bypassing the is_association check.

from jwst.associations.asn_from_list import asn_from_list
from jwst.datamodels import ModelContainer
import glob
files = glob.glob('*.fits')
asn = asn_from_list(files, product_name='test')
images = ModelContainer()
images.from_asn(asn)