Skip to content

Refactor CHC to use smoothing utils #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion changehc/delphi_changehc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from . import load_data
from . import run
from . import sensor
from . import smooth
from . import update_sensor
from . import weekday

Expand Down
10 changes: 7 additions & 3 deletions changehc/delphi_changehc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
# third party
import numpy as np
import pandas as pd
from delphi_utils import Smoother

# first party
from .config import Config
from .smooth import left_gauss_linear



class CHCSensor:
"""Sensor class to fit a signal using Covid counts from Change HC outpatient data.
"""
smoother = Smoother("savgol",
poly_fit_degree=1,
gaussian_bandwidth=Config.SMOOTHER_BANDWIDTH)

@staticmethod
def gauss_smooth(count,total):
Expand All @@ -29,8 +33,8 @@ def gauss_smooth(count,total):
Args:
count, total: array
"""
count_smooth = left_gauss_linear(count)
total_smooth = left_gauss_linear(total)
count_smooth = CHCSensor.smoother.smooth(count)
total_smooth = CHCSensor.smoother.smooth(total)
total_clip = np.clip(total_smooth, 0, None)
count_clip = np.clip(count_smooth, 0, total_clip)
return count_clip, total_clip
Expand Down
36 changes: 0 additions & 36 deletions changehc/delphi_changehc/smooth.py

This file was deleted.

9 changes: 7 additions & 2 deletions changehc/tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

# third party
from delphi_utils import read_params
from delphi_utils import read_params, Smoother
import numpy as np
import numpy.random as nr
import pandas as pd
Expand All @@ -20,7 +20,12 @@

class TestLoadData:
combined_data = load_combined_data(DENOM_FILEPATH, COVID_FILEPATH, DROP_DATE,
"fips")
"fips")
# change smoother window length for test data
CHCSensor.smoother = Smoother("savgol",
poly_fit_degree=1,
gaussian_bandwidth=Config.SMOOTHER_BANDWIDTH,
window_length=20)

def test_backfill(self):
num0 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=float).reshape(-1, 1)
Expand Down
17 changes: 0 additions & 17 deletions changehc/tests/test_smooth.py

This file was deleted.