extract_region

specutils.manipulation.extract_region(spectrum, region, return_single_spectrum=False)[source]

Extract a region from the input Spectrum1D defined by the lower and upper bounds defined by the region instance. The extracted region will be returned as a new Spectrum1D.

Parameters:
spectrum: `~specutils.Spectrum1D`

The spectrum object from which the region will be extracted.

region: `~specutils.SpectralRegion`

The spectral region to extract from the original spectrum.

return_single_spectrum: `bool`

If region has multiple sections, whether to return a single spectrum instead of multiple Spectrum1D objects. The returned spectrum will be a unique, concatenated, spectrum of all sub-regions.

Returns:
spectrum: Spectrum1D or list of Spectrum1D

Excised spectrum, or list of spectra if the input region contained multiple subregions and return_single_spectrum is False.

Notes

The region extracted is a discrete subset of the input spectrum. No interpolation is done on the left and right side of the spectrum.

The region is assumed to be a closed interval (as opposed to Python which is open on the upper end). For example:

Given:

A spectrum with spectral_axis of [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]*u.um.

A region defined as SpectralRegion(0.2*u.um, 0.5*u.um)

And we calculate sub_spectrum = extract_region(spectrum, region), then the sub_spectrum spectral axis will be [0.2, 0.3, 0.4, 0.5] * u.um.

If the region does not overlap with the spectrum then an empty Spectrum1D object will be returned.