This repository has been archived by the owner on Jul 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
der_snr.py
63 lines (49 loc) · 2.35 KB
/
der_snr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
A spectral Signal-to-Noise ratio calculator, as set forth by the
Spectral Container Working Group of ST-ECF, MAST and CADC.
'''
# =====================================================================================
def DER_SNR(flux):
# =====================================================================================
"""
DESCRIPTION This function computes the signal to noise ratio DER_SNR following the
definition set forth by the Spectral Container Working Group of ST-ECF,
MAST and CADC.
signal = median(flux)
noise = 1.482602 / sqrt(6) median(abs(2 flux_i - flux_i-2 - flux_i+2))
snr = signal / noise
values with padded zeros are skipped
USAGE snr = DER_SNR(flux)
PARAMETERS none
INPUT flux (the computation is unit independent)
OUTPUT the estimated signal-to-noise ratio [dimensionless]
USES numpy
NOTES 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
For most spectra, these conditions are met.
REFERENCES * ST-ECF Newsletter, Issue #42:
www.spacetelescope.org/about/further_information/newsletters/html/newsletter_42.html
* Software:
www.stecf.org/software/ASTROsoft/DER_SNR/
AUTHOR Felix Stoehr, ST-ECF
24.05.2007, fst, initial import
01.01.2007, fst, added more help text
28.04.2010, fst, return value is a float now instead of a numpy.float64
"""
from numpy import array, where, median, abs
flux = array(flux)
# Values that are exactly zero (padded) are skipped
flux = array(flux[where(flux != 0.0)])
n = len(flux)
# For spectra shorter than this, no value can be returned
if (n>4):
signal = median(flux)
noise = 0.6052697 * median(abs(2.0 * flux[2:n-2] - flux[0:n-4] - flux[4:n]))
return float(signal / noise)
else:
return 0.0
# end DER_SNR -------------------------------------------------------------------------