Skip to content

Commit

Permalink
Merge pull request #92 from pllim/doctest
Browse files Browse the repository at this point in the history
TST: doctest and linkcheck
  • Loading branch information
pllim authored Oct 10, 2019
2 parents cccbfc2 + 12224d4 commit 9b0d584
Show file tree
Hide file tree
Showing 24 changed files with 390 additions and 359 deletions.
18 changes: 18 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ stages:
codecov_token: $(CODECOV_TOKEN)
displayName: 'Calculate coverage'

- job: 'LinkCheck'
pool:
vmImage: 'Ubuntu-16.04'
strategy:
maxParallel: 4

steps:
- task: UsePythonVersion@0

- script: |
python -m pip install --upgrade pip setuptools
pip install sphinx-astropy
python setup.py install
- bash: |
cd docs
make linkcheck
displayName: 'Run docs link check'
- template: azure-templates.yml
parameters:
name: 'Older_Versions'
Expand Down
8 changes: 8 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@
intersphinx_mapping.update({
'astropy': ('https://docs.astropy.org/en/latest/', None),
'synphot': ('https://synphot.readthedocs.io/en/latest/', None)})


# -- Options for linkcheck output -------------------------------------------
linkcheck_retry = 5
linkcheck_ignore = ['https://hsthelp.stsci.edu',
'https://www.as.arizona.edu/observing']
linkcheck_timeout = 180
linkcheck_anchors = False
53 changes: 30 additions & 23 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. doctest-skip-all
.. _stsynphot_index:

*********************************************
Expand Down Expand Up @@ -98,16 +96,22 @@ Below are the instructions to install:
stsynphot/data_hst
stsynphot/data_jwst

.. testsetup::

>>> # This is not marked remote data because it is essential for VEGAMAG
>>> from stsynphot.spectrum import load_vega
>>> load_vega(vegafile='http://ssb.stsci.edu/cdbs/calspec/alpha_lyr_stis_009.fits', encoding='binary') # doctest: +IGNORE_OUTPUT

To ensure consistency for all data files used, **stsynphot silently overwrites
synphot data file locations within the Python session**. For example::

>>> from synphot.config import conf as syn_conf
>>> print(syn_conf.johnson_v_file)
>>> print(syn_conf.johnson_v_file) # doctest: +IGNORE_OUTPUT
http://ssb.stsci.edu/cdbs/comp/nonhst/johnson_v_004_syn.fits
>>> from stsynphot.config import conf
>>> print(conf.rootdir)
>>> print(conf.rootdir) # doctest: +IGNORE_OUTPUT
/my/local/dir/cdbs/
>>> print(syn_conf.johnson_v_file)
>>> print(syn_conf.johnson_v_file) # doctest: +IGNORE_OUTPUT
/my/local/dir/cdbs//comp/nonhst/johnson_v_004_syn.fits

You can also take advantage of
Expand Down Expand Up @@ -154,8 +158,8 @@ before proceeding.
Display the current settings for graph and component tables, telescope area
(in squared centimeter), and default wavelength set (in Angstrom)::

>>> import stsynphot as STS
>>> STS.showref()
>>> import stsynphot as stsyn
>>> stsyn.showref() # doctest: +SKIP
graphtable: /my/local/dir/cdbs/mtab/07r1502mm_tmg.fits
comptable : /my/local/dir/cdbs/mtab/07r1502nm_tmc.fits
thermtable: /my/local/dir/cdbs/mtab/tae17277m_tmt.fits
Expand All @@ -168,14 +172,16 @@ consistency, as stated in :ref:`stsynphot-installation-setup` (the double
slash in path name does not affect software operation)::

>>> import synphot
>>> synphot.conf.vega_file
'/my/local/dir/cdbs//calspec/alpha_lyr_stis_008.fits'
>>> synphot.conf.vega_file # doctest: +IGNORE_OUTPUT
'/my/local/dir/cdbs//calspec/alpha_lyr_stis_009.fits'

Plot the built-in Vega spectrum, which is used to compute VEGAMAG. This is
pre-loaded at start-up for convenience::

>>> from synphot import units
>>> STS.Vega.plot(right=20000, flux_unit=units.FLAM, title='Vega spectrum')
>>> stsyn.Vega.plot(
... right=20000, flux_unit=units.FLAM,
... title='Vega spectrum') # doctest: +SKIP

.. image:: stsynphot/images/vega_spec.png
:width: 600px
Expand All @@ -184,8 +190,8 @@ pre-loaded at start-up for convenience::
Construct a bandpass for HST/ACS camera using WFC1 detector and F555W filter;
Then, show all the individual throughput files used in its construction::

>>> bp = STS.band('acs,wfc1,f555w')
>>> bp.showfiles()
>>> bp = stsyn.band('acs,wfc1,f555w') # doctest: +SKIP
>>> bp.showfiles() # doctest: +SKIP
INFO: #Throughput table names:
/my/local/dir/cdbs/comp/ota/hst_ota_007_syn.fits
/my/local/dir/cdbs/comp/acs/acs_wfc_im123_004_syn.fits
Expand All @@ -198,14 +204,14 @@ star with blackbody temperature of 5770 Kelvin, at solar metallicity, and log
surface gravity of 4.5, renormalized to 20 VEGAMAG in Johnson *V* filter,
using IRAF SYNPHOT syntax::

>>> sp = STS.parse_spec(
... 'rn(icat(k93models,5770,0.0,4.5),band(johnson,v),20,vegamag)')
>>> sp = stsyn.parse_spec(
... 'rn(icat(k93models,5770,0.0,4.5),band(johnson,v),20,vegamag)') # doctest: +SKIP

Construct an extinction curve for Milky Way (diffuse) with :math:`E(B-V)` of
0.7 mag. Then, apply the extinction to the source spectrum from before::

>>> ext = STS.ebmvx('mwavg', 0.7)
>>> sp_ext = sp * ext
>>> ext = stsyn.ebmvx('mwavg', 0.7) # doctest: +REMOTE_DATA
>>> sp_ext = sp * ext # doctest: +SKIP

Construct an observation using the ACS bandpass and the extincted source
spectrum. (For accurate detector binning, you can pass in the binned wavelength
Expand All @@ -214,8 +220,8 @@ observation mode is stored in ``bp.binset``.) Then, compute the count rate
for HST collecting area::

>>> from synphot import Observation
>>> obs = Observation(sp_ext, bp, binset=bp.binset)
>>> obs.countrate(area=STS.config.conf.area)
>>> obs = Observation(sp_ext, bp, binset=bp.binset) # doctest: +SKIP
>>> obs.countrate(area=stsyn.config.conf.area) # doctest: +SKIP
<Quantity 23.839134880103543 ct / s>

To find out exactly how ``bp.binset`` was computed, you can use the following
Expand All @@ -224,14 +230,15 @@ mode in use is stored in ``wavecats/acs.dat`` in the **stsynphot** software
data directory (``synphot$``, which is named so for backward compatibility
with ASTROLIB PYSYNPHOT)::

>>> STS.wavetable.WAVECAT['acs,wfc1,f555w']
>>> from stsynphot import wavetable
>>> wavetable.WAVECAT['acs,wfc1,f555w']
'synphot$wavecats/acs.dat'

Calculate thermal background for a HST/WFC3 bandpass for its IR detector using
F110W filter::

>>> wfc3 = STS.band('wfc3,ir,f110w')
>>> wfc3.thermback()
>>> wfc3 = stsyn.band('wfc3,ir,f110w') # doctest: +SKIP
>>> wfc3.thermback() # doctest: +SKIP
<Quantity 0.051636304994833425 ct / (pix s)>


Expand Down Expand Up @@ -332,7 +339,7 @@ Fukugita, M., Ichikawa, T., Gunn, J. E., Doi, M., Shimasaku, K., & Schneider, D.

.. _stsynphot-ref-gunn2001:

`Gunn, J. E., Hogg, D., Finkbeiner, D., & Schlegel, D. 2001, Photometry White Paper <http://www.sdss.org/dr3/algorithms/sdssphot.ps>`_
`Gunn, J. E., Hogg, D., Finkbeiner, D., & Schlegel, D. 2001, Photometry White Paper <http://classic.sdss.org/dr3/algorithms/sdssphot.ps>`_

.. _stsynphot-ref-gunn1983:

Expand Down Expand Up @@ -388,7 +395,7 @@ Lim, P. L., Diaz, R. I., & Laidler, V. 2015, PySynphot User's Guide (Baltimore,

.. _stsynphot-ref-lim2016:

Lim, P. L., et al. 2016, synphot User's Guide (Baltimore, MD: STScI), http://synphot.readthedocs.io/en/latest/
Lim, P. L., et al. 2016, synphot User's Guide (Baltimore, MD: STScI), https://synphot.readthedocs.io/en/latest/

.. _stsynphot-ref-lub1977:

Expand Down
80 changes: 39 additions & 41 deletions docs/stsynphot/appendixa.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. doctest-skip-all
.. _stsynphot-appendixa:

Appendix A: Catalogs and Spectral Atlases
Expand Down Expand Up @@ -82,8 +80,8 @@ The example below generates a spectrum with metallicity ``[M/H] = +0.1``,
temperature :math:`T_{\text{eff}} = 10000 \text{K}`, and gravity
:math:`\log g = 3.0`::

>>> import stsynphot as STS
>>> sp = STS.grid_to_spec('ck04models', 10000, 0.1, 3.0)
>>> import stsynphot as stsyn
>>> sp = stsyn.grid_to_spec('ck04models', 10000, 0.1, 3.0) # doctest: +SKIP


.. _stsynphot-appendixa-kurucz1993:
Expand Down Expand Up @@ -125,9 +123,9 @@ columns in the file are filled with zeroes::
>>> from astropy.io import fits
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'k93models',
... 'kp00', 'kp00_8000.fits')
>>> hdr = fits.getheader(filename)
>>> hdr
... 'kp00', 'kp00_8000.fits') # doctest: +SKIP
>>> hdr = fits.getheader(filename) # doctest: +SKIP
>>> hdr # doctest: +SKIP
SIMPLE = T / file does conform to FITS standard
BITPIX = 16 / number of bits per data pixel
NAXIS = 0 / number of data axes
Expand Down Expand Up @@ -166,16 +164,16 @@ means :math:`\log g = 3.0`::

>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'k93models',
... 'kp01', 'kp01_10000.fits')
>>> spec = fits.getdata(filename)
>>> wave = spec['WAVELENGTH']
>>> flux = spec['g30']
... 'kp01', 'kp01_10000.fits') # doctest: +SKIP
>>> spec = fits.getdata(filename) # doctest: +SKIP
>>> wave = spec['WAVELENGTH'] # doctest: +SKIP
>>> flux = spec['g30'] # doctest: +SKIP

The easier way is to use :func:`~stsynphot.catalog.grid_to_spec` (also see
:ref:`stsynphot-spec-atlas`). Equivalent to the example above::

>>> import stsynphot as STS
>>> sp = STS.grid_to_spec('k93models', 10000, 0.1, 3.0)
>>> import stsynphot as stsyn
>>> sp = stsyn.grid_to_spec('k93models', 10000, 0.1, 3.0) # doctest: +SKIP


.. _stsynphot-appendixa-phoenix:
Expand Down Expand Up @@ -205,8 +203,8 @@ The example below generates a spectrum with metallicity ``[M/H] = +0.1``,
temperature :math:`T_{\text{eff}} = 10000 \text{K}`, and gravity
:math:`\log g = 3.0`::

>>> import stsynphot as STS
>>> sp = STS.grid_to_spec('phoenix', 10000, 0.1, 3.0)
>>> import stsynphot as stsyn
>>> sp = stsyn.grid_to_spec('phoenix', 10000, 0.1, 3.0) # doctest: +SKIP


.. _stsynphot-appendixa-calspec:
Expand All @@ -225,9 +223,9 @@ the header from G191B2B spectrum and then loads it into **stsynphot**::
>>> from astropy.io import fits
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'calspec', 'g191b2b_mod_010.fits')
>>> hdr = fits.getheader(filename)
>>> hdr
... os.environ['PYSYN_CDBS'], 'calspec', 'g191b2b_mod_010.fits') # doctest: +SKIP
>>> hdr = fits.getheader(filename) # doctest: +SKIP
>>> hdr # doctest: +SKIP
SIMPLE = T / Fits standard
BITPIX = 16 / Bits per pixel
NAXIS = 0 / Number of axes
Expand Down Expand Up @@ -259,7 +257,7 @@ the header from G191B2B spectrum and then loads it into **stsynphot**::
HISTORY Vega Flux(5556A)=3.44e-9 (Bohlin 2014, AJ, 147, 127)
HISTORY INPUT FILE: /internal/1/wd/dat/g191.rauch59000-nlte
HISTORY Written by MAKE_MOD_CALSPEC.pro 23-Dec-2014 10:20:09.00
>>> sp = SourceSpectrum.from_file(filename)
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP

Note that in some cases, the calibration spectrum is truncated in the blue or
the red at wavelength longer or shorter, respectively, than the sensitivity
Expand Down Expand Up @@ -307,8 +305,8 @@ subset of the library::
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'pickles',
... 'dat_uvk', 'pickles_uk_27.fits')
>>> sp = SourceSpectrum.from_file(filename)
... 'dat_uvk', 'pickles_uk_27.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-bkmodels:
Expand Down Expand Up @@ -340,8 +338,8 @@ The example below loads Block S (models for the Sun and Vega) with
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'bkmodels', 'bk_s0001.fits')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'grid', 'bkmodels', 'bk_s0001.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-bz77:
Expand All @@ -361,8 +359,8 @@ The example below loads a source spectrum of spectral type G5V from the atlas::
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'bz77', 'bz_27.fits')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'grid', 'bz77', 'bz_27.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-gs:
Expand All @@ -385,8 +383,8 @@ The example below loads a source spectrum of spectral type G5V from the atlas::
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'gunnstryker', 'gs_44.fits')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'grid', 'gunnstryker', 'gs_44.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-bpgs:
Expand Down Expand Up @@ -419,8 +417,8 @@ The example below loads a source spectrum of spectral type G5V from the atlas::
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'bpgs', 'bpgs_44.fits')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'grid', 'bpgs', 'bpgs_44.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-jacobi:
Expand All @@ -444,8 +442,8 @@ The example below loads a source spectrum of spectral type G0V from the atlas::
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'jacobi', 'jc_43.fits')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'grid', 'jacobi', 'jc_43.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-bc95:
Expand Down Expand Up @@ -474,8 +472,8 @@ instantaneous burst::
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'bc95',
... 'templates', 'bc95_c_50E5.fits')
>>> sp = SourceSpectrum.from_file(filename)
... 'templates', 'bc95_c_50E5.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-kc96:
Expand All @@ -499,8 +497,8 @@ The example below loads a galaxy spectrum from the elliptical template::
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'kc96',
... 'elliptical_template.fits')
>>> sp = SourceSpectrum.from_file(filename)
... 'elliptical_template.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-agn:
Expand All @@ -523,8 +521,8 @@ The example below loads a Seyfert 2 spectrum::
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'agn', 'seyfert2_template.fits')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'grid', 'agn', 'seyfert2_template.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-galactic:
Expand All @@ -544,8 +542,8 @@ The example below loads the spectrum for Orion nebula::
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'grid', 'galactic',
... 'orion_template.fits')
>>> sp = SourceSpectrum.from_file(filename)
... 'orion_template.fits') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP


.. _stsynphot-appendixa-etcsource:
Expand All @@ -563,5 +561,5 @@ The example below loads a spectrum for Gliese 229B brown dwarf::
>>> import os
>>> from synphot import SourceSpectrum
>>> filename = os.path.join(
... os.environ['PYSYN_CDBS'], 'etc', 'source', 'gl229b_001.dat')
>>> sp = SourceSpectrum.from_file(filename)
... os.environ['PYSYN_CDBS'], 'etc', 'source', 'gl229b_001.dat') # doctest: +SKIP
>>> sp = SourceSpectrum.from_file(filename) # doctest: +SKIP
2 changes: 0 additions & 2 deletions docs/stsynphot/appendixb.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. doctest-skip-all
.. include:: appb_ref.txt

.. _stsynphot-appendixb:
Expand Down
Loading

0 comments on commit 9b0d584

Please sign in to comment.