astropy / astroquery

Functions and classes to access online data resources. Maintainers: @keflavich and @bsipocz and @ceb8
http://astroquery.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
688 stars 392 forks source link

Astroquery.gaia API Error: RA cannot be converted to hour or hourangle. #3062

Closed kaya4me2 closed 1 day ago

kaya4me2 commented 5 days ago

Attempt to execute a query of the Gaia catalogs using examples posted at https://learn.astropy.org/tutorials/1-Coordinates-Intro and also at https://astroquery.readthedocs.io/en/latest/gaia/gaia.html

system configuration MacOSX M3 14.2.1

print(astropy.version) print(astroquery.version) astropy 6.0.0 astroquery 0.4.8.dev9321

Code snippet

# Gaia specifc query packages
## https://astroquery.readthedocs.io/en/latest/

import astroquery
from astroquery.gaia import Gaia

Gaia.MAIN_GAIA_TABLE = "gaiadr2.gaia_source"  # Select Data Release 2
#Gaia.MAIN_GAIA_TABLE = "gaiadr3.gaia_source"  # Reselect Data Release 3, default

from astropy.coordinates import (SkyCoord, Distance, Galactic, 
                                 EarthLocation, AltAz)
import astropy.coordinates as coord
from astropy.coordinates import ICRS, Galactic, FK4, FK5  # Low-level frames
from astropy.coordinates import Angle, Latitude, Longitude  # Angles

from astropy.time import Time

coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
width = u.Quantity(0.1, u.deg)
height = u.Quantity(0.1, u.deg)
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)

However getting an commons.py:112 error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[27], line 8
      6 width = u.Quantity(0.1, u.deg)
      7 height = u.Quantity(0.1, u.deg)
----> 8 r = Gaia.query_object_async(coordinate=coord, width=width, height=height)

File ~/anaconda3/envs/jwst_mast_query/lib/python3.9/site-packages/astroquery/gaia/core.py:592, in GaiaClass.query_object_async(self, coordinate, radius, width, height, verbose, columns)
    568 def query_object_async(self, coordinate, *, radius=None, width=None, height=None, verbose=False, columns=()):
    569     """Launches an asynchronous cone search for the input search radius or the box on the sky, sorted by angular
    570     separation
    571     TAP & TAP+
   (...)
    590     The job results (astropy.table).
    591     """
--> 592     return self.__query_object(coordinate, radius=radius, width=width, height=height, async_job=True,
    593                                verbose=verbose, columns=columns)

File ~/anaconda3/envs/jwst_mast_query/lib/python3.9/site-packages/astroquery/gaia/core.py:495, in GaiaClass.__query_object(self, coordinate, radius, width, height, async_job, verbose, columns)
    493     job = self.__cone_search(coord, radius, async_job=async_job, verbose=verbose, columns=columns)
    494 else:
--> 495     raHours, dec = commons.coord_to_radec(coord)
    496     ra = raHours * 15.0  # Converts to degrees
    497     widthQuantity = self.__getQuantityInput(width, "width")

File ~/anaconda3/envs/jwst_mast_query/lib/python3.9/site-packages/astroquery/utils/commons.py:112, in coord_to_radec(coordinate)
    110     ra = C.ra.hourangle
    111 else:
--> 112     raise ValueError("API Error: RA cannot be converted to hour "
    113                      "or hourangle.")
    114 dec = C.dec.degree
    115 return ra, dec

ValueError: API Error: RA cannot be converted to hour or hourangle.
kaya4me2 commented 5 days ago

Resolved looking at some older posting 👍 at : https://gist.github.com/elnjensen/20e9b7bd9c18444be6ea63b131d5d329

The following functions now correctly with the Gaia database query(s) which is not obvious in the Astropy Coordinate 1 tutorial or the ESA Gaia Python query examples at https://astroquery.readthedocs.io/en/latest/gaia/gaia.html

import warnings warnings.filterwarnings("ignore", module='astropy.io.votable.tree') warnings.filterwarnings("ignore", message='.*unclosed..socket')

from future import print_function, division from astropy.coordinates import (SkyCoord, Distance, Galactic, EarthLocation, AltAz) import astropy.coordinates as coord from astropy.coordinates import ICRS, Galactic, FK4, FK5 # Low-level frames from astropy.coordinates import Angle, Latitude, Longitude # Angles from astropy import units as u

from astropy.time import Time

from astroquery.gaia import Gaia

Gaia.MAIN_GAIA_TABLE = "gaiadr2.gaia_source" # Select Data Release 2

Gaia.MAIN_GAIA_TABLE = "gaiadr3.gaia_source" # Reselect Data Release 3, default

Cone search around target coordinates in a 1.0 degree cone, return the first 50 objects

Ensure the default row limit.

Gaia.ROW_LIMIT = 50

Define the object and perform a SIMBAD search

object_name = 'T Tauri' zap = SkyCoord.from_name(object_name)

print(zap.ra.to_string(u.deg), zap.dec.to_string(u.deg) )

coord = SkyCoord(ra=zap.ra, dec=zap.dec, unit=(u.degree, u.degree), frame='icrs') print(coord) j = Gaia.cone_search_async(coord, radius=u.Quantity(1.0, u.deg)) r = j.get_results() r.pprint()

RETURNS NOW SUCCESSFULLY COMPLETED

<SkyCoord (ICRS): (ra, dec) in deg (65.49763328, 19.53512011)> INFO: Query finished. [astroquery.utils.tap.core] solution_id designation source_id ... libname_gspphot dist
...
------------------- -------------------------- ----------------- ... --------------- -------------------- 1636148068921376768 Gaia DR3 48192969034959232 48192969034959232 ... MARCS 7.44373348693752e-05

bsipocz commented 1 day ago

I couldn't reproduce the first traceback, and it seems the issue has been resolved for the OP, too, so I'm closing.