Example #1
0
def _get_metric_type_df(metrics: RunMetrics, metric_type: str) -> pd.DataFrame:
    variables = sorted(metrics.get_metric_variables(metric_type))
    table = {}
    for varname in variables:
        units = metrics.get_metric_units(metric_type, varname, metrics.runs[0])
        column_name = f"{varname} [{units}]"
        table[column_name] = [
            metrics.get_metric_value(metric_type, varname, run)
            for run in metrics.runs
        ]
    return pd.DataFrame(table, index=metrics.runs)
Example #2
0
def _render_map_title(
    metrics: RunMetrics,
    variable: str,
    run: str,
    metrics_for_title: Mapping[str, str],
) -> str:
    title_parts = []
    for name_in_figure_title, metric_type in metrics_for_title.items():
        metric_value = metrics.get_metric_value(metric_type, variable, run)
        metric_units = metrics.get_metric_units(metric_type, variable, run)
        title_parts.append(
            f"{name_in_figure_title}: {metric_value:.3f} {metric_units}")
    return ", ".join(title_parts)
Example #3
0
def test__get_metric_df():
    metrics = RunMetrics(METRICS_DF)
    table = _get_metric_df(metrics, {"rmse_of_time_mean": ["h500", "precip"]})
    expected_data = {
        "h500 rmse_of_time_mean [m]": [2, np.nan],
        "precip rmse_of_time_mean [mm/day]": [-1, 1],
    }
    expected_table = pd.DataFrame(expected_data, index=["run1", "run2"])
    pd.testing.assert_frame_equal(table, expected_table)
Example #4
0
def test_RunMetrics_get_metric_units():
    metrics = RunMetrics(metrics_df)
    assert metrics.get_metric_units("rmse_of_time_mean", "precip", "run1") == "mm/day"
Example #5
0
def test_RunMetrics_get_metric_value_missing():
    metrics = RunMetrics(metrics_df)
    assert np.isnan(metrics.get_metric_value("rmse_of_time_mean", "h500", "run2"))
Example #6
0
def test_RunMetrics_get_metric_value():
    metrics = RunMetrics(metrics_df)
    assert metrics.get_metric_value("rmse_of_time_mean", "precip", "run1") == -1
Example #7
0
def test_RunMetrics_get_metric_variables():
    metrics = RunMetrics(metrics_df)
    assert metrics.get_metric_variables("rmse_of_time_mean") == {"precip", "h500"}
Example #8
0
def test_RunMetrics_types():
    metrics = RunMetrics(metrics_df)
    assert metrics.types == {"rmse_of_time_mean", "time_and_global_mean_bias"}
Example #9
0
def test_RunMetrics_runs():
    metrics = RunMetrics(metrics_df)
    assert metrics.runs == ["run1", "run2"]