Cannot parse FITS unit
See original GitHub issueDescription
I want to parse the unit “e” as u.electron from a FITS table. I am not sure whether I did it right; I however followed the message of the ValueError
below:
import astropy.units as u
e = u.def_unit('e', u.electron, format={'fits': 'e'})
u.add_enabled_units(e)
fits_e = u.Unit('e', format="fits")
Expected behavior
I would expect that fits_e = e
, and that I can now open a table that has TUNITn = 'e '
with QTable.read()
and get a column that has a unit convertive to u.electron
.
Actual behavior
I get the ValueError
:
‘e’ did not parse as fits unit: At col 0, Unit ‘e’ not supported by the FITS standard. 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
With parse_strict="warn"
, this is a warning only, but then the created unit is an UnrecognizedUnit
. The same happens when I try to open a table now.
System Details
That is astropy 4.2 on Debian Testing (Bullseye).
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Good points. Actually, what perhaps would be easiest is if the new unit aliases were understood by all unit readers. Temporary aliases is more or less what they are meant for: https://docs.astropy.org/en/latest/api/astropy.units.add_enabled_aliases.html#astropy.units.add_enabled_aliases
I am not sure about the use of the “generic” parser: I would guess that sometimes names are not unique for a unit, but depend on the context. For example
e
could mean either a count or a charge unit. Also, usually one wouldn’t want to allow just “any” unit to be read, but a certain selection on top of the FITS standard: Some people would just want to add'flam'
to the list of units, or'electron'
as a count. Therefore, I would (instead of just using the “generic” reader) rather like to have the FITS unit parser extensible, by the API similar to the example in the top posting (since this is what one would usually expect). Another advantage would be that one would not just switch to “lazy”, but still keep a “standard, with well-defined exceptions”.@mhvk wrote:
The FITS standard has two tables: