12
12
import numpy as np
13
13
import pandas as pd
14
14
15
- from delphi_utils import read_params
15
+ from delphi_utils import read_params , GeoMapper
16
16
import covidcast
17
17
from .api_config import APIConfig
18
18
from .covidnet import CovidNet
19
- from .geo_maps import GeoMaps
20
19
from .constants import SIGNALS
21
20
22
21
def write_to_csv (data : pd .DataFrame , out_name : str , output_path : str ):
@@ -49,17 +48,18 @@ def write_to_csv(data: pd.DataFrame, out_name: str, output_path: str):
49
48
50
49
51
50
def update_sensor (
52
- state_files : List [str ], mmwr_info : pd .DataFrame ,
53
- output_path : str , static_path : str ,
54
- start_date : datetime , end_date : datetime ) -> pd .DataFrame :
51
+ state_files : List [str ],
52
+ mmwr_info : pd .DataFrame ,
53
+ output_path : str ,
54
+ start_date : datetime ,
55
+ end_date : datetime ) -> pd .DataFrame :
55
56
"""
56
57
Generate sensor values, and write to csv format.
57
58
58
59
Args:
59
60
state_files: List of JSON files representing COVID-NET hospitalization data for each state
60
61
mmwr_info: Mappings from MMWR week to actual dates, as a pd.DataFrame
61
62
output_path: Path to write the csvs to
62
- static_path: Path for the static geographic fiels
63
63
start_date: First sensor date (datetime.datetime)
64
64
end_date: Last sensor date (datetime.datetime)
65
65
@@ -85,9 +85,15 @@ def update_sensor(
85
85
]
86
86
87
87
# Set state id to two-letter abbreviation
88
- geo_map = GeoMaps (static_path )
89
- hosp_df = geo_map .state_name_to_abbr (hosp_df )
90
-
88
+ gmpr = GeoMapper ()
89
+ hosp_df = gmpr .add_geocode (hosp_df ,
90
+ from_col = APIConfig .STATE_COL ,
91
+ from_code = "state_name" ,
92
+ new_code = "state_id" ,
93
+ dropna = False )
94
+ # To use the original column name, reassign original column and drop new one
95
+ hosp_df [APIConfig .STATE_COL ] = hosp_df ["state_id" ].str .upper ()
96
+ hosp_df .drop ("state_id" , axis = 1 , inplace = True )
91
97
assert not hosp_df .duplicated (["date" , "geo_id" ]).any (), "Non-unique (date, geo_id) pairs"
92
98
hosp_df .set_index (["date" , "geo_id" ], inplace = True )
93
99
0 commit comments