def clip_region(spectrum, region): """ Given a region, clips the lower and upper bounds to the limits of the spectrum's spectral axis. Parameters ---------- spec : :class:`specutils.Spectrum1D` The spectrum whose bounds will be used in clipping. region : :class:`specutils.SpectralRegion` The region object whose bounds will change. Returns ------- :class:`specutils.SpectralRegion` New spectral region object with correct bounds. """ # 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 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 spectral_regions(self): """ Currently plotted ROIs returned as a :class:`~specutils.spectra.SpectralRegion`. """ regions = self.regions if len(regions) == 0: return None units = u.Unit(self.plot_window.plot_widget.spectral_axis_unit or "") positions = [] for region in regions: pos = (region.getRegion()[0] * units, region.getRegion()[1] * units) if pos is not None: positions.append(pos) return SpectralRegion(positions)
def pos_to_spectral_region(pos): """ Vet input region position and construct a `~specutils.utils.SpectralRegion`. Parameters ---------- 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)