pl.plot(t,
            cases,
            marker=markers[i + 2],
            c=colors[i + 2],
            label='data',
            mfc='None')
    pl.plot(tt, f(tt, *p), c='k', lw=1, label='$Q_I$')

    _c = i % (n_col)
    _r = i // (n_col)
    if _r == n_row - 1:
        pl.xlabel('days since Jan. 20th')
    if _c == 0 and _r == 0:
        pl.ylabel('confirmed cases', )
        pl.gca().yaxis.set_label_coords(-0.3, -0.2)
    pl.xlim([1, 30])
    pl.xscale('log')
    pl.yscale('log')

    ylim = ax[i].set_ylim([1, 2e3])
    ylim = ax[i].get_ylim()
    ax[i].plot([12, 12], ylim, ':')

    ax[i].text(0.03,
               0.97,
               "{}".format(roman[i]),
               transform=ax[i].transAxes,
               ha='left',
               va='top',
               fontweight='bold',
               fontsize=10,
            r"$N_\mathrm{eff}=%d$" %(params['N'].value),
            transform=ax[i].transAxes,
            ha='right',
            va='bottom',
            bbox={'facecolor':'w','edgecolor':'w','pad':0}
            )

    pl.xscale('log')
    pl.yscale('log')
    ylim = pl.gca().get_ylim()
    min_ylim = 10**np.floor(np.log(ylim[0])/np.log(10))
    max_ylim = 10**np.ceil(np.log(ylim[1])/np.log(10))
    if min_ylim < 1:
        min_ylim = 1
    pl.ylim([min_ylim, max_ylim])
    pl.xlim([1,35])
    if _r < n_row-1:
        [ x.set_visible(False) for x in ax[i].xaxis.get_major_ticks() ]
    bp.strip_axis(pl.gca())

pl.gcf().tight_layout()
pl.gcf().subplots_adjust(wspace=0.34,hspace=0.3)
pl.gcf().savefig("model_fit_figures/quarantine_model_all_confirmed_fit_after_feb_11.png",dpi=300)
pl.gcf().savefig("model_fit_figures/SI_Fig_03.png",dpi=300)

if not loaded_fits:
    with open('fit_parameters/quarantined_model_all_provinces_after_feb_12.p','wb') as f:
        pickle.dump(fit_parameters,f)

pl.show()
               va='bottom',
               bbox={
                   'facecolor': 'w',
                   'edgecolor': 'w',
                   'pad': 0
               })

    #pl.xscale('log')
    #pl.yscale('log')
    ylim = pl.gca().get_ylim()
    min_ylim = 10**np.floor(np.log(ylim[0]) / np.log(10))
    max_ylim = 10**np.ceil(np.log(ylim[1]) / np.log(10))
    if min_ylim < 1:
        min_ylim = 1
    #pl.ylim([min_ylim, max_ylim])
    pl.xlim([1, 32])
    if _r < n_row - 1:
        [x.set_visible(False) for x in ax[i].xaxis.get_major_ticks()]
    bp.strip_axis(pl.gca())

pl.gcf().tight_layout()
pl.gcf().subplots_adjust(wspace=0.34, hspace=0.3)
pl.gcf().savefig("model_fit_figures/all_confirmed_fit.png", dpi=300)
pl.gcf().savefig("model_fit_figures/Fig_03.png", dpi=300)

if not loaded_fits:
    with open('fit_parameters/all_provinces.p', 'wb') as f:
        pickle.dump(fit_parameters, f)

pl.show()
    ax[i].text(0.8,0.03,
            r"$P=%4.2f$" %((params['kappa0'].value)/(params['kappa'].value+params['kappa0'].value)),
            transform=ax[i].transAxes,
            ha='right',
            va='bottom',
            bbox={'facecolor':'w','edgecolor':'w','pad':0}
            )

    pl.xscale('log')
    pl.yscale('log')
    ylim = pl.gca().get_ylim()
    min_ylim = 10**np.floor(np.log(ylim[0])/np.log(10))
    max_ylim = 10**np.ceil(np.log(ylim[1])/np.log(10))
    if min_ylim < 1:
        min_ylim = 1
    pl.ylim([min_ylim, max_ylim])
    pl.xlim([1,60])
    if _r < n_row-1:
        [ x.set_visible(False) for x in ax[i].xaxis.get_major_ticks() ]
    bp.strip_axis(pl.gca())

pl.gcf().tight_layout()
pl.gcf().subplots_adjust(wspace=0.34,hspace=0.3)
pl.gcf().savefig("model_fit_figures/all_confirmed_fit_before_feb_12.png",dpi=300)

if not loaded_fits:
    with open('fit_parameters/all_provinces_before_feb_12.p','wb') as f:
        pickle.dump(fit_parameters,f)

pl.show()
Пример #5
0
        #        ha='right',
        #        va='bottom',
        #        bbox={'facecolor':'w','edgecolor':'w','pad':0}
        #        )

    if not LINLIN:
        pl.xscale('log')
        pl.yscale('log')
    ylim = pl.gca().get_ylim()
    min_ylim = 10**np.floor(np.log(ylim[0]) / np.log(10))
    max_ylim = 10**np.ceil(np.log(ylim[1]) / np.log(10))
    if min_ylim < 1:
        min_ylim = 1
    if not LINLIN:
        pl.ylim([min_ylim, max_ylim])
        pl.xlim([1, 60])
    else:
        pl.xlim([0, 40])
    if not LINLIN:
        if _r < n_row - 1:
            [x.set_visible(False) for x in ax[i].xaxis.get_major_ticks()]
    bp.strip_axis(pl.gca())

pl.gcf().tight_layout()
pl.gcf().subplots_adjust(wspace=0.34, hspace=0.3)
fn = 'all_provinces_after_feb_12.p'
#fn = 'different_initial_conds_after_feb_12.p'
name = 'linlin' if LINLIN else 'loglog'
pl.gcf().savefig(
    "model_fit_figures/all_confirmed_fit_after_feb_12_{}.png".format(name),
    dpi=300)
Пример #6
0
    #        ha='right',
    #        va='bottom',
    #        bbox={'facecolor':'w','edgecolor':'w','pad':0}
    #        )

    #pl.xscale('log')
    #pl.yscale('log')
    ylim = pl.gca().get_ylim()
    min_ylim = 10**np.floor(np.log(ylim[0]) / np.log(10))
    max_ylim = 10**np.ceil(np.log(ylim[1]) / np.log(10))
    if min_ylim < 1:
        min_ylim = 1
    #pl.ylim([min_ylim, max_ylim])
    #if _r < n_row-1:
    #    [ x.set_visible(False) for x in ax[i].xaxis.get_major_ticks() ]
    pl.xlim([0, 35])
    pl.xticks([0, 10, 20, 30])
    bp.strip_axis(pl.gca())

pl.gcf().tight_layout()
pl.gcf().subplots_adjust(wspace=0.34, hspace=0.3)
pl.gcf().savefig(
    "model_fit_figures/linlin_shutdown_model_all_confirmed_fit_after_feb_12.png",
    dpi=300)
pl.gcf().savefig("model_fit_figures/SI_Fig_06.png", dpi=300)

if not loaded_fits:
    with open('fit_parameters/shutdown_model_all_provinces_after_feb_12.p',
              'wb') as f:
        pickle.dump(fit_parameters, f)
    #        transform=ax[i].transAxes,
    #        ha='right',
    #        va='bottom',
    #        bbox={'facecolor':'w','edgecolor':'w','pad':0}
    #        )

    #pl.xscale('log')
    #pl.yscale('log')
    ylim = pl.gca().set_ylim([1,1.5e3])
    ylim = pl.gca().get_ylim()
    min_ylim = 10**np.floor(np.log(ylim[0])/np.log(10))
    max_ylim = 10**np.ceil(np.log(ylim[1])/np.log(10))
    if min_ylim < 1:
        min_ylim = 1
    #pl.ylim([min_ylim, max_ylim])
    pl.xlim([0,30])
    if _r < n_row-1:
        ax[i].set_xticklabels('')
    #    [ x.set_visible(False) for x in ax[i].xaxis.get_major_ticks() ]
    ax[i].set_yticks([0,500,1000,1500])
    ax[i].set_yticklabels(['0','0.5k','1.0k','1.5k'])
    bp.strip_axis(pl.gca())
    #bp.humanify_yticks(ax[i],precision=1)

ax[0].text(-0.4,1.1,
           'C',
            transform=ax[0].transAxes,
            ha='left',
            va='top',
            fontweight='bold',
            fontsize=14,
Пример #8
0
if __name__ == "__main__":

    import numpy as np
    import bfmplot as bp
    fig, ax = pl.subplots(1, 1)

    x = np.linspace(1, 10, 100)
    mus = np.linspace(1, 4, 4)

    for mu in mus:
        y = x**mu
        pl.plot(x, y, c=bp.brewer_qualitative[0])

    #pl.xscale('log')
    bp.strip_axis(ax, horizontal='left')
    pl.yscale('log')
    ax.set_xlabel('x')
    ax.set_ylabel('y')

    pl.gcf().tight_layout()
    pl.xlim([1, 10])

    for mu in mus:
        label = r'$\mu={:d}$'.format(int(mu))
        y = x**mu
        add_curve_label(ax, x, y, label, label_pos_rel=0.5 + mu / 50)

    print(human_format(112345, precision=2))

    pl.show()
Пример #9
0
import numpy as np
#import matplotlib.pyplot as plt
from bfmplot import pl as plt
from ThredgeCorr.basic_patterns import *

### mean degree plots
n = 10**5
t = np.linspace(-6, 6, 800)
density = np.array([edges(tt) for tt in t]).astype(float)
k = (n - 1) * density

fig = plt.figure(1, figsize=(8, 4))
ax = fig.add_subplot(1, 2, 1)
ax.plot(t, density)
plt.xlim(-3, 3)
plt.xlabel(r'$t$')
plt.ylabel(r'$1 - \Phi\left( t \right)$')

ax = fig.add_subplot(1, 2, 2)
ax.plot(t, k)
plt.xlim(2.5, 4.5)
plt.ylim(float((n - 1) * edges(4.5) * 0.9), float(1.1 * (n - 1) * edges(2.5)))
ax.set_yscale('log')
plt.xlabel(r'$t$')
plt.ylabel(r'$E \left[ k \right]$')

plt.savefig('figures/edges.pdf')

### variance plot
n = 10**5
NMAX = 20
Пример #10
0
for iC, (C, res) in enumerate(result_sim.items()):
    pl.plot(t, res, label=C, lw=1.5, c=bp.colors[iC])

model.set_processes([
    (S, I, alpha, I, I),
    (I, beta, R),
    (None, gamma, S),
])

result = model.integrate(t)

for iC, (C, res) in enumerate(result.items()):
    pl.plot(t, res, c=bp.colors[iC], ls='-.')

bp.strip_axis(pl.gca())
pl.xlim([0, 150])
pl.ylim([0, 1000])

pl.xlabel('time [days]')
pl.ylabel('incidence')
pl.legend()

pl.gcf().tight_layout()
pl.gcf().savefig('SIR_birth_model_reimports_zoom.png', dpi=300)

pl.xlim([0, max(t)])
pl.ylim([0, max(result_sim['S'])])

pl.gcf().savefig('SIR_birth_model_reimports_all.png', dpi=300)

pl.yscale('log')
Пример #11
0
ax = fig.add_subplot(1, 3, 1)
pl.hist(k,
        bins=np.arange(0, kmax, 2),
        density=True,
        alpha=1,
        align='left',
        color=bp.brewer_qualitative[1],
        label='data',
        histtype='step')
p = pk(n, t, rho, kmax, X, W)
pl.plot(np.arange(kmax),
        p,
        lw=1,
        c=bp.brewer_qualitative[2],
        label='model fit')
pl.xlim(0, 30)
ax.text(0.04, 0.95, '(a)', va='top', ha='left', transform=ax.transAxes)
bp.strip_axis(ax)
leg = pl.legend()
bp.align_legend_right(leg)

ax.set_ylabel('probability density $p_k$')
ax.set_xlabel('node degree $k$')

#pl.show()
#sys.exit(0)
### collab network
print("loading", 'degree_sequences/cond-mat.degree_sequence', '...')
k = np.loadtxt('degree_sequences/cond-mat.degree_sequence')
k = np.array(k, dtype=int)
kmax = np.max(k) + 1
Пример #12
0
    I0f = p['I0_factor'].value

    N = pdata['population'] / 1e6

    print(p['kappa0'],p['kappa'])
    Q = (k+k0)/(b+k+k0)
    P = k0/(k+k0)
    R0eff = a / (b+k+k0)
    tabledata.append([titlemap[province], N, Q, P, R0eff, k, k0, I0f, ])
    ks.append(k)
    k0s.append(k0)

for i, (_k0, _ks) in enumerate(zip(k0s, ks)):
    pl.plot([_k0],[_ks],marker=markers[i],color=colors[i],markersize=7)

pl.xlim([0,0.14])
pl.ylim([-.05,0.55])
pl.gcf().savefig('model_fit_figures/'+fn+'.png',dpi=300)

pl.show()

headers = [
             'Province', 
             '$N/10^6$','$Q$', 
             '$P$', 
             '$R_{0,\mathrm{eff}}$', 
             '$\kappa$ [$\mathrm{d}^{-1}$]',
             '$\kappa_{0}$ [$\mathrm{d}^{-1}$]',
             '$I_0/X_0$', 
          ]
floatfmt = (