Skip to content

Commit

Permalink
Merge fd5ca40 into c02ee8b
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Nov 27, 2018
2 parents c02ee8b + fd5ca40 commit 08e2659
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ env:
- NUMPY_VERSION=stable
- ASTROPY_VERSION=stable
- MAIN_CMD='python setup.py'
- SETUP_CMD='test'
- SETUP_CMD='test --remote-data=any'
- PIP_DEPENDENCIES='gwcs scipy matplotlib'
- EVENT_TYPE='pull_request push'
- CONDA_DEPENDENCIES=''
- CONDA_DEPENDENCIES='pytest-remotedata'
- CONDA_CHANNELS='astropy-ci-extras'

# If there are matplotlib or other GUI tests, uncomment the following
Expand All @@ -53,11 +53,11 @@ matrix:
include:
# Try MacOS X
- os: osx
env: SETUP_CMD='test'
env: SETUP_CMD='test --remote-data=any'

# Do a coverage test.
- os: linux
env: SETUP_CMD='test --coverage'
env: SETUP_CMD='test --coverage --remote-data=any'

# Check for sphinx doc build warnings - we do this first because it
# may run for a long time
Expand All @@ -70,7 +70,8 @@ matrix:
# time.

- os: linux
env: PYTHON_VERSION=3.5 ASTROPY_VERSION=lts
# pytest>=3.7,<4 is not supported by Astropy LTS
env: PYTHON_VERSION=3.5 ASTROPY_VERSION=lts PYTEST_VERSION=3.6
- os: linux
env: NUMPY_VERSION=1.14
- os: linux
Expand Down
23 changes: 12 additions & 11 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,22 @@ may have downloaded from some archive, or reduced from your own observations.

Now we load the dataset from it's canonical source:

>>> f = fits.open('https://dr14.sdss.org/optical/spectrum/view/data/format=fits/spec=lite?plateid=1323&mjd=52797&fiberid=12') # doctest: +IGNORE_OUTPUT
>>> specdata = f[1].data # The spectrum is in the second HDU of this file.
>>> f.close()
>>> f = fits.open('https://dr14.sdss.org/optical/spectrum/view/data/format=fits/spec=lite?plateid=1323&mjd=52797&fiberid=12') # doctest: +IGNORE_OUTPUT +REMOTE_DATA
>>> # The spectrum is in the second HDU of this file.
>>> specdata = f[1].data # doctest: +REMOTE_DATA
>>> f.close() # doctest: +REMOTE_DATA

Then we re-format this dataset into astropy quantities, and create a
`~specutils.Spectrum1D` object:

>>> from specutils import Spectrum1D
>>> lamb = 10**specdata['loglam'] * u.AA
>>> flux = specdata['flux'] * 10**-17 * u.Unit('erg cm-2 s-1 AA-1')
>>> spec = Spectrum1D(spectral_axis=lamb, flux=flux)
>>> lamb = 10**specdata['loglam'] * u.AA # doctest: +REMOTE_DATA
>>> flux = specdata['flux'] * 10**-17 * u.Unit('erg cm-2 s-1 AA-1') # doctest: +REMOTE_DATA
>>> spec = Spectrum1D(spectral_axis=lamb, flux=flux) # doctest: +REMOTE_DATA

And we plot it:

>>> lines = plt.step(spec.spectral_axis, spec.flux)
>>> lines = plt.step(spec.spectral_axis, spec.flux) # doctest: +REMOTE_DATA

Now maybe you want the equivalent width of a spectral line. That requires
normalizing by a continuum estimate:
Expand All @@ -80,9 +81,9 @@ normalizing by a continuum estimate:
:context: close-figs

>>> from specutils.fitting import fit_generic_continuum
>>> cont_norm_spec = spec / fit_generic_continuum(spec)(spec.spectral_axis)
>>> lines = plt.step(cont_norm_spec.wavelength, cont_norm_spec.flux)
>>> plt.xlim(654*u.nm, 660*u.nm) # doctest: +IGNORE_OUTPUT
>>> cont_norm_spec = spec / fit_generic_continuum(spec)(spec.spectral_axis) # doctest: +REMOTE_DATA
>>> lines = plt.step(cont_norm_spec.wavelength, cont_norm_spec.flux) # doctest: +REMOTE_DATA
>>> plt.xlim(654*u.nm, 660*u.nm) # doctest: +IGNORE_OUTPUT +REMOTE_DATA

But then you can apply a single function over the region of the spectrum
containing the line:
Expand All @@ -91,7 +92,7 @@ containing the line:
>>> from specutils import SpectralRegion
>>> from specutils.analysis import equivalent_width
>>> equivalent_width(cont_norm_spec, regions=SpectralRegion(6562*u.AA, 6575*u.AA))
>>> equivalent_width(cont_norm_spec, regions=SpectralRegion(6562*u.AA, 6575*u.AA)) # doctest: +REMOTE_DATA
<Quantity -14.78092438 Angstrom>
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ minversion = 3.1
testpaths = "specutils" "docs"
norecursedirs = build docs/_build
doctest_plus = enabled
remote_data_strict = True
# The remote data tests will run by default. Passing --remote-data=none on the
# command line will override this setting.
addopts = --remote-data=any --doctest-rst

[ah_bootstrap]
auto_use = True
Expand Down
9 changes: 8 additions & 1 deletion specutils/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
# by importing them here in conftest.py they are discoverable by py.test
# no matter how it is invoked within the source tree.

from astropy.tests.pytest_plugins import *
from astropy.version import version as astropy_version
# TODO: Remove once it is no longer necessary to support Astropy LTS
if astropy_version < '3':
from astropy.tests.plugins import *
else:
from astropy.tests.plugins.display import (PYTEST_HEADER_MODULES,
TESTED_VERSIONS)
from astropy.tests.helper import enable_deprecations_as_exceptions

## Uncomment the following line to treat all DeprecationWarnings as
## exceptions
Expand Down
7 changes: 6 additions & 1 deletion specutils/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def remote_data_path(request):
Remotely access the Zenodo deposition archive to retrieve the versioned
test data.
"""
# Make use of configuration option from pytest-remotedata in order to
# control access to remote data.
if request.config.getoption('remote_data', 'any') != 'any':
pytest.skip()

file_id, file_name = request.param.values()

url = "https://zenodo.org/record/{}/files/{}?download=1".format(
Expand All @@ -24,4 +29,4 @@ def remote_data_path(request):
with urllib.request.urlopen(url) as r, open(file_path, 'wb') as tmp_file:
tmp_file.write(r.read())

yield file_path
yield file_path
2 changes: 2 additions & 0 deletions specutils/tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_hst_stis(remote_data_path):
assert spec.flux.size > 0


@pytest.mark.remote_data
def test_sdss_spec():
with urllib.request.urlopen('https://dr14.sdss.org/optical/spectrum/view/data/format%3Dfits/spec%3Dlite?mjd=55359&fiberid=596&plateid=4055') as response:
with tempfile.NamedTemporaryFile() as tmp_file:
Expand All @@ -114,6 +115,7 @@ def test_sdss_spec():
assert spec.flux.size > 0


@pytest.mark.remote_data
def test_sdss_spspec():
with urllib.request.urlopen('http://das.sdss.org/spectro/1d_26/0273/1d/spSpec-51957-0273-016.fit') as response:
with tempfile.NamedTemporaryFile() as tmp_file:
Expand Down

0 comments on commit 08e2659

Please sign in to comment.