Skip to content

Commit

Permalink
additional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 11, 2024
1 parent 734b015 commit 8f9245f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
2 changes: 1 addition & 1 deletion specutils/io/default_loaders/desi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _desi_identify(desitype, origin, *args, **kwargs):
# If the input was a file-like object:
with read_fileobj_or_hdulist(*args, **kwargs) as hdulist:
check0 = ('FIBERMAP' in hdulist and
'EXP_FIBERMAP' in hdulist)
'SCORES' in hdulist)
if desitype == 'spectra':
check1 = 'INFIL000' not in hdulist[0].header
else:
Expand Down
68 changes: 30 additions & 38 deletions specutils/io/default_loaders/tests/test_desi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
has_importlib = True
try:
from importlib.resources import files
except ImportError:
from pkg_resources import resource_filename as files
has_importlib = False
from astropy.utils.data import download_file
from astropy.config import set_temp_cache
import pytest
Expand All @@ -13,6 +7,14 @@
from ....spectra import SpectrumList


has_importlib = True
try:
from importlib.resources import files
except ImportError:
from pkg_resources import resource_filename as files
has_importlib = False


@pytest.fixture(scope="function")
def local_filename(request):
if has_importlib:
Expand All @@ -21,6 +23,14 @@ def local_filename(request):
return files('specutils.io.default_loaders.tests', f't/{request.param}')


@pytest.fixture(scope="function")
def remote_filename(request):
if 'dark' in request.param:
return f'https://data.desi.lbl.gov/public/edr/spectro/redux/fuji/healpix/sv3/dark/260/26065/{request.param}'
else:
return f'https://data.desi.lbl.gov/public/edr/spectro/redux/fuji/tiles/cumulative/169/20210419/{request.param}'


@pytest.mark.parametrize('local_filename, loader', [('coadd-sv3-dark-26065.fits', coadd_loader),
('spectra-sv3-dark-26065.fits', spectra_loader),
('coadd-5-169-thru20210419.fits', coadd_loader),
Expand All @@ -35,52 +45,34 @@ def test_loader(local_filename, loader):
@pytest.mark.parametrize('local_filename', ['coadd-sv3-dark-26065.fits',
'spectra-sv3-dark-26065.fits',
'coadd-5-169-thru20210419.fits',
'spectra-5-169-thru20210419.fits'], indirect=True)
'spectra-5-169-thru20210419.fits'], indirect=['local_filename'])
def test_SpectrumList_reader(local_filename):
spectrum = SpectrumList.read(local_filename) # noqa
assert spectrum[0].meta['band'] == 'b'
assert spectrum[1].meta['band'] == 'r'
assert spectrum[2].meta['band'] == 'z'


@pytest.mark.remote_data
def test_coadd_loader_remote(tmp_path):
coadd = 'https://data.desi.lbl.gov/public/edr/spectro/redux/fuji/healpix/sv3/dark/260/26065/coadd-sv3-dark-26065.fits'
with set_temp_cache(path=str(tmp_path)):
filename = download_file(coadd, cache=True)
spectrum = coadd_loader(filename) # noqa
assert spectrum[0].meta['band'] == 'b'
assert spectrum[1].meta['band'] == 'r'
assert spectrum[2].meta['band'] == 'z'


@pytest.mark.remote_data
def test_spectra_loader_remote(tmp_path):
spectra = 'https://data.desi.lbl.gov/public/edr/spectro/redux/fuji/healpix/sv3/dark/260/26065/spectra-sv3-dark-26065.fits'
@pytest.mark.parametrize('remote_filename, loader', [pytest.param('coadd-sv3-dark-26065.fits', coadd_loader, marks=pytest.mark.remote_data),
pytest.param('spectra-sv3-dark-26065.fits', spectra_loader, marks=pytest.mark.remote_data),
pytest.param('coadd-5-169-thru20210419.fits', coadd_loader, marks=pytest.mark.remote_data),
pytest.param('spectra-5-169-thru20210419.fits', spectra_loader, marks=pytest.mark.remote_data)], indirect=['remote_filename'])
def test_loader_remote(tmp_path, remote_filename, loader):
with set_temp_cache(path=str(tmp_path)):
filename = download_file(spectra, cache=True)
spectrum = spectra_loader(filename) # noqa
assert spectrum[0].meta['band'] == 'b'
assert spectrum[1].meta['band'] == 'r'
assert spectrum[2].meta['band'] == 'z'


@pytest.mark.remote_data
def test_SpectrumList_coadd_reader_remote(tmp_path):
coadd = 'https://data.desi.lbl.gov/public/edr/spectro/redux/fuji/healpix/sv3/dark/260/26065/coadd-sv3-dark-26065.fits'
with set_temp_cache(path=str(tmp_path)):
filename = download_file(coadd, cache=True)
spectrum = SpectrumList.read(filename) # noqa
filename = download_file(remote_filename, cache=True)
spectrum = loader(filename) # noqa
assert spectrum[0].meta['band'] == 'b'
assert spectrum[1].meta['band'] == 'r'
assert spectrum[2].meta['band'] == 'z'


@pytest.mark.remote_data
def test_SpectrumList_spectra_reader_remote(tmp_path):
spectra = 'https://data.desi.lbl.gov/public/edr/spectro/redux/fuji/healpix/sv3/dark/260/26065/spectra-sv3-dark-26065.fits'
@pytest.mark.parametrize('remote_filename', [pytest.param('coadd-sv3-dark-26065.fits', marks=pytest.mark.remote_data),
pytest.param('spectra-sv3-dark-26065.fits', marks=pytest.mark.remote_data),
pytest.param('coadd-5-169-thru20210419.fits', marks=pytest.mark.remote_data),
pytest.param('spectra-5-169-thru20210419.fits', marks=pytest.mark.remote_data)], indirect=['remote_filename'])
def test_SpectrumList_reader_remote(tmp_path, remote_filename):
with set_temp_cache(path=str(tmp_path)):
filename = download_file(spectra, cache=True)
filename = download_file(remote_filename, cache=True)
spectrum = SpectrumList.read(filename) # noqa
assert spectrum[0].meta['band'] == 'b'
assert spectrum[1].meta['band'] == 'r'
Expand Down

0 comments on commit 8f9245f

Please sign in to comment.