Repository navigation
units: units in fits file does not parse - #1911
Conversation
|
The unit parsers in astropy are based on the grammars provided by the unity library [1], which came out of the IVOA's VOUnit project to unify Unit syntaxes. That's where the strict insistence on a single solidus comes from. We've discussed case sensitivity elsewhere and have #1870 in the pipeline, but that won't fully address the issue of just loading a FITS file. My general view on this in other areas of astropy is that users should know when their files are not written to a standard, because it inhibits interoperability with other tools. In that light it's probably time to introduce a "relaxed" mode on FITS units, which could be accessed through the existing |
|
I'm going to stop you slightly there because I have plans to overhaul PyFITS/ That said, there will still be a similar functionality to allow fixing fixable validation errors, so maybe I don't need to stop you there at all. I feel like the parser should remain strict--it should return an exception. But is it possible for the parser to figure out what the user meant, or should that be handled on the FITS validation end upon catching an exception in unit parsing? |
|
The FITS standard should not impose a requirement that is contrary to generally accepted usage. Check the AIP style guide, for example. The name of a unit should not be capitalized (e.g. watt, not Watt). Abbreviations for units should be capitalized if and only if (except L is OK for liter) the unit is a person's name (e.g. W). |
|
Perhaps; but the FITS standard does exactly that in a lot of ways. Of course we could try to get that changed but it would take...months? Years? And then all the FITS files that do follow the standard on this admittedly minor issue would be invalid. So much for "once FITS always FITS" (which itself has almost never been quite true...) |
|
@philhodge: We have to work with the standard we have, not the one we want, at least until such time that we've worked to change the standard (which as @embray points out is epic), or replaced it with a new one (which the VOUnit initiative aims to do). I think part of the problem here is that so many tools have treated units as opaque strings without much attempt to interpret them, so these sorts of incompatibilities go unchecked... Strangely, the VOUnit document, which serves as a pretty good survey of all things in astronomical units, lists "Angstrom" as deprecated for the FITS format (without any citation, so I'm not sure where they get that from, given that FITS 3.0 lists it explicitly), and it lists "angstrom" as never having been accepted. |
|
I think that the "deprecation" they're referring to is a footnote in the FITS Standard on Angstrom (as well as G (for gauss), erg, and barn): "Deprecated in IAU Style Manual (McNally 1988) but still in use." I think probably this goes back to "once FITS always FITS". I don't think the usage is actually deprecated in the FITS format itself, as no alternative is provided. |
|
On 12/18/2013 01:43 PM, Erik Bray wrote:
You don't have to raise an exception just because the unit is written |
|
Well, in the case of reading/writing actual FITS files I agree, and that's part of what I've been wanting to overhaul in the validation handling. I want to explicitly classify all validation issues between errors, warnings, and perhaps a category for issues that, while they do technically violate the standard, are little more than cosmetic. But the units parser I think should be strict and should raise an exception. However the exception should contain enough information for a FITS validator to catch it and understand what went wrong and handle it--in most cases by raising a warning, fixing the issue, or possibly taking no action at all. |
|
And just to clear this up (since @hamogu's original post doesn't really address it), the current behavior is that unparsable units found while reading a file raise warnings, not exceptions, so that behavior already agrees with what @philhodge is suggesting. I'm not advocating changing that, only that if we decide to veer from the spec to try to guess the intent of the FITS file, that should be optional. |
|
I agree that we don't want to guess too much. However, guessing where it's unambiguous (Angstrom vs. angstrom) would make the software more usable. As a second point, to come back to the original issue, using multiple "/" is explicitly declared valid (although discouraged) in the fits standard. So, that should work for strict and loose interpretation of units. |
|
I've gone ahead and implemented parsing for multiple "/", since we probably should support that somehow, however, the interpretation is ambiguous. This is from the VOUnit spec: So, my implementation here treats things as "km m-1 s-1", but also raises a big warning when using multiple slashes. This seems to agree with what wcslib does when parsing units. Note that the implementation will never write out a (parsed) unit string with multiple slashes. As for |
|
The reason I wrote the units for flux as "erg /s /cm2 /angstrom" was the recommendations in the paper "Specification of Physical Units within OGIP FITS files", by Ian M George & Lorella Angelini. I was reading the 1993 Aug 06 version, but the current version, 1995 May 04, is similar and what I quote below. (OGIP is the Office of Guest Investigators Program for high-energy astrophysics.) Table 2 lists "angstrom" (not "Angstrom"). In the examples, example 3 is: STRING = 'count /m2 /s /eV' (recommended). |
|
The great thing about standards is that there are so many of them. ;) So in fact the units in question are not based on the FITS standard, but the OGIP conventions, which are considerably different from the FITS standard in a number of ways, including the names of the units themselves and the operators (OGIP doesn't support (since in OGIP, the '/' only affects the unit immediately after it). In the case of the original example here, Therefore (and I think this is getting out of the scope of this single PR), I think ultimately what we need to do here is:
|
|
Side rant: who thought that it would be a good idea to have |
|
On Dec 19, 2013, at 10:48 AM, Thomas Robitaille wrote:
In any case, given the different uses actually appearing in FITS files, I think one has to conclude that units in FITS is effectively broken. One more item to pass to the ongoing FITS paper I think. |
|
In a (non-representative) survey of fits files I happen to be working on right now, it seems that most of them parse unambiguously. @mdboom I understand that you want to alert users if there files are not standard complaint so that they complain and eventually get the software that makes the files fixed. In the case of fits that's never going to happen (for all the reasons mentioned above and elsewhere). So, unlike e.g. in vofiles the justification to "alert the user to every violations of the standard" is not very important here and, as long as we have fits (which will be a long time), a "just works" for all unambiguously parsing files would be great. |
|
If we're to support OGIP units at all I would suggest devising some heuristics rather than allowing an explicit argument. I would consider adding a flag for enabling/disabling handling of such units, but the default always needs to be "enabled". Yep, another good item to pass on the "Why FITS is failing..." paper or whatever it's called today. |
|
Just for reference (some of the people on this list may have been involved from the other side), here is the official answer I received from the STScI helpdesk, where I reported this problem: Dear Dr. Günther, On behalf of the COS/STIS Help Desk I would like to thank you for pointing this [the non-complience with the fits standard for the HST/COS file in question] out to us. This information will be provided to the responsible individuals to determine what course of action should be taken. Thank you very much for your time. Best Regards, Kevin Lindsay |
|
@embray: So let's assume we add a third "parsing" mode by default which attempts to handle both the FITS and OGIP unit formats through some sort of heuristic. As far as unit names go, there isn't really anything contradictory, so we can just accept the union of them. The issue is with the handling of the slash. When multiple slashes are used, but no multiplication is found after the first slash the two are equivalent. However, if a slash is followed by a multiplication, we'll have to throw up our hands, since it's ambiguous. I don't know how common that case is in practice. But that suggests to me we still need some way for the user specify which kind of units they are expecting to find and force an interpretation of the slash character -- or maybe we can determine that automatically from the source of the FITS file (determined from some other keyword), but we'll probably never have a complete database of how to interpret units given the source of the FITS file. |
|
Note also I think we can merge this PR without resolving the question about how to automatically handle FITS vs. OGIP units, as this makes sense to do independently of that. |
units: units in fits file does not parse
units: units in fits file does not parse
units: units in fits file does not parse
|
I came across this discussion at the end of last week (I'm one of the VOUnit authors). Thanks for the various observations here. @mdboom and @embray: yes, the 'deprecations' listed for FITS are indeed based on that footnote to the FITS spec's table 4. I've clarified this in the repository version of the document. I've also clarified that the although the unit name is indeed 'angstrom' (lower-case initial) the 'preferred' symbol is 'Angstrom' over 'angstrom', following the pattern of other symbols named after surnames, and following FITS and CDS, and against OGIP. Also, @mdboom mentions that "[...]replaced it with a new one (which the VOUnit initiative aims to do)." Our position on that is that the VOUnits spec wasn't intended to replace anything, as such, but that (a) VO specs had to have something to refer to as an allowed syntax in unit contexts, and (b) none of the existing syntaxes was universally adopted, or completely unambiguous, with a grammar. The goal was that the VOUnits syntax would be as much as possible a superset of the three pre-existing common standards. This last isn't quite possible in practice; section 2.12 of the document discusses this. I've created a page of VOUnits errata-ettes. Thanks again for the notes which prompted these. |
I'm am trying to read a fits file from HST/COS, downloaded from MAST today.
All the flux units in the fits file fail to parse.
One problem seems to be that no unit with more than one '/' is accepted, although the fits standard allows for this (even if it is discouraged).
From http://www.aanda.org/articles/aa/full_html/2010/16/aa15362-10/aa15362-10.html :
The IAU style manual forbids the use of more than one slash (“/”) character in a units string. However, since normal mathematical precedence rules apply in this context, more than one slash may be used but is discouraged.
Here is the error:
The second problem is that
'angstrom'is not recognized in thefitsformat, because it should be spelled'Angstrom'. While I recognize that it's technically correct to refuse parsing the unit in lower case for fits, there are plenty of HST files out there that use'angstrom'and there is no potential for confusion, so I suggest to accept this, even if not allowed by the definition of the standard.Note that I'll file this as a bug report with STScI well, but for the foreseeable future users will have to live with HST data files that do not conform to the standard, so we should support them.