Skip to content

Commit 8878749

Browse files
committed
Add trivial smoother
1 parent 6c32060 commit 8878749

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

_delphi_utils_python/delphi_utils/smooth.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ class Smoother:
4444
half the gaussian_bandwidth. If None, performs unweighted regression. (Applies
4545
to 'left_gauss_linear' and 'savgol'.)
4646
Here are some reference values:
47-
time window (days) | bandwidth
48-
7 36
49-
14 144
50-
21 325
47+
time window | bandwidth
48+
7 36
49+
14 144
50+
21 325
5151
28 579
52-
35 905
53-
42 1303
52+
35 905
53+
42 1303
5454
impute: bool
5555
If True, will fill nan values before smoothing. Currently uses the 'savgol' method
5656
for imputation.
@@ -93,7 +93,7 @@ def __init__(
9393
else:
9494
self.coeffs = None
9595

96-
METHODS = {"savgol", "left_gauss_linear", "moving_average"}
96+
METHODS = {"savgol", "left_gauss_linear", "moving_average", "identity"}
9797

9898
if self.method_name not in METHODS:
9999
raise ValueError("Invalid method name given.")
@@ -120,6 +120,8 @@ def smooth(self, signal):
120120
signal_smoothed = self.left_gauss_linear_smoother(signal)
121121
elif self.method_name == "moving_average":
122122
signal_smoothed = self.moving_average_smoother(signal)
123+
elif self.method_name == "identity":
124+
signal_smoothed = signal
123125

124126
return signal_smoothed
125127

_delphi_utils_python/tests/test_smooth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414

1515
class TestSmoothers:
16+
def test_identity_smoother(self):
17+
signal = np.arange(30) + np.random.rand(30)
18+
assert np.allclose(signal, Smoother(method_name="identity").smooth(signal))
19+
1620
def test_moving_average_smoother(self):
1721
# The raw and smoothed lengths should match
1822
signal = np.ones(30)

0 commit comments

Comments
 (0)