question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot parse FITS unit

See original GitHub issue

Description

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:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Jun 17, 2021

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

0reactions
olebolecommented, Jun 17, 2021

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:

I could not find a list of supported units on https://fits.gsfc.nasa.gov/

The FITS standard has two tables:

  • Table 3 IAU-recommended basic units.
  • Table 4 Additional allowed units.
Read more comments on GitHub >

github_iconTop Results From Across the Web

FITS unit parsing with "1 / ..." sometimes fails #3986 - GitHub
Looking over old units issues, I came across this one. My own feeling is that the behaviour in units itself is fine: if...
Read more >
FITS File Handling (astropy.io.fits)
Working with large files. The open() function supports a memmap=True argument that allows the array data of each HDU to be accessed with...
Read more >
Astropy cannot parse inches - python - Stack Overflow
I am trying to convert inches to mm with astropy. In input I have unit as string ("inch","mm"). I create for it example...
Read more >
FITS File handling (astropy.io.fits)
Working with large files. The open() function supports a memmap=True argument that allows the array data of each HDU to be accessed with...
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
Parsing a CSV with mixed timezones#. pandas cannot natively represent a column or index with mixed timezones. If your CSV file contains columns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found