Skip to content

Commit 2aeb51e

Browse files
committed
Update after initial review; remote tests working.
1 parent ae122d6 commit 2aeb51e

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

astroquery/sdss/core.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ def query_region_async(self, coordinates, *, radius=None,
294294
ValueError
295295
If both ``radius`` and ``width`` are set (or neither),
296296
or if the ``radius`` exceeds 3 arcmin,
297-
or if the sizes of ``coordinates`` and ``obj_names`` do not match.
297+
or if the sizes of ``coordinates`` and ``obj_names`` do not match,
298+
or if the units of ``width`` or ``height`` could not be parsed.
298299
299300
Examples
300301
--------
@@ -322,9 +323,9 @@ def query_region_async(self, coordinates, *, radius=None,
322323
radius = 2.0 * u.arcsec
323324

324325
if radius is None and width is None:
325-
raise ValueError("Either radius or width must be selected!")
326+
raise ValueError("Either radius or width must be specified!")
326327
if radius is not None and width is not None:
327-
raise ValueError("Either radius or width must be selected!")
328+
raise ValueError("Either radius or width must be specified, not both!")
328329

329330
if radius is not None:
330331
request_payload, files = self.query_crossid_async(coordinates=coordinates,
@@ -339,25 +340,11 @@ def query_region_async(self, coordinates, *, radius=None,
339340
data_release=data_release)
340341

341342
if width is not None:
342-
if isinstance(width, Angle):
343-
width = width.to_value(u.degree)
344-
else:
345-
try:
346-
width = Angle(width).to_value(u.degree)
347-
except ValueError:
348-
raise TypeError("width should be either Quantity or "
349-
"convertible to float.")
343+
width = u.Quantity(width, u.degree).value
350344
if height is None:
351345
height = width
352346
else:
353-
if isinstance(height, Angle):
354-
height = height.to_value(u.degree)
355-
else:
356-
try:
357-
height = Angle(height).to_value(u.degree)
358-
except ValueError:
359-
raise TypeError("height should be either Quantity or "
360-
"convertible to float.")
347+
height = u.Quantity(height, u.degree).value
361348

362349
dummy_payload = self._args_to_payload(coordinates=coordinates,
363350
fields=fields,
@@ -378,7 +365,7 @@ def query_region_async(self, coordinates, *, radius=None,
378365
coordinates = [coordinates]
379366

380367
rectangles = list()
381-
for n, target in enumerate(coordinates):
368+
for target in coordinates:
382369
# Query for a rectangle
383370
target = commons.parse_coordinates(target).transform_to('fk5')
384371
rectangles.append(self._rectangle_sql(target.ra.degree, target.dec.degree, width, height=height))

astroquery/sdss/tests/test_sdss.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,14 @@ def test_sdss_photoobj(patch_request, dr):
275275
@pytest.mark.parametrize("radius", [None, Angle('2 arcsec')])
276276
@pytest.mark.parametrize("width", [None, Angle('2 arcsec')])
277277
def test_list_coordinates(patch_request, dr, radius, width):
278-
if (radius is None and width is None) or (radius is not None and width is not None):
278+
if (radius is None and width is None):
279279
with pytest.raises(ValueError) as e:
280280
sdss.SDSS.query_region(coords, radius=radius, width=width)
281-
assert str(e.value) == "Either radius or width must be selected!"
281+
assert str(e.value) == "Either radius or width must be specified!"
282+
elif (radius is not None and width is not None):
283+
with pytest.raises(ValueError) as e:
284+
sdss.SDSS.query_region(coords, radius=radius, width=width)
285+
assert str(e.value) == "Either radius or width must be specified, not both!"
282286
else:
283287
xid = sdss.SDSS.query_region(coords_list, radius=radius, width=width, data_release=dr)
284288

@@ -298,16 +302,25 @@ def test_list_coordinates(patch_request, dr, radius, width):
298302
url_tester(dr)
299303

300304

301-
@pytest.mark.parametrize("width", [Angle('2 arcsec'), 2.0 * u.arcsec, '2.0 arcsec', 'bad angle'])
302-
@pytest.mark.parametrize("height", [None, Angle('2 arcsec'), 2.0 * u.arcsec, '2.0 arcsec', 'bad angle'])
305+
@pytest.mark.parametrize("width", [Angle('2 arcsec'), 2.0 * u.arcsec, '2.0 arcsec', 'bad angle', '2.0 things'])
306+
@pytest.mark.parametrize("height", [None, Angle('2 arcsec'), 2.0 * u.arcsec, '2.0 arcsec', 'bad angle', '2.0 things'])
303307
def test_list_coordinates_with_height(patch_request, width, height):
304-
if width == 'bad angle' or height == 'bad angle':
308+
if width == 'bad angle':
305309
with pytest.raises(TypeError) as e:
306310
sdss.SDSS.query_region(coords, width=width, height=height)
307-
if width == 'bad angle':
308-
assert str(e.value) == "width should be either Quantity or convertible to float."
309-
else:
310-
assert str(e.value) == "height should be either Quantity or convertible to float."
311+
assert str(e.value) == 'Cannot parse "bad angle" as a Quantity. It does not start with a number.'
312+
elif width == '2.0 things':
313+
with pytest.raises(ValueError) as e:
314+
sdss.SDSS.query_region(coords, width=width, height=height)
315+
assert str(e.value).startswith("'things' did not parse as unit")
316+
elif height == 'bad angle':
317+
with pytest.raises(TypeError) as e:
318+
sdss.SDSS.query_region(coords, width=width, height=height)
319+
assert str(e.value) == 'Cannot parse "bad angle" as a Quantity. It does not start with a number.'
320+
elif height == '2.0 things':
321+
with pytest.raises(ValueError) as e:
322+
sdss.SDSS.query_region(coords, width=width, height=height)
323+
assert str(e.value).startswith("'things' did not parse as unit")
311324
else:
312325
xid = sdss.SDSS.query_region(coords_list, width=width, height=height)
313326

astroquery/sdss/tests/test_sdss_remote.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from numpy.testing import assert_allclose
44
import pytest
55

6+
import astropy.units as u
67
from astropy.coordinates import SkyCoord
78
from astropy.table import Table
89
from astropy.utils.exceptions import AstropyUserWarning
@@ -36,7 +37,7 @@ def test_images_timeout(self):
3637
This test *must* be run before `test_sdss_image` because that query
3738
caches!
3839
"""
39-
xid = sdss.SDSS.query_region(self.coords)
40+
xid = sdss.SDSS.query_region(self.coords, width=2.0 * u.arcsec)
4041
assert len(xid) == 18
4142
try:
4243
with pytest.raises(TimeoutError):
@@ -51,9 +52,9 @@ def test_images_timeout(self):
5152
def test_sdss_spectrum(self, dr):
5253
if dr in dr_warn_list:
5354
with pytest.warns(AstropyUserWarning, match='Field info are not available for this data release'):
54-
xid = sdss.SDSS.query_region(self.coords, spectro=True, data_release=dr)
55+
xid = sdss.SDSS.query_region(self.coords, width=2.0 * u.arcsec, spectro=True, data_release=dr)
5556
else:
56-
xid = sdss.SDSS.query_region(self.coords, spectro=True, data_release=dr)
57+
xid = sdss.SDSS.query_region(self.coords, width=2.0 * u.arcsec, spectro=True, data_release=dr)
5758

5859
assert isinstance(xid, Table)
5960
sdss.SDSS.get_spectra(matches=xid, data_release=dr)
@@ -85,7 +86,7 @@ class = 'galaxy'
8586
assert isinstance(xid, Table)
8687

8788
def test_sdss_image(self):
88-
xid = sdss.SDSS.query_region(self.coords)
89+
xid = sdss.SDSS.query_region(self.coords, width=2.0 * u.arcsec)
8990
assert isinstance(xid, Table)
9091
sdss.SDSS.get_images(matches=xid)
9192

@@ -170,14 +171,14 @@ def test_spectra_timeout(self):
170171

171172
def test_query_non_default_field(self):
172173
# A regression test for #469
173-
query1 = sdss.SDSS.query_region(self.coords, fields=['r', 'psfMag_r'])
174+
query1 = sdss.SDSS.query_region(self.coords, width=2.0 * u.arcsec, fields=['r', 'psfMag_r'])
174175

175-
query2 = sdss.SDSS.query_region(self.coords, fields=['ra', 'dec', 'r'])
176+
query2 = sdss.SDSS.query_region(self.coords, width=2.0 * u.arcsec, fields=['ra', 'dec', 'r'])
176177
assert isinstance(query1, Table)
177178
assert isinstance(query2, Table)
178179

179-
assert query1.colnames == ['objID', 'r', 'psfMag_r']
180-
assert query2.colnames == ['objID', 'ra', 'dec', 'r']
180+
assert query1.colnames == ['r', 'psfMag_r']
181+
assert query2.colnames == ['ra', 'dec', 'r']
181182

182183
@pytest.mark.parametrize("dr", dr_list)
183184
def test_query_crossid(self, dr):

docs/sdss/sdss.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ photometry:
2828
>>> from astroquery.sdss import SDSS
2929
>>> from astropy import coordinates as coords
3030
>>> pos = coords.SkyCoord('0h8m05.63s +14d50m23.3s', frame='icrs')
31-
>>> xid = SDSS.query_region(pos, spectro=True)
31+
>>> xid = SDSS.query_region(pos, radius='5 arcsec', spectro=True)
3232
>>> print(xid)
3333
ra dec ... specobjid run2d
3434
---------------- ---------------- ... ------------------ -----

0 commit comments

Comments
 (0)