I'm trying to obtain coordinates for all frames using the Simbad
class from astroquery
, just like it is shown on the SIMBAD web page
(Basic data section)
I have the following code :
from astroquery.simbad import Simbad
def get():
Simbad.reset_votable_fields()
Simbad.remove_votable_fields('coordinates')
Simbad.add_votable_fields('ra(:;A;ICRS;J2000)', 'dec(:;D;ICRS;2000)')
Simbad.add_votable_fields('ra(:;A;FK5;J2000)', 'dec(:;D;FK5;2000)')
table = Simbad.query_object("Betelgeuse", wildcard=False)
but I'm getting the error:
KeyError: 'ra(:;A;FK5;J2000): field already present. Fields ra,dec,id,otype, and bibcodelist can only be specified once. To change their options, first remove the existing entry, then add a new one.'
Everything I could find in the doc about manipulating votable fields, especially coordinates is this :
Is there a way to get coordinates for all frames sending one query to SIMBAD?
Instead of querying multiple coordinates (which seems impossible with astroquery) from SIMBAD you could convert the coordinates by using astropy.coordinates.SkyCoord
.
For example:
from astroquery.simbad import Simbad
from astropy.coordinates import SkyCoord
Simbad.reset_votable_fields()
Simbad.remove_votable_fields('coordinates')
Simbad.add_votable_fields('ra(:;A;ICRS;J2000)', 'dec(:;D;ICRS;2000)')
table = Simbad.query_object("Betelgeuse", wildcard=False)
coords = SkyCoord(ra=['{}h{}m{}s'.format(*ra.split(':')) for ra in table['RA___A_ICRS_J2000']],
dec=['{}d{}m{}s'.format(*dec.split(':')) for dec in table['DEC___D_ICRS_2000']],
frame='icrs', equinox='J2000')
Which is a now a SkyCoord object that can be transformed to other frames:
>>> coords
<SkyCoord (ICRS): (ra, dec) in deg
( 88.79293875, 7.40706389)>
>>> coords.fk4
<SkyCoord (FK4: equinox=J2000.000, obstime=B1950.000): (ra, dec) in deg
( 88.79274075, 7.40705223)>
>>> coords.fk5
<SkyCoord (FK5: equinox=J2000.000): (ra, dec) in deg
( 88.79294545, 7.40705842)>
This can be converted to strings again, for example in hms dms
formatting:
>>> coords.fk5.to_string('hmsdms')
['05h55m10.3069s +07d24m25.4103s']
If you want these as additional columns in your table, you can simply add these:
>>> table['RA FK5'] = coords.fk5.ra
>>> table['DEC FK5'] = coords.fk5.dec
>>> table['FK4'] = coords.fk4.to_string('hmsdms')
>>> table
MAIN_ID RA___A_ICRS_J2000 DEC___D_ICRS_2000 RA FK5 DEC FK5 FK4
"h:m:s" "d:m:s" deg deg
--------- ----------------- ----------------- ------------- ------------- -----------------------------
* alf Ori 05:55:10.3053 +07:24:25.430 88.7929454548 7.40705841559 05h55m10.2578s +07d24m25.388s