1

I am trying to update an existing fits table with pyfits. It is working fine for some columns of the table, unfortunately not for the first column. Here is the columns definition:

ColDefs(
name = 'EVENT_ID'; format = '1J'; bscale = 1; bzero = 2147483648
name = 'TEL_ID'; format = '1I'
name = 'TIMESLICE'; format = '1I'; null = 0...

And the simple code fragment to update it:

event = pyfits.open('file.fits.gz')[1]
event.data.field('EVENT_ID')[0] = np.uint32(event.event_ID)
event.data.field('TEL_ID')[0] = int(tel.ID[2])
event.writeto('test.fits')

Writing TEL_ID (and others not shown here) works, EVENT_ID does not. I already tried different formats (np.int32, int) but always the same...

type(event.data.field('EVENT_ID')[0]) 

returns numpy.uint32 (for the unmodified file)

Thanks for your help

Edit:

If I change the definition of 'EVENT_ID', leaving out 'bscale' and 'bzero' the update of the value works. So it seems there is a problem with the unsigned integer.

The hun
  • 11
  • 3
  • is there any Error or does it just ignore it? – MSeifert Mar 10 '16 at 18:23
  • Just as an aside, you can use `data['EVENT_ID']` instead of `data.field('EVENT_ID')`. No real difference, the former is just clearer. – Iguananaut Mar 11 '16 at 10:20
  • No error message, 'test.fits' just contains the unmodified values. – The hun Mar 11 '16 at 10:39
  • I think this is a bug. I'll look into it later. – Iguananaut Mar 11 '16 at 11:56
  • Just to be clear, I've confirmed that this is a bug. I haven't had time to finish the fix yet though. And yes, it's just related to unsigned integers. FITS, to this day, does not natively support unsigned integers and requires this bzero hack to get around it. If you can use signed ints for now that's a fine workaround. It's also *possible* to work around this by monkey-patching some internal methods but I don't know how important this is for you right now...? – Iguananaut Mar 18 '16 at 09:01
  • I think this is probably the same issue: https://github.com/astropy/astropy/issues/3921 – Iguananaut Mar 18 '16 at 09:06
  • The workaround is fine for me, there is no crucial reason for the Event_ID being unsigned int. Thanks for your help. – The hun Mar 29 '16 at 10:16

0 Answers0