6
6
from io import BytesIO
7
7
8
8
from astropy .table import QTable , MaskedColumn
9
- from astropy .io import ascii
10
9
from astropy .time import Time
11
10
from astropy .io .votable import parse
12
11
import astropy .units as u
13
12
from 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
14
18
15
- from ..query import BaseQuery
16
- from ..utils import async_to_sync , commons
17
19
from . import conf
18
20
19
21
__all__ = ['Miriade' , 'MiriadeClass' , 'Skybot' , 'SkybotClass' ]
@@ -599,7 +601,7 @@ def cone_search_async(self,
599
601
+ str (int (find_comets )),
600
602
'-refsys' : 'EQJ2000' ,
601
603
'-output' : 'all' ,
602
- '-mime' : 'text ' }
604
+ '-mime' : 'votable ' }
603
605
604
606
# check for diagnostic flags
605
607
if get_query_payload :
@@ -611,42 +613,42 @@ def cone_search_async(self,
611
613
params = request_payload ,
612
614
timeout = TIMEOUT , cache = cache )
613
615
616
+ response .raise_for_status ()
617
+
614
618
self ._uri = response .url
615
619
616
620
return response
617
621
618
622
def _parse_result (self , response , * , verbose = False ):
619
623
"""
620
- internal wrapper to parse queries
624
+ internal wrapper to parse queries.
621
625
"""
622
626
623
627
if self ._get_raw_response :
624
628
return response .text
625
629
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' )
630
635
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
635
639
636
640
# convert coordinates to degrees
637
- coo = SkyCoord (ra = results ['RA(h) ' ], dec = results ['DE(deg) ' ],
641
+ coo = SkyCoord (ra = results ['ra ' ], dec = results ['de ' ],
638
642
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
641
647
642
648
colnames = results .columns [:]
643
649
for fieldname in colnames :
644
650
# apply field name change
645
651
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 ]]
650
652
651
653
# convert object numbers to int
652
654
# unnumbered asteroids return as non numeric values ('-')
0 commit comments