Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Affiliated package for 1D spectral operations. Maintainer: @wkerzendorf
Python
branch: master

README.rst

Specutils

An AstroPy affiliated package containing operations and tools on astronomical spectra.

First Steps

The Spectrum1D class is one of the core classes of the specutils package. You can import it like this:

from specutils import Spectrum1D

To instantiate it you can define a wave and a flux:

wave = np.arange(6000, 9000) * u.Angstrom
flux = np.random.random(3000) * u.Unit('W m-2 angstrom-1 sr-1')

and then call the from_array method:

spec1d = Spectrum1D.from_array(wave, flux)
spec1d.wavelength
<Quantity [ 6000., 6001., 6002.,...,  8997., 8998., 8999.] Angstrom>
spec1d.flux
<Quantity [ 0.75639906, 0.23677036, 0.08408417,...,  0.82740303, 0.38345114,
            0.77815595] W / (Angstrom m2 sr)>

Or you can read a Spectrum from a .fits file with the read_fits method:

from specutils.io import read_fits
myspec = read_fits.read_fits_spectrum1d('myfile.fits')

It supports the types of FITS formats listed in this page. Note: A list of spectra is returned whenever the input file is a multispec file.

Writing spectra to .fits files works in the same way with the write_fits method:

from specutils.io import write_fits
write_fits.write(myspec, 'mynewfile.fits')

Note: write_fits.write deciphers the type of object passed and writes spectra to the given file in FITS format.

Reading a Spectrum from a FITS file with no specified units in the header will give the following warning:

myspec = read_fits.read_fits_spectrum1d('specutils/io/tests/files/UVES.fits')
UserWarning: Initializing a Spectrum1D WCS with units set to `None` is not recommended

the Spectrum1D.dispersion will be an array:

myspec.dispersion
array([ 3732.05623192,  3732.0858853 ,  3732.11553869, ...,  4999.67906915,
        4999.70872253,  4999.73837591])

and thus the Spectrum1D's wavelength, energy and frequency will not be available. In order to be convertible, the dispersion must be an astropy Quantity, which will happen if the FITS header has specified the units or if you specify them manually like this:

myspec = read_fits.read_fits_spectrum1d('specutils/io/tests/files/UVES.fits', dispersion_unit='angstrom')
myspec.dispersion
<Quantity [ 3732.05623192, 3732.0858853 , 3732.11553869,...,
            4999.67906915, 4999.70872253, 4999.73837591] Angstrom>
myspec.wavelength
<Quantity [ 3732.05623192, 3732.0858853 , 3732.11553869,...,
            4999.67906915, 4999.70872253, 4999.73837591] Angstrom>
myspec.energy
<Quantity [ 5.32265743e-19,  5.32261514e-19,  5.32257285e-19,...,
            3.97314639e-19,  3.97312282e-19,  3.97309926e-19] J>
myspec.frequency
<Quantity [ 8.03290303e+14,  8.03283920e+14,  8.03277538e+14,...,
            5.99623404e+14,  5.99619847e+14,  5.99616291e+14] Hz>

You can easily make a plot of the Spectrum using matplotlib in ipython with the --pylab flag and calling:

plot(myspec.wavelength, myspec.flux)

World Coordinate System

  • Spectral 1D WCS

The simplest WCS for 1D is a lookup table. This is often found in a ascii tables where one column is the lookup table (wavelength array) and one column is the flux array. In terms of the functional transform view: the lookup table represents a parameter (c0):

lookup_table_wcs = specwcs.Spectrum1DLookupWCS(wave, unit='angstrom') # create the wcs
lookup_table_wcs(0) # doing the transformation for pixel 0
<Quantity 6000.0 Angstrom>
Spectrum1D(flux=flux, wcs=lookup_table_wcs)
Spectrum1D([ 0.66118716,  0.39584688,  0.81210479, ...,  0.5238203 ,
             0.05986459,  0.11621466])

Another common WCS is the linear dispersion and commonly serialized (encoded) to FITS keyword headers. For linear dispersion we are using the general Spectrum1DPolynomialWCS WCS.

The CompositeWCS and WeightedCombinationWCS models can be useful to combine different WCS. Another important model available is the DopplerShift model. This model is specifically for calculating the doppler shift from velocity (v).

In addition, the following WCS models exist as well:

These models are just IRAF extensions of already existing models. This extensions enable the user to read and write from IRAF FITS files.

Spectral Tools and Utilities

  • Interstellar Extinction calculations

This module contains extinction law functions. See the documentation for individual functions.

Full Documentation

https://travis-ci.org/astropy/specutils.png?branch=master https://coveralls.io/repos/astropy/specutils/badge.png
Something went wrong with that request. Please try again.