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

io.fits creates a corrupt FITS files if a ImageHDU contains zero-dimensional data #14527

Closed
kYwzor opened this issue Mar 14, 2023 · 1 comment · Fixed by #14528
Closed

io.fits creates a corrupt FITS files if a ImageHDU contains zero-dimensional data #14527

kYwzor opened this issue Mar 14, 2023 · 1 comment · Fixed by #14528

Comments

@kYwzor
Copy link
Member

kYwzor commented Mar 14, 2023

Description

ImageHDU accepts a ndarray with shape () (zero-dimensional) as a data array. This later causes issues when writing to a file because io.fits assumes that the data has at least 1 dimension, resulting in a corrupt FITS file.

Expected behavior

io.fits should never silently create a corrupt FITS file.

How to Reproduce

Minimal reproducible example:

import numpy as np
from astropy.io import fits

filename = 'corrupted.fits'
hdu = fits.ImageHDU(name='test', data=np.array(1.0))
hdu.writeto(filename, overwrite=True)

Although this causes no errors/warnings, the resulting file is not valid FITS and will fail to properly open with fits.getdata(filename).

Versions

Windows-10-10.0.19044-SP0
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
astropy 5.2.1
Numpy 1.24.2
pyerfa 2.0.0.1
Scipy 1.10.0
Matplotlib 3.6.3

@kYwzor kYwzor added the Bug label Mar 14, 2023
@kYwzor
Copy link
Member Author

kYwzor commented Mar 14, 2023

This seems to have a trivial fix, I will provide a PR soon.

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

Successfully merging a pull request may close this issue.

2 participants