Beispiel #1
0
def main(configpath):
    # Load the model configuration file and the data (observed cases)
    config = load_config(configpath)
    data = load_data(config)
    outpath = config['outpath']

    useworldfile = config['worldfile']
    if (not useworldfile):
        data = generate_hos_actual(data, config)
    else:
        data = generate_zero_columns(data, config)
    # Run the forward model to obtain a prior ensemble of models
    save_input_data(configpath, outpath, data)
    prior, time, prior_param, fwd_args = run_prior(config)

    # Calibrate the model (as calibration data, we either use 'hospitalized' or 'dead')
    calibration_mode = get_calibration_modes(config['calibration_mode'])[0]
    if calibration_mode == 'dead':
        data_index = I_DEAD
        output_index = O_DEAD
    elif calibration_mode == 'hospitalized':
        data_index = I_HOS
        output_index = O_HOS
    elif calibration_mode == 'hospitalizedcum':
        data_index = I_HOSCUM
        output_index = O_HOSCUM
    elif calibration_mode == 'ICU':
        data_index = I_ICU
        output_index = O_ICU
    else:
        raise NotImplementedError

    plotplume = config['plot']['hindcast_plume']

    p = calibrate_with_data(
        prior, time, data, data_index,
        output_index)  # Posterior probability for each ensemble member
    integrated_parameter_values = integrate_parameters(prior_param, p)
    np.savetxt(outpath + "/integrated_parameter_values.csv",
               integrated_parameter_values,
               delimiter=";")

    integrated_results = integrate_calibration(prior,
                                               p)  # Mean posterior model

    # Create output of the calibration phase
    plot_results(prior,
                 time,
                 configpath,
                 outpath,
                 config,
                 data,
                 integrated_results,
                 calibration_mode,
                 prior=True,
                 plot_plume=plotplume)

    # Based on the model performance in the past, run models again, forecasting the future

    forecast = rerun_model_with_alpha_uncertainty(prior_param, p, config,
                                                  fwd_args)

    plot_results(forecast,
                 time,
                 configpath,
                 outpath,
                 config,
                 data,
                 cal_mode=config['calibration_mode'],
                 prior=False,
                 plot_plume=True)

    plot_posterior(forecast, config, configpath, outpath, data, ['time'])

    hospital_forecast_to_txt(forecast, time, configpath, outpath, config)
Beispiel #2
0
def main(configpath):
    # Load the model configuration file and the data (observed cases)
    config = load_config(configpath)
    data = load_data(config)
    base_filename = (os.path.split(configpath)[-1]).split('.')[0]

    useworldfile = config['worldfile']
    if (not useworldfile):
        data = generate_hos_actual(data, config)
    else:
        data = generate_zero_columns(data, config)
    # Run the forward model to obtain a prior ensemble of models
    save_input_data(base_filename, data)
    ndata = np.size(data[:, 0])
    prior, time, prior_param, fwd_args = run_prior(config, ndata)

    # Calibrate the model (as calibration data, we either use 'hospitalized' or 'dead')
    calibration_mode = get_calibration_modes(config['calibration_mode'])[0]
    if calibration_mode == 'dead':
        data_index = I_DEAD
        output_index = O_DEAD
    elif calibration_mode == 'hospitalized':
        data_index = I_HOS
        output_index = O_HOS
    elif calibration_mode == 'hospitalizedcum':
        data_index = I_HOSCUM
        output_index = O_HOSCUM
    elif calibration_mode == 'ICU':
        data_index = I_ICU
        output_index = O_ICU
    else:
        raise NotImplementedError

    plotplume = config['plot']['hindcast_plume']

    p = calibrate_with_data(
        prior, time, data, data_index,
        output_index)  # Posterior probability for each ensemble member
    integrated_results = integrate_calibration(prior,
                                               p)  # Mean posterior model

    # Create output of the calibration phase
    plot_results(prior,
                 time,
                 configpath,
                 config,
                 data,
                 integrated_results,
                 calibration_mode,
                 prior=True,
                 plot_plume=plotplume)

    # Based on the model performance in the past, run models again, forecasting the future

    forecast = rerun_model_with_alpha_uncertainty(prior_param, p, config,
                                                  fwd_args)
    base = (os.path.split(configpath)[-1]).split('.')[0]
    outbase = os.path.join(os.path.split(os.getcwd())[0], 'output', base)

    plot_results(forecast,
                 time,
                 configpath,
                 config,
                 data,
                 cal_mode=config['calibration_mode'],
                 prior=False,
                 plot_plume=True)

    plot_posterior(forecast, config, outbase, data, ['time'])

    try:
        hospital_forecast_to_txt(forecast, time, configpath, config, data)
    except:
        pass