Esempio n. 1
0
def run_dashboard():
    app_name, app_dirpath = selectors.app_name(run_type="run")
    if not app_name:
        st.write("No applications have been run yet")
        return

    region_name, region_dirpath = selectors.output_region_name(app_dirpath, app_name)
    if not region_name:
        st.write("No parameter set folder found")
        return

    run_datestr, run_dirpath = selectors.model_run(region_dirpath)
    if not run_datestr:
        st.write("No model run folder found")
        return

    # Import the app so we can re-build the model if we need to
    app_module = import_module(f"apps.{app_name}")
    app_region = app_module.app.get_region(region_name)

    # Get database from model data dir.
    db_path = os.path.join(run_dirpath, "outputs.db")
    if not os.path.exists(db_path):
        db_path = os.path.join(run_dirpath, "outputs")

    scenarios = db.load.load_model_scenarios(db_path, app_region.params)

    # Create plotter which will write to streamlit UI.
    plotter = StreamlitPlotter(app_region.targets)

    # Get user to select plot type / scenario
    plot_type = st.sidebar.selectbox("Select plot type", list(PLOT_FUNCS.keys()))
    plot_func = PLOT_FUNCS[plot_type]
    plot_func(plotter, app_region, scenarios)
Esempio n. 2
0
def run_dashboard():
    app_name, app_dirpath = selectors.app_name(run_type="calibrate")
    if not app_name:
        st.write("No calibrations have been run yet")
        return

    # Prelims
    n_countries = st.sidebar.slider("Number of countries", 2, 6, 3)
    (
        region_names,
        region_dirpaths,
        calib_names,
        calib_dirpaths,
        mcmc_tables,
        mcmc_params,
        targets,
    ) = ({}, {}, {}, {}, {}, {}, {})

    for i_region in range(n_countries):

        # Get regions for comparison
        region_names[i_region], region_dirpaths[
            i_region] = selectors.output_region_name(
                app_dirpath, f"Select region #{str(i_region)}")
        if not region_names[i_region]:
            st.write("No region folder found")
            return

        # Specific calibration run name and path
        calib_names[i_region], calib_dirpaths[
            i_region] = selectors.calibration_run(
                region_dirpaths[i_region], f"Select region #{str(i_region)}")
        if not calib_names[i_region]:
            st.write("No model run folder found")
            return

        # Load MCMC tables
        mcmc_tables[i_region] = db.load.load_mcmc_tables(
            calib_dirpaths[i_region])
        mcmc_params[i_region] = db.load.load_mcmc_params_tables(
            calib_dirpaths[i_region])
        targets[i_region] = load_targets(app_name, region_names[i_region])

        plot_type = "Multi-country uncertainty"
        plot_func = PLOT_FUNCS[plot_type]

    plotter = StreamlitPlotter(targets[0])
    plot_func(plotter, calib_dirpaths, mcmc_tables, mcmc_params, targets,
              app_name, region_names)
Esempio n. 3
0
def run_dashboard():
    app_name, app_dirpath = selectors.app_name(run_type="calibrate")
    if not app_name:
        st.write("No calibrations have been run yet")
        return

    region_name, region_dirpath = selectors.output_region_name(
        app_dirpath, app_name)
    if not region_name:
        st.write("No region folder found")
        return

    calib_name, calib_dirpath = selectors.calibration_run(
        region_dirpath, region_name)
    if not calib_name:
        st.write("No model run folder found")
        return

    # Load MCMC tables
    mcmc_tables = db.load.load_mcmc_tables(calib_dirpath)
    mcmc_params = db.load.load_mcmc_params_tables(calib_dirpath)
    targets = load_targets(app_name, region_name)

    plotter = StreamlitPlotter(targets)
    plot_type = st.sidebar.selectbox("Select plot type",
                                     list(PLOT_FUNCS.keys()))
    plot_func = PLOT_FUNCS[plot_type]

    plot_func(
        plotter,
        calib_dirpath,
        mcmc_tables,
        mcmc_params,
        targets,
        app_name,
        region_name,
    )