fitsio icon indicating copy to clipboard operation
fitsio copied to clipboard

Comments for binary table columns

Open ghost opened this issue 8 years ago • 2 comments

Dear all,

I create fits file with the following (simplified) script:

import fitsio, numpy
from fitsio import FITS,FITSHDR

filename='test.fits'

fits = FITS(filename,'rw')
data = numpy.zeros(1, dtype=[('freq','i4')])
data[0]['freq'] = 0
hdr = [
    {'name':'TSTART',   'value':  0, 'comment':'Moment when this log file was started'},
]

fits.write(data, units=["Hz"], extname="logs", header=hdr)
fits.close()

File is created correctly with units being assigned as units for the column "freq" but when I check the header, e.g. with

data,h = fitsio.read(filename, header=True)

I see the following:

XTENSION= 'BINTABLE' / binary table extension BITPIX = 8 / 8-bit bytes NAXIS = 2 / 2-dimensional binary table NAXIS1 = 4 / width of table in bytes NAXIS2 = 1 / number of rows in table PCOUNT = 0 / size of special data area GCOUNT = 1 / one data group (required keyword) TFIELDS = 1 / number of fields in each row TTYPE1 = 'freq ' / label for field 1 TFORM1 = 'J ' / data format of field: 4-byte INTEGER TUNIT1 = 'Hz ' / physical unit of field EXTNAME = 'logs ' / name of this binary table extension TSTART = 0 / Moment when this log file was started

Can I somehow change the "label for field 1" comment for the TTYPE1 to put a description of the physical meaning of the data in the "freq" column?

Thank you for any help.

P.S. I tried to create file in such a way, then read the data and header, modify the header by inserting custom comment in h._record_map and execute with modified header (h_new) the fits.write(...) again, like this:

fits.write(data, units=["Hz"], extname="logs", header=h_new)

But as a result I get exactly the same headers, so probably the create_table_hdu(...) overwrites the header with identical to original one with empty comment which is then replaced with the standard "label for field 1" string.

ghost avatar Dec 21 '17 17:12 ghost

I'm sorry I didn't reply to this earlier. I think this should be possible, but would be some work to implement. Is this something you would like to contribute?

esheldon avatar Mar 20 '18 15:03 esheldon

I have not been able to find a way to do this

esheldon avatar Nov 12 '20 14:11 esheldon