1212import numpy as np
1313import pandas as pd
1414
15- from delphi_utils import read_params
15+ from delphi_utils import read_params , GeoMapper
1616import covidcast
1717from .api_config import APIConfig
1818from .covidnet import CovidNet
19- from .geo_maps import GeoMaps
2019from .constants import SIGNALS
2120
2221def 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):
4948
5049
5150def 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 :
5556 """
5657 Generate sensor values, and write to csv format.
5758
5859 Args:
5960 state_files: List of JSON files representing COVID-NET hospitalization data for each state
6061 mmwr_info: Mappings from MMWR week to actual dates, as a pd.DataFrame
6162 output_path: Path to write the csvs to
62- static_path: Path for the static geographic fiels
6363 start_date: First sensor date (datetime.datetime)
6464 end_date: Last sensor date (datetime.datetime)
6565
@@ -85,9 +85,15 @@ def update_sensor(
8585 ]
8686
8787 # 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 )
9197 assert not hosp_df .duplicated (["date" , "geo_id" ]).any (), "Non-unique (date, geo_id) pairs"
9298 hosp_df .set_index (["date" , "geo_id" ], inplace = True )
9399
0 commit comments