Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwestfall committed Oct 19, 2023
1 parent 33a1520 commit 4379d29
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pypeit/tests/test_specutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
from pypeit import specobjs
from pypeit.specutils import Spectrum1D, SpectrumList
from pypeit.tests import tstutils
from pypeit.pypmsgs import PypeItError

import pytest
specutils_required = pytest.mark.skipif(Spectrum1D is None or SpectrumList is None,
reason='specutils not installed')


@specutils_required
def test_onespec_io():
rng = np.random.default_rng()
Expand Down Expand Up @@ -134,3 +136,32 @@ def test_spec1d_io():

ofile.unlink()


@specutils_required
def test_onespec_monotonic():
rng = np.random.default_rng(999)
grid_wave = np.linspace(3500,10000,1000)
wave = grid_wave + (10*rng.uniform(size=grid_wave.size) - 1)
flux = np.ones(1000, dtype=float)
# TODO: PYP_SPEC is required if we want to be able to read the file!
spec = onespec.OneSpec(wave, grid_wave, flux, PYP_SPEC='shane_kast_blue')
ofile = Path(tstutils.data_path('tmp.fits')).resolve()
spec.to_file(str(ofile), overwrite=True)

with pytest.raises(PypeItError):
# Should fault because the wavelength vector is not monotonically
# increasing
_spec = Spectrum1D.read(ofile)

# This will be fine because the grid *is* monotonically increasing
_spec = Spectrum1D.read(ofile, grid=True)

# This should be fine because reader will remove non-monotonically
# increasing wavelength measurements.
__spec = Spectrum1D.read(ofile, strict=False)

assert _spec.shape[0] > __spec.shape[0], 'Strict should remove data'

ofile.unlink()


0 comments on commit 4379d29

Please sign in to comment.