def generate_T2s():
    scenarii = json.loads(open('scenarii.json').read())
    for key, info in scenarii.items():
        # Define the switch points
        times = np.linspace(0, info['maxTime'], info['switches'] + 1,
                            endpoint=False)
        # Build the theoretical model
        model = StSICMR(info['true_n'], times, info['true_M'])
        # Choose points in which to evaluate the model
        steps = generate_times(info['maxTime'])
        scenarii[key]['times'] = list(steps)
        scenarii[key]['lambdas'] = [model.lambda_s(s) for s in steps]
        scenarii[key]['true_T'] = list(times)
    # Save it a s a .json file
    with open('scenarii.json', 'w') as outfile:
        json.dump(scenarii, outfile)
sampling = 'same'

T_max = 120
n_tw = 64
psmc_t_vector = 0.1*np.array([np.exp(np.true_divide(i*np.log(1+10*T_max),
                                                    n_tw))-1
                             for i in range(1, n_tw+1)])
print (psmc_t_vector)
#t_vector = psmc_t_vector
t_vector = np.arange(0, 50, 0.1)

N_ref = 1000
path2ms = '../bin'

if __name__ == "__main__":
    model = StSICMR(n, T_list, M_list)
    T_list_ms = np.true_divide(np.array(T_list), 2)
    cmd = create_ms_command_T2(n_obs, n, T_list_ms, M_list, sampling)
    obs_T2 = simulate_T2_ms(cmd, path2ms)
    (x, empirical_lambda) = compute_empirical_hist(obs_T2, t_vector, N_ref,
                                                     path2ms)
    theoretical_lambda = [model.lambda_s(t) for t in t_vector]

    times = 2 * N_ref * np.array(x)
    empirical_sizes = N_ref * np.array(empirical_lambda)
    theoretical_sizes = N_ref * np.array(theoretical_lambda)

    # Now we plot
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    ax.step(times, empirical_sizes, '-r', where='post', label='empirical')