コード例 #1
0
def render_model_sensitivity(figures_dir, output_dir) -> str:
    report_sections: MutableMapping[str, Sequence[str]] = {}

    for png in copy_pngs_to_report(figures_dir, output_dir):
        report_sections[png] = [png]

    return report.create_html(
        sections=report_sections,
        title="Model sensitivity to inputs",
    )
コード例 #2
0
def render_zonal_pressures(metadata, diagnostics):
    sections_zonal_pressure = {
        "Links":
        navigation,
        "Zonal mean values at pressure levels":
        list(zonal_pressure_plot_manager.make_plots(diagnostics)),
    }
    return create_html(
        title="Pressure versus latitude plots",
        metadata=metadata,
        sections=sections_zonal_pressure,
        html_header=get_html_header(),
    )
コード例 #3
0
def render_hovmollers(metadata, diagnostics):
    sections_hovmoller = {
        "Links":
        navigation,
        "Zonal mean value and bias":
        list(hovmoller_plot_manager.make_plots(diagnostics)),
    }
    return create_html(
        title="Latitude versus time hovmoller plots",
        metadata=metadata,
        sections=sections_hovmoller,
        html_header=get_html_header(),
    )
コード例 #4
0
def render_maps(metadata, diagnostics, metrics):
    # the plotting functions here require two inputs so can't use a PlotManager
    sections = {
        "Links":
        navigation,
        "Time-mean maps": [
            time_mean_cubed_sphere_maps(diagnostics, metrics),
            time_mean_bias_cubed_sphere_maps(diagnostics, metrics),
        ],
    }
    return create_html(
        title="Time-mean maps",
        metadata=metadata,
        sections=sections,
        html_header=get_html_header(),
    )
コード例 #5
0
def render_time_mean_maps(output_dir, ds_diags) -> str:
    report_sections: MutableMapping[str, Sequence[str]] = {}

    ds_time_mean = get_plot_dataset(ds_diags,
                                    var_filter="time_mean",
                                    column_filters=["global"])

    # snapshot maps
    snapshot_vars = [
        v for v in ds_diags
        if v.endswith("snapshot") and DERIVATION_DIM_NAME in ds_diags[v].dims
    ]
    for section, ds in zip(["Time averaged maps", "Snapshot maps"],
                           [ds_time_mean, ds_diags[snapshot_vars]]):
        map_vars = [v for v in ds if not is_3d(ds[v])]
        for var in ds[map_vars]:
            ds[f"error_in_{var}"] = (ds.sel(derivation="predict")[var] -
                                     ds.sel(derivation="target")[var])
            fig = plot_column_integrated_var(
                ds.update(ds_diags[["lat", "lon", "latb", "lonb"]]),
                var,
                derivation_plot_coords=ds_diags[DERIVATION_DIM_NAME].values,
            )
            report.insert_report_figure(
                report_sections,
                fig,
                filename=f"{var}.png",
                section_name=section,
                output_dir=output_dir,
            )
            fig_error = plot_column_integrated_var(
                ds.update(ds_diags[["lat", "lon", "latb", "lonb"]]),
                f"error_in_{var}",
                derivation_plot_coords=None,
                derivation_dim=None,
            )
            report.insert_report_figure(
                report_sections,
                fig_error,
                filename=f"error_in_{var}.png",
                section_name=section,
                output_dir=output_dir,
            )
    return report.create_html(
        sections=report_sections,
        title="Maps",
    )
コード例 #6
0
def render_process_diagnostics(metadata, diagnostics, metrics):
    percentile_names = {f"percentile_{p}": [PRECIP_RATE] for p in PERCENTILES}
    sections = {
        "Links":
        navigation,
        "Precipitation percentiles": [metric_table(metrics, percentile_names)],
        "Diurnal cycle":
        list(diurnal_plot_manager.make_plots(diagnostics)),
        "Precipitation and water vapor path":
        list(histogram_plot_manager.make_plots(diagnostics)),
    }
    return create_html(
        title="Process diagnostics",
        metadata=metadata,
        sections=sections,
        html_header=get_html_header(),
    )
コード例 #7
0
def render_index(metadata, diagnostics, metrics, movie_links):
    sections_index = {
        "Links": navigation,
        "Top-level metrics": [metric_table(metrics, TOP_LEVEL_METRICS)],
        "Timeseries": list(timeseries_plot_manager.make_plots(diagnostics)),
        "Zonal mean": list(zonal_mean_plot_manager.make_plots(diagnostics)),
        "Complete metrics": list(metrics_plot_manager.make_plots(metrics)),
    }
    return create_html(
        title="Prognostic run report",
        metadata={
            **metadata,
            **render_links(movie_links)
        },
        sections=sections_index,
        html_header=get_html_header(),
    )
コード例 #8
0
def render_index(config, metrics, ds_diags, ds_transect, output_dir) -> str:
    report_sections: MutableMapping[str, Sequence[str]] = {}

    # Links
    report_sections["Links"] = [
        report.Link("Model input sensitivity", MODEL_SENSITIVITY_HTML),
        report.Link("Maps", TIME_MEAN_MAPS_HTML),
    ]

    # histogram of timesteps used for testing
    try:
        timesteps = ds_diags["time"]
    except KeyError:
        pass
    else:
        timesteps = np.vectorize(vcm.cast_to_datetime)(timesteps)
        fig = fv3viz.plot_daily_and_hourly_hist(timesteps)
        fig.set_size_inches(10, 3)
        report.insert_report_figure(
            report_sections,
            fig,
            filename="timesteps_used.png",
            section_name="Timesteps used for testing",
            output_dir=output_dir,
        )

    # Zonal average of vertical profiles for R2
    zonal_avg_pressure_level_metrics = [
        var for var in ds_diags.data_vars
        if var.endswith("_pressure_level_zonal_avg_global") and (
            "r2" in var.lower())
    ]
    for var in sorted(zonal_avg_pressure_level_metrics):
        fig = plot_zonal_average(
            data=ds_diags[var],
            title=tidy_title(var),
            plot_kwargs={
                "vmin": 0,
                "vmax": 1
            },
        )
        report.insert_report_figure(
            report_sections,
            fig,
            filename=f"zonal_avg_pressure_{var}.png",
            section_name="Zonal averaged pressure level metrics",
            output_dir=output_dir,
        )

    # vertical profiles of bias and R2
    pressure_level_metrics = [
        var for var in ds_diags.data_vars
        if var.endswith("pressure_level_global") and ("r2" in var.lower())
    ]
    for var in sorted(pressure_level_metrics):
        ylim = (0, 1) if "r2" in var.lower() else None
        fig = plot_generic_data_array(ds_diags[var],
                                      xlabel="pressure [Pa]",
                                      ylim=ylim,
                                      title=tidy_title(var))
        report.insert_report_figure(
            report_sections,
            fig,
            filename=f"{var}.png",
            section_name="Pressure level metrics",
            output_dir=output_dir,
        )

    # time averaged quantity vertical profiles over land/sea, pos/neg net precip
    vars_3d = [v for v in ds_diags if is_3d(ds_diags[v])]
    ds_profiles = get_plot_dataset(
        ds_diags[vars_3d],
        var_filter="time_domain_mean",
        column_filters=[
            "global",
            "land",
            "sea",
            "positive_net_precipitation",
            "negative_net_precipitation",
        ],
    )
    for var in sorted(ds_profiles):
        fig = plot_profile_var(
            ds_profiles,
            var,
            derivation_dim=DERIVATION_DIM_NAME,
            domain_dim="domain",
        )
        report.insert_report_figure(
            report_sections,
            fig,
            filename=f"{var}.png",
            section_name="Vertical profiles of predicted variables",
            output_dir=output_dir,
        )

    # 2d quantity diurnal cycles
    ds_diurnal = get_plot_dataset(ds_diags,
                                  var_filter="diurnal_cycle",
                                  column_filters=["global", "land", "sea"])
    for var in ds_diurnal:
        fig = plot_diurnal_cycles(
            ds_diurnal,
            var=var,
        )
        report.insert_report_figure(
            report_sections,
            fig,
            filename=f"{var}.png",
            section_name="Diurnal cycles of column integrated quantities",
            output_dir=output_dir,
        )

    # transect of predicted fields at lon=0
    if len(ds_transect) > 0:
        transect_time = ds_transect.time.item()
        for var in sorted(ds_transect.data_vars):
            fig = plot_transect(ds_transect[var])
            report.insert_report_figure(
                report_sections,
                fig,
                filename=f"transect_lon0_{var}.png",
                section_name=f"Transect snapshot at lon=0 deg, {transect_time}",
                output_dir=output_dir,
            )

    # scalar metrics for RMSE and bias
    metrics_formatted = []
    scalar_vars_r2 = sorted([var for var in metrics if "r2" in var])
    scalar_vars_bias = [var.replace("_r2", "_bias") for var in scalar_vars_r2]

    for var_r2, var_bias in zip(scalar_vars_r2, scalar_vars_bias):
        values = {
            "r2":
            get_metric_string(metrics[var_r2]),
            "bias":
            " ".join(
                [get_metric_string(metrics[var_bias]),
                 units_from_name(var)]),
        }
        metrics_formatted.append((var_r2.replace("_r2", ""), values))

    if "water_vapor_path_versus_minus_column_integrated_q2_hist_2d" in ds_diags:
        hist2d_wvp_vs_q2 = plot_histogram2d(ds_diags, "water_vapor_path",
                                            "minus_column_integrated_q2")
        report.insert_report_figure(
            report_sections,
            hist2d_wvp_vs_q2,
            filename=f"hist2d_wvp_vs_q2.png",
            section_name=f"Water vapor path versus column integrated drying",
            output_dir=output_dir,
        )
        hist_wvp = plot_histogram(ds_diags, f"{WVP}_histogram")
        report.insert_report_figure(
            report_sections,
            hist_wvp,
            filename=f"hist_wvp.png",
            section_name=f"Water vapor path versus column integrated drying",
            output_dir=output_dir,
        )
        hist_col_drying = plot_histogram(ds_diags, f"{COL_DRYING}_histogram")
        report.insert_report_figure(
            report_sections,
            hist_col_drying,
            filename=f"hist_col_drying.png",
            section_name=f"Water vapor path versus column integrated drying",
            output_dir=output_dir,
        )
    return report.create_html(
        sections=report_sections,
        title="ML offline diagnostics",
        metadata=config,
        metrics=dict(metrics_formatted),
    )
コード例 #9
0
#images = list(filter(lambda i: i[2] == "22276.png" or i[2] == "10635.png" or i[2] == "15055.png" or i[2] == "input_7_1.png" or i[2] == "input_2404_1.png" ,images))
images = list(filter(lambda i: i[0] != "unknown", images))

classified = []
threads = []

q = Queue(maxsize=0)
num_theads = 20


def thread(_q):
    while not _q.empty():
        image = _q.get()
        classified.append(process.classify(image))
        _q.task_done()


for i in images:
    q.put(i)

for t in range(num_theads):
    t = Thread(target=thread, args=(q, ))
    t.start()

q.join()

classified, evaluation = report.evaluation(classified)
report = report.create_html(classified, evaluation)
report_file = open("report.test.html", "w")
report_file.write(report)
report_file.close()
コード例 #10
0
def test_create_html_inserts_header_image():
    title = "Report Name"
    sections = {"header": ["image.png"]}
    html = create_html(title=title, sections=sections)
    assert '<img src="image.png"' in html
コード例 #11
0
                            index_label=['id'],
                            sep="|")

    if parameters.html_report:
        # We copy the SlickGrid package
        slickGrid_output_path = os.path.join(parameters.output_path,
                                             "SlickGrid")
        if not os.path.exists(slickGrid_output_path):
            copytree(os.path.join(script_location, "SlickGrid/"),
                     slickGrid_output_path)

        Results_noMultiIndex = Results.reset_index(level=list(
            range(Results.index.nlevels)),
                                                   inplace=False)
        Results_html = create_html(parameters.output_path,
                                   Results_noMultiIndex,
                                   parameters.output_path,
                                   os.path.join(script_location, "templates/"),
                                   sortable_set=set(
                                       Results_noMultiIndex.columns),
                                   link_formatter_set=set(["Timeline"]),
                                   base_template="base.html",
                                   slickGrid_path="./SlickGrid")

        with open(os.path.join(parameters.output_path, "scores_probes.html"),
                  "w") as f:
            f.write(Results_html)
            f.write("\n")

    print("Done.")