2
2
"""
3
3
Access Sloan Digital Sky Survey database online.
4
4
"""
5
- import io
6
5
import warnings
7
6
import numpy as np
8
7
@@ -518,9 +517,9 @@ class = 'galaxy' \
518
517
timeout = timeout , cache = cache )
519
518
return response
520
519
521
- def get_spectra_async (self , coordinates = None , radius = 2. * u .arcsec ,
520
+ def get_spectra_async (self , * , coordinates = None , radius = 2. * u .arcsec ,
522
521
matches = None , plate = None , fiberID = None , mjd = None ,
523
- timeout = TIMEOUT ,
522
+ timeout = TIMEOUT , get_query_payload = False ,
524
523
data_release = conf .default_release , cache = True ,
525
524
show_progress = True ):
526
525
"""
@@ -559,6 +558,9 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
559
558
timeout : float, optional
560
559
Time limit (in seconds) for establishing successful connection with
561
560
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.
562
564
data_release : int, optional
563
565
The data release of the SDSS to use. With the default server, this
564
566
only supports DR8 or later.
@@ -599,12 +601,19 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
599
601
if coordinates is None :
600
602
matches = self .query_specobj (plate = plate , mjd = mjd , fiberID = fiberID ,
601
603
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 )
603
606
else :
604
- matches = self .query_crossid (coordinates , radius = radius ,
607
+ matches = self .query_crossid (coordinates , radius = radius , timeout = timeout ,
605
608
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
+
608
617
if matches is None :
609
618
warnings .warn ("Query returned no results." , NoResultsWarning )
610
619
return
@@ -638,10 +647,10 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
638
647
return results
639
648
640
649
@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 ,
642
651
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 ,
645
654
show_progress = True ):
646
655
"""
647
656
Returns
@@ -654,9 +663,14 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
654
663
radius = radius , matches = matches ,
655
664
plate = plate , fiberID = fiberID ,
656
665
mjd = mjd , timeout = timeout ,
666
+ get_query_payload = get_query_payload ,
657
667
data_release = data_release ,
668
+ cache = cache ,
658
669
show_progress = show_progress )
659
670
671
+ if get_query_payload :
672
+ return readable_objs
673
+
660
674
if readable_objs is not None :
661
675
if isinstance (readable_objs , dict ):
662
676
return readable_objs
@@ -666,7 +680,7 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
666
680
def get_images_async (self , coordinates = None , radius = 2. * u .arcsec ,
667
681
matches = None , run = None , rerun = 301 , camcol = None ,
668
682
field = None , band = 'g' , timeout = TIMEOUT ,
669
- cache = True ,
683
+ cache = True , get_query_payload = False ,
670
684
data_release = conf .default_release ,
671
685
show_progress = True ):
672
686
"""
@@ -714,6 +728,9 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
714
728
timeout : float, optional
715
729
Time limit (in seconds) for establishing successful connection with
716
730
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.
717
734
cache : bool, optional
718
735
Cache the images using astropy's caching system
719
736
data_release : int, optional
@@ -753,12 +770,19 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
753
770
matches = self .query_photoobj (run = run , rerun = rerun ,
754
771
camcol = camcol , field = field ,
755
772
fields = ['run' , 'rerun' , 'camcol' , 'field' ],
756
- timeout = timeout ,
773
+ timeout = timeout , get_query_payload = get_query_payload ,
757
774
data_release = data_release , cache = cache )
758
775
else :
759
- matches = self .query_crossid (coordinates , radius = radius ,
776
+ matches = self .query_crossid (coordinates , radius = radius , timeout = timeout ,
760
777
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
+
762
786
if matches is None :
763
787
warnings .warn ("Query returned no results." , NoResultsWarning )
764
788
return
@@ -786,7 +810,7 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
786
810
return results
787
811
788
812
@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 ,
790
814
matches = None , run = None , rerun = 301 , camcol = None , field = None ,
791
815
band = 'g' , timeout = TIMEOUT , cache = True ,
792
816
get_query_payload = False , data_release = conf .default_release ,
@@ -798,10 +822,22 @@ def get_images(self, coordinates=None, radius=2. * u.arcsec,
798
822
799
823
"""
800
824
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
805
841
806
842
if readable_objs is not None :
807
843
if isinstance (readable_objs , dict ):
@@ -906,7 +942,7 @@ def _parse_result(self, response, verbose=False):
906
942
else :
907
943
return arr
908
944
909
- def _args_to_payload (self , coordinates = None ,
945
+ def _args_to_payload (self , * , coordinates = None ,
910
946
fields = None , spectro = False , region = False ,
911
947
plate = None , mjd = None , fiberID = None , run = None ,
912
948
rerun = 301 , camcol = None , field = None ,
0 commit comments