-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FITS unit parsing with "1 / ..." sometimes fails #3986
Comments
I think it should always raise an error, if my reading of the FITS units specification is correct (not sure though). |
We're adjusting our software to generate these FITS files.
But if I'm reading the examples from the standard correctly, this is the recommended encoding, but it fails to parse with Astropy!? >>> Unit('/MeV /s /sr', format='fits')
ValueError: '/MeV /s /sr' did not parse as fits unit: Syntax error parsing unit '/MeV /s /sr' Going through the "recommended way to write compound units examples" in the FITS standard, there's some others that don't parse with Astropy, e.g. >>> Unit('/pixel /s', format='fits')
ValueError: '/pixel /s' did not parse as fits unit: Syntax error parsing unit '/pixel /s' Is there a bug in the parser or does it only cover a subset of FITS units? |
The OGIP unit spec is not the same as the unit spec defined in the FITS standard. It is similar, but subtly different. I'll let @mdboom explain: #1911 (comment) Anyways: In [2]: Unit('/MeV /s /sr', format='ogip')
Out[2]: Unit("1 / (MeV s sr)")
In [3]: Unit('/pixel /s', format='ogip')
Out[3]: Unit("1 / (pix s)") I wouldn't use the OGIP unit convention unless there is an operational requirement for it. |
FWIW the FITS Standard as defined by the IAU FITS WG is found here: http://fits.gsfc.nasa.gov/fits_standard.html The current version (3.0) defines the current recommendations for formatting units in FITS. The OGIP convention long predates any attempt to systematically describe a unit formatting convention in the FITS Standard itself. But for new FITS files that don't have to conform to the OGIP convention (e.g. for inclusion in an existing archive that uses it consistently), the FITS Standard should be the reference on units in FITS. Of course, since there is only one version of FITS there should never be any ambiguity about what unit formatting convention a given FITS file is using. [And yes, that should be read dripping with sarcasm :)] |
One thing we might consider doing (I feel like there's been an issue about this before, but I'm not sure), is add a special case when parsing a unit with |
(Ah, I wrote something similar here--there I was talking about unit integration directly in |
@embray: Yes, I recall discussing a fallback somewhat like that before, but I don't think it ever went anywhere. I'm not opposed to something like that. I recommend always using this form: |
@mdboom If you want, I can work on this. I need to dig more into the unit code anyways as I figure out how to best handle units in fitting... |
Sure. I guess the design question is whether to have the existing |
Maybe instead of |
Sure -- either of those names is better. |
@embray @mdboom - Thanks for the explanations! And sorry for the confusion about the OGIP and FITS units standards ... I wasn't aware. For now it's not clear if we'll use OGIP or FITS, so we'll probably use this for now, which seems to be valid and the same in both standards:
|
No need to apologize, any reasonable person would be confused about this :) |
I'm still under the impression that the fact that |
Yes, the fact that |
What about the fallback to OGIP? |
I'm going to add a PR for that in a bit. I think we can just change |
Looking over old units issues, I came across this one. My own feeling is that the behaviour in |
|
As mentioned in #602 (comment), the FITS unit parsing with "1 / .." sometimes works and sometimes fails:
This is confusing and maybe it would be better to always make this work or always raise an error?
For reference, the FITS unit standard is here:https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_93_001/ogip_93_001.html
EDIT by @mdboom to avoid confusion for others coming across this in the future:
The OGIP unit standard is here: https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_93_001/ogip_93_001.html
The FITS unit standard is here:
http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf
cc @embray @mdboom @mapazarr
The text was updated successfully, but these errors were encountered: