Skip to content

Commit

Permalink
Added a new tutorial as requested by Misty Cracraft.
Browse files Browse the repository at this point in the history
git-svn-id: https://aeon.stsci.edu/ssb/svn/astrolib/trunk/pysynphot@5214 90a0a646-be8a-0410-bb88-9290da87bc01
  • Loading branch information
pllim committed Nov 4, 2015
1 parent 3ad9e2e commit 6ee2267
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/source/bandpass.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ array([ 0.00000000e+00, 0.00000000e+00, 1.87380003e-27, ...,
>>> bp.sample(2100)
0.0

:ref:`pysynphot_tutorial_10` offers hints on how to load a bandpass from an ASCII table
of any format.


.. _pysynphot-bandpass-arrays:

Expand Down
3 changes: 3 additions & 0 deletions doc/source/spectrum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ be one of the :ref:`pysynphot-appendixa-calspec`:
array([ 6.83127903e-12, 6.83185409e-12, 6.83168973e-12, ...,
3.47564168e-21, 3.47547205e-21, 3.47530241e-21])

See :ref:`Tutorial 10 <pysynphot_tutorial_10>` for example on how to load a
source spectrum from an ASCII table of any format.


.. _pysynphot-empirical-source:

Expand Down
37 changes: 37 additions & 0 deletions doc/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,43 @@ the F555W filter in HST/ACS WFC1 detector:
STmag zeropoint for acs,wfc1,f555w is 25.65880


.. _pysynphot_tutorial_10:

Tutorial 10: Spectrum from Custom Text File
===========================================

In this tutorial, you will learn how to load a source spectrum from an ASCII
table that does not conform to the expected format stated in
:ref:`pysynphot-io`. Since `~pysynphot.spectrum.FileSourceSpectrum` does not
allow explicit setting of units, if your table data have non-default wavelength
or flux units, you have to first load them into Numpy arrays and then use
`~pysynphot.spectrum.ArraySourceSpectrum` to obtain the spectrum object
correctly. Similar workflow applies to bandpass for non-default
wavelength units, using `~pysynphot.spectrum.ArraySpectralElement` (not shown).

Let's say your ASCII table looks like this::

# My source spectrum
# ROW WAVELENGTH(NM) FLUX(PHOTLAM)
1 400.0 0.1
2 401.0 0.1234
3 405.0 0.4556
... ... ...

There are many ways you can read the ASCII table into Numpy arrays. The example
below uses Astropy:

>>> from astropy.io import ascii
>>> tab = ascii.read('myfile.txt', names=['row', 'wave', 'flux'])
>>> wave = tab['wave'] # Second column
>>> flux = tab['flux'] # Third column

Construct the source spectrum from the arrays above:

>>> sp = S.ArraySpectrum(
... wave=wave, flux=flux, waveunits='nm', fluxunits='photlam')


.. _pysynphot_tutorial_exercises:

Exercises
Expand Down

0 comments on commit 6ee2267

Please sign in to comment.