[AstroPy] Writing unsigned int with pyfits

Martin Raue martin.raue@desy...
Mon Apr 30 08:45:38 CDT 2012


Dear all,

I am trying to create a FITS file with a bintable extension containing unsigned integers with pyfits but could not get it to work (example below). Does maybe someone know what I am doing wrong here?

Best wishes,
Martin

import numpy as np
import pyfits as pf

phdu = pf.PrimaryHDU(uint=True)

a_uint = np.ones(1, dtype=np.uint32)
                     
events = pf.new_table(
    pf.ColDefs([
        pf.Column(name='EVENT_ID', array=a_uint, format='J', bscale=1, bzero=2**31)
        pf.Column(name='OBS_ID', array=a_uint, format='J', bscale=1, bzero=2**31)
#       ... a few more columns
        ])
    )

hdulist = pf.HDUList([phdu, events])

hdulist.writeto('tmp.fits')

hdulist = None

f = pf.open('tmp.fits')

In [2]: f[1].data
Out[2]: 
FITS_rec([(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)], 
      dtype=[('EVENT_ID', '>i4'), ('OBS_ID', '>i4'), ('TIME', '>f4'), ('RA', '>f4'), ('DEC', '>f4'), ('DETX', '>f4'), ('DETY', '>f4'), ('ENERGY', '>f4'), ('HIL_MSW', '>f4'), ('HIL_MSL', '>f4')])

In [3]: f[1].data.field('EVENT_ID')[0].dtype
Out[3]: dtype('float64')


-----------------------------------

Martin Raue

Group Leader - LEXI Young Investigator Group
"Cosmic radiation fields and search for dark matter in the early universe"
http://wwwiexp.desy.de/groups/astroparticle/crf/

University of Hamburg
Institute for Experimental Physics
Luruper Chaussee 149
D-22761 Hamburg
Germany

Phone  : +49-40-8998-2993
Fax    : +49-40-8998-2170
E-Mail : martin.raue@desy.de



More information about the AstroPy mailing list