[AstroPy] astropy.io.fits

Erik Bray embray at stsci.edu
Mon Nov 30 10:49:36 EST 2015


On 11/30/2015 10:42 AM, Paul Kuin wrote:
> Well, I did work around it, NP. It would be good to have that done some time.  I
> was creating an ascii table from the FITS version and for consistency I changed
> all the NaN and -2147483648 to blanks. It was one shot thing.
> Keep up the good work!

Thanks for understanding.  Part of the problem with this is that in order to 
interpret the TNULL keyword as NaNs you have no choice but to take existing 
integer data and convert it to floating point.

And yeah, for the record a simple workaround is to do something like

col = hdu.data['colname'].astype(float)
col[col == hdu.header['TNULL1']] = np.nan

If you don't convert the column from int to float, the default behavior of Numpy 
when assigning np.nan to that array is to write -2147483648 to the array as a 
"null" value.  It won't automatically re-cast the array to floats, I believe.

Erik

> On Mon, Nov 30, 2015 at 2:00 PM, Erik Bray <embray at stsci.edu
> <mailto:embray at stsci.edu>> wrote:
>
>     On 11/26/2015 04:28 PM, Paul Kuin wrote:
>
>         I was reading in a fits binary table.
>
>         Some fields have defined TNULL??=-2147483648 <tel:2147483648>, while
>         TFORM?? = 'J       '
>
>         If I display the variable, it shows -2147483648 <tel:2147483648>, while
>         it should be set to Nan,
>         or blank, I think.
>
>         Is that a bug or a feature?
>
>
>     Looks to be a bug, more or less.  I only recently implemented working(?)
>     support for the BLANK keyword in image arrays [1].  Proper support for TNULL
>     would involve applying the same work to table columns, which should be
>     straightforward.  I think just nobody's ever asked.
>
>     Erik
>
>
>     [1] https://github.com/astropy/astropy/pull/3865
>
>     _______________________________________________
>     AstroPy mailing list
>     AstroPy at scipy.org <mailto:AstroPy at scipy.org>
>     https://mail.scipy.org/mailman/listinfo/astropy
>
>
>
>
> --
>
> * * * * * * * * http://www.mssl.ucl.ac.uk/~npmk/ * * * *
> Dr. N.P.M. Kuin      (n.kuin at ucl.ac.uk <mailto:n.kuin at ucl.ac.uk>)
> phone +44-(0)1483 (prefix) -204927 (work)
> mobile +44(0)7806985366  skype ID: npkuin
> Mullard Space Science Laboratory  – University College London  –
> Holmbury St Mary – Dorking – Surrey RH5 6NT–  U.K.
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
>




More information about the AstroPy mailing list