def run_dashboard(): st.header("Visualise Commonwealth Victorian ensemble data") url = st.text_input("Enter the URL of the VIC ensemble CSV", value="", type="default") if not url.endswith(".csv"): st.warning(f"Not a CSV file: {url}") return df = get_url_df(url) plotter = StreamlitPlotter({}) fig, axis, _, _, _, _ = plotter.get_figure() runs = df.run.unique().tolist() is_logscale = st.checkbox("Log scale") for run in runs: run_df = df[df["run"] == run] axis.plot(run_df["times"], run_df["notifications_at_sympt_onset"], alpha=0.7) if is_logscale: axis.set_yscale("log") plotter.save_figure( fig, filename="ensemble", title_text="Notifications at symptom onset - 6 week projection")
def plot_dynamic_mixing_matrix(plotter: StreamlitPlotter, app: AppRegion): model = app.build_model(app.params["default"]) t = st.slider("Time", min_value=0, max_value=int(model.times[-1])) mixing_matrix = model._get_mixing_matrix(t) fig, _, _, _, _, _ = plotter.get_figure() pyplot.imshow(mixing_matrix, cmap="hot", interpolation="none", extent=[0, 80, 80, 0]) plotter.save_figure(fig, filename="mixing-matrix", title_text="Mixing matrix") st.write(mixing_matrix)
def plot_multicluster_mobility( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): app = covid_19.app.get_region("victoria") params = app.params["default"] all_cluster_mobility_values = {} fig, axes, max_dims, n_rows, n_cols, _ = plotter.get_figure() for i_region in Region.VICTORIA_METRO + Region.VICTORIA_RURAL: google_mobility_values, google_mobility_days = get_mobility_data( params["country"]["iso3"], i_region.replace("-", "_").upper(), BASE_DATE, params["mobility"]["google_mobility_locations"]) all_cluster_mobility_values[i_region] = google_mobility_values for i_region in Region.VICTORIA_METRO: axes.plot(google_mobility_days, apply_moving_average( all_cluster_mobility_values[i_region]["work"], 7), color="k", alpha=0.5) axes.plot(google_mobility_days, apply_moving_average( all_cluster_mobility_values[i_region]["other_locations"], 7), color="g", alpha=0.5) for i_region in Region.VICTORIA_RURAL: axes.plot(google_mobility_days, apply_moving_average( all_cluster_mobility_values[i_region]["work"], 7), color="b", alpha=0.5) axes.plot(google_mobility_days, apply_moving_average( all_cluster_mobility_values[i_region]["other_locations"], 7), color="brown", alpha=0.5) axes.set_xlim(left=STANDARD_X_LIMITS[0], right=STANDARD_X_LIMITS[1]) axes.set_ylim(top=1.) change_xaxis_to_date(axes, REF_DATE, rotation=0) plotter.save_figure(fig, filename=f"multi_cluster_mobility", title_text="Google mobility")
def plot_seroprevalence_by_age( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): n_columns = 2 n_rows = 2 fig = pyplot.figure(constrained_layout=True, figsize=(n_columns * 7, n_rows * 5)) # (w, h) spec = fig.add_gridspec(ncols=n_columns, nrows=n_rows) i_row = 0 i_col = 0 for region in Region.PHILIPPINES_REGIONS: calib_dir_path = calib_dir_path.replace("philippines", region) uncertainty_df = get_uncertainty_df(calib_dir_path, mcmc_tables, targets) # available_scenarios = uncertainty_df["scenario"].unique() # selected_scenario = st.sidebar.selectbox("Select scenario", available_scenarios, key=str()) selected_scenario = 0 # min_time = int(min(uncertainty_df["time"])) # max_time = int(max(uncertainty_df["time"])) # time = st.sidebar.slider("time", min_time, max_time, max_time) time = 397 with pyplot.style.context("ggplot"): ax = fig.add_subplot(spec[i_row, i_col]) _, _, _ = plots.uncertainty.plots.plot_seroprevalence_by_age( plotter, uncertainty_df, selected_scenario, time, axis=ax, name=region.title()) i_col += 1 if i_col >= n_columns: i_col = 0 i_row += 1 plotter.save_figure(fig, filename="sero_by_age", subdir="outputs", title_text="")
def run_mcmc_plots(): app_name, app_dirpath = selectors.app(run_type="calibrate") if not app_name: st.write("No calibrations have been run yet") return param_set_name, param_set_dirpath = selectors.param_set(app_dirpath) if not param_set_name: st.write("No parameter set folder found") return calib_name, calib_dirpath = selectors.calibration_run(param_set_dirpath) if not calib_name: st.write("No model run folder found") return # Load MCMC tables mcmc_tables = load_mcmc_tables(calib_dirpath) plot_config = utils.load_plot_config(app_name, param_set_name) plotter = StreamlitPlotter({}) 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, plot_config)
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)
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)
def run_dashboard(): st.header("Visualise DHHS data") url = st.text_input("Enter the URL of the DHHS CSV", value="", type="default") if not url.endswith(".csv"): st.warning(f"Not a CSV file: {url}") return df = get_url_df(url) regions = df["region"].unique().tolist() region = st.selectbox("Select region", regions) region_mask = df["region"] == region region_df = df[region_mask].drop(columns=["region"]) region_name = Region.to_name(region) if not region_name == "victoria": app_region = covid_19.app.get_region(region_name) targets = app_region.targets else: targets = {} for region in Region.VICTORIA_SUBREGIONS: app_region = covid_19.app.get_region(region) region_targets = app_region.targets for key, target in region_targets.items(): if key in targets: targets[key]["values"] = [ a + b for a, b in zip(targets[key]["values"], target["values"]) ] else: targets[key] = target plotter = StreamlitPlotter(targets) outputs = region_df["type"].unique().tolist() output = st.selectbox("Select output", outputs) dates = pd.to_datetime(region_df["time"], infer_datetime_format=True) region_df["time"] = (dates - BASE_DATE).dt.days region_df["scenario"] = 0 plots.uncertainty.plots.plot_timeseries_with_uncertainty( plotter, uncertainty_df=region_df, output_name=output, scenario_idxs=[0], targets=targets, )
def run_dashboard(): app_name, app_dirpath = "covid_19", os.path.join( os.getcwd(), "data\outputs\calibrate\covid_19") if not app_name: st.write("No calibrations have been run yet") return region_name = "victoria" region_dirpath = os.path.join(app_dirpath, region_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, ) path_name = os.path.join(calib_dirpath, "saved_plots") if not os.path.exists(path_name): os.makedirs(path_name) with st.spinner("Saving files..."): file_plotter = FilePlotter(path_name, targets) plot_func(file_plotter, calib_dirpath, mcmc_tables, mcmc_params, targets, app_name, region_name)
def run_mcmc_plots(): app_dirname, app_dirpath = selectors.app() calib_dirname, calib_dirpath = selectors.calibration_run(app_dirpath) if not calib_dirname: st.write("No calibration folder found") return # Load MCMC tables mcmc_tables = [] db_paths = [ os.path.join(calib_dirpath, f) for f in os.listdir(calib_dirpath) if f.endswith(".db") ] for db_path in db_paths: db = Database(db_path) mcmc_tables.append(db.db_query("mcmc_run")) plotter = StreamlitPlotter({}) plot_type = st.sidebar.selectbox("Select plot type", list(PLOT_FUNCS.keys())) plot_func = PLOT_FUNCS[plot_type] plot_func(plotter, mcmc_tables)
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, )
def run_scenario_plots(): app_name, app_dirpath = selectors.app(run_type="run") if not app_name: st.write("No applications have been run yet") return param_set_name, param_set_dirpath = selectors.param_set(app_dirpath) if not param_set_name: st.write("No parameter set folder found") return run_datestr, run_dirpath = selectors.model_run(param_set_dirpath) if not run_datestr: st.write("No model run folder found") return params = utils.load_params(run_dirpath) plot_config = utils.load_plot_config(app_name, param_set_name) post_processing_config = utils.load_post_processing_config(app_name) # Get database from model data dir. db_path = os.path.join(run_dirpath, "outputs.db") scenarios = load_model_scenarios(db_path, params, post_processing_config) # Create plotter which will write to streamlit UI. translations = plot_config["translations"] plotter = StreamlitPlotter(translations) # Import the app so we can re-build the model if we need to app_module = import_module(f"apps.{app_name}") region_app = app_module.get_region_app(param_set_name) # 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, region_app, scenarios, plot_config)
def run_scenario_plots(): app_dirname, app_dirpath = selectors.app() run_dirname, run_dirpath = selectors.model_run(app_dirpath) if not run_dirname: st.write("No model run folder found") return params = utils.load_params(run_dirpath) plot_config = utils.load_plot_config(app_dirname) post_processing_config = utils.load_post_processing_config(app_dirname) # Get database from model data dir. db_path = os.path.join(run_dirpath, "outputs.db") scenarios = load_model_scenarios(db_path, params, post_processing_config) # Create plotter which will write to streamlit UI. translations = plot_config["translations"] plotter = StreamlitPlotter(translations) # 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, scenarios, plot_config)