[AstroPy] How to read and write keyword with no value with astropy.io.fits?

Tim Jenness tim.jenness at gmail.com
Tue Sep 27 14:21:11 EDT 2016


On Tue, Sep 27, 2016 at 4:00 AM, Thomas Robitaille <
thomas.robitaille at gmail.com> wrote:

> Hi Russell,
>
> Does this mean that the following:
>
> In [8]: header = fits.Header()
>
> In [9]: header['DATE-OBS'] = None,'this date is now known'
>
> In [10]: header
> Out[10]: DATE-OBS= '' / this date is now known
>
> should ideally be returning:
>
> In [10]: header
> Out[10]: DATE-OBS=    / this date is now known
>
>
I think so. Python None is conceptually similar to FITS null.



> ? Just to make sure I understand, what is the downside of having the
> empty quotes?
>
>
It's the same as asking why None exists at all in python. When you assign
None to the header you are not declaring a type. You are saying  that the
entire value is undefined. Defaulting to an empty string means you are also
stating that the header is a string. Verification tools that are checking
types will fail if the header is meant to contain a number, but can pass if
the value is also allowed to be undefined. If you put a string in for
undefined then that is confusing.

Pence et al 2010 in section 4.2.1 makes clear that:

DATE-OBS= ''
DATE-OBS= '       '
DATE-OBS=

Have three distinct meanings: null string, empty string, typeless undefined
value (except where the standard explicitly states the type of that
keyword).

Of course, as soon as you make astropy FITS compliant, people will have
code that breaks because they have written it to assume empty string and
undefined value are equivalent.

Does astropy handle the undefined case at all at the moment?

-- 
Tim Jenness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160927/69a6ec79/attachment.html>


More information about the AstroPy mailing list