17 """Gaussian smoothing module - expect to import from smoothing module directly
24 Gaussian smoothing class applies a smoothing by summing nearby data and
25 weighting according to a truncated Gaussian distribution.
27 The Smoothing function has two parameters
28 - sigma (float) controls the width of the Gaussian distribution
29 - range_ (int) controls the truncation of the Gaussian. Only data points
30 within range_ of the principle data point will be added into the smoothed
31 value of the principle data point.
34 Smoothing near to the boundaries is performed using whatever data is
35 available. Normalisation at the boundaries can be handled in either of two
37 - if adjust_boundary_normalisation is True, normalisation is performed using
38 the sum of available weights (so if we are on the boundary, the
39 normalisation factor is increased and we get larger weightings).
40 - if adjust_boundary_normalisation is False, every smoothed element gets the
43 def __init__(self, sigma, range_, adjust_boundary_normalisation):
45 Initialise the smoothing
46 - sigma (float) width of the Gaussian distribution
47 - range_ (int) truncation distance applied to the Gaussian distribution
48 - adjust_boundary_normalisation (bool) set to true to adjust the
49 normalisation factor near to the edge of the data array due to the
50 fact there are fewer elements in the smoothing
54 two_sig_sq = 2.*sigma**2
58 if not adjust_boundary_normalisation:
62 """Smooth the signal"""
63 signal_out = [self.
_smooth_one(signal, i)
for i
in range(len(signal))]
67 """Smooth the point in signal at index i"""
68 s_0 = max(0, i-self.
range_)
69 s_1 = min(len(signal), i+self.
range_+1)
70 sigs = [signal[s_index]
for s_index
in range(s_0, s_1)]
73 w_1 = s_1 - i + self.
range_
74 assert(w_1-w_0 == s_1 - s_0)
75 weights = [self.
_weights[w_index]
for w_index
in range(w_0, w_1)]
78 this_norm = sum(weights)
81 weighted = [weights[j]*sigs[j]/this_norm
for j
in range(s_1-s_0)]
82 smoothed = sum(weighted)
def smooth
Smooth the signal.
def _smooth_one
Smooth the point in signal at index i.
Gaussian smoothing class applies a smoothing by summing nearby data and weighting according to a trun...