mangadap.proc.bandpassfilter module

Container class that defines a bandpass filter.

Class usage examples

To define an bandpass filter:

from mangadap.par.bandpassfilter import BandPassFilterPar
p = BandPassFilterPar(index=44, name='Ha', blueside=[6483.0,6513.0],
                      redside=[6623.0,6653.0], restwave=6564.632,
                      primary=[6557.6,6571.6])

However, this class is mostly to provide a base class used by mangadap.par.emissionmomentsdb.EmissionMomentsDB, mangadap.par.absorptionindexdb.AbsorptionIndexDB, and mangadap.par.bandheadindexdb.BandheadIndexDB; it is not really meant to be used as given above.


License

Copyright © 2019, SDSS-IV/MaNGA Pipeline Group


class mangadap.proc.bandpassfilter.BandPassFilterPar(index=None, name=None, blueside=None, redside=None, restwave=None, primary=None, units=None, component=None, integrand=None, order=None)[source]

Bases: KeywordParSet

Parameter object that defines a set of band-pass filters. This is a base class for similar objects used calculating fluxes and flux moments of emission lines (mangadap.par.emissionmomentsdb.EmissionMomentsDB), absorption line indices (mangadap.par.absorptionindexdb.AbsorptionIndexDB), and spectral continuum bandheads (mangadap.par.bandheadindexdb.BandheadIndexDB) in the DAP.

All wavelengths are expected to be in vacuum, to match the expected application of this filter to SDSS MaNGA spectra.

See mangadap.par.parset.ParSet for attributes and raised exceptions.

The defined parameters are:

Key

Type

Options

Default

Description

index

int

An index used to refer to the bandpass filter

name

str

A name for the bandpass filter

restwave

int, float

The rest wavelength of the line in the primary passband in angstroms in vacuum. This is used to convert the first and second moments to velocity (km/s) for emission lines.

primary

ndarray, list

A two-element vector with the starting and ending wavelength (angstroms in vacuum) for a passband to the blue of the primary spectral feature.

blueside

ndarray, list

A two-element vector with the starting and ending wavelength (angstroms in vacuum) for a passband to the red of the primary spectral feature.

redside

ndarray, list

A two-element vector with the starting and ending wavelength (angstroms in vacuum) for the primary passband surrounding the spectral feature of interest. This is used by mangadap.par.emissionmomentsdb.EmissionMomentsDB and mangadap.par.absorptionindexdb.AbsorptionIndexDB, but it is irrelevant for mangadap.par.bandheadindexdb.BandheadIndexDB.

units

str

ang, mag

Define the unit for the spectral index as either angstroms (ang) or magnitudes (mag). Currently only used by mangadap.par.absorptionindexdb.AbsorptionIndexDB.

component

bool

Flag that the bandpass definition is a component of a larger set of bandpass filters. This is currently only used by mangadap.par.absorptionindexdb.AbsorptionIndexDB to combine index measurements into a single index. If True, all components with the same name are summed to form the composite index.

integrand

str

flambda, fnu

Currently only used by mangadap.par.bandheadindexdb.BandheadIndexDB. Define the integrand over the passband used to construct and index as either flux per unit frequency (fnu), \(F_\nu\), or flux per unit wavelength (flambda), \(F_\lambda\).

order

str

b_r, r_b

Currently only used by mangadap.par.bandheadindexdb.BandheadIndexDB. Define the order to use when constructing the index. The options are either a ratio of red-to-blue or blue-to-red, which are respectively selected using r_b or b_r.

_check()[source]

Check the parameter list:

  • Make sure arrays only have two elements.

Todo

  • Add check to __setitem__()?

Raises:

ValueError – Raised if one of the conditions above are not met.

mangadap.proc.bandpassfilter.emission_line_equivalent_width(wave, flux, bluebands, redbands, line_centroid, line_flux, ivar=None, mask=None, log=True, redshift=None, line_flux_err=None, include_band=None)[source]

Compute the equivalent width for emission lines provided the spectra and the previously measured line flux.

Parameters:
  • wave (numpy.ndarray) – Vector with the observed wavelength of each spectrum in angstroms.

  • flux (numpy.ndarray) – Array (1 or 2) with the observed flux density (units in per angstrom) with size Nspec x Nwave.

  • blueside (numpy.ndarray) – Wavelength limits for the blue sidebands in angstroms, with size Nbands x 2.

  • redside (numpy.ndarray) – Wavelength limits for the red sidebands in angstroms, with size Nbands x 2.

  • line_centroid (numpy.ndarray) – Wavelengths at which to sample the continuum for the equivalent width measurement. Can be anything, but should typically be the observed wavelength of line center in angstroms, with size Nspec x Nband.

  • line_flux (numpy.ndarray) – Integrated flux of the emission feature with size Nspec x Nband.

  • ivar (numpy.ndarray, optional) – Inverse variance in the observed flux, with shape that matches flux. Default ignores error calculation. Currently the equivalent width errors do not account for errors in the continuum characterization beneath the line. So this ivar array is ignored!

  • mask (numpy.ndarray, optional) – Boolean bad-pixel mask: True values are considered to be bad pixels. Default assumes all pixels are good.

  • log (bool, optional) – Boolean that the spectra are logarithmically sampled in wavelength.

  • redshift (numpy.ndarray, optional) – Redshift of each spectrum used to appropriately shift the definition of the bandpasses. If a single vector is provided, the length must match the number of provided spectra; if an array is provided, the shape must be (Nspec,Nband). If None, all measurements are done assuming the redshift is 0 (i.e., that the observed and rest frames are identical).

  • line_flux_err (numpy.ndarray, optional) – Errors in the line flux, with size Nspec x Nband. Default is to ignore the error propagation.

  • include_band (numpy.ndarray, optional) – Boolean array with size Nspec x Nband used to select which bands to use in the calculation for each spectrum. Default is to include all bands for all spectra.

Returns:

Returns the following arrays, all with shape (Nspec, Nbands):

  1. the passband median in the blue and red sidebands

  2. a boolean array if the sideband medians were measured and have positive values

  3. The continuum value used to calculate the equivalent width

  4. The equivalent with measurements and their errors; the errors are 0 if no line flux errors were provided

Return type:

tuple

Raises:

ValueError – Raised if the shapes of the input arrays are not correct.

mangadap.proc.bandpassfilter.passband_integral(x, y, passband=None, borders=False, log=False, base=10.0, quad=False)[source]

Determine the integral of a discrete set of data over a passband accounting for fractional pixels.

The integral is done by a simple sum:

\[S(y) = \sum_i \delta_i y_i {\rm d}x_i\]

where \(\delta_i\) is the fraction of pixel \(i\) within the integration limits as determined by pixel_fraction_in_passband(). Given the errors in \(y\) (\(\epsilon_i\)), the propagated error in \(S\) is

\[[\epsilon S(y)]^2 = \sum_i (\delta_i \epsilon_i {\rm d}x_i)^2,\]

which can be calculated using the quad keyword. For example, given values to integrate, y, and errors, e, calculate the passband integral and its error as follows:

integral = passband_integral(x, y)
integral_error = passband_integral(x, e, quad=True)

Warning

Although the equation for the formal error propagation is correct, a comparison of the formal errors to errors from a Monte Carlo simulation show that the former are pretty poor estimates of the latter.

Parameters:
  • x (array-like) – The 1D array of x coordinates for the integration. If borders=True, this array provides the borders of the interval over which y is measured. These can be non-uniform. In this case, the number of x values must be \(N+1\) for \(N\) 1D y values (see below). Otherwise, the x values are expected to be uniformly sampled either linearly or geometrically. In this case, x can be either a two element vector giving the (geometric) centers of the first and last sample interval or a vector with the \(N\) samples. In either case, mangadap.util.sampling.grid_borders() is used to determine the borders of the sample intervals.

  • y (array-like) – The 1D or 2D array of measured values to be integrated. The first axis must always provide the values to be integrated. If those values are specific to the passband, y should be 2D with shape \((N_y,N_{\rm passband})\).

  • passband (array-like, optional) – The 1D or 2D array with the set of passbands (in units of x) to integrate. The length of the last dimension must always be 2, providing the starting and ending x coordinate. If 2D, the array must have shape \((N_{\rm passband},2)\). If not provided, the integral is just performed over the full \(y\) vector. If y is 2D, the last axis of y and the first axis here must match.

  • borders (bool, optional) – The \(x\) values provided are the border coordinates over which the \(y\) values have been determined.

  • log (bool, optional) – The coordinates are logarithmically sampled. Ignored if borders is True.

  • base (float, optional) – The base of the logarithm used in the geometric sampling if log is True.

  • quad (bool, optional) – Perform the quadrature sum instead of the direct sum. This is used for error calculations.

Returns:

The passband integral for each passband.

Return type:

float, numpy.ndarray

Raises:

ValueError – Raised if x is not a 1D array, if the shapes of x and y are not appropriately matched, if passbands has more than 2 dimensions, if the last axis of passbands is not 2 elements long, or if the shapes of passbands and y are not appropriately matched.

mangadap.proc.bandpassfilter.passband_integrated_mean(x, y, err=None, passband=None, borders=False, log=False, base=10.0)[source]

Determine the integrated mean over a (set of) passband(s). Nominal errors are returned if err is provided.

mangadap.proc.bandpassfilter.passband_integrated_width(x, y, passband=None, borders=False, log=False, base=10.0)[source]

Determine the integrated width of the passband, accounting for masked pixels.

mangadap.proc.bandpassfilter.passband_median(x, y, passband=None)[source]

Determine the median of the y values within the passband

mangadap.proc.bandpassfilter.passband_weighted_mean(x, y, z, passband=None, borders=False, yerr=None, zerr=None, log=False, base=10.0)[source]

Determine the y-weighted mean of z over the passband; i.e.,

\[\mu = \frac{\int_{x_1}^{x_2} y z dx}{\int_{x_1}_{x_2} y dx},\]

where the integrals are determined by the discrete sum; i.e., \(\mu = S(y z)/S(y)\) where \(S(y)\) is provided by passband_integral().

Because the error in the numerator and denominator of \(\mu\) are correlated, they are calculated here by explicit error propagation:

\[\epsilon_\mu^2 = \frac{1}{S(y)^2} (S((z-\mu)^2 \epsilon_y^2) + S(y^2\epsilon_z^2)).\]

Todo

-doc the args

Returns:

Two masked arrays with the passband-weighted mean and its error. The error is returned as None if no errors are provided.

Return type:

numpy.ma.MaskedArray

mangadap.proc.bandpassfilter.passband_weighted_sdev(x, y, z, passband=None, borders=False, yerr=None, zerr=None, log=False, base=10.0)[source]

Determine the y-weighted standard deviation of z over the passband; i.e.,

\[\sigma^2 = \frac{\int_{x_1}^{x_2} y z^2 dx}{\int_{x_1}_{x_2} y dx} - \mu^2,\]

where \(\mu\) is the y-weighted mean of z over the passband (see passband_weighted_mean()) and the integrals are determined by the discrete sum; i.e., \(\sigma^2 = S(y z^2)/S(y) - \mu^2\) where \(S(y)\) is provided by passband_integral().

Because the error in the various components of the \(\sigma\) calculation are correlated, they are calculated here by explicit error propagation:

\[\epsilon_{\sigma^2}^2 = \frac{1}{S(y)^2} (S([(z-\mu)^2 + \mu^2 - \mu_2]^2 \epsilon_y^2) + S(4 (z-\mu)^2 y^2\epsilon_z^2)),\]

where \(\mu_2\) is the first term in the \(\sigma^2\) calculation above and

\[\epsilon_\sigma = \frac{\epsilon_{\sigma^2}}{2 \sigma}.\]
Returns:

Two masked arrays with the passband-weighted standard deviation and its error. The error is returned as None if no errors are provided.

Return type:

numpy.ma.MaskedArray

mangadap.proc.bandpassfilter.pixel_fraction_in_passband(x, passband, dx=None)[source]

Determine the width of each x interval to include in one or more passband integrals.

Parameters:
  • x (array-like) – 1D array with pixel borders.

  • passband (array-like) – 1D or 2D array with the passbands to integrate over. If more than one passband is provided, the shape of the input should be \((N_{\rm passband},2)\).

  • dx (array-like, optional) – 1D array with the size of each pixel. If not provided, calculated from x. Can be provided to speed calculations for multiple calls.

Returns:

The array with the fraction of each pixel within each passband. The output shape is \((N_{\rm pixel},N_{\rm passband})\), where \(N_{\rm pixel}\) is the 1 less than the number of pixel borders.

Return type:

numpy.ndarray

mangadap.proc.bandpassfilter.pseudocontinuum(x, y, passband=None, err=None, log=True, weighted_center=False)[source]

Get the pseudocontinua in a set of passbands for a single vector (y)

Returns:

Return five arrays or floats: (1) The center of each passband, (2) the mean continuum level, (3) the propagated error in the continuum level (will be None if no errors are provided), (4) flag that part of the passband was masked, (5) flag that the passband was fully masked or empty.

Return type:

float, numpy.ndarray