I’m reading in ASCII data like this, where the RA values are in decimal hours:
data = """Star 3865: expected And, found Psc at B1875 RA= 0.716812, DEC= 29.753839
Star 7751: expected Phe, found Eri at B1875 RA= 1.583496, DEC=-52.227227
Star 10342: expected Per, found And at B1875 RA= 2.089285, DEC= 50.478508
Star 19173: expected Hyi, found Ret at B1875 RA= 4.110955, DEC=-67.498972
"""
It seemed good to use a parsing method which allows me to cleanly describe the units involved so the table is easy to turn into SkyCoord
s later on. So I’m trying
header = """Byte-by-byte Description of file: data.txt
--------------------------------------------------------------------------------
Bytes Format Units Label Explanations
--------------------------------------------------------------------------------
5- 11 I7 --- Index HYG Star number
23- 25 A3 --- expected expected constellation
34- 36 A3 --- found HYG constellation
50- 59 F3.6 hourangle ra Hours of Right Ascension (J2000)
66- 75 F3.6 deg dec Degrees of declination (J2000)
--------------------------------------------------------------------------------
"""
Then I read it in with
from astropy.table import Table
t = Table.read(header + data, format="ascii.cds")
WARNING: UnitsWarning: 'hourangle' did not parse as cds unit: At col 0,
Unit 'hourangle' not supported by the CDS SAC 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 [astropy.units.core]
I picked hourangle
since it is available as an astropy unit u.hourangle
If instead I use the unit h
, the table reads in fine, but then I can’t convert it to an angle:
>>> SkyCoord(t.columns[3].quantity, t.columns[4].quantity )
UnitTypeError: Longitude instances require units equivalent to 'rad', so cannot set it to 'h'.
I even tried following the instructions at the page linked to in the error message:
hourangle = u.hourangle
u.add_enabled_units([hourangle])
But I still got the same error.
I assume it is supposed to be easy to read in a table with ra,dec in hourangles, degrees, and convert that to SkyCoords. And it’s hard to believe I’d have to define a custom unit to do that.
How can I do it?
Many thanks!