Skip to content

Commit c012908

Browse files
authored
Merge pull request #245 from cmu-delphi/jhu_fix_0824
fixed geo test
2 parents c04c722 + 31649e2 commit c012908

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

jhu/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ params.json
55

66
# Do not commit output files
77
receiving/*.csv
8+
tests/receiving/*.csv
89

910
# Remove macOS files
1011
.DS_Store

jhu/delphi_jhu/run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ def run_module():
9393
df = dfs[metric]
9494
# Aggregate to appropriate geographic resolution
9595
df = geo_map(df, geo_res)
96-
df["val"] = SMOOTHERS_MAP[smoother][0](df[sensor].values)
96+
df.set_index(["timestamp", "geo_id"], inplace=True)
97+
df["val"] = df[sensor].groupby(level=1).transform(SMOOTHERS_MAP[smoother][0])
9798
df["se"] = np.nan
9899
df["sample_size"] = np.nan
99100
# Drop early entries where data insufficient for smoothing
100-
df = df.loc[~df["val"].isnull(), :]
101+
df = df[~df["val"].isnull()]
102+
df = df.reset_index()
101103
sensor_name = SENSOR_NAME_MAP[sensor][0]
102104
# if (SENSOR_NAME_MAP[sensor][1] or SMOOTHERS_MAP[smoother][2]):
103105
# metric = f"wip_{metric}"

jhu/tests/receiving/.gitkeep

Whitespace-only changes.

jhu/tests/test_geo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_incorrect_geo(self):
2020
)
2121

2222
with pytest.raises(ValueError):
23-
geo_map(df, "département", 'new_counts')
23+
geo_map(df, "département")
2424

2525
def test_county(self):
2626
df = pd.DataFrame(
@@ -45,7 +45,7 @@ def test_county(self):
4545

4646
df = df.append(df_mega)
4747

48-
new_df = geo_map(df, "county", 'new_counts')
48+
new_df = geo_map(df, "county")
4949

5050
exp_incidence = df["new_counts"] / df["population"] * 100000
5151
exp_cprop = df["cumulative_counts"] / df["population"] * 100000
@@ -78,7 +78,7 @@ def test_state(self):
7878

7979
df = df.append(df_mega)
8080

81-
new_df = geo_map(df, "state", 'new_counts')
81+
new_df = geo_map(df, "state")
8282

8383
exp_incidence = np.array([27 + 5, 13 + 10]) / np.array([2500, 25]) * 100000
8484
exp_cprop = np.array([165 + 30, 60 + 100]) / np.array([2500, 25]) * 100000
@@ -114,7 +114,7 @@ def test_hrr(self):
114114

115115
# df = df.append(df_mega)
116116

117-
new_df = geo_map(df, "hrr", 'new_counts')
117+
new_df = geo_map(df, "hrr")
118118

119119
exp_incidence = np.array([13, 27]) / np.array([25, 2500]) * 100000
120120
exp_cprop = np.array([60, 165]) / np.array([25, 2500]) * 100000
@@ -145,7 +145,7 @@ def test_msa(self):
145145

146146
# df = df.append(df_mega)
147147

148-
new_df = geo_map(df, "msa", 'new_counts')
148+
new_df = geo_map(df, "msa")
149149

150150
assert new_df["geo_id"].isin([31420, 49340]).all()
151151
assert new_df["timestamp"].isin(["2020-02-15"]).all()

jhu/tests/test_smooth.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@
1010
class TestSmooth:
1111
def test_output_files_smoothed(self, run_as_module):
1212

13-
dates = [str(x) for x in range(20200701, 20200730)]
13+
dates = [str(x) for x in range(20200303, 20200310)]
1414

1515
smoothed = pd.read_csv(
16-
join("../receiving",
16+
join("./receiving",
1717
f"{dates[-1]}_state_confirmed_7dav_cumulative_num.csv")
1818
)
1919

20+
# Build a dataframe out of the individual day files
2021
raw = pd.concat([
2122
pd.read_csv(
22-
join("../receiving",
23+
join("./receiving",
2324
f"{date}_state_confirmed_cumulative_num.csv")
2425
) for date in dates
2526
])
26-
27+
# Compute the mean across the time values; order doesn't matter
28+
# this corresponds to the smoothed value on the last day
29+
# 2020-03-10
2730
raw = raw.groupby('geo_id')['val'].mean()
28-
df = pd.merge(smoothed, raw, on='geo_id', suffixes=('_smoothed', '_raw'))
2931

32+
df = pd.merge(smoothed, raw, on='geo_id', suffixes=('_smoothed', '_raw'))
3033
assert np.allclose(df['val_smoothed'].values, df['val_raw'].values)
34+

0 commit comments

Comments
 (0)