Пример #1
0
def plot_param_matrix(
    plotter: StreamlitPlotter,
    mcmc_params: List[pd.DataFrame],
    parameters: List,
    label_param_string=False,
    show_ticks=False,
    file_name="",
):

    burn_in, label_font_size, label_chars, bins, style, dpi_request = BURN_INS, 8, 2, 20, "Shade", 300
    plots.calibration.plots.plot_param_vs_param(
        plotter,
        mcmc_params,
        parameters,
        burn_in,
        style,
        bins,
        label_font_size,
        label_chars,
        dpi_request,
        label_param_string=label_param_string,
        show_ticks=show_ticks,
        file_name=file_name,
    )
    param_names = [get_plot_text_dict(param) for param in parameters]
    params_df = pd.DataFrame({"names": param_names})
    params_df["numbers"] = range(1, len(params_df) + 1)
    create_downloadable_csv(params_df, "parameter_indices")
    key_string = ""
    for i_param, param_name in enumerate(param_names):
        key_string += str(i_param + 1) + ", " + param_name + "; "
    st.write(key_string)
    st.dataframe(params_df)
Пример #2
0
def write_mcmc_centiles(
    mcmc_params,
    mcmc_tables,
    burn_in,
    sig_figs,
    centiles,
):
    """
    Write a table of parameter centiles from the MCMC chain outputs.
    """

    # Get parameter names
    parameters = get_epi_params(mcmc_params)

    # Create empty dataframe
    params_df = pd.DataFrame(index=parameters, columns=centiles)

    # Populate with data
    for param_name in parameters:
        param_values = get_posterior(mcmc_params, mcmc_tables, param_name,
                                     burn_in)
        centile_values = np.percentile(param_values, centiles)
        rounded_centile_values = [
            round_sig_fig(i_value, sig_figs) for i_value in centile_values
        ]
        params_df.loc[param_name] = rounded_centile_values

    # Display
    create_downloadable_csv(params_df, "posterior_centiles")
    st.write(params_df)
Пример #3
0
def print_mle_parameters(
    plotter: StreamlitPlotter,
    calib_dir_path: str,
    mcmc_tables: List[pd.DataFrame],
    mcmc_params: List[pd.DataFrame],
    targets: dict,
    app_name: str,
    region: str,
):
    df = db.load.append_tables(mcmc_tables)
    param_df = db.load.append_tables(mcmc_params)
    params = db.process.find_mle_params(df, param_df)
    create_downloadable_csv(pd.Series(params), "mle_parameters")
    st.write(params)
Пример #4
0
def create_seroprev_csv(seroprev_by_age):
    """
    Create downloadable CSV from seroprevalence by age data as it is created in the seroprevalence plotting function.
    """

    # Hack to convert single-element lists from seroprevalence data to just single values
    for age_group in seroprev_by_age.keys():
        for centile in seroprev_by_age[age_group]:
            if len(seroprev_by_age[age_group][centile]) == 1:
                seroprev_by_age[age_group][centile] = seroprev_by_age[
                    age_group][centile][0]
            elif len(seroprev_by_age[age_group][centile]) == 0:
                seroprev_by_age[age_group][centile] = "no estimate"

    # Create the CSV
    create_downloadable_csv(
        pd.DataFrame.from_dict(seroprev_by_age),
        "seroprev_by_age",
        text="click to download age-specific seroprevalence values",
    )
Пример #5
0
def plot_timeseries_with_uncertainty(
    plotter: StreamlitPlotter,
    calib_dir_path: str,
    mcmc_tables: List[pd.DataFrame],
    mcmc_params: List[pd.DataFrame],
    targets: dict,
    app_name: str,
    region: str,
):
    available_outputs = [o["output_key"] for o in targets.values()]
    chosen_output = st.sidebar.selectbox("Select calibration target",
                                         available_outputs)
    targets = {
        k: v
        for k, v in targets.items() if v["output_key"] == chosen_output
    }

    uncertainty_df = get_uncertainty_df(calib_dir_path, mcmc_tables, targets)

    x_min = round(min(uncertainty_df["time"]))
    x_max = round(max(uncertainty_df["time"]))
    x_low, x_up = selectors.create_xrange_selector(x_min, x_max)

    available_scenarios = uncertainty_df["scenario"].unique()
    selected_scenarios = st.multiselect("Select scenarios",
                                        available_scenarios)

    (
        title_font_size,
        label_font_size,
        dpi_request,
        capitalise_first_letter,
    ) = selectors.create_standard_plotting_sidebar()
    is_logscale = st.sidebar.checkbox("Log scale")
    is_targets = st.sidebar.checkbox("Show targets")
    is_overlay_unceratinty = st.sidebar.checkbox("Overlay uncertainty")
    is_legend = st.sidebar.checkbox("Add legend")
    quantiles = plots.uncertainty.plots.plot_timeseries_with_uncertainty(
        plotter,
        uncertainty_df,
        chosen_output,
        selected_scenarios,
        targets,
        is_logscale,
        x_low,
        x_up,
        add_targets=is_targets,
        overlay_uncertainty=is_overlay_unceratinty,
        title_font_size=title_font_size,
        label_font_size=label_font_size,
        dpi_request=dpi_request,
        capitalise_first_letter=capitalise_first_letter,
        legend=is_legend,
    )

    # Provide outputs as CSV
    if selected_scenarios:
        scenario_for_csv = selected_scenarios[0]
        st.write(
            "The following downloadable CSV is for the first scenario selected in the select box above:"
        )
        create_downloadable_csv(
            quantiles[scenario_for_csv],
            f"output_quantiles_for_scenario_{scenario_for_csv}_for_indicator_{chosen_output}",
            include_row=False,
        )