Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pos : `~astropy.units.Quantity`
A tuple `~astropy.units.Quantity` with
(min, max) range of roi.
Returns
-------
None or `~specutils.utils.SpectralRegion`
"""
if not isinstance(pos, u.Quantity):
return None
elif pos.unit == u.Unit("") or \
pos[0] == pos[1]:
return None
elif pos[0] > pos[1]:
pos = [pos[1], pos[0]] * pos.unit
return SpectralRegion(*pos)
pos : `~astropy.units.Quantity`
A tuple `~astropy.units.Quantity` with
(min, max) range of roi.
Returns
-------
None or `~specutils.utils.SpectralRegion`
"""
if not isinstance(pos, u.Quantity):
return None
elif pos.unit == u.Unit("") or \
pos[0] == pos[1]:
return None
elif pos[0] > pos[1]:
pos = [pos[1], pos[0]] * pos.unit
return SpectralRegion(*pos)
def clip_region(spectrum, region):
# If the region is out of data range return None:
if region.lower > spectrum.spectral_axis.max() or \
region.upper < spectrum.spectral_axis.min():
return None
# Clip region. There is currently no way to update
# SpectralRegion lower and upper so we have to create
# a new object here.
lower = max(region.lower, spectrum.spectral_axis.min())
upper = min(region.upper, spectrum.spectral_axis.max())
return SpectralRegion(lower, upper)
def __getslice__(self, item):
"""
Enable slicing of the SpectralRegion list.
"""
return SpectralRegion(self._subregions[item])