def get_fitting_data(args, df, country): df = cu.get_country_data(df, country) dates = df['date'].to_list() data = df['confirmed'] - df['recovered'] - df['deaths'] data.index = df['date'].to_list() data = data[data > args.start_number] #return data[start_date:] return data
def update_graph(country, start_date, end_date, mode, plot_style): df = get_country_data(dF, country) df.index = df['date'].to_list() mask = (df['date'] > start_date) & (df['date'] <= end_date) df = df.loc[mask] X = df['confirmed'] Y = df['recovered'] Z = df['deaths'] if mode == 'Cumulative': x = X y = Y z = Z title = country + " Covid-19 (Total Cases)" if mode == 'Daily': x = X.diff(periods=1).iloc[1:] y = Y.diff(periods=1).iloc[1:] z = Z.diff(periods=1).iloc[1:] title = country + " Covid-19 (Daily Cases)" fig1 = px.scatter(x) fig2 = px.scatter(y) fig3 = px.scatter(z) trace1 = fig1['data'][0] trace2 = fig2['data'][0] trace3 = fig3['data'][0] fig = make_subplots(rows=2, cols=1,shared_xaxes=False,\ horizontal_spacing=0.1, vertical_spacing=0.05,\ y_title=country,subplot_titles=([title])) fig.add_trace(trace1, row=1, col=1) fig.add_trace(trace2, row=1, col=1) fig.add_trace(trace3, row=2, col=1) if plot_style == 'DotLine': fig.data[0].update(mode='markers+lines') fig.data[1].update(mode='markers+lines') fig.data[2].update(mode='markers+lines') fig['data'][0]['marker']['color'] = "blue" fig['data'][1]['marker']['color'] = "green" fig['data'][2]['marker']['color'] = "red" fig.update_layout(width=1200, height=600, margin=dict(l=10, r=10, t=20, b=40)) return fig
default='../data/world_population.csv') parser.add_argument('-c', '--country-name', help='Country name', default='Italy') parser.add_argument('-m', '--epd-model', help='Epidemiologcal model', default='SIR') parser.add_argument('-b', '--beta-model', help='Beta model', default='exp') args = parser.parse_args() dF = pd.read_csv(args.input_file) df = get_country_data(dF, args.country_name) df['removed'] = df['recovered'] + df['deaths'] df['infected'] = df['confirmed'] - df['removed'] df.index = df['date'].to_list() data = df[['infected', 'removed']].copy() data = data[data['infected'] > 25] days = [int(i) for i in range(0, data.shape[0])] I0, R0 = data.iloc[0]['infected'], data.iloc[0]['removed'] L = Learner(args.epd_model, beta_model=args.beta_model) kwargs = {'N': 6.0E07, 'I0': I0, 'R0': R0}
import pandas as pd import matplotlib.pyplot as plt import numpy as np import sys from common_utils import get_country_data if __name__ == "__main__": dF = pd.read_csv(sys.argv[1]) df1 = get_country_data(dF, 'US') df2 = get_country_data(dF, 'Brazil') df3 = get_country_data(dF, 'India') df4 = get_country_data(dF, 'Russia') fig = plt.figure(figsize=(12, 12)) ax = fig.add_plot(221) bx = fig.add_plot(222) cx = fig.add_plot(222) dx = fig.add_plot(222)
countries = df_top['country'].to_list() #with open ("/Users/jayanti/Projects/Softlab/Covid-19/code/output/17-05-2020/bad_fit.txt","r") as fp: # data = fp.read() #countries=data.split('\n') #print(countries) #sys.exit() fig = plt.figure(figsize=(12, 18)) col = 1 for c in countries: try: dF = get_country_data(df, c) except: continue x = [int(i) for i in range(0, dF.shape[0])] x = dF['date'].to_list() y = dF['confirmed'] - dF['deaths'] - dF['recovered'] if dF.shape[0] > 0 and col < 51 and c != 'China': #lockdown_day = np.max (get_date_diff(dF.iloc[0]['date'], L[c]),0) print(c, dF.shape, dF.iloc[0]['date']) ax = fig.add_subplot(10, 5, col) #fig = plt.figure(figsize=(18,12)) #ax = fig.add_subplot(1,1,1) #plt.setp(ax.get_xticklabels(), rotation=90, horizontalalignment='right') #ax.axvline(x=float(lockdown_day),c='k',ls='--') ax.plot(x, y, 'b')
ax.append(fig.add_subplot(324)) ax.append(fig.add_subplot(325)) ax.append(fig.add_subplot(326)) for a in ax: a.set_xlim(-1, 67) a.set_ylim(-8.0, 11.0) plt.subplots_adjust(wspace=0, hspace=0) count = 0 for country in countries: N, L, T = lockdown_info(args.lockdown_file, country) df1 = get_country_data(df, country) df1 = df1[df1['confirmed'] > 25] print(country, df1.shape) R = BetaSolver(df1, N) beta = R.solve(gamma_in, sigma_in, alpha) lockdown = beta.index.get_loc(L, method='ffill') dates = beta.index y = beta days = np.array([i for i in range(0, beta.shape[0])]) print(count + 1, '&', country, '&', N, '&', T, '&', dates[0], '&', L, ' \\\ \hline')