Masks

Classes inheriting form Mask create good pixel masks for spectra. They are called by the main routine with each component as parameter. So in order to work, derived classes must implement both the constructor __init__() and __call__().

spexxy comes with a few pre-defined mask classes:

  • MaskEnds masks a given number of pixels at both ends of a spectrum.
  • MaskFromPath loads a mask from a file with the same name in a given directory.
  • MaskRanges accepts wavelength ranges in its constructor that are then used to create a mask.

Mask

class spexxy.mask.Mask(*args, **kwargs)

Mask is the base class for all objects that can create a good pixel mask for spectra.

__call__(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray

Creates a new mask for a spectrum.

Parameters:
  • spectrum – Spectrum to create mask for.
  • filename – Name of file containing spectrum to create mask for.
Returns:

Boolean array containing good pixel mask for given spectrum.

__init__(*args, **kwargs)

Initialize a new mask.

MaskEnds

class spexxy.mask.MaskEnds(npixels=10, *args, **kwargs)

Masks the ends of a spectrum.

This class, when called, creates a mask that masks the N pixels at each end of the given spectrum.

__call__(spectrum: spexxy.data.spectrum.Spectrum, filename: str = None) → numpy.ndarray

Creates a new mask for the given spectrum masking only the N pixels at each end.

Parameters:
  • spectrum – Spectrum to create mask for.
  • filename – Name of file containing spectrum to create mask for (unused).
Returns;
Boolean array containing good pixel mask for given spectrum.
__init__(npixels=10, *args, **kwargs)

Initializes a new mask masking the ends of a spectrum.

Parameters:npixels – Number of pixels to mask at each end of the spectrum.

MaskFromPath

class spexxy.mask.MaskFromPath(path: str, fits_extension: str = 'GOODPIXELS', *args, **kwargs)

Reads a pre-calculated mask from another file of a given name.

This class, when called, searches for a file of the given name in the directory specified in the configuration. If it exists, the extension of the given name (defaults to “GOODPIXELS”) is read, converted into a Boolean array, and returned. If it doesn’t exist, an empty mask is returned.

__call__(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray

Creates a new mask for a spectrum from a file of the same name in a given directory.

Parameters:
  • spectrum – Spectrum to create mask for.
  • filename – Name of file containing spectrum to create mask for.
Returns:

Boolean array containing good pixel mask for given spectrum.

__init__(path: str, fits_extension: str = 'GOODPIXELS', *args, **kwargs)

Initializes a new mask from a file in a given path.

Parameters:
  • path – Path to search in for file containing mask.
  • fits_extension – FITS extension to read mask from.

MaskNegative

class spexxy.mask.MaskNegative(*args, **kwargs)

Masks negative fluxes in a spectrum.

This class, when called, creates a mask that masks all negative pixels in the given spectrum.

__call__(spectrum: spexxy.data.spectrum.Spectrum, filename: str = None) → numpy.ndarray

Creates a new mask for the given spectrum masking all negative pixels.

Parameters:
  • spectrum – Spectrum to create mask for.
  • filename – Name of file containing spectrum to create mask for (unused).
Returns;
Boolean array containing good pixel mask for given spectrum.
__init__(*args, **kwargs)

Initializes a new mask for masking negative pixels in a spectrum.

MaskRanges

class spexxy.mask.MaskRanges(ranges: list, vrad: Union[str, float] = None, component: str = None, vrad_parameter: str = None, *args, **kwargs)

Masks ranges in spectra.

This class, when called, creates a mask on the given wavelength ranges

__call__(spectrum: spexxy.data.spectrum.Spectrum, filename: str = None) → numpy.ndarray

Creates a new dynamic mask for a spectrum in the wavelength ranges given in the configuration and shifted by the current radial velocity of the given component.

Parameters:
  • spectrum – Spectrum to create mask for.
  • filename – Name of file containing spectrum to create mask for.
Returns:

Boolean array containing good pixel mask for given spectrum.

__init__(ranges: list, vrad: Union[str, float] = None, component: str = None, vrad_parameter: str = None, *args, **kwargs)

Initializes a new mask.

Parameters:
  • ranges – List of tuples defining (start, end) of wavelength ranges to mask.
  • vrad – Radial velocity to shift by, either a number or the name of a FITS header entry, in which case “-<name>” negates the value.
  • component – Name of component to read the radial velocity from.
  • vrad_parameter – Name of parameter in given component to use as radial velocity.