Beispiel #1
0
def write_hospital_data_to_targets(country,
                                   data_start_time=0,
                                   data_end_time=365,
                                   weekly_average=True):
    region = country if country != "united-kingdom" else "united_kingdom"
    target_path = os.path.join("../apps", "covid_19", "regions", region,
                               "targets.json")

    times, values = read_hospital_data(country, data_start_time, data_end_time)
    if weekly_average:
        times, values = get_weekly_summed_targets(times, values)

    if country in list(start_reporting.keys()):
        min_time = start_reporting[country]
        first_idx_to_keep = next(x[0] for x in enumerate(times)
                                 if x[1] >= min_time)
        times = times[first_idx_to_keep:]
        values = values[first_idx_to_keep:]

    with open(target_path, mode="r") as f:
        targets = json.load(f)
        targets[country_targets[country][1]]["times"] = times
        targets[country_targets[country][1]]["values"] = values
    with open(target_path, "w") as f:
        json.dump(targets, f, indent=2)
def drop_who_data_to_targets(
    country="australia", data_start_time=0, data_end_time=365, weekly_average=True
):
    data = {}
    output_name = {"confirmed": "notifications", "deaths": "infection_deaths"}
    for variable in ["confirmed", "deaths"]:
        times, values = read_who_data_from_csv(variable, country, data_start_time, data_end_time)
        if weekly_average:
            times, values = get_weekly_summed_targets(times, values)
        data[variable] = {"times": times, "values": values}

    region = country if country != "united-kingdom" else "united_kingdom"
    target_path = os.path.join("../apps", "covid_19", "regions", region, "targets.json")

    with open(target_path, mode="r") as f:
        targets = json.load(f)
        for variable in ["confirmed", "deaths"]:
            targets[output_name[variable]]["times"] = data[variable]["times"]
            targets[output_name[variable]]["values"] = data[variable]["values"]
    with open(target_path, "w") as f:
        json.dump(targets, f, indent=2)
Beispiel #3
0
country = Region.ITALY

PAR_PRIORS = get_prior_distributions_for_opti()

for i, par in enumerate(PAR_PRIORS):
    if par["param_name"] == "contact_rate":
        PAR_PRIORS[i]["distri_params"] = [0.025, 0.06]

TARGET_OUTPUTS = get_target_outputs_for_opti(country,
                                             source='who',
                                             data_start_time=61,
                                             data_end_time=182)

# Use weekly counts
for target in TARGET_OUTPUTS:
    target["years"], target["values"] = get_weekly_summed_targets(
        target["years"], target["values"])

MULTIPLIERS = {}

PAR_PRIORS = add_dispersion_param_prior_for_gaussian(PAR_PRIORS,
                                                     TARGET_OUTPUTS,
                                                     MULTIPLIERS)


def run_calibration_chain(max_seconds: int, run_id: int, num_chains: int):
    base.run_calibration_chain(
        max_seconds,
        run_id,
        num_chains,
        country,
        PAR_PRIORS,