[AstroPy] Type changing (float to int) of header fields in astropy.wcs.to_header ?

Erik Bray embray at stsci.edu
Thu Jan 23 15:35:33 EST 2014


On 01/22/2014 05:12 PM, Michael Droettboom wrote:
> On 01/22/2014 02:42 PM, Eric L. N. Jensen wrote:

>> Still, there's something unsatisfying to me about this happening within astropy:
>>
>>>>  From WCS object:
>>>>
>>>> CRVAL3 is type <type 'numpy.float64'> with value:
>>>> 345797143190.0
>>>>
>>>> After to_header conversion:
>>>>
>>>> CRVAL3 is type <type 'int'> with value:
>>>> 345797143190

Incidentally this was just brought up here: 
https://github.com/spacetelescope/PyFITS/issues/49

I don't know whether or not that was in response to this thread, as I don't see 
Julian on it anywhere, but it's the same issue nonetheless.

I agree with Mike that if you need the value to be *strictly* treated as a 
float, in particular for the purposes of division, that it's a bug in the 
software to not ensure that it's doing floating point division.  It's also true 
that "1" is a perfectly good "floating point" value as far as FITS is concerned, 
and is also just as much an integer.

There are other keywords in the FITS standard that must be *strictly* treated as 
integers, so it makes sense to return something like "1" as an integer and not a 
float.  That said, I think that if you have

CRVAL3 = 345797143190

and you enter in PyFITS:

header['CRVAL3'] = 345797143190.0

then that should upcast the value to a float, with ".0" IMO.  This should be 
easy to fix.

As an aside: I'm working on (and am nearly ready with a prototype of) a new FITS 
keyword schema definition interface for PyFITS.  This will enable providing 
PyFITS with more semantic information about known keywords (both keywords 
specified in the FITS standard, or keywords in a user-specified convention). 
For example, the header will "know" that it is adhering to the FITS WCS 
convention, and that by that convetion CRVAL3 should be treated as a float, so 
that even entering:

header['CRVAL3'] = 345797143190

would make sure that it is upcast to a float, as well as returned as a float.

The first prototype of the schema definition interface is nearly complete, but 
there's still a little ways to go on full integration with the PyFITS Header 
interface.

Erik B.




More information about the AstroPy mailing list