Trouble with pytest validating non-standard unit
aureliocarnero opened this issue · 4 comments
Hello, maybe someone can help me.
Im in the process of implementing the LSS datamodel for the EDR products, and there is a column unit in some rst files which is giving me troubles through the pytest step.
I describe the problem: the unit is for a column called NZ, and the unit is: (h/Mpc)^3
When I run the pytest module, it fails with the following error message:
CRITICAL desiutil.log.dlm58.info:unit.py:51 '(h/Mpc)^3' did not parse as fits unit: Syntax error parsing unit '(h/Mpc)^3' If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html
How could I solve this problem?
Thank you in advance
The issue is the parentheses. h3/Mpc3
and h^3 Mpc^-3
will both parse successfully.
Note that h
is the unit for hours in FITS, but for the purposes of desidatamodel, we will just assume people recognize the convention for small h.
See https://fits.gsfc.nasa.gov/standard40/fits_standard40aa-le.pdf for full details. We also have some guidelines for units in desidatamodel.
Thanks for the explanation, @weaverba137 . The FITS standard section 4.3.1 says "Parentheses are used for symbol grouping and are strongly recommended whenever the order of operations might be subject to misinterpretation", which I think means that (h/Mpc)^3
should be a legal units expression, but that it isn't supported by the units parsing infrastructure that we use. Do you agree @weaverba137, or do you think that (h/Mpc)^3
is actually illegal under the FITS standard? In the short term h^3 Mpc^-3
is a workaround, though somewhat less user-friendly to my eye. In the long term, if (h/Mpc)^3
actually is a legal FITS units expression, we should file an astropy ticket about supporting it.
I think exponentiation trumps the recommendation of grouping with parentheses:
A unit raised to a power is indicated by the unit string followed, with no intervening spaces, by the optional symbols
**
orˆ
followed by the power given as a numeric expression, calledexpr
in Table 6.
It is possible that Astropy has taken an especially strict interpretation of that, and maybe it is worth a ticket, but I would not be surprised if it were not acted upon, given there are workarounds that we've already come up with.
Thank you for the help and the explanation. h^3 Mpc^-3 is good enough. I'm closing this issue.