import update_severity_index as severity_index import load_data import merge_data import numpy as np import pandas as pd if __name__ == "__main__": data_dir = oj(parentdir, 'data') # load in county data df_county = load_data.load_county_level(data_dir=oj(parentdir, 'data')) # add predictions NUM_DAYS_LIST = [1, 2, 3, 4, 5] df_county = add_preds(df_county, NUM_DAYS_LIST=NUM_DAYS_LIST, cached_dir=data_dir) deaths_fig = viz_map.plot_cumulative_deaths_map_with_slider( df_county, auto_open=False, target_days=np.array([0] + NUM_DAYS_LIST), filename=oj(parentdir, 'results', 'deaths.html')) print('successfully updated map of deaths') deaths_fig.write_image(oj(parentdir, 'results', 'deaths.png'), width=900, height=600, scale=2) print('successfully updated png of map of deaths') # load in hospital data and merge
add_predictions_7day(pd.read_pickle(cached_fname), df_tab) else: k += 1 if k > 1: break return df_tab, date2 if __name__ == '__main__': print('loading data...') NUM_DAYS_LIST = [1, 2, 3, 4, 5, 6, 7] df_county = load_data.load_county_level( data_dir=oj(parentdir, 'data')).fillna(0) df_county = add_preds( df_county, NUM_DAYS_LIST=NUM_DAYS_LIST, cached_dir=oj(parentdir, 'data')) # adds keys like "Predicted Deaths 1-day" ## orgnize predicts as array add_pre(df_county, 'Predicted Cases ', 'pred_cases', 'pred_new_cases') add_pre(df_county, 'Predicted Deaths ', 'pred_deaths', 'pred_new_deaths') ## add new cases/death to dataframe add_new(df_county) ## Add new cases/deaths predictions and their intervals df_county = add_new_pre(df_county, 'Predicted Cases ', 'tot_cases', 'pred_new_cases') df_county = add_new_pre(df_county, 'Predicted Deaths ', 'tot_deaths', 'pred_new_deaths')
ks.append(f'Surge {i}-day') ks.append(f'Predicted New Deaths Hospital {i}-day') ks.append(f'Predicted Deaths Hospital {i}-day') df[f'Severity Index {i}-day'] = [remap[x] for x in df[f'Severity {i}-day']] ks.append(f'Severity Index {i}-day') ks += ['Surge County 3-day', 'tot_deaths', 'SVIPercentile'] # county keys return df[ks] if __name__ == '__main__': # load and merge data print('loading data...') NUM_DAYS_LIST = [1, 2, 3, 4, 5, 6, 7] df_county = load_data.load_county_level(data_dir=oj(parentdir, 'data')) df_county = add_preds(df_county, NUM_DAYS_LIST=NUM_DAYS_LIST + [14, 21, 28], cached_dir=oj(parentdir, 'data'), add_predict_interval=True, interval_target_days=NUM_DAYS_LIST) # adds keys like "Predicted Deaths 1-day" df_hospital = load_data.load_hospital_level(data_dir=oj(os.path.dirname(parentdir), 'covid-19-private-data')) df = merge_data.merge_county_and_hosp(df_county, df_hospital) df = add_severity_index(df, NUM_DAYS_LIST) df = df.sort_values('Total Deaths Hospital', ascending=False) # write to gsheets dfc = prep_county_df(df_county, NUM_DAYS_LIST) # data for chicago mapping team print('dfc.shape', dfc.shape) write_to_gsheet(dfc, sheet_name='County-level Predictions', service_file=oj(parentdir, 'creds.json')) ks_output = ['Severity 1-day', 'Severity 2-day', 'Severity 3-day', 'Severity 4-day', 'Severity 5-day', 'Severity 6-day', 'Severity 7-day', 'Total Deaths Hospital', 'Hospital Name', 'CMS Certification Number', 'countyFIPS', 'CountyName', 'StateName',
ks.append(f'Severity Index {i}-day') ks += ['Surge County 3-day', 'tot_deaths', 'SVIPercentile'] # county keys return df[ks] if __name__ == '__main__': # load and merge data print('severity index loading data...') NUM_DAYS_LIST = [1, 2, 3, 4, 5, 6, 7] df_county = load_data.load_county_level(data_dir=oj(parentdir, 'data')) print('loaded county level!') df_county = add_preds( df_county, NUM_DAYS_LIST=NUM_DAYS_LIST + [14, 21, 28], # should save the cached pkl cached_dir=oj(parentdir, 'data'), add_predict_interval=True, interval_target_days=NUM_DAYS_LIST, force_predict=True ) #, force_predict=True) # adds keys like "Predicted Deaths 1-day" print('loading hosp data...') df_hospital = load_data.load_hospital_level( data_dir=oj(os.path.dirname(parentdir), 'covid-19-private-data')) df = merge_data.merge_county_and_hosp(df_county, df_hospital) print('adding severity index...') df = add_severity_index(df, NUM_DAYS_LIST) df = df.sort_values('Total Deaths Hospital', ascending=False) # write to gsheets print('\tprep for gsheets') dfc = prep_county_df(df_county,
import numpy as np import pandas as pd from os.path import join as oj import pygsheets import pandas as pd import sys sys.path.append('../modeling') sys.path.append('..') import load_data from fit_and_predict import add_preds from functions import merge_data if __name__ == '__main__': NUM_DAYS_LIST = [1] df_county = load_data.load_county_level(data_dir='../data') df_hospital = load_data.load_hospital_level( data_dir='../data_hospital_level') df_county = add_preds( df_county, NUM_DAYS_LIST=NUM_DAYS_LIST) # adds keys like "Predicted Deaths 1-day" print('succesfully ran pipeline!')
import load_data import numpy as np import pandas as pd if __name__ == "__main__": data_dir = oj(parentdir, 'data') # load in county data df = load_data.load_county_level(data_dir=oj(parentdir, 'data')) # add lat and lon to the dataframe county_lat_lon = pd.read_csv(oj(data_dir, 'county_pop_centers.csv'), dtype={ 'STATEFP': str, 'COUNTYFP': str }) county_lat_lon['fips'] = (county_lat_lon['STATEFP'] + county_lat_lon['COUNTYFP']).astype(np.int64) # add predictions df = add_preds(df, NUM_DAYS_LIST=[1, 2, 3, 4, 5], cached_dir=data_dir) # join lat / lon to df df = df.join(county_lat_lon.set_index('fips'), on='countyFIPS', how='left').rename(columns={ 'LATITUDE': 'lat', 'LONGITUDE': 'lon' }) # create plot plot_counties_slider(df, auto_open=False, n_past_days=1, target_days=np.array([1, 2, 3, 4, 5]), filename=oj(parentdir, 'results', 'deaths.html'))
if __name__ == '__main__': print('loading data...') NUM_DAYS_LIST = [1, 2, 3, 4, 5, 6, 7] df_county = load_data.load_county_level( data_dir=oj(parentdir, 'data')).fillna(0) df_county_dis = load_data.load_county_level( data_dir=oj(parentdir, 'data'), discard=True).fillna(0) # discard one day in time series num_days_in_past = 3 output_key = f'Predicted Deaths {num_days_in_past}-day Lagged' df_county = add_preds( df_county, NUM_DAYS_LIST=NUM_DAYS_LIST, cached_dir=oj(parentdir, 'data'), discard=False) # adds keys like "Predicted Deaths 1-day" df_county_old = add_preds( df_county_dis, NUM_DAYS_LIST=NUM_DAYS_LIST, cached_dir=oj(parentdir, 'data'), d=datetime.date.today() - timedelta(days=1)) # adds keys like "Predicted Deaths 1-day" ''' # don't use add_preds here, since we need preds from 3 days ago df_county = fit_and_predict_ensemble(df_county, outcome='deaths', mode='eval_mode', target_day=np.array([num_days_in_past]), output_key=output_key)