Skip to content

Commit 2ee7cd5

Browse files
committed
Add hhs and nation
1 parent e5c80f1 commit 2ee7cd5

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

doctor_visits/delphi_doctor_visits/geo_maps.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ def county_to_state(self, data):
6161

6262
return data.groupby("state_id"), "state_id"
6363

64+
def county_to_hhs(self, data):
65+
"""Aggregate county data to the HHS region resolution.
66+
67+
Args:
68+
data: dataframe aggregated to the daily-county resolution (all 7 cols expected)
69+
70+
Returns: tuple of dataframe at the daily-HHS resolution, and geo_id column name
71+
"""
72+
data = self.gmpr.add_geocode(data,
73+
"fips",
74+
"hhs",
75+
from_col="PatCountyFIPS")
76+
data.drop(columns="PatCountyFIPS", inplace=True)
77+
data = data.groupby(["ServiceDate", "hhs"]).sum().reset_index()
78+
79+
return data.groupby("hhs"), "hhs"
80+
81+
def county_to_nation(self, data):
82+
"""Aggregate county data to the nation resolution.
83+
84+
Args:
85+
data: dataframe aggregated to the daily-county resolution (all 7 cols expected)
86+
87+
Returns: tuple of dataframe at the daily-nation resolution, and geo_id column name
88+
"""
89+
data = self.gmpr.add_geocode(data,
90+
"fips",
91+
"nation",
92+
from_col="PatCountyFIPS")
93+
data.drop(columns="PatCountyFIPS", inplace=True)
94+
data = data.groupby(["ServiceDate", "nation"]).sum().reset_index()
95+
96+
return data.groupby("nation"), "nation"
97+
6498
def county_to_hrr(self, data):
6599
"""Aggregate county data to the HRR resolution.
66100

doctor_visits/delphi_doctor_visits/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_module(params):
6868
logging.info("n_waiting_days:\t{n_waiting_days}")
6969

7070
## geographies
71-
geos = ["state", "msa", "hrr", "county"]
71+
geos = ["state", "msa", "hrr", "county", "hhs", "nation"]
7272

7373

7474
## print out other vars

doctor_visits/delphi_doctor_visits/update_sensor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def update_sensor(
7878
startdate: first sensor date (YYYY-mm-dd)
7979
enddate: last sensor date (YYYY-mm-dd)
8080
dropdate: data drop date (YYYY-mm-dd)
81-
geo: geographic resolution, one of ["county", "state", "msa", "hrr"]
81+
geo: geographic resolution, one of ["county", "state", "msa", "hrr", "nation", "hhs"]
8282
parallel: boolean to run the sensor update in parallel
8383
weekday: boolean to adjust for weekday effects
8484
se: boolean to write out standard errors, if true, use an obfuscated name
@@ -142,8 +142,15 @@ def update_sensor(
142142
data_groups, _ = geo_map.county_to_msa(data)
143143
elif geo.lower() == "hrr":
144144
data_groups, _ = geo_map.county_to_hrr(data)
145+
elif geo.lower() == "hhs":
146+
data_groups, _ = geo_map.county_to_hhs(data)
147+
elif geo.lower() == "nation":
148+
data_groups, _ = geo_map.county_to_nation(data)
145149
else:
146-
logging.error(f"{geo} is invalid, pick one of 'county', 'state', 'msa', 'hrr'")
150+
151+
logging.error(
152+
f"{geo} is invalid, pick one of 'county', 'state', 'msa', 'hrr', 'hhs', 'nation'"
153+
)
147154
return {}
148155
unique_geo_ids = list(data_groups.groups.keys())
149156

0 commit comments

Comments
 (0)