Skip to content

Commit 63f2697

Browse files
authored
Merge pull request #613 from cmu-delphi/change-hhs-nation
Add nation and HHS to CHC
2 parents 473ef27 + 56d7701 commit 63f2697

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

ansible/templates/changehc-params-prod.json.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"n_waiting_days": 3,
1818
"se": false,
1919
"parallel": false,
20-
"geos": ["state", "msa", "hrr", "county"],
20+
"geos": ["state", "msa", "hrr", "county", "hhs", "nation"],
2121
"weekday": [true, false],
2222
"types": ["covid","cli"],
2323
"wip_signal": "",

changehc/delphi_changehc/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ class Constants:
6868
NUM_HRRS = 308
6969
NUM_MSAS = 392 + 52 # MSA + States
7070
NUM_STATES = 52 # including DC and PR
71+
NUM_NATIONS = 1
72+
NUM_HHSS = 10
7173

7274
MAX_GEO = {"county": NUM_COUNTIES,
7375
"hrr": NUM_HRRS,
7476
"msa": NUM_MSAS,
75-
"state": NUM_STATES}
77+
"state": NUM_STATES,
78+
"nation": NUM_NATIONS,
79+
"hhs": NUM_HHSS}

changehc/delphi_changehc/update_sensor.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self,
9191
startdate: first sensor date (YYYY-mm-dd)
9292
enddate: last sensor date (YYYY-mm-dd)
9393
dropdate: data drop date (YYYY-mm-dd)
94-
geo: geographic resolution, one of ["county", "state", "msa", "hrr"]
94+
geo: geographic resolution, one of ["county", "state", "msa", "hrr", "hhs", "nation"]
9595
parallel: boolean to run the sensor update in parallel
9696
weekday: boolean to adjust for weekday effects
9797
numtype: type of count data used, one of ["covid", "cli"]
@@ -104,9 +104,8 @@ def __init__(self,
104104
), f"not enough data to produce estimates starting {self.startdate}"
105105
assert self.startdate < self.enddate, "start date >= end date"
106106
assert self.enddate <= self.dropdate, "end date > drop date"
107-
assert geo in ['county', 'state', 'msa', 'hrr'],\
108-
f"{geo} is invalid, pick one of 'county', 'state', 'msa', 'hrr'"
109-
self.geo, self.parallel, self.weekday, self.numtype, self.se = geo.lower(), parallel, weekday, numtype, se
107+
self.geo, self.parallel, self.weekday, self.numtype, self.se = geo.lower(), parallel, \
108+
weekday, numtype, se
110109

111110
# output file naming
112111
if self.numtype == "covid":
@@ -145,10 +144,9 @@ def geo_reindex(self, data):
145144
# get right geography
146145
geo = self.geo
147146
gmpr = GeoMapper()
148-
if geo not in {"county", "state", "msa", "hrr"}:
149-
logging.error("{0} is invalid, pick one of 'county', 'state', 'msa', 'hrr'".format(
150-
geo
151-
))
147+
if geo not in {"county", "state", "msa", "hrr", "nation", "hhs"}:
148+
logging.error("{0} is invalid, pick one of 'county', "
149+
"'state', 'msa', 'hrr', 'hss','nation'".format(geo))
152150
return False
153151
if geo == "county":
154152
data_frame = gmpr.fips_to_megacounty(data,
@@ -158,10 +156,8 @@ def geo_reindex(self, data):
158156
mega_col=geo)
159157
elif geo == "state":
160158
data_frame = gmpr.replace_geocode(data, "fips", "state_id", new_col="state")
161-
elif geo == "msa":
162-
data_frame = gmpr.replace_geocode(data, "fips", "msa")
163-
elif geo == "hrr":
164-
data_frame = gmpr.replace_geocode(data, "fips", "hrr")
159+
else:
160+
data_frame = gmpr.replace_geocode(data, "fips", geo)
165161

166162
unique_geo_ids = pd.unique(data_frame[geo])
167163
data_frame.set_index([geo, Config.DATE_COL],inplace=True)

changehc/params.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"n_waiting_days": 3,
1818
"se": false,
1919
"parallel": false,
20-
"geos": ["state", "msa", "hrr", "county"],
20+
"geos": ["state", "msa", "hrr", "county", "nation", "hhs"],
2121
"weekday": [true, false],
2222
"types": ["covid","cli"],
2323
"wip_signal": "",

changehc/tests/params.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"n_waiting_days": 3,
1212
"se": false,
1313
"parallel": false,
14-
"geos": ["state", "msa", "hrr", "county"],
14+
"geos": ["state", "msa", "hrr", "county", "nation", "hhs"],
1515
"weekday": [true, false],
1616
"wip_signal": "",
1717
"aws_credentials": {

changehc/tests/test_update_sensor.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestCHCSensorUpdator:
3636
prefix = "foo"
3737
small_test_data = pd.DataFrame({
3838
"num": [0, 100, 200, 300, 400, 500, 600, 100, 200, 300, 400, 500, 600],
39-
"fips": [1.0] * 7 + [2.0] * 6,
39+
"fips": ['01001'] * 7 + ['04007'] * 6,
4040
"den": [1000] * 7 + [2000] * 6,
4141
"date": [pd.Timestamp(f'03-{i}-2020') for i in range(1, 14)]}).set_index(["fips","date"])
4242

@@ -64,20 +64,21 @@ def test_shift_dates(self):
6464

6565
def test_geo_reindex(self):
6666
"""Tests that the geo reindexer changes the geographic resolution."""
67-
su_inst = CHCSensorUpdator(
68-
"02-01-2020",
69-
"06-01-2020",
70-
"06-12-2020",
71-
'county',
72-
self.parallel,
73-
self.weekday,
74-
self.numtype,
75-
self.se
76-
)
77-
su_inst.shift_dates()
78-
data_frame = su_inst.geo_reindex(self.small_test_data.reset_index())
79-
assert data_frame.shape[0] == 2*len(su_inst.fit_dates)
80-
assert (data_frame.sum() == (4200,19000)).all()
67+
for geo, multiple in [("nation", 1), ("county", 2), ("hhs", 2)]:
68+
su_inst = CHCSensorUpdator(
69+
"02-01-2020",
70+
"06-01-2020",
71+
"06-12-2020",
72+
geo,
73+
self.parallel,
74+
self.weekday,
75+
self.numtype,
76+
self.se
77+
)
78+
su_inst.shift_dates()
79+
data_frame = su_inst.geo_reindex(self.small_test_data.reset_index())
80+
assert data_frame.shape[0] == multiple*len(su_inst.fit_dates)
81+
assert (data_frame.sum() == (4200,19000)).all()
8182

8283
def test_update_sensor(self):
8384
"""Tests that the sensors are properly updated."""

0 commit comments

Comments
 (0)