You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some code which attempts to update the FITS checksums:
output = "out.fits"
with fits.open(self.filepath, do_not_scale_image_data=True) as hdus:
for hdu in hdus:
fits.append(output, hdu.data, hdu.header, checksum=True)
For a file which has no data in an HDU (primary), this code now raises an exception requiring that the data array be an np.array rather than None.
There's a relatively easy "work" around something like this:
data = hdu.data if hdu.data is not None else np.array([])
but I wasn't positive it's correct.
Since it used to be possible to round trip these HDUs, I thought I should raise it as an issue and possible bug.
It's my fault, sorry. This is because of 6800eec : _makehdu relies on _BaseHDU(data, header) being able to use the HDU detection from the header, and there is no test for this...
I removed _BaseHDU.__new__ because when reading from a FITS file this HDU detection was done twice. So I'm hesitating between just reverting this commit, or adding a classmethod which would explicitly call the class detection. I will look into this later today.
In [2]: output = "out.fits"
...: with fits.open('astropy/io/fits/tests/data/test0.fits', do_not_scale_image_data=True) as hdus:
...: for hdu in hdus:
...: fits.append(output, hdu.data, hdu.header, checksum=True)
...:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-2-579e0ac3115e> in <module>
2 with fits.open('astropy/io/fits/tests/data/test0.fits', do_not_scale_image_data=True) as hdus:
3 for hdu in hdus:
----> 4 fits.append(output, hdu.data, hdu.header, checksum=True)
~/dev/astropy/astropy/io/fits/convenience.py in append(filename, data, header, checksum, verify, **kwargs)
619 # output to the empty object.
620 #
--> 621 writeto(filename, data, header, checksum=checksum, **kwargs)
622 else:
623 hdu = _makehdu(data, header)
~/dev/astropy/astropy/utils/decorators.py in wrapper(*args, **kwargs)
519 kwargs[new_name[i]] = value
520
--> 521 return function(*args, **kwargs)
522
523 return wrapper
~/dev/astropy/astropy/io/fits/convenience.py in writeto(filename, data, header, output_verify, overwrite, checksum)
414 """
415
--> 416 hdu = _makehdu(data, header)
417 if hdu.is_image and not isinstance(hdu, PrimaryHDU):
418 hdu = PrimaryHDU(data, header=header)
~/dev/astropy/astropy/io/fits/convenience.py in _makehdu(data, header)
1045 hdu = ImageHDU(data, header=header)
1046 else:
-> 1047 raise KeyError('Data must be a numpy array.')
1048 return hdu
1049
KeyError: 'Data must be a numpy array.'
Activity
pllim commentedon May 6, 2019
saimn commentedon May 6, 2019
It's my fault, sorry. This is because of 6800eec :
_makehdurelies on_BaseHDU(data, header)being able to use the HDU detection from the header, and there is no test for this...I removed
_BaseHDU.__new__because when reading from a FITS file this HDU detection was done twice. So I'm hesitating between just reverting this commit, or adding a classmethod which would explicitly call the class detection. I will look into this later today.EDIT: xref #8502
Add test reproducing astropy#8660
Add test reproducing astropy#8660
Add test reproducing astropy#8660