SpectralRegion#
- class specutils.SpectralRegion(*args)[source]#
Bases:
objectA
SpectralRegionis a container class for regions (intervals) along a spectral coordinate.This class can either represent a single contiguous region or a set of regions related to each other in some way (For example, a pair of continuum windows around a line or a doublet of lines).
- Parameters:
Notes
The subregions will be ordered based on the lower bound of each subregion.
Attributes Summary
Compute the lower and upper extent of the SpectralRegion.
The most minimum value of the sub-regions.
An iterable over
(lower, upper)tuples that are each of the sub-regions.The most maximum value of the sub-regions.
Methods Summary
as_table()Returns an
QTablewith the upper and lower bound of each subregion in theSpectralRegion.contains(spectral_value)Determine whether a spectral axis value is within the defined spectral region.
from_center([center, width])SpectralRegion class method that enables the definition of a
SpectralRegionfrom the center and width rather than lower and upper bounds.from_line_list(table[, width])Generate a
SpectralRegioninstance from theQTableobject returned fromfind_lines_derivativeorfind_lines_threshold.from_qtable(table)Generate a
SpectralRegioninstance from anQTableobject has haslower_boundandupper_boundcolumnsintersection(other)Return a region representing the intersection of this region with
other.invert(lower_bound, upper_bound)Invert this spectral region.
invert_from_spectrum(spectrum)Invert a SpectralRegion based on the extent of the input spectrum.
read(filename)Create a
SpectralRegionfrom an ecsv file output by theSpectralRegion.writemethod.symmetric_difference(other)Return the union of the two regions minus any areas contained in the intersection of the two regions.
Dummy method to allow simpler recursion in CompoundSpectralRegion
union(other)Return a region representing the union of this region with
other.write([filename, overwrite])Write the SpectralRegion to an ecsv file using
QTable.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#
An iterable over
(lower, upper)tuples that are each of the sub-regions.
- 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
- as_table()[source]#
Returns an
QTablewith the upper and lower bound of each subregion in theSpectralRegion.
- contains(spectral_value)[source]#
Determine whether a spectral axis value is within the defined spectral region.
- Parameters:
- spectral_value
Quantity The value (wavelength, frequency, etc) to check for inclusion in the SpectralRegion.
- spectral_value
- classmethod from_center(center=None, width=None)[source]#
SpectralRegion class method that enables the definition of a
SpectralRegionfrom the center and width rather than lower and upper bounds.
- classmethod from_line_list(table, width=1)[source]#
Generate a
SpectralRegioninstance from theQTableobject returned fromfind_lines_derivativeorfind_lines_threshold.- Parameters:
- table
QTable List of found lines.
- widthfloat
The width of the spectral line region. If not unit information is provided, it’s assumed to be the same units as used in the line list table.
- table
- Returns:
SpectralRegionThe spectral region based on the line list.
- classmethod from_qtable(table)[source]#
Generate a
SpectralRegioninstance from anQTableobject has haslower_boundandupper_boundcolumns- Parameters:
- Returns:
SpectralRegionThe spectral region based on the table of bounds.
- intersection(other)[source]#
Return a region representing the intersection of this region with
other.- Parameters:
- other
SpectralRegion The other region to use for the intersection.
- other
- invert(lower_bound, upper_bound)[source]#
Invert this spectral region. That is, given a set of sub-regions this object defines, create a new
SpectralRegionsuch that the sub-regions are defined in the new one as regions not in thisSpectralRegion.- Parameters:
- lower_bound
Quantity The lower bound of the region. Can be scalar with pixel or any valid
spectral_axisunit that is equal to or compatible with the unit oflower_bound.- upper_bound
Quantity The upper bound of the region. Can be scalar with pixel or any valid
spectral_axisunit that is equal to or compatible with the unit oflower_bound.
- lower_bound
- Returns:
- spectral_region
SpectralRegion Spectral region of the non-selected regions.
- spectral_region
- Raises:
- ValueError
Raised when
upper_boundandlower_bounddo not have compatible units.
Notes
This is applicable if, for example, a
SpectralRegionhas sub-regions defined for peaks in a spectrum and then one wants to create aSpectralRegiondefined as all the non-peaks, then one could use this function.As an example, assume this SpectralRegion is defined as
sr = SpectralRegion([(0.45*u.um, 0.6*u.um), (0.8*u.um, 0.9*u.um)]). If we callsr_invert = sr.invert(0.3*u.um, 1.0*u.um)thensr_invertwill beSpectralRegion([(0.3*u.um, 0.45*u.um), (0.6*u.um, 0.8*u.um), (0.9*u.um, 1*u.um)])
- invert_from_spectrum(spectrum)[source]#
Invert a SpectralRegion based on the extent of the input spectrum.
See notes in SpectralRegion.invert() method.
- classmethod read(filename)[source]#
Create a
SpectralRegionfrom an ecsv file output by theSpectralRegion.writemethod.- Parameters:
- filenamestr
The name of the ecsv file on disk to be read in as a
SpectralRegion.
- symmetric_difference(other)[source]#
Return the union of the two regions minus any areas contained in the intersection of the two regions.
- Parameters:
- other
SpectralRegion The other region to use for the symmetric difference.
- other
- union(other)[source]#
Return a region representing the union of this region with
other.- Parameters:
- other
SpectralRegion The other region to use for the union.
- other