Skip to content

Commit 35ab469

Browse files
authored
Merge pull request #431 from cmu-delphi/change-smooth-refactor
Refactor CHC to use smoothing utils
2 parents 9056fa3 + 97ec39c commit 35ab469

File tree

5 files changed

+14
-59
lines changed

5 files changed

+14
-59
lines changed

changehc/delphi_changehc/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from . import load_data
1313
from . import run
1414
from . import sensor
15-
from . import smooth
1615
from . import update_sensor
1716
from . import weekday
1817

changehc/delphi_changehc/sensor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
# third party
1313
import numpy as np
1414
import pandas as pd
15+
from delphi_utils import Smoother
1516

1617
# first party
1718
from .config import Config
18-
from .smooth import left_gauss_linear
19+
1920

2021

2122
class CHCSensor:
2223
"""Sensor class to fit a signal using Covid counts from Change HC outpatient data.
2324
"""
25+
smoother = Smoother("savgol",
26+
poly_fit_degree=1,
27+
gaussian_bandwidth=Config.SMOOTHER_BANDWIDTH)
2428

2529
@staticmethod
2630
def gauss_smooth(count,total):
@@ -29,8 +33,8 @@ def gauss_smooth(count,total):
2933
Args:
3034
count, total: array
3135
"""
32-
count_smooth = left_gauss_linear(count)
33-
total_smooth = left_gauss_linear(total)
36+
count_smooth = CHCSensor.smoother.smooth(count)
37+
total_smooth = CHCSensor.smoother.smooth(total)
3438
total_clip = np.clip(total_smooth, 0, None)
3539
count_clip = np.clip(count_smooth, 0, total_clip)
3640
return count_clip, total_clip

changehc/delphi_changehc/smooth.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

changehc/tests/test_sensor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
# third party
5-
from delphi_utils import read_params
5+
from delphi_utils import read_params, Smoother
66
import numpy as np
77
import numpy.random as nr
88
import pandas as pd
@@ -20,7 +20,12 @@
2020

2121
class TestLoadData:
2222
combined_data = load_combined_data(DENOM_FILEPATH, COVID_FILEPATH, DROP_DATE,
23-
"fips")
23+
"fips")
24+
# change smoother window length for test data
25+
CHCSensor.smoother = Smoother("savgol",
26+
poly_fit_degree=1,
27+
gaussian_bandwidth=Config.SMOOTHER_BANDWIDTH,
28+
window_length=20)
2429

2530
def test_backfill(self):
2631
num0 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=float).reshape(-1, 1)

changehc/tests/test_smooth.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)