22"""
33Access Sloan Digital Sky Survey database online.
44"""
5- import io
65import warnings
76import numpy as np
87
@@ -518,9 +517,9 @@ class = 'galaxy' \
518517 timeout = timeout , cache = cache )
519518 return response
520519
521- def get_spectra_async (self , coordinates = None , radius = 2. * u .arcsec ,
520+ def get_spectra_async (self , * , coordinates = None , radius = 2. * u .arcsec ,
522521 matches = None , plate = None , fiberID = None , mjd = None ,
523- timeout = TIMEOUT ,
522+ timeout = TIMEOUT , get_query_payload = False ,
524523 data_release = conf .default_release , cache = True ,
525524 show_progress = True ):
526525 """
@@ -559,6 +558,9 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
559558 timeout : float, optional
560559 Time limit (in seconds) for establishing successful connection with
561560 remote server. Defaults to `SDSSClass.TIMEOUT`.
561+ get_query_payload : bool, optional
562+ If True, this will return the data the query would have sent out,
563+ but does not actually do the query.
562564 data_release : int, optional
563565 The data release of the SDSS to use. With the default server, this
564566 only supports DR8 or later.
@@ -599,12 +601,19 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
599601 if coordinates is None :
600602 matches = self .query_specobj (plate = plate , mjd = mjd , fiberID = fiberID ,
601603 fields = ['run2d' , 'plate' , 'mjd' , 'fiberID' ],
602- timeout = timeout , data_release = data_release , cache = cache )
604+ timeout = timeout , get_query_payload = get_query_payload ,
605+ data_release = data_release , cache = cache )
603606 else :
604- matches = self .query_crossid (coordinates , radius = radius ,
607+ matches = self .query_crossid (coordinates , radius = radius , timeout = timeout ,
605608 specobj_fields = ['run2d' , 'plate' , 'mjd' , 'fiberID' ],
606- spectro = True ,
607- timeout = timeout , data_release = data_release , cache = cache )
609+ spectro = True , get_query_payload = get_query_payload ,
610+ data_release = data_release , cache = cache )
611+ if get_query_payload :
612+ if coordinates is None :
613+ return matches
614+ else :
615+ return matches [0 ]
616+
608617 if matches is None :
609618 warnings .warn ("Query returned no results." , NoResultsWarning )
610619 return
@@ -638,10 +647,10 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
638647 return results
639648
640649 @prepend_docstr_nosections (get_spectra_async .__doc__ )
641- def get_spectra (self , coordinates = None , radius = 2. * u .arcsec ,
650+ def get_spectra (self , * , coordinates = None , radius = 2. * u .arcsec ,
642651 matches = None , plate = None , fiberID = None , mjd = None ,
643- timeout = TIMEOUT , cache = True ,
644- data_release = conf .default_release ,
652+ timeout = TIMEOUT , get_query_payload = False ,
653+ data_release = conf .default_release , cache = True ,
645654 show_progress = True ):
646655 """
647656 Returns
@@ -654,9 +663,14 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
654663 radius = radius , matches = matches ,
655664 plate = plate , fiberID = fiberID ,
656665 mjd = mjd , timeout = timeout ,
666+ get_query_payload = get_query_payload ,
657667 data_release = data_release ,
668+ cache = cache ,
658669 show_progress = show_progress )
659670
671+ if get_query_payload :
672+ return readable_objs
673+
660674 if readable_objs is not None :
661675 if isinstance (readable_objs , dict ):
662676 return readable_objs
@@ -666,7 +680,7 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
666680 def get_images_async (self , coordinates = None , radius = 2. * u .arcsec ,
667681 matches = None , run = None , rerun = 301 , camcol = None ,
668682 field = None , band = 'g' , timeout = TIMEOUT ,
669- cache = True ,
683+ cache = True , get_query_payload = False ,
670684 data_release = conf .default_release ,
671685 show_progress = True ):
672686 """
@@ -714,6 +728,9 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
714728 timeout : float, optional
715729 Time limit (in seconds) for establishing successful connection with
716730 remote server. Defaults to `SDSSClass.TIMEOUT`.
731+ get_query_payload : bool, optional
732+ If True, this will return the data the query would have sent out,
733+ but does not actually do the query.
717734 cache : bool, optional
718735 Cache the images using astropy's caching system
719736 data_release : int, optional
@@ -753,12 +770,19 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
753770 matches = self .query_photoobj (run = run , rerun = rerun ,
754771 camcol = camcol , field = field ,
755772 fields = ['run' , 'rerun' , 'camcol' , 'field' ],
756- timeout = timeout ,
773+ timeout = timeout , get_query_payload = get_query_payload ,
757774 data_release = data_release , cache = cache )
758775 else :
759- matches = self .query_crossid (coordinates , radius = radius ,
776+ matches = self .query_crossid (coordinates , radius = radius , timeout = timeout ,
760777 fields = ['run' , 'rerun' , 'camcol' , 'field' ],
761- timeout = timeout , data_release = data_release , cache = cache )
778+ get_query_payload = get_query_payload ,
779+ data_release = data_release , cache = cache )
780+ if get_query_payload :
781+ if coordinates is None :
782+ return matches
783+ else :
784+ return matches [0 ]
785+
762786 if matches is None :
763787 warnings .warn ("Query returned no results." , NoResultsWarning )
764788 return
@@ -786,7 +810,7 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
786810 return results
787811
788812 @prepend_docstr_nosections (get_images_async .__doc__ )
789- def get_images (self , coordinates = None , radius = 2. * u .arcsec ,
813+ def get_images (self , * , coordinates = None , radius = 2. * u .arcsec ,
790814 matches = None , run = None , rerun = 301 , camcol = None , field = None ,
791815 band = 'g' , timeout = TIMEOUT , cache = True ,
792816 get_query_payload = False , data_release = conf .default_release ,
@@ -798,10 +822,22 @@ def get_images(self, coordinates=None, radius=2. * u.arcsec,
798822
799823 """
800824
801- readable_objs = self .get_images_async (
802- coordinates = coordinates , radius = radius , matches = matches , run = run ,
803- rerun = rerun , data_release = data_release , camcol = camcol , field = field ,
804- band = band , timeout = timeout , show_progress = show_progress )
825+ readable_objs = self .get_images_async (coordinates = coordinates ,
826+ radius = radius ,
827+ matches = matches ,
828+ run = run ,
829+ rerun = rerun ,
830+ camcol = camcol ,
831+ field = field ,
832+ band = band ,
833+ timeout = timeout ,
834+ cache = cache ,
835+ get_query_payload = get_query_payload ,
836+ data_release = data_release ,
837+ show_progress = show_progress )
838+
839+ if get_query_payload :
840+ return readable_objs
805841
806842 if readable_objs is not None :
807843 if isinstance (readable_objs , dict ):
@@ -906,7 +942,7 @@ def _parse_result(self, response, verbose=False):
906942 else :
907943 return arr
908944
909- def _args_to_payload (self , coordinates = None ,
945+ def _args_to_payload (self , * , coordinates = None ,
910946 fields = None , spectro = False , region = False ,
911947 plate = None , mjd = None , fiberID = None , run = None ,
912948 rerun = 301 , camcol = None , field = None ,
0 commit comments