`fits.writeto()` discards header input for non-image data
See original GitHub issueWhen I use fits.writeto(filename,data=data, header=header)
, the header information is not included in the output file’s header.
I make a minimal FITS file:
import numpy as np
from astropy.io import fits
data=np.zeros((5,),dtype=[('x',np.float),('y',np.int)])
h_in = fits.Header()
h_in['ANSWER']=(42.0,'LTU&E')
fname='/tmp/foo.fits'
fits.writeto(fname,data=data,header=h_in,clobber=True)
h_out=fits.getheader(fname,ext=1)
h_in,'------------------------------------------------',h_out
and the output header doesn’t have the ANSWER
field that was passed to the writeto()
:
(ANSWER = 42.0 / LTU&E ,
'------------------------------------------------',
XTENSION= 'BINTABLE' / binary table extension
BITPIX = 8 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 16 / length of dimension 1
NAXIS2 = 5 / length of dimension 2
PCOUNT = 0 / number of group parameters
GCOUNT = 1 / number of groups
TFIELDS = 2 / number of table fields
TTYPE1 = 'x '
TFORM1 = 'D '
TTYPE2 = 'y '
TFORM2 = 'K ' )
The ANSWER
field is also not in extension 0.
On the other hand, if I make an image FITS file, the header data is retained:
image = np.zeros((10,10),dtype=np.float)
fname='/tmp/foo_image.fits'
fits.writeto(fname,data=image,header=h_in,clobber=True)
h_out_image=fits.getheader(fname,ext=0)
h_out_image
which has ANSWER
in the ext=0 header:
SIMPLE = T / conforms to FITS standard
BITPIX = -64 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 10
NAXIS2 = 10
ANSWER = 42.0 / LTU&E
This is in astropy 1.3.2 .
Work-around:
hdu = fits.BinTableHDU(data=data, header=h_in)
hdu.writeto(fname, clobber=True)
fits.getheader(fname,ext=1)
gives a file with the ANSWER
in the header.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
FITS File Handling (astropy.io.fits)
The open function returns an object called an HDUList which is a list -like collection of HDU objects. An HDU (Header Data Unit)...
Read more >Classification - Rocket Software Documentation
Interface definition for a variable or operation parameter with Data Type Handle or XMLStream.
Read more >Chapter 6 Image Analysis - NRAO CASA
imhead — summarize and manipulate the “header” information in a CASA image ... The FITS keyword hdvalue = '' # Value of hdkey...
Read more >Video and Image Processing Suite User Guide - Intel
image data header has been received for all its input. ... input data on the second input is discarded ... Write to the...
Read more >Db2 12 for z/OS: Utility Guide and Reference - IBM
Invoking a Db2 online utility by creating the JCL data set yourself . ... Preparing Db2 internal format input records that are not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
oops 😁
@saimn , did you just pinged yourself? >_>