EoN.get_time_shift(times, L, threshold)[source]

Identifies the first time at which list/array L crosses a threshold. Useful for shifting times.

times list or numpy array (ordered)
the times we have observations
L a list or numpy array
order of L corresponds to times
threshold number
the threshold value
t number
the first time at which L reaches or exceeds threshold.
import networkx as nx
import EoN
import numpy as np
import matplotlib.pyplot as plt

""" in this example we will run 20 stochastic simulations.
    We plot the unshifted curves (grey) and the curves shifted
    so that t=0 when 1% have been infected (I+R = 0.01N) (red)
plt.clf() # just clearing any previous plotting.

kave = 10.
G = nx.fast_gnp_random_graph(N,kave/(N-1.))
tau = 0.2
gamma = 1.
report_times = np.linspace(0,5,101)
Ssum = np.zeros(len(report_times))
Isum = np.zeros(len(report_times))
Rsum = np.zeros(len(report_times))
iterations = 20
for counter in range(iterations):
    while R[-1]<1000: #if an epidemic doesn't happen, repeat
        t, S, I, R = EoN.fast_SIR(G, tau, gamma)
        print R[-1]
    plt.plot(t, I, linewidth = 1, color = 'gray', alpha=0.4)
    tshift = EoN.get_time_shift(t, I+R, 0.01*N)
    plt.plot(t-tshift, I, color = 'red', linewidth = 1, alpha = 0.4)