Skip to content

Commit 66c6c9e

Browse files
committed
restore get_query_payload to all methods
1 parent 4362450 commit 66c6c9e

File tree

2 files changed

+108
-15
lines changed

2 files changed

+108
-15
lines changed

astroquery/sdss/core.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class = 'galaxy' \
520520

521521
def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
522522
matches=None, plate=None, fiberID=None, mjd=None,
523-
timeout=TIMEOUT,
523+
timeout=TIMEOUT, get_query_payload=False,
524524
data_release=conf.default_release, cache=True,
525525
show_progress=True):
526526
"""
@@ -559,6 +559,9 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
559559
timeout : float, optional
560560
Time limit (in seconds) for establishing successful connection with
561561
remote server. Defaults to `SDSSClass.TIMEOUT`.
562+
get_query_payload : bool, optional
563+
If True, this will return the data the query would have sent out,
564+
but does not actually do the query.
562565
data_release : int, optional
563566
The data release of the SDSS to use. With the default server, this
564567
only supports DR8 or later.
@@ -599,12 +602,19 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
599602
if coordinates is None:
600603
matches = self.query_specobj(plate=plate, mjd=mjd, fiberID=fiberID,
601604
fields=['run2d', 'plate', 'mjd', 'fiberID'],
602-
timeout=timeout, data_release=data_release, cache=cache)
605+
timeout=timeout, get_query_payload=get_query_payload,
606+
data_release=data_release, cache=cache)
603607
else:
604-
matches = self.query_crossid(coordinates, radius=radius,
608+
matches = self.query_crossid(coordinates, radius=radius, timeout=timeout,
605609
specobj_fields=['run2d', 'plate', 'mjd', 'fiberID'],
606-
spectro=True,
607-
timeout=timeout, data_release=data_release, cache=cache)
610+
spectro=True, get_query_payload=get_query_payload,
611+
data_release=data_release, cache=cache)
612+
if get_query_payload:
613+
if coordinates is None:
614+
return matches
615+
else:
616+
return matches[0]
617+
608618
if matches is None:
609619
warnings.warn("Query returned no results.", NoResultsWarning)
610620
return
@@ -640,8 +650,8 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
640650
@prepend_docstr_nosections(get_spectra_async.__doc__)
641651
def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
642652
matches=None, plate=None, fiberID=None, mjd=None,
643-
timeout=TIMEOUT, cache=True,
644-
data_release=conf.default_release,
653+
timeout=TIMEOUT, get_query_payload=False,
654+
data_release=conf.default_release, cache=True,
645655
show_progress=True):
646656
"""
647657
Returns
@@ -654,9 +664,14 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
654664
radius=radius, matches=matches,
655665
plate=plate, fiberID=fiberID,
656666
mjd=mjd, timeout=timeout,
667+
get_query_payload=get_query_payload,
657668
data_release=data_release,
669+
cache=cache,
658670
show_progress=show_progress)
659671

672+
if get_query_payload:
673+
return readable_objs
674+
660675
if readable_objs is not None:
661676
if isinstance(readable_objs, dict):
662677
return readable_objs
@@ -666,7 +681,7 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
666681
def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
667682
matches=None, run=None, rerun=301, camcol=None,
668683
field=None, band='g', timeout=TIMEOUT,
669-
cache=True,
684+
cache=True, get_query_payload=False,
670685
data_release=conf.default_release,
671686
show_progress=True):
672687
"""
@@ -714,6 +729,9 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
714729
timeout : float, optional
715730
Time limit (in seconds) for establishing successful connection with
716731
remote server. Defaults to `SDSSClass.TIMEOUT`.
732+
get_query_payload : bool, optional
733+
If True, this will return the data the query would have sent out,
734+
but does not actually do the query.
717735
cache : bool, optional
718736
Cache the images using astropy's caching system
719737
data_release : int, optional
@@ -753,12 +771,19 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
753771
matches = self.query_photoobj(run=run, rerun=rerun,
754772
camcol=camcol, field=field,
755773
fields=['run', 'rerun', 'camcol', 'field'],
756-
timeout=timeout,
774+
timeout=timeout, get_query_payload=get_query_payload,
757775
data_release=data_release, cache=cache)
758776
else:
759-
matches = self.query_crossid(coordinates, radius=radius,
777+
matches = self.query_crossid(coordinates, radius=radius, timeout=timeout,
760778
fields=['run', 'rerun', 'camcol', 'field'],
761-
timeout=timeout, data_release=data_release, cache=cache)
779+
get_query_payload=get_query_payload,
780+
data_release=data_release, cache=cache)
781+
if get_query_payload:
782+
if coordinates is None:
783+
return matches
784+
else:
785+
return matches[0]
786+
762787
if matches is None:
763788
warnings.warn("Query returned no results.", NoResultsWarning)
764789
return
@@ -798,10 +823,22 @@ def get_images(self, coordinates=None, radius=2. * u.arcsec,
798823
799824
"""
800825

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)
826+
readable_objs = self.get_images_async(coordinates=coordinates,
827+
radius=radius,
828+
matches=matches,
829+
run=run,
830+
rerun=rerun,
831+
camcol=camcol,
832+
field=field,
833+
band=band,
834+
timeout=timeout,
835+
cache=cache,
836+
get_query_payload=get_query_payload,
837+
data_release=data_release,
838+
show_progress=show_progress)
839+
840+
if get_query_payload:
841+
return readable_objs
805842

806843
if readable_objs is not None:
807844
if isinstance(readable_objs, dict):

astroquery/sdss/tests/test_sdss.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,62 @@ def test_photoobj_run_camcol_field_payload(patch_request, dr):
454454
assert query_payload['format'] == 'csv'
455455

456456

457+
@pytest.mark.parametrize("dr", dr_list)
458+
def test_get_spectra_specobj_payload(patch_request, dr):
459+
expect = ("SELECT DISTINCT "
460+
"s.run2d, s.plate, s.mjd, s.fiberID "
461+
"FROM PhotoObjAll AS p "
462+
"JOIN SpecObjAll AS s ON p.objID = s.bestObjID "
463+
"WHERE "
464+
"(s.plate=751 AND s.mjd=52251)")
465+
query_payload = sdss.SDSS.get_spectra_async(plate=751, mjd=52251,
466+
get_query_payload=True,
467+
data_release=dr)
468+
assert query_payload['cmd'] == expect
469+
assert query_payload['format'] == 'csv'
470+
471+
472+
@pytest.mark.parametrize("dr", dr_list)
473+
def test_get_spectra_coordinates_payload(patch_request, dr):
474+
expect = ("SELECT\r\n"
475+
"s.run2d, s.plate, s.mjd, s.fiberID, s.SpecObjID AS obj_id, dbo.fPhotoTypeN(p.type) AS type "
476+
"FROM #upload u JOIN #x x ON x.up_id = u.up_id JOIN PhotoObjAll AS p ON p.objID = x.objID "
477+
"JOIN SpecObjAll AS s ON p.objID = s.bestObjID "
478+
"ORDER BY x.up_id")
479+
query_payload = sdss.SDSS.get_spectra_async(coordinates=coords_column,
480+
get_query_payload=True,
481+
data_release=dr)
482+
assert query_payload['uquery'] == expect
483+
assert query_payload['format'] == 'csv'
484+
assert query_payload['photoScope'] == 'nearPrim'
485+
486+
@pytest.mark.parametrize("dr", dr_list)
487+
def test_get_images_photoobj_payload(patch_request, dr):
488+
expect = ("SELECT DISTINCT "
489+
"p.run, p.rerun, p.camcol, p.field "
490+
"FROM PhotoObjAll AS p WHERE "
491+
"(p.run=5714 AND p.camcol=6 AND p.rerun=301)")
492+
query_payload = sdss.SDSS.get_images_async(run=5714, camcol=6,
493+
get_query_payload=True,
494+
data_release=dr)
495+
assert query_payload['cmd'] == expect
496+
assert query_payload['format'] == 'csv'
497+
498+
499+
@pytest.mark.parametrize("dr", dr_list)
500+
def test_get_images_coordinates_payload(patch_request, dr):
501+
expect = ("SELECT\r\n"
502+
"p.run, p.rerun, p.camcol, p.field, dbo.fPhotoTypeN(p.type) AS type "
503+
"FROM #upload u JOIN #x x ON x.up_id = u.up_id JOIN PhotoObjAll AS p ON p.objID = x.objID "
504+
"ORDER BY x.up_id")
505+
query_payload = sdss.SDSS.get_images_async(coordinates=coords_column,
506+
get_query_payload=True,
507+
data_release=dr)
508+
assert query_payload['uquery'] == expect
509+
assert query_payload['format'] == 'csv'
510+
assert query_payload['photoScope'] == 'nearPrim'
511+
512+
457513
@pytest.mark.parametrize("dr", dr_list)
458514
def test_spectra_plate_mjd_payload(patch_request, dr):
459515
expect = ("SELECT DISTINCT "

0 commit comments

Comments
 (0)