question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`fits.writeto()` discards header input for non-image data

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
saimncommented, May 10, 2017

oops 😁

1reaction
pllimcommented, May 10, 2017

@saimn , did you just pinged yourself? >_>

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found