Skip to content

Commit f80926f

Browse files
authored
Merge pull request #429 from cmu-delphi/usafacts-smooth-refactor
Refactor Usafacts to use smoothing utils
2 parents 4483021 + 983d691 commit f80926f

File tree

3 files changed

+7
-81
lines changed

3 files changed

+7
-81
lines changed

usafacts/delphi_usafacts/run.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,22 @@
66
"""
77
from datetime import datetime, date, time, timedelta
88
from itertools import product
9-
from functools import partial
109
from os.path import join
1110

1211
import numpy as np
1312
import pandas as pd
1413
from delphi_utils import (
15-
read_params,
1614
create_export_csv,
15+
read_params,
16+
GeoMapper,
1717
S3ArchiveDiffer,
18-
GeoMapper
18+
Smoother
1919
)
2020

2121
from .geo import geo_map
2222
from .pull import pull_usafacts_data
23-
from .smooth import (
24-
identity,
25-
kday_moving_average,
26-
)
27-
2823

2924
# global constants
30-
seven_day_moving_average = partial(kday_moving_average, k=7)
3125
METRICS = [
3226
"confirmed",
3327
"deaths",
@@ -55,9 +49,10 @@
5549
# "incidence": ("incid_prop", False),
5650
# "cumulative_prop": ("cumul_prop", False),
5751
# }
52+
5853
SMOOTHERS_MAP = {
59-
"unsmoothed": (identity, '', False, lambda d: d - timedelta(days=7)),
60-
"seven_day_average": (seven_day_moving_average, '7dav_', True, lambda d: d),
54+
"unsmoothed": (Smoother("identity"), "", False, lambda d: d - timedelta(days=7)),
55+
"seven_day_average": (Smoother("moving_average", window_length=7), "7dav_", True, lambda d: d),
6156
}
6257
GEO_RESOLUTIONS = [
6358
"county",
@@ -99,7 +94,7 @@ def run_module():
9994
df = dfs[metric]
10095
# Aggregate to appropriate geographic resolution
10196
df = geo_map(df, geo_res, map_df, sensor)
102-
df["val"] = SMOOTHERS_MAP[smoother][0](df[sensor].values)
97+
df["val"] = SMOOTHERS_MAP[smoother][0].smooth(df[sensor].values)
10398
df["se"] = np.nan
10499
df["sample_size"] = np.nan
105100
# Drop early entries where data insufficient for smoothing

usafacts/delphi_usafacts/smooth.py

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

usafacts/tests/test_smooth.py

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

0 commit comments

Comments
 (0)