mangadap.util.pixelmask module
A class hierarchy for pixel masks.
Copyright © 2019, SDSS-IV/MaNGA Pipeline Group
- class mangadap.util.pixelmask.PixelMask[source]
Bases:
object
Base class for a general 1D or 2D pixel mask.
- shape
Shape of the array for the mask.
- Type:
tuple
- _empty_mask(x, ny=None)[source]
Return an empty mask with the correct shape.
- Parameters:
x (numpy.ndarray) – Coordinate vector
ny (int) – (Optional) Size of the second dimension. Default is that there is only one dimension.
- Returns:
Boolean mask of the correct shape.
- Return type:
numpy.ndarray
- _mask_coordinate_ranges(x, rng, ny=None)[source]
Flag any x coordinates between a set of range limits as True. The mask is repeated in the second dimension, if requested.
- Parameters:
x (numpy.ndarray) – Coordinate vector
rng (list, numpy.ndarray) – (List of) Coordinate ranges that should be masked.
ny (int) – (Optional) Size of the second dimension. Default is that there is only one dimension.
- Returns:
Boolean mask of the correct shape.
- Return type:
numpy.ndarray
- class mangadap.util.pixelmask.SpectralPixelMask(artdb=None, emldb=None, waverange=None, nsig=None)[source]
Bases:
PixelMask
Container that produces a mask for the stellar continuum based on a set of emission lines and artifacts.
- Parameters:
artdb (
mangadap.proc.artifactdb.ArtifactDB
) – (Optional) Database with the list of artifacts to mask.emldb (
mangadap.proc.emissionlinedb.EmissionLineDB
) – (Optional) Database with the list of emission lines to mask.waverange (numpy.ndarray) – (Optional) Any pixels outside this wavelength range are masked.
- artdb
Database with the list of artifacts to mask.
- Type:
mangadap.proc.artifactdb.ArtifactDB
- emldb
Database with the list of emission lines to mask.
- Type:
mangadap.proc.emissionlinedb.EmissionLineDB
- waverange
Any pixels outside this wavelength range are masked.
- Type:
numpy.ndarray
- _artifact_mask(wave, nspec=None)[source]
Mask the pixels in the wavelength range(s) defined by the artifact database.
- Parameters:
wave (numpy.ndarray) – Wavelength coordinate vector
nspec (int) – (Optional) Number of spectra to mask. Default is just one.
- Returns:
Boolean mask of the correct shape.
- Return type:
numpy.ndarray
- _check_eml_kin_argument(kin)[source]
Check and return the correct kinematics vectors. If a single number is provided, the function returns the number repeated for each emission line.
- Parameters:
kin (float, list, numpy.ndarray) – An input set of kinematics to used by the mask.
- Returns:
A 1D float array of the correct shape with the kinematics
- Return type:
numpy.ndarray
- Raises:
ValueError – Raised if the length of the kin array is not the same as the number of emission lines in
emldb
.
- _emission_line_mask(wave, nspec=None, velocity_offsets=0.0, sigma=250.0)[source]
Mask the pixels in the wavelength range(s) defined by the emission-line database that has been adjusted by a set of velocities and dispersions.
Currently, the velocity offsets are applied to all lines for each spectrum, whereas sigma and nsigma are applied to all spectra for each line.
- Parameters:
wave (numpy.ndarray) – Wavelength coordinate vector
nspec (int) – (Optional) Number of spectra to mask. Default is just one.
velocity_offsets (float, numpy.ndarray) – (Optional) One or more velocity offsets to apply to the emission-line bands on a spectrum-by-spectrum basis. Default is to apply no velocity offset.
sigma (float, numpy.ndarray) – (Optional) One or more velocity dispersions to use for setting the width of the emission-line band on a line-by-line basis. Default is a width based on a dispersion of 250 km/s.
nsigma (float, numpy.ndarray) – (Optional) One or more numbers that sets the width of the band in units of the provided velocity dipsersions band on a line-by-line basis.
- Returns:
Boolean mask of the correct shape.
- Return type:
numpy.ndarray
- _get_emission_line_bands(velocity_offsets=0.0, sigma=250.0)[source]
Set the emission-line masks, using the emission-line parameters defined by
emldb
(seemangadap.par.emissionlinedb.EmissionLineDB
.All emission lines in the database, except for those marked with action==i are masked.
The center of the masked region is constructed using emldb[‘restwave’] and the provided velocity (velocity_offset). The velocity of any lines marked as sky (action==s) is always set to 0.
The width of the mask is set to be \(\pm n_\sigma \sigma\) about this center, where both \(n_\sigma\) and \(\sigma\) are parameters (nsigma, sigma). If sigma is None, emldb[‘sig’] is used for each line.
- Parameters:
velocity_offsets (float, numpy.ndarray) – (Optional) The velocity offset to apply to each emission-line mask. Must be either a single number or one number per emission line. Assumed to be 0 if set to None.
sigma (float, numpy.ndarray) – (Optional) Line velocity dispersions used to set the mask width. Must be either a single number or one number per emission line. If None, the dispersion provided by the emission-line database is used (emldb[‘sig’]).
nsigma (float, numpy.ndarray) – (Optional) The half-width of the band in units of the provided velocity dipsersions. Must be either a single number or one number per emission line. Cannot be None.
- Returns:
A \(N_l \times 2\) array with the wavelength limits of the emission-line bands.
- Return type:
numpy.ndarray
- Raises:
ValueError – Raised if nsigma is None, or any nsigma is not greater than 0; raised if the half-width of any mask is not greater than 0.
- _waverange_mask(wave, nspec=None)[source]
Mask the pixels not within the selected wavelength range.
- Parameters:
wave (numpy.ndarray) – Wavelength coordinate vector
nspec (int) – (Optional) Number of spectra to mask. Default is just one.
- Returns:
Boolean mask of the correct shape.
- Return type:
numpy.ndarray
- bits(bitmask, wave, nspec=None, mask=None, velocity_offsets=0.0, sigma=250.0, waverange_flag='OUTSIDE_RANGE', art_flag='ARTIFACT', eml_flag='EML_REGION')[source]
Construct a bit mask that signifies pixels as outside the desired wavelength range, as being affected by an artifact, and being designated as an emission-line region. To simply flag the pixels as a binary masked or unmasked, use
boolean()
.- Parameters:
bitmask (
mangadap.util.bitmask.BitMask
) – Bitmask used to flag pixels. The flags waverange_flag, art_flag, and eml_flag must be defined in the provided instance of BitMask.wave (numpy.ndarray) – Wavelength coordinate vector
nspec (int) – (Optional) Number of spectra to mask. Default is just one.
mask (numpy.array) – (Optional) Baseline mask to add pixels masks. Should have data type that matches provided bitmask. Default is to start with all pixels unmasked.
velocity_offsets (float, numpy.ndarray) – (Optional) One or more velocity offsets to apply to the emission-line bands on a spectrum-by-spectrum basis. Default is to apply no velocity offset.
sigma (float, numpy.ndarray) – (Optional) One or more velocity dispersions to use for setting the width of the emission-line band on a line-by-line basis. Default is a width based on a dispersion of 250 km/s.
nsigma (float, numpy.ndarray) – (Optional) One or more numbers that sets the width of the band in units of the provided velocity dipsersions band on a line-by-line basis.
waverange_flag (str) – (Optional) Bitmask name used to flag a pixel as outside of the desired wavelength range. Default is ‘OUTSIDE_RANGE’.
art_flag (str) – (Optional) Bitmask name used to flag a pixel being affected by an artifact. Default is ‘ARTIFACT’.
eml_flag (str) – (Optional) Bitmask name used to flag a pixel being within an emission-line region. Default is ‘EML_REGION’.
- Returns:
Bit mask of the correct shape.
- Return type:
numpy.ndarray
- boolean(wave, nspec=None, velocity_offsets=0.0, sigma=250.0)[source]
Construct the full boolean mask that includes the desired wavelength range, omitting artifacts, and omitting emission lines.
- Parameters:
wave (numpy.ndarray) – Wavelength coordinate vector
nspec (int) – (Optional) Number of spectra to mask. Default is just one.
velocity_offsets (float, numpy.ndarray) – (Optional) One or more velocity offsets to apply to the emission-line bands on a spectrum-by-spectrum basis. Default is to apply no velocity offset.
sigma (float, numpy.ndarray) – (Optional) One or more velocity dispersions to use for setting the width of the emission-line band on a line-by-line basis. Default is a width based on a dispersion of 250 km/s.
nsigma (float, numpy.ndarray) – (Optional) One or more numbers that sets the width of the band in units of the provided velocity dipsersions band on a line-by-line basis.
- Returns:
Boolean mask of the correct shape.
- Return type:
numpy.ndarray