Skip to content

Commit 1d720ea

Browse files
committed
Refactor JHU smoother to use util:
* remove local smoothing module * update run.py
1 parent 647e05d commit 1d720ea

File tree

6 files changed

+13
-62
lines changed

6 files changed

+13
-62
lines changed

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
from .geomap import GeoMapper
1212
from .smooth import Smoother
1313
from .signal import add_prefix, public_signal
14+
from .smooth import Smoother
1415

1516
__version__ = "0.1.0"

_delphi_utils_python/tests/test_smooth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Tests for the smoothing utility.
33
Authors: Dmitry Shemetov, Addison Hu, Maria Jahja
44
"""
5-
from numpy.lib.polynomial import poly
65
import pytest
76

87
import numpy as np

jhu/delphi_jhu/run.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@
66
"""
77
from datetime import datetime
88
from itertools import product
9-
from functools import partial
109

1110
import numpy as np
11+
import pandas as pd
1212
from delphi_utils import (
13-
read_params,
14-
create_export_csv,
15-
S3ArchiveDiffer,
13+
read_params,
14+
create_export_csv,
15+
S3ArchiveDiffer,
16+
Smoother,
17+
GeoMapper
1618
)
1719

18-
from delphi_utils import GeoMapper
1920
from .geo import geo_map
2021
from .pull import pull_jhu_data
21-
from .smooth import (
22-
identity,
23-
kday_moving_average,
24-
)
2522

2623

2724
# global constants
28-
seven_day_moving_average = partial(kday_moving_average, k=7)
2925
METRICS = [
3026
"deaths",
3127
"confirmed",
@@ -54,8 +50,8 @@
5450
# "cumulative_prop": ("cumul_prop", False),
5551
# }
5652
SMOOTHERS_MAP = {
57-
"unsmoothed": (identity, ''),
58-
"seven_day_average": (seven_day_moving_average, '7dav_'),
53+
"unsmoothed": (Smoother("identity").smooth, ''),
54+
"seven_day_average": (Smoother("moving_average", window_length=7).smooth, '7dav_'),
5955
}
6056
GEO_RESOLUTIONS = [
6157
"county",

jhu/delphi_jhu/smooth.py

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

jhu/tests/test_run.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from os.path import join
55

66
import pandas as pd
7-
from delphi_jhu.run import run_module
87

98

109
class TestRun:

jhu/tests/test_smooth.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import pytest
22

3-
from os import listdir
43
from os.path import join
54

65
import numpy as np
76
import pandas as pd
8-
from delphi_jhu.run import run_module
97

108
class TestSmooth:
119
def test_output_files_smoothed(self, run_as_module):
12-
13-
dates = [str(x) for x in range(20200303, 20200310)]
10+
dates = [str(x) for x in range(20200304, 20200311)]
1411

1512
smoothed = pd.read_csv(
1613
join("./receiving",
@@ -27,8 +24,6 @@ def test_output_files_smoothed(self, run_as_module):
2724
# Compute the mean across the time values; order doesn't matter
2825
# this corresponds to the smoothed value on the last day
2926
# 2020-03-10
30-
raw = raw.groupby('geo_id')['val'].mean()
31-
32-
df = pd.merge(smoothed, raw, on='geo_id', suffixes=('_smoothed', '_raw'))
33-
assert np.allclose(df['val_smoothed'].values, df['val_raw'].values)
34-
27+
raw = raw.groupby("geo_id")["val"].mean()
28+
df = pd.merge(smoothed, raw, on="geo_id", suffixes=("_smoothed", "_raw"))
29+
assert np.allclose(df["val_smoothed"].values, df["val_raw"].values)

0 commit comments

Comments
 (0)