From 8f9245fc907acad2bc9a670ef742faf8566ce39d Mon Sep 17 00:00:00 2001 From: Benjamin Alan Weaver Date: Wed, 10 Jan 2024 18:07:56 -0700 Subject: [PATCH] additional parameters --- specutils/io/default_loaders/desi.py | 2 +- .../io/default_loaders/tests/test_desi.py | 68 ++++++++----------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/specutils/io/default_loaders/desi.py b/specutils/io/default_loaders/desi.py index c18767590..4b48e492a 100644 --- a/specutils/io/default_loaders/desi.py +++ b/specutils/io/default_loaders/desi.py @@ -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: diff --git a/specutils/io/default_loaders/tests/test_desi.py b/specutils/io/default_loaders/tests/test_desi.py index 0f2ef81c2..23f52cdbe 100644 --- a/specutils/io/default_loaders/tests/test_desi.py +++ b/specutils/io/default_loaders/tests/test_desi.py @@ -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 @@ -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: @@ -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), @@ -35,7 +45,7 @@ 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' @@ -43,44 +53,26 @@ def test_SpectrumList_reader(local_filename): 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'