66from io import BytesIO
77
88from astropy .table import QTable , MaskedColumn
9- from astropy .io import ascii
109from astropy .time import Time
1110from astropy .io .votable import parse
1211import astropy .units as u
1312from astropy .coordinates import SkyCoord , Angle
13+ from astropy .utils .exceptions import AstropyUserWarning
14+
15+ from astroquery .exceptions import NoResultsWarning
16+ from astroquery .query import BaseQuery
17+ from astroquery .utils import async_to_sync , commons
1418
15- from ..query import BaseQuery
16- from ..utils import async_to_sync , commons
1719from . import conf
1820
1921__all__ = ['Miriade' , 'MiriadeClass' , 'Skybot' , 'SkybotClass' ]
@@ -599,7 +601,7 @@ def cone_search_async(self,
599601 + str (int (find_comets )),
600602 '-refsys' : 'EQJ2000' ,
601603 '-output' : 'all' ,
602- '-mime' : 'text ' }
604+ '-mime' : 'votable ' }
603605
604606 # check for diagnostic flags
605607 if get_query_payload :
@@ -611,42 +613,42 @@ def cone_search_async(self,
611613 params = request_payload ,
612614 timeout = TIMEOUT , cache = cache )
613615
616+ response .raise_for_status ()
617+
614618 self ._uri = response .url
615619
616620 return response
617621
618622 def _parse_result (self , response , * , verbose = False ):
619623 """
620- internal wrapper to parse queries
624+ internal wrapper to parse queries.
621625 """
622626
623627 if self ._get_raw_response :
624628 return response .text
625629
626- # intercept error messages
627- response_txt = response .text .split ('\n ' )[2 :- 1 ]
628- if len (response_txt ) < 3 and len (response_txt [- 1 ].split ('|' )) < 21 :
629- raise RuntimeError (response_txt [- 1 ])
630+ with warnings .catch_warnings ():
631+ # We deal with RA/DEC manually
632+ warnings .filterwarnings ("ignore" , category = AstropyUserWarning ,
633+ message = r"column ra|(column de) has a unit but is kept as a MaskedColumn" )
634+ results = QTable .read (BytesIO (response .content ), format = 'votable' )
630635
631- names = response_txt [0 ].replace ('# ' , '' ).strip ().split (' | ' )
632- results = ascii .read (response_txt [1 :], delimiter = '|' ,
633- names = names , fast_reader = False )
634- results = QTable (results )
636+ if len (results ) == 0 :
637+ warnings .warn ("No objects were found with the query constraints." , NoResultsWarning )
638+ return results
635639
636640 # convert coordinates to degrees
637- coo = SkyCoord (ra = results ['RA(h) ' ], dec = results ['DE(deg) ' ],
641+ coo = SkyCoord (ra = results ['ra ' ], dec = results ['de ' ],
638642 unit = (u .hourangle , u .deg ), frame = 'icrs' )
639- results ['RA(h)' ] = coo .ra .deg
640- results ['DE(deg)' ] = coo .dec .deg
643+ results ['ra' ] = coo .ra .deg
644+ results ['ra' ].unit = u .deg
645+ results ['de' ] = coo .dec .deg
646+ results ['de' ].unit = u .deg
641647
642648 colnames = results .columns [:]
643649 for fieldname in colnames :
644650 # apply field name change
645651 results .rename_column (fieldname , conf .field_names [fieldname ])
646- # apply unit, if available
647- if conf .field_names [fieldname ] in conf .field_units :
648- results [conf .field_names [fieldname ]].unit = conf .field_units [
649- conf .field_names [fieldname ]]
650652
651653 # convert object numbers to int
652654 # unnumbered asteroids return as non numeric values ('-')
0 commit comments