SpectrumTemplate

class grizli.utils.SpectrumTemplate(wave=None, flux=None, central_wave=None, fwhm=None, velocity=False, fluxunits=Unit('erg / (Angstrom s cm2)'), waveunits=Unit('Angstrom'), name='template', lorentz=False, err=None)[source]

Bases: object

Container for template spectra.

Parameters
wavearray-like

Wavelength In astropy.units.Angstrom.

fluxfloat array-like

If float, then the integrated flux of a Gaussian line. If array, then f-lambda flux density.

central_wave, fwhmfloat

Initialize the template with a Gaussian at this wavelength (in astropy.units.Angstrom.) that has an integrated flux of flux and fwhm in astropy.units.Angstrom or km/s for velocity=True.

velocitybool

fwhm is a velocity in km/s.

Examples

import matplotlib.pyplot as plt
from grizli.utils import SpectrumTemplate

ha = SpectrumTemplate(central_wave=6563., fwhm=10)
plt.plot(ha.wave, ha.flux)

ha_z = ha.zscale(0.1)
plt.plot(ha_z.wave, ha_z.flux, label='z=0.1')

plt.legend()
plt.xlabel(r'$\lambda$')
plt.xlim(6000, 7500)

plt.show()

(Source code, png, hires.png, pdf)

../_images/grizli-utils-SpectrumTemplate-1.png
Attributes
wave, fluxarray-like

Passed from the input parameters or generated/modified later.

Methods

__add__, __mul__

(Addition and multiplication of templates.)

Attributes Summary

eazy

Convert to eazy.template.Template object

Methods Summary

integrate_filter(filter[, abmag, use_wave])

Integrate the template through an FilterDefinition filter object.

make_gaussian(central_wave, fwhm[, ...])

Make Gaussian template

to_fnu([fnu_units])

Make fnu version of the template.

zscale(z[, scalar, apply_igm])

Redshift the template and multiply by a scalar.

Attributes Documentation

eazy

Convert to eazy.template.Template object

Methods Documentation

integrate_filter(filter, abmag=False, use_wave='filter')[source]

Integrate the template through an FilterDefinition filter object.

Parameters
filterObsBandpass

Or any object that has wave and throughput attributes, with the former in the same units as the input spectrum.

abmagbool

Return AB magnitude rather than fnu flux

Returns
temp_fluxfloat

Examples

Compute the WFC3/IR F140W AB magnitude of a pure emission line at the 5-sigma 3D-HST line detection limit (5e-17 erg/s/cm2):

>>> import numpy as np
>>> from grizli.utils import SpectrumTemplate
>>> from eazy.filters import FilterDefinition
>>> import pysynphot as S
>>> line = SpectrumTemplate(central_wave=1.4e4, fwhm=150.,
                            velocity=True)*5.e-17
>>> filter = FilterDefinition(bp=S.ObsBandpass('wfc3,ir,f140w'))
>>> fnu = line.integrate_filter(filter)
>>> print('AB mag = {0:.3f}'.format(-2.5*np.log10(fnu)-48.6))
AB mag = 26.619
static make_gaussian(central_wave, fwhm, max_sigma=5, step=0.1, wave_grid=None, velocity=False, clip=1e-06, lorentz=False)[source]

Make Gaussian template

Parameters
central_wave, fwhmNone or float or array-like

Central wavelength and FWHM of the desired Gaussian

velocitybool

fwhm is a velocity.

max_sigma, stepfloat

Generated wavelength array is

>>> rms = fwhm/2.35
>>> xgauss = np.arange(-max_sigma, max_sigma, step)*rms+central_wave
clipfloat

Clip values where the value of the gaussian function is less than clip times its maximum (i.e., 1/sqrt(2*pi*sigma**2)).

lorentzbool

Make a Lorentzian line instead of a Gaussian.

Returns
wave, fluxarray-like

Wavelength and flux of a Gaussian line

to_fnu(fnu_units=Unit('erg / (Hz s cm2)'))[source]

Make fnu version of the template.

Sets the flux_fnu attribute, assuming that the wavelength is given in Angstrom and the flux is given in flambda:

>>> flux_fnu = self.flux * self.wave**2 / 3.e18
zscale(z, scalar=1, apply_igm=True)[source]

Redshift the template and multiply by a scalar.

Parameters
zfloat

Redshift to use.

scalarfloat

Multiplicative factor. Additional factor of 1./(1+z) is implicit.

Returns
new_spectrumSpectrumTemplate

Redshifted and scaled spectrum.