Skip to content

Commit

Permalink
Fix SDSS-I/II spSpec units (astropy#1066)
Browse files Browse the repository at this point in the history
* Add test for checking SDSS wavelength

* Enforce Angstroms in SDSS

* Add links to SDSS-I/II spectra formats docs

This should mean that future editors of those loaders (e.g. to add new
features or fix bugs) know what they can assume about the files.
  • Loading branch information
aragilar authored and rosteen committed Aug 15, 2023
1 parent c6b8be6 commit f6d8525
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions specutils/io/default_loaders/sdss.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def _sdss_wcs_to_log_wcs(old_wcs):
claims to be linear, but is logarithmic in base-10.
The wavelength is given by:
λ = 10^(w0 + w1 * i)
with i being the pixel index starting from 0.
with i being the pixel index starting from 0. This formula is documented at
https://classic.sdss.org/dr7/products/spectra/read_spSpec.php and appears to
be the same across all SDSS-I and SDSS-II data releases (replace dr7 with
dr<x> in the above URL).
The FITS standard uses a natural log with a sightly different formulation,
see WCS Paper 3 (which discusses spectral WCS).
Expand All @@ -41,7 +44,7 @@ def _sdss_wcs_to_log_wcs(old_wcs):
w1 = old_wcs.wcs.cd[0,0]
crval = 10 ** w0
cdelt = crval * w1 * np.log(10)
cunit = old_wcs.wcs.cunit[0] or Unit('Angstrom')
cunit = Unit('Angstrom')
ctype = "WAVE-LOG"

w = WCS(naxis=1)
Expand Down Expand Up @@ -147,6 +150,11 @@ def spSpec_loader(file_obj, **kwargs):
"""
Loader for SDSS-I/II spSpec files.
The content of these files is documented at
https://classic.sdss.org/dr7/dm/flatFiles/spSpec.php, with instructions for
reading them at
https://classic.sdss.org/dr7/products/spectra/read_spSpec.php.
Parameters
----------
file_obj: str, file-like, or HDUList
Expand Down
1 change: 1 addition & 0 deletions specutils/tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_sdss_spspec(tmp_path):
spec = Spectrum1D.read(response, format="SDSS-I/II spSpec")
assert isinstance(spec, Spectrum1D)
assert spec.flux.size > 0
assert (spec.wavelength[0] / u.AA).value == pytest.approx(3799.268615)

file_path = str(tmp_path / sp_pattern)
with urllib.request.urlopen(url) as response:
Expand Down

0 comments on commit f6d8525

Please sign in to comment.