7
7
Created: 2020-04-18
8
8
Last modified: 2020-04-30 by Aaron Rumack (add megacounty code)
9
9
"""
10
+ from functools import partial
10
11
11
12
import pandas as pd
12
13
from delphi_utils .geomap import GeoMapper
@@ -20,6 +21,14 @@ class GeoMaps:
20
21
def __init__ (self ):
21
22
"""Create the underlying GeoMapper."""
22
23
self .gmpr = GeoMapper ()
24
+ self .geo_func = {"county" : partial (self .county_to_megacounty ,
25
+ threshold_visits = Config .MIN_RECENT_VISITS ,
26
+ threshold_len = Config .RECENT_LENGTH ),
27
+ "state" : self .county_to_state ,
28
+ "msa" : self .county_to_msa ,
29
+ "hrr" : self .county_to_hrr ,
30
+ "hhs" : self .county_to_hhs ,
31
+ "nation" : self .county_to_nation }
23
32
24
33
@staticmethod
25
34
def convert_fips (x ):
@@ -61,6 +70,40 @@ def county_to_state(self, data):
61
70
62
71
return data .groupby ("state_id" ), "state_id"
63
72
73
+ def county_to_hhs (self , data ):
74
+ """Aggregate county data to the HHS region resolution.
75
+
76
+ Args:
77
+ data: dataframe aggregated to the daily-county resolution (all 7 cols expected)
78
+
79
+ Returns: tuple of dataframe at the daily-HHS resolution, and geo_id column name
80
+ """
81
+ data = self .gmpr .add_geocode (data ,
82
+ "fips" ,
83
+ "hhs" ,
84
+ from_col = "PatCountyFIPS" )
85
+ data .drop (columns = "PatCountyFIPS" , inplace = True )
86
+ data = data .groupby (["ServiceDate" , "hhs" ]).sum ().reset_index ()
87
+
88
+ return data .groupby ("hhs" ), "hhs"
89
+
90
+ def county_to_nation (self , data ):
91
+ """Aggregate county data to the nation resolution.
92
+
93
+ Args:
94
+ data: dataframe aggregated to the daily-county resolution (all 7 cols expected)
95
+
96
+ Returns: tuple of dataframe at the daily-nation resolution, and geo_id column name
97
+ """
98
+ data = self .gmpr .add_geocode (data ,
99
+ "fips" ,
100
+ "nation" ,
101
+ from_col = "PatCountyFIPS" )
102
+ data .drop (columns = "PatCountyFIPS" , inplace = True )
103
+ data = data .groupby (["ServiceDate" , "nation" ]).sum ().reset_index ()
104
+
105
+ return data .groupby ("nation" ), "nation"
106
+
64
107
def county_to_hrr (self , data ):
65
108
"""Aggregate county data to the HRR resolution.
66
109
0 commit comments