Exemple #1
0
def plot_single_area_all_sources(area, sw, cap_limit=2.):
    print('-' * 58)
    print('-' * 20 + ' ' + area + ' ' + '-' * 20)
    print('= Getting data...')
    pu = plotter.PlotUtils(sw.png_dir_path, cap_limit=cap_limit)

    output = StringIO()
    header_set = False
    for name, source in sw.sources:
        print('= Gathering for:', name)
        states, daily_cases_path = sw.get_daily_cases(source=source)
        if states is None:
            with open(daily_cases_path, 'r') as f:
                contents = f.readlines()
                for index, line in enumerate(contents):
                    contents[index] = line.replace(area, area + '_' + name)

                if header_set:
                    contents = contents[1:]
                output.writelines(contents)
                header_set = True

    output.seek(0)
    states = pd.read_csv(output,
                         usecols=[0, 1, 2],
                         index_col=['state', 'date'],
                         parse_dates=['date'],
                         squeeze=True).sort_index()

    pu.plot_all_states(states,
                       dump_file_name='all_sources_realtime_rt',
                       ncols=3)
    print('-' * 26 + ' DONE ' + '-' * 26)
Exemple #2
0
def plot_test_eu_incoherent_data():
    sw_eu = sweeper.SweeperEU()
    sw_eu.create_output_dirs()
    pu = plotter.PlotUtils(sw_eu.png_dir_path)
    pu.create_dump_dir()
    states, daily_cases_path = sw_eu.get_daily_cases_cssegi()

    state_name = 'France'
    print(states[state_name].to_string())

    window = 7
    pu.debug = True
    pu.plot_state_cases_per_day(states, state_name, window)
    pu.plot_state_realtime_rt(states, state_name, window)
Exemple #3
0
def plot_all_in_one(area, sw, start_date='2020-03-01', cap_limit=2.):
    print('-' * 58)
    print('-' * 20 + ' ' + area + ' ' + '-' * 20)
    print('= Getting data...')
    pu = plotter.PlotUtils(sw.png_dir_path,
                           start_date=start_date,
                           cap_limit=cap_limit)
    states, daily_cases_path = sw.get_cases_by_county()
    if states is None:
        states = pd.read_csv(daily_cases_path,
                             usecols=[0, 1, 2],
                             index_col=['state', 'date'],
                             parse_dates=['date'],
                             squeeze=True).sort_index()
    pu.plot_all_states(states)
    print('-' * 26 + ' DONE ' + '-' * 26)
Exemple #4
0
def plot_single_area(area, sw, source=None):
    print('-' * 58)
    print('-' * 20 + ' ' + area + ' ' + '-' * 20)
    print('= Getting data...')
    pu = plotter.PlotUtils(sw.png_dir_path)
    states, daily_cases_path = sw.get_daily_cases(source=source)
    if states is None:
        states = pd.read_csv(daily_cases_path,
                             usecols=[0, 1, 2],
                             index_col=['state', 'date'],
                             parse_dates=['date'],
                             squeeze=True).sort_index()
    state_name = area
    window = 7

    pu.plot_state_cases_per_day(states, state_name, window)
    pu.plot_state_realtime_rt(states, state_name, window)

    print('-' * 26 + ' DONE ' + '-' * 26)
Exemple #5
0
def plot_test_ro_incoherent_data():
    sw_ro = sweeper.SweeperRO()
    sw_ro.create_output_dirs()
    pu = plotter.PlotUtils(sw_ro.png_dir_path,
                           start_date='2020-04-01',
                           cap_limit=4.)
    pu.create_dump_dir()
    states, daily_cases_path = sw_ro.get_cases_by_county()
    states = pd.read_csv(daily_cases_path,
                         usecols=[0, 1, 2],
                         index_col=['state', 'date'],
                         parse_dates=['date'],
                         squeeze=True).sort_index()

    state_name = 'BR'
    # state_name = 'IS'
    print(states[state_name].to_string())

    window = 7
    pu.debug = True
    pu.plot_state_cases_per_day(states, state_name, window)
    pu.plot_state_realtime_rt(states, state_name, window)
Exemple #6
0
#!/usr/bin/env python
import pandas as pd
import plotter

from matplotlib import pyplot as plt

pu = plotter.PlotUtils('')
fig, ax = plt.subplots(figsize=(600 / 72, 400 / 72))

url = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv'
states = pd.read_csv(url,
                     usecols=[0, 1, 3],
                     index_col=['state', 'date'],
                     parse_dates=['date'],
                     squeeze=True).sort_index()
state_name = 'New York'

cases = states.xs(state_name).rename(f"{state_name} cases")

original, smoothed = pu.prepare_cases(cases)

posteriors = pu.get_posteriors(smoothed)

hdis = pu.highest_density_interval(posteriors)

most_likely = posteriors.idxmax().rename('ML')

# Look into why you shift -1
result = pd.concat([most_likely, hdis], axis=1)
result.tail()