Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: asdf_in_fits.open cannot accept HDUList (stdatamodels v1.1.0) #135

Closed
pllim opened this issue Mar 1, 2023 · 3 comments · Fixed by #136
Closed

BUG: asdf_in_fits.open cannot accept HDUList (stdatamodels v1.1.0) #135

pllim opened this issue Mar 1, 2023 · 3 comments · Fixed by #136

Comments

@pllim
Copy link
Contributor

pllim commented Mar 1, 2023

Good ol' AsdfInFits.open was able to accept astropy.io.fits.HDUList and parse the contents properly. However, using what I thought is equivalent, asdf_in_fits.open, in stdatamodels v1.1.0, I get an error. This breaks backward compatibility and blocks:

Minimally reproducible example (adapted from Jdaviz regression test):

from astropy.io import fits
from astropy.utils.data import download_file
from stdatamodels import asdf_in_fits

jwst_asdf_url_1 = 'https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/imviz_test_data/jw00042001001_01101_00001_nrcb5_cal.fits'
filename = download_file(jwst_asdf_url_1, cache=True, timeout=100)

pf = fits.open(filename)
af = asdf_in_fits.open(pf)  # Error (see below)

# But this works
from asdf.fits_embed import AsdfInFits
af2 = AsdfInFits.open(pf)  # Works
File stdatamodels/asdf_in_fits.py:52, in open(filename, **kwargs)
     33 def open(filename, **kwargs):
     34     """Read ASDF data embedded in a fits file
     35
     36     Parameters
   (...)
     49         fits file.
     50     """
---> 52     hdulist = fits.open(filename)
     53     if 'ignore_missing_extensions' not in kwargs:
     54         kwargs['ignore_missing_extensions'] = False

(This gets into io.fits internals and then io module internals.)

TypeError: stat: path should be string, bytes, os.PathLike or integer, not method

I don't think you should ask FITS to open something that is already a FITS object.

hdulist = fits.open(filename)

William asked me to cc @braingram

@pllim
Copy link
Contributor Author

pllim commented Mar 1, 2023

I am also not sure about this if HDUList is provided by the user, but whatever that is consistent with asdf.fits_embed old behavior is good enough?

af.close = wrap_close(af, hdulist)

@braingram
Copy link
Collaborator

Thanks for the detailed issue.

Do the changes in #136 address your needs?

@pllim
Copy link
Contributor Author

pllim commented Mar 2, 2023

Let's merge #136 and then I can have my Jdaviz PR pull the dev version of stdatamodels. If I pull your fork's branch, the version is gonna get messed up and that messes with dep version resolution in pip. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants