Possible precision loss bug when reading FITS files with astropy.io
See original GitHub issueI and my colleague @wafels encountered a possible bug when attempting to read modified julian day (MJD) values out of a FITS file using astropy.io.fits. A working example is below. For reference, the file in question can be found here. It contains a catalogue of triggers marked ‘SFLARE’ detected by the Fermi mission.
In [2]: from astropy.io import fits
In [3]: from astropy.time import Time
In [4]: result = fits.open('browse_results.fits’)
In [5]: hdu1 = result[1]
In [6]: hdu1.data['TRIGGER_TIME'][108]
Out[6]: 55719.266
In [7]: tt = Time(hdu1.data['TRIGGER_TIME'][108],format = 'mjd')
In [8]: tt.datetime
Out[8]: datetime.datetime(2011, 6, 7, 6, 22, 30)
For reference, the correct time (verified from manually viewing the file, and also from the original Fermi catalogue online) for this trigger is actually: 2011-06-07 06:23:06:652
As a further test, the correct trigger time is read out by MRDFITS in IDL. As best I can tell, there seems to be some sort of precision loss when reading this file with astropy.io.fits. This can be seen here:
In [9]: print repr(np.float64(hdu1.data['TRIGGER_TIME'][108]))
55719.265625
Whereas from IDL:
IDL> result = mrdfits('browse_results.fits',1)
IDL> print,result[108].trigger_time,format='(d20.13)'
55719.2660492089999
Putting these numbers into a time conversion, e.g. xTIME gives you the same difference in times, 55719.265625 --> 06:22:30 UT, and 55719.26604921 --> 06:23:06.652 UT
Although this example is specific to times in MJD format, it could be a more general problem - I have not tested this behaviour on other data types. Another possibility is that something is slightly non-standard regarding how the FITS file is formatted, but I am not sure what would cause this.
Issue Analytics
- State:
- Created 7 years ago
- Comments:59 (58 by maintainers)
Ops, @saimn … Didn’t see your comment above. 😅
I think it is because
TFORM6 = F15.0
. I can’t find any entry forF
in http://docs.astropy.org/en/stable/io/fits/usage/table.html#creating-a-fits-table . When I change that toTFORM6 = D15.0
, that column is read in asfloat64
(I usedtab = table.read(filename, format='fits')
).