Skip to content

Commit cbec82e

Browse files
authored
Merge pull request #2214 from weaverba137/sdss-spectra-url
Update Spectra URLs
2 parents e440f2b + 6d47ac7 commit cbec82e

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ New Tools and Services
88
Service fixes and enhancements
99
------------------------------
1010

11+
sdss
12+
^^^^
13+
14+
- Fix URL for individual spectrum file download in recent data releases. [#2214]
1115

1216
Infrastructure, Utility and Other Changes and Additions
1317
-------------------------------------------------------

astroquery/sdss/core.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class SDSSClass(BaseQuery):
3838
'{rerun}/{run}/{camcol}/'
3939
'frame-{band}-{run:06d}-{camcol}-'
4040
'{field:04d}.fits.bz2')
41-
SPECTRA_URL_SUFFIX = ('{base}/dr{dr}/{instrument}/spectro/redux/'
42-
'{run2d}/spectra/{plate:04d}/'
43-
'spec-{plate:04d}-{mjd}-{fiber:04d}.fits')
41+
SPECTRA_URL_SUFFIX = ('{base}/dr{dr}/sdss/spectro/redux/'
42+
'{run2d}/spectra/{plate:0>4d}/'
43+
'spec-{plate:0>4d}-{mjd}-{fiber:04d}.fits')
4444

4545
TEMPLATES_URL = 'http://classic.sdss.org/dr7/algorithms/spectemplates/spDR2'
4646
# Cross-correlation templates from DR-7 - no clear way to look this up via
@@ -555,7 +555,7 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
555555

556556
if not matches:
557557
request_payload = self._args_to_payload(
558-
specobj_fields=['instrument', 'run2d', 'plate',
558+
specobj_fields=['run2d', 'plate',
559559
'mjd', 'fiberID'],
560560
coordinates=coordinates, radius=radius, spectro=True,
561561
plate=plate, mjd=mjd, fiberID=fiberID,
@@ -583,14 +583,16 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
583583
# - run2d sometimes (#739)
584584
if isinstance(row['run2d'], bytes):
585585
run2d = row['run2d'].decode()
586+
elif isinstance(row['run2d'], (np.integer, int)):
587+
run2d = str(row['run2d'])
586588
else:
587589
run2d = row['run2d']
590+
if data_release > 15 and run2d not in ('26', '103', '104'):
591+
linkstr = linkstr.replace('/spectra/', '/spectra/full/')
588592
link = linkstr.format(
589593
base=conf.sas_baseurl, dr=data_release,
590-
instrument=row['instrument'].lower(),
591594
run2d=run2d, plate=row['plate'],
592595
fiber=row['fiberID'], mjd=row['mjd'])
593-
594596
results.append(commons.FileContainer(link,
595597
encoding='binary',
596598
remote_timeout=timeout,
@@ -859,9 +861,12 @@ def _parse_result(self, response, verbose=False):
859861

860862
if 'error_message' in io.BytesIO(response.content):
861863
raise RemoteServiceError(response.content)
864+
skip_header = 0
865+
if response.content.startswith(b'#Table'):
866+
skip_header = 1
862867
arr = np.atleast_1d(np.genfromtxt(io.BytesIO(response.content),
863868
names=True, dtype=None,
864-
delimiter=',', skip_header=1,
869+
delimiter=',', skip_header=skip_header,
865870
comments='#'))
866871

867872
if len(arr) == 0:

astroquery/sdss/field_names.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
# Default photometric and spectroscopic quantities to retrieve.
1818
photoobj_defs = ['ra', 'dec', 'objid', 'run', 'rerun', 'camcol', 'field']
19-
specobj_defs = ['z', 'plate', 'mjd', 'fiberID', 'specobjid', 'run2d',
20-
'instrument']
19+
specobj_defs = ['z', 'plate', 'mjd', 'fiberID', 'specobjid', 'run2d']
2120
crossid_defs = ['ra', 'dec', 'psfMag_u', 'psfMagerr_u', 'psfMag_g',
2221
'psfMagerr_g', 'psfMag_r', 'psfMagerr_r', 'psfMag_i',
2322
'psfMagerr_i', 'psfMag_z', 'psfMagerr_z']

astroquery/sdss/tests/test_sdss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def data_path(filename):
125125
coords_column = Column(coords_list, name='coordinates')
126126

127127
# List of all data releases.
128-
dr_list = list(range(1, sdss.conf.default_release + 1))
128+
dr_list = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
129129

130130

131131
# We are not testing queries for DR11 because it is not easily available to

astroquery/sdss/tests/test_sdss_remote.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from ... import sdss
1212
from ...exceptions import TimeoutError
1313

14+
# DR11 is a quasi-internal data release that does not have SkyServer support.
15+
dr_list = (8, 9, 10, 12, 13, 14, 15, 16)
16+
1417

1518
@pytest.mark.remote_data
1619
class TestSDSSRemote:
@@ -34,10 +37,19 @@ def test_images_timeout(self):
3437
"error with 'No route to host'. We don't know a "
3538
"workaround for this yet.")
3639

37-
def test_sdss_spectrum(self):
38-
xid = sdss.SDSS.query_region(self.coords, spectro=True)
40+
@pytest.mark.parametrize("dr", dr_list)
41+
def test_sdss_spectrum(self, dr):
42+
xid = sdss.SDSS.query_region(self.coords, spectro=True, data_release=dr)
3943
assert isinstance(xid, Table)
40-
sp = sdss.SDSS.get_spectra(matches=xid)
44+
sp = sdss.SDSS.get_spectra(matches=xid, data_release=dr)
45+
46+
def test_sdss_spectrum_plate_mjd_fiber(self):
47+
"""These plates are only available in recent data releases.
48+
"""
49+
sp = sdss.SDSS.get_spectra(plate=9403, mjd=58018, fiberID=485,
50+
data_release=16)
51+
sp = sdss.SDSS.get_spectra(plate=10909, mjd=58280, fiberID=485,
52+
data_release=16)
4153

4254
def test_sdss_spectrum_mjd(self):
4355
sp = sdss.SDSS.get_spectra(plate=2345, fiberID=572)
@@ -75,25 +87,22 @@ def test_sdss_image_coord(self):
7587

7688
def test_sdss_specobj(self):
7789
colnames = ['ra', 'dec', 'objid', 'run', 'rerun', 'camcol', 'field',
78-
'z', 'plate', 'mjd', 'fiberID', 'specobjid', 'run2d',
79-
'instrument']
90+
'z', 'plate', 'mjd', 'fiberID', 'specobjid', 'run2d']
8091
dtypes = [float, float, np.int64, int, int, int, int, float, int, int,
81-
int, np.int64, int, bytes]
92+
int, np.int64, int]
8293
data = [
8394
[46.8390680395307, 5.16972676625711, 1237670015125750016, 5714,
8495
301, 2, 185, -0.0006390358, 2340, 53733, 291, 2634685834112034816,
85-
26, 'SDSS'],
96+
26],
8697
[46.8705377929765, 5.42458826592292, 1237670015662621224, 5714,
87-
301, 3, 185, 0, 2340, 53733, 3, 2634606669274834944, 26, 'SDSS'],
98+
301, 3, 185, 0, 2340, 53733, 3, 2634606669274834944, 26],
8899
[46.8899751105478, 5.09432755808192, 1237670015125815346, 5714,
89100
301, 2, 186, -4.898809E-05, 2340, 53733, 287, 2634684734600407040,
90-
26, 'SDSS'],
101+
26],
91102
[46.8954031261838, 5.9739184644185, 1237670016199491831, 5714,
92-
301, 4, 185, 0, 2340, 53733, 329, 2634696279472498688, 26,
93-
'SDSS'],
103+
301, 4, 185, 0, 2340, 53733, 329, 2634696279472498688, 26],
94104
[46.9155836662379, 5.50671723824944, 1237670015662686398, 5714,
95-
301, 3, 186, 0, 2340, 53733, 420, 2634721293362030592, 26,
96-
'SDSS']]
105+
301, 3, 186, 0, 2340, 53733, 420, 2634721293362030592, 26]]
97106
table = Table(data=[x for x in zip(*data)],
98107
names=colnames, dtype=dtypes)
99108
xid = sdss.SDSS.query_specobj(plate=2340)

0 commit comments

Comments
 (0)