1111
1212from __future__ import print_function
1313import io
14+ import warnings
1415import numpy as np
1516from astropy import units as u
1617import astropy .coordinates as coord
1920from . import conf
2021from ..utils import commons , async_to_sync
2122from ..utils .docstr_chompers import prepend_docstr_noreturns
22- from ..exceptions import RemoteServiceError
23+ from ..exceptions import RemoteServiceError , NoResultsWarning
2324
2425__all__ = ['SDSS' , 'SDSSClass' ]
2526
@@ -513,9 +514,12 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
513514 r = commons .send_request (SDSS .QUERY_URL , request_payload , timeout ,
514515 request_type = 'GET' )
515516 matches = self ._parse_result (r )
517+ if matches is None :
518+ warnings .warn ("Query returned no results." , NoResultsWarning )
519+ return
516520
517521 if not isinstance (matches , Table ):
518- raise TypeError ("Matches must be an astropy Table." )
522+ raise TypeError ("'matches' must be an astropy Table." )
519523
520524 results = []
521525 for row in matches :
@@ -549,7 +553,11 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
549553 plate = plate , fiberID = fiberID ,
550554 mjd = mjd , timeout = timeout )
551555
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 ]
553561
554562 def get_images_async (self , coordinates = None , radius = 2. * u .arcsec ,
555563 matches = None , run = None , rerun = 301 , camcol = None ,
@@ -640,9 +648,11 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
640648 r = commons .send_request (SDSS .QUERY_URL , request_payload , timeout ,
641649 request_type = 'GET' )
642650 matches = self ._parse_result (r )
643-
651+ if matches is None :
652+ warnings .warn ("Query returned no results." , NoResultsWarning )
653+ return
644654 if not isinstance (matches , Table ):
645- raise ValueError
655+ raise ValueError ( "'matches' must be an astropy Table" )
646656
647657 results = []
648658 for row in matches :
@@ -665,7 +675,8 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
665675 @prepend_docstr_noreturns (get_images_async .__doc__ )
666676 def get_images (self , coordinates = None , radius = 2. * u .arcsec ,
667677 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 ):
669680 """
670681 Returns
671682 -------
@@ -678,9 +689,13 @@ def get_images(self, coordinates=None, radius=2. * u.arcsec,
678689 run = run , rerun = rerun ,
679690 camcol = camcol , field = field ,
680691 band = band , timeout = timeout ,
681- get_query_payload = False )
692+ get_query_payload = get_query_payload )
682693
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 ]
684699
685700 def get_spectral_template_async (self , kind = 'qso' , timeout = TIMEOUT ):
686701 """
@@ -744,7 +759,8 @@ def get_spectral_template(self, kind='qso', timeout=TIMEOUT):
744759 readable_objs = self .get_spectral_template_async (kind = kind ,
745760 timeout = timeout )
746761
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 ]
748764
749765 def _parse_result (self , response , verbose = False ):
750766 """
@@ -831,7 +847,7 @@ def _args_to_payload(self, coordinates=None, radius=2. * u.arcsec,
831847 SpecObj quantities to return. If photoobj_fields is None and
832848 specobj_fields is None then the value of fields is used
833849 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
835851 field name. If `True` or it is an invalid field name all the valid
836852 field names are returned as a dict.
837853 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,
857873 return
858874 else :
859875 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 ))
863879 return {'photoobj_all' : photoobj_all ,
864880 'specobj_all' : specobj_all }
865881
0 commit comments