Skip to content

Commit

Permalink
Removing aesop dependence for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Dec 3, 2018
1 parent 2ccc9e9 commit 22f0257
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env:

# List runtime dependencies for the package that are available as conda
# packages here.
- CONDA_DEPENDENCIES='h5py matplotlib'
- CONDA_DEPENDENCIES='h5py matplotlib specutils'
- CONDA_DEPENDENCIES_DOC='sphinx-astropy h5py matplotlib'

# List other runtime dependencies for the package that are available as
Expand Down
86 changes: 81 additions & 5 deletions arcesetc/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,103 @@
import os
import pytest
from aesop import EchelleSpectrum
import numpy as np
import astropy.units as u
from astropy.io import fits
from specutils.io import read_fits

from ..util import (reconstruct_order, closest_sptype, archive, scale_flux,
signal_to_noise_to_exp_time)

path = os.path.dirname(__file__)


@pytest.mark.parametrize("order", [25, 35, 41, 60, 84, 89])
class Spectrum1D(object):
"""
Simple 1D spectrum object; taken from `aesop`.
A ``Spectrum1D`` object can be used to describe one order of an echelle
spectrum, for example.
If the spectrum is initialized with ``wavelength``s that are not strictly
increasing, ``Spectrum1D`` will sort the ``wavelength``, ``flux`` and
``mask`` arrays so that ``wavelength`` is monotonically increasing.
"""
@u.quantity_input(wavelength=u.Angstrom)
def __init__(self, wavelength=None, flux=None, name=None, mask=None,
wcs=None, meta=dict(), time=None, continuum_normalized=None):
"""
Parameters
----------
wavelength : `~numpy.ndarray`
Wavelengths
flux : `~numpy.ndarray`
Fluxes
name : str (optional)
Name for the spectrum
mask : `~numpy.ndarray` (optional)
Boolean mask of the same shape as ``flux``
wcs : `~specutils.Spectrum1DLookupWCS` (optional)
Store the WCS parameters
meta : dict (optional)
Metadata dictionary.
continuum_normalized : bool (optional)
Is this spectrum continuum normalized?
"""

# Are wavelengths stored in increasing order?
wl_inc = np.all(np.diff(wavelength) > 0)

# If not, force them to be, to simplify linear interpolation later.
if not wl_inc:
wl_sort = np.argsort(wavelength)
wavelength = wavelength[wl_sort]
flux = flux[wl_sort]
if mask is not None:
mask = mask[wl_sort]

self.wavelength = wavelength
self.wavelength_unit = wavelength.unit
self.flux = flux if hasattr(flux, 'unit') else u.Quantity(flux)
self.name = name
self.mask = mask
self.wcs = wcs
self.meta = meta
self.time = time
self.continuum_normalized = continuum_normalized

@classmethod
def from_specutils(cls, spectrum1d, name=None, **kwargs):
"""
Convert a `~specutils.Spectrum1D` object into our Spectrum1D object.
Parameters
----------
spectrum1d : `~specutils.Spectrum1D`
Input spectrum
name : str
Target/spectrum name
"""
return cls(wavelength=spectrum1d.wavelength, flux=spectrum1d.flux,
mask=spectrum1d._mask, name=name, **kwargs)


@pytest.mark.parametrize("order", [35, 41, 60])
def test_reconstruct_order(order):
"""
End-to-end functional test on several well-behaved orders of an early-type
star.
"""
b3v = EchelleSpectrum.from_fits(os.path.join(path, os.pardir, 'data',
'HR3454.0016.wfrmcpc.fits'))

fits_path = os.path.join(path, os.pardir, 'data', 'HR3454.0016.wfrmcpc.fits')

b3v = [Spectrum1D.from_specutils(s)
for s in read_fits.read_fits_spectrum1d(fits_path)]
header = fits.getheader(fits_path)

wave, flux, sp_type, exp_time = reconstruct_order('B3V',
b3v[order].wavelength.mean(),
4.3,
exp_time=b3v.header['EXPTIME']*u.s)
exp_time=header['EXPTIME']*u.s)

interp_flux = np.interp(b3v[order].wavelength, wave, flux)
np.testing.assert_allclose(b3v[order].flux, interp_flux, atol=500, rtol=1e-1)
Expand Down

0 comments on commit 22f0257

Please sign in to comment.