Пример #1
0
    )
    county_lat_lon['fips'] = (county_lat_lon['STATEFP'] + county_lat_lon['COUNTYFP'])#.astype(np.int64)
    # 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)
    # join lat / lon to df_county
    # This does not seem necessary as lat and lon is already in the df_county
    #df_county = df_county.join(county_lat_lon.set_index('fips'), on='countyFIPS', how='left').rename(
    #    columns={'LATITUDE': 'lat', 'LONGITUDE': 'lon'}
    #)
    # create county-level predictions plot
    viz_map.plot_counties_slider(df_county, auto_open=False,
                         n_past_days=1,
                         target_days=np.array(NUM_DAYS_LIST),
                         filename=oj(parentdir, 'results', 'deaths.html'))

    # load in hospital data and merge
    df_hospital = load_data.load_hospital_level(data_dir=oj(parentdir, 'data_hospital_level'))
    df = merge_data.merge_county_and_hosp(df_county, df_hospital)
    df = severity_index.add_severity_index(df, NUM_DAYS_LIST)

    # load counties geojson
    counties_json = json.load(open(oj(parentdir, 'data', 'geojson-counties-fips.json'), "r"))

    # create hospital-level severity index plot
    viz_map.plot_hospital_severity_slider(
        df, target_days=np.array(NUM_DAYS_LIST),
        df_county=df_county, counties_json=counties_json, dark=True,
        auto_open=False, filename=oj(parentdir, 'results', 'severity_map.html')
    )
                          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
    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 = severity_index.add_severity_index(df, NUM_DAYS_LIST)

    # load counties geojson
    # counties_json = json.load(open(oj(parentdir, 'data', 'geojson-counties-fips.json'), "r"))

    # create hospital-level severity index plot
    severity_fig = viz_map.plot_hospital_severity_slider(
        df,
        target_days=np.array(NUM_DAYS_LIST),
        plot_choropleth=False,
        dark=True,
        auto_open=False,
        filename=oj(parentdir, 'results', 'severity_map.html'))
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!')