Skip to content

Commit 588f805

Browse files
committed
Add hhs and nation
1 parent 8b02dbd commit 588f805

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-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
@@ -64,6 +64,40 @@ def county_to_state(self, data):
6464

6565
return data.groupby("state_id"), "state_id"
6666

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

doctor_visits/delphi_doctor_visits/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def run_module():
4848
logging.info(f"n_waiting_days:\t{n_waiting_days}")
4949

5050
## geographies
51-
geos = ["state", "msa", "hrr", "county"]
51+
geos = ["state", "msa", "hrr", "county", "hhs", "nation"]
5252

5353
## print out other vars
5454
logging.info("outpath:\t\t%s", params["export_dir"])

doctor_visits/delphi_doctor_visits/update_sensor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def update_sensor(
8989
startdate: first sensor date (YYYY-mm-dd)
9090
enddate: last sensor date (YYYY-mm-dd)
9191
dropdate: data drop date (YYYY-mm-dd)
92-
geo: geographic resolution, one of ["county", "state", "msa", "hrr"]
92+
geo: geographic resolution, one of ["county", "state", "msa", "hrr", "nation", "hhs"]
9393
parallel: boolean to run the sensor update in parallel
9494
weekday: boolean to adjust for weekday effects
9595
se: boolean to write out standard errors, if true, use an obfuscated name
@@ -154,8 +154,14 @@ def update_sensor(
154154
data_groups, _ = geo_map.county_to_msa(data)
155155
elif geo.lower() == "hrr":
156156
data_groups, _ = geo_map.county_to_hrr(data)
157+
elif geo.lower() == "hhs":
158+
data_groups, _ = geo_map.county_to_hhs(data)
159+
elif geo.lower() == "nation":
160+
data_groups, _ = geo_map.county_to_nation(data)
157161
else:
158-
logging.error(f"{geo} is invalid, pick one of 'county', 'state', 'msa', 'hrr'")
162+
logging.error(
163+
f"{geo} is invalid, pick one of 'county', 'state', 'msa', 'hrr', 'hhs', 'nation'"
164+
)
159165
return False
160166
unique_geo_ids = list(data_groups.groups.keys())
161167

0 commit comments

Comments
 (0)