Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
-----
The spectrum will need to have the uncertainty defined in order for the SNR
to be calculated. If the goal is instead signal to noise *per pixel*, this
should be computed directly as ``spectrum.flux / spectrum.uncertainty``.
"""
if not hasattr(spectrum, 'uncertainty') or spectrum.uncertainty is None:
raise Exception("Spectrum1D currently requires the uncertainty be defined.")
# No region, therefore whole spectrum.
if region is None:
return _snr_single_region(spectrum)
# Single region
elif isinstance(region, SpectralRegion):
return _snr_single_region(spectrum, region=region)
# List of regions
elif isinstance(region, list):
return [_snr_single_region(spectrum, region=reg)
for reg in region]
Centroid of the spectrum or within the regions
Notes
-----
The spectrum will need to be continuum subtracted before calling
this method. See the
`analysis documentation `_ for more information.
"""
# No region, therefore whole spectrum.
if region is None:
return _centroid_single_region(spectrum)
# Single region
elif isinstance(region, SpectralRegion):
return _centroid_single_region(spectrum, region=region)
# List of regions
elif isinstance(region, list):
return [_centroid_single_region(spectrum, region=reg)
for reg in region]
The DER_SNR algorithm is an unbiased estimator describing the spectrum
as a whole as long as the noise is uncorrelated in wavelength bins spaced
two pixels apart, the noise is Normal distributed, for large wavelength
regions, the signal over the scale of 5 or more pixels can be approximated
by a straight line.
Code and some docs copied from
``http://www.stecf.org/software/ASTROsoft/DER_SNR/der_snr.py``
"""
# No region, therefore whole spectrum.
if region is None:
return _snr_derived(spectrum)
# Single region
elif isinstance(region, SpectralRegion):
return _snr_derived(spectrum, region=region)
# List of regions
elif isinstance(region, list):
return [_snr_derived(spectrum, region=reg)
for reg in region]
-------
spectrum : `~specutils.Spectrum1D`
Output `~specutils.Spectrum1D` with the region excised.
Raises
------
ValueError
In the case that ``spectrum`` and ``region`` are not the correct types.
"""
# Parameter checks
if not isinstance(spectrum, Spectrum1D):
raise ValueError('The spectrum parameter must be a Spectrum1D object.')
if not isinstance(region, SpectralRegion):
raise ValueError('The region parameter must be a SpectralRegion object.')
#
# Call the exciser method
#
return exciser(spectrum, region)