11
11
12
12
from __future__ import print_function
13
13
import io
14
+ import warnings
14
15
import numpy as np
15
16
from astropy import units as u
16
17
import astropy .coordinates as coord
19
20
from . import conf
20
21
from ..utils import commons , async_to_sync
21
22
from ..utils .docstr_chompers import prepend_docstr_noreturns
22
- from ..exceptions import RemoteServiceError
23
+ from ..exceptions import RemoteServiceError , NoResultsWarning
23
24
24
25
__all__ = ['SDSS' , 'SDSSClass' ]
25
26
@@ -513,9 +514,12 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
513
514
r = commons .send_request (SDSS .QUERY_URL , request_payload , timeout ,
514
515
request_type = 'GET' )
515
516
matches = self ._parse_result (r )
517
+ if matches is None :
518
+ warnings .warn ("Query returned no results." , NoResultsWarning )
519
+ return
516
520
517
521
if not isinstance (matches , Table ):
518
- raise TypeError ("Matches must be an astropy Table." )
522
+ raise TypeError ("'matches' must be an astropy Table." )
519
523
520
524
results = []
521
525
for row in matches :
@@ -549,7 +553,11 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
549
553
plate = plate , fiberID = fiberID ,
550
554
mjd = mjd , timeout = timeout )
551
555
552
- return [obj .get_fits () for obj in readable_objs ]
556
+ if readable_objs is not None :
557
+ if isinstance (readable_objs , dict ):
558
+ return readable_objs
559
+ else :
560
+ return [obj .get_fits () for obj in readable_objs ]
553
561
554
562
def get_images_async (self , coordinates = None , radius = 2. * u .arcsec ,
555
563
matches = None , run = None , rerun = 301 , camcol = None ,
@@ -640,9 +648,11 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
640
648
r = commons .send_request (SDSS .QUERY_URL , request_payload , timeout ,
641
649
request_type = 'GET' )
642
650
matches = self ._parse_result (r )
643
-
651
+ if matches is None :
652
+ warnings .warn ("Query returned no results." , NoResultsWarning )
653
+ return
644
654
if not isinstance (matches , Table ):
645
- raise ValueError
655
+ raise ValueError ( "'matches' must be an astropy Table" )
646
656
647
657
results = []
648
658
for row in matches :
@@ -665,7 +675,8 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
665
675
@prepend_docstr_noreturns (get_images_async .__doc__ )
666
676
def get_images (self , coordinates = None , radius = 2. * u .arcsec ,
667
677
matches = None , run = None , rerun = 301 , camcol = None , field = None ,
668
- band = 'g' , timeout = TIMEOUT , cache = True ):
678
+ band = 'g' , timeout = TIMEOUT , cache = True ,
679
+ get_query_payload = False ):
669
680
"""
670
681
Returns
671
682
-------
@@ -678,9 +689,13 @@ def get_images(self, coordinates=None, radius=2. * u.arcsec,
678
689
run = run , rerun = rerun ,
679
690
camcol = camcol , field = field ,
680
691
band = band , timeout = timeout ,
681
- get_query_payload = False )
692
+ get_query_payload = get_query_payload )
682
693
683
- return [obj .get_fits () for obj in readable_objs ]
694
+ if readable_objs is not None :
695
+ if isinstance (readable_objs , dict ):
696
+ return readable_objs
697
+ else :
698
+ return [obj .get_fits () for obj in readable_objs ]
684
699
685
700
def get_spectral_template_async (self , kind = 'qso' , timeout = TIMEOUT ):
686
701
"""
@@ -744,7 +759,8 @@ def get_spectral_template(self, kind='qso', timeout=TIMEOUT):
744
759
readable_objs = self .get_spectral_template_async (kind = kind ,
745
760
timeout = timeout )
746
761
747
- return [obj .get_fits () for obj in readable_objs ]
762
+ if readable_objs is not None :
763
+ return [obj .get_fits () for obj in readable_objs ]
748
764
749
765
def _parse_result (self , response , verbose = False ):
750
766
"""
@@ -831,7 +847,7 @@ def _args_to_payload(self, coordinates=None, radius=2. * u.arcsec,
831
847
SpecObj quantities to return. If photoobj_fields is None and
832
848
specobj_fields is None then the value of fields is used
833
849
field_help: str or bool, optional
834
- Field name to check whether a valid PhotoObjAll or SpecObjAll
850
+ Field name to check whether it is a valid PhotoObjAll or SpecObjAll
835
851
field name. If `True` or it is an invalid field name all the valid
836
852
field names are returned as a dict.
837
853
obj_names : str, or list or `~astropy.table.Column`, optional
@@ -857,9 +873,9 @@ def _args_to_payload(self, coordinates=None, radius=2. * u.arcsec,
857
873
return
858
874
else :
859
875
if field_help is not True :
860
- print ("{0} isn't a valid 'photobj_field' or "
861
- "'specobj_field' field, valid fields are "
862
- "returned." .format (field_help ))
876
+ warnings . warn ("{0} isn't a valid 'photobj_field' or "
877
+ "'specobj_field' field, valid fields are"
878
+ "returned." .format (field_help ))
863
879
return {'photoobj_all' : photoobj_all ,
864
880
'specobj_all' : specobj_all }
865
881
0 commit comments