Base class to handle spectra

class qmostetc.Spectrum(wavelength, flux)

Spectrum representing a flux or a transmission.

This class is somewhat generic. It may represent any flux quantity, like enery flux, photon flux, CCD photoelectron flux etc, but also throughput spectra, like atmospheric throughput, detector throughputs etc.

To a Spectrum, another Spectrum can be added, as long as the units are compatible. Both spectra need to have the same wavelength bins.

A Spectrum may be multiplied with either an array of the correct shape, or with a Spectrum, which needs to have the same wavelength bins.

Attributes:
wavelengthastropy.units.Quantity

Wavelength array [nm]

fluxastropy.units.Quantity

Flux, in any convenient unit

to(unit)

Create a new spectrum with the flux values converted

This also allows to convert between energy flux and photon flux.

Parameters:
unitastropy.units.Unit or str

The unit to convert the flux to.

Returns:
Spectrum

Converted flux spectrum.

Examples

Convert a constant photon flux into an energy flux:

>>> import numpy as np
>>> import astropy.units as u
>>> from qmostetc import Spectrum
>>> wavelength = np.linspace(600., 650., 4) * u.nm
>>> flux = np.ones(wavelength.shape) * u.photon/(u.m**2*u.s*u.nm)
>>> spec = Spectrum(wavelength, flux)
>>> print(spec.to('erg/(nm m² s)').flux)
[3.31074310e-12 3.22126355e-12 3.13649346e-12 3.05607055e-12] erg / (nm s m2)
subspectrum(lower, upper)

Extract a subspectrum with given limits

Parameters:
lowerastropy.units.Quantity

Lower wavelength limit [nm]

upperastropy.units.Quantity

Upper wavelength limit [nm]

Returns:
Spectrum

New flux spectrum within the given limits

__call__(wavelength)

Return the (interpolated) flux value(s) for given wavelength(s)

The interpolation is done linearly.

Parameters:
wavelengthastropy.units.Quantity

Wavelength or wavelength array to retrieve the values [nm]

Returns:
astropy.units.Quantity

Value or Value array corresponding to the given wavelength(s).

get_mag(magunit, flt)

Get the magnitude for this spectrum.

Parameters:
magunitastropy.units.MagUnit

Star magnitude unit (astropy.units.ABmag or qmostetc.VEGAmag)

fltstr or pathlib.Path or Spectrum

Filter to apply, given by name, file path, or as a spectrum

Returns:
astropy.units.Quantity

Estimated magnitude when applying the filter, with the given unit.

Examples

Retrieve the VEGA magnitude for a scaled template:

>>> from qmostetc import SEDTemplate, VEGAmag
>>> import astropy.units as u
>>> pck = SEDTemplate('Pickles_G0V')
>>> spectrum = pck(15*u.ABmag, 'GAIA_GAIA2r.G')
>>> spectrum.get_mag(u.ABmag, 'GAIA_GAIA2r.G')
<Magnitude 15. mag(AB)>
>>> spectrum.get_mag(VEGAmag, 'GAIA_GAIA2r.G')
<Magnitude 14.87880973 mag(VEGA)>
check_coverage(flt)

Check the wavelength range coverage

Ensure that the wavelength range of the spectrum covers the range of the given filter.

Parameters:
fltstr or pathlib.Path or Spectrum

Filter to apply, given by name, file path, or as a spectrum

Raises:
ValueError

If the wavelength range does not cover the wavelength range of the filter

Examples

Raise an exception for a really small wavelength range:

>>> import numpy as np
>>> import astropy.units as u
>>> from qmostetc import Spectrum
>>> wavelength = np.arange(300., 310.) * u.nm
>>> spec = Spectrum(wavelength, np.zeros(wavelength.shape))
>>> spec.check_coverage('GAIA_GAIA2r.G')
Traceback (most recent call last):
...
ValueError: Insufficient wavelength coverage (300…309 nm) for filter (300…1098 nm)
static read(table)

Read a template spectrum from a table

The table needs to have the following columns:

  • WAVELENGTH, LAMBDA, LAMB, WAVE, or LAM for the wavelength column,

  • FLAM, FLUX_DENSITY, FLUXDENSITY, F, FLUX, or TRANS for the flux column.

The method tries to fix some glitches in the file; however it is best to have the units stored correctly, for FITS files according to the FITS standard.

Parameters:
tablepathlib.Path or astropy.table.QTable

File name or table

Returns:
Spectrum

Spectrum stored in the table