SpectralRegion

class specutils.spectra.spectral_region.SpectralRegion(*args)[source]

Bases: object

A SpectralRegion is a container class enables some simplicty in defining and passing a region (interval) for a spectrum.

In the future, there might be more functionality added in here and there is some discussion that this might/could move to Astropy Regions.

Parameters:

lower: Scalar `~astropy.units.Quantity` with pixel or any valid ``spectral_axis`` unit

The lower bound of the region.

upper: Scalar `~astropy.units.Quantity` with pixel or any valid ``spectral_axis`` unit

The upper bound of the region.

Notes

The subregions will be ordered based on the lower bound of each subregion.

Lower and upper values for the interval.

Attributes Summary

bounds Compute the lower and upper extent of the SpectralRegion.
lower The most minimum value of the sub-regions.
subregions
upper The most maximum value of the sub-regions.

Methods Summary

from_center([center, width]) SpectralRegion class method that enables the definition of a SpectralRegion from the center and width rather than lower and upper bounds.
invert(lower_bound, upper_bound) Given a set of sub-regions this SpectralRegion defines, create a new SpectralRegion such that the sub-regions are defined in the new one as regions not in this SpectralRegion.
invert_from_spectrum(spectrum) Invert a SpectralRegion based on the extent of the input spectrum.

Attributes Documentation

bounds

Compute the lower and upper extent of the SpectralRegion.

lower

The most minimum value of the sub-regions.

The sub-regions are ordered based on the lower bound, so the lower bound for this instance is the lower bound of the first sub-region.

subregions
upper

The most maximum value of the sub-regions.

The sub-regions are ordered based on the lower bound, but the upper bound might not be the upper bound of the last sub-region so we have to look for it.

Methods Documentation

classmethod from_center(center=None, width=None)[source]

SpectralRegion class method that enables the definition of a SpectralRegion from the center and width rather than lower and upper bounds.

Parameters:

center: Scalar `~astropy.units.Quantity` with pixel or any valid ``spectral_axis`` unit

The center of the spectral region.

Width: Scalar `~astropy.units.Quantity` with pixel or any valid ``spectral_axis`` unit

The width of the spectral region.

invert(lower_bound, upper_bound)[source]

Given a set of sub-regions this SpectralRegion defines, create a new SpectralRegion such that the sub-regions are defined in the new one as regions not in this SpectralRegion.

Parameters:

lower: Scalar `~astropy.units.Quantity` with pixel or any valid ``spectral_axis`` unit

The lower bound of the region.

upper: Scalar `~astropy.units.Quantity` with pixel or any valid ``spectral_axis`` unit

The upper bound of the region.

Returns:

spectral_region: SpectralRegion

Spectral region of the non-selected regions

Notes

For example, if this SpectralRegion is defined as:
sr = SpectralRegion([(0.45*u.um, 0.6*u.um), (0.8*u.um, 0.9*u.um)])

and we call sr_invert = sr.invert(0.3*u.um, 1.0*u.um) then sr_invert will be SpectralRegion([(0.3*u.um, 0.45*u.um), (0.6*u.um, 0.8*u.um), (0.9*u.um, 1*u.um)])

This could be useful if a SpectralRegion has sub-regions defined for peaks in a spectrum and then one wants to create a SpectralRegion defined as all the non-peaks, then one could use this function.

invert_from_spectrum(spectrum)[source]

Invert a SpectralRegion based on the extent of the input spectrum.

See notes in SpectralRegion.invert() method.