def test_threshold_brier_score_multiple_thresholds_list(o, f_prob, keep_attrs):
    threshold = [0.1, 0.3, 0.5]
    actual = threshold_brier_score(o, f_prob, threshold, keep_attrs=keep_attrs)
    assert actual.chunks is None or actual.chunks == ()
    if keep_attrs:
        assert actual.attrs == o.attrs
    else:
        assert actual.attrs == {}
def test_threshold_brier_score_multiple_thresholds_xr(o, f_prob, keep_attrs):
    threshold = xr.DataArray([0.1, 0.3, 0.5], dims="threshold")
    actual = threshold_brier_score(o, f_prob, threshold, keep_attrs=keep_attrs)
    assert actual.chunks is None or actual.chunks == ()
    if keep_attrs:
        assert actual.attrs == o.attrs
    else:
        assert actual.attrs == {}
def test_threshold_brier_score_threshold_dataset(o_dask, f_prob_dask):
    """Test that threshold_brier_score accepts xr.Dataset thresholds."""
    threshold = xr.DataArray([0.1, 0.3, 0.5], dims="threshold").to_dataset(name="var")
    threshold["var2"] = xr.DataArray([0.2, 0.4, 0.6], dims="threshold")
    o_dask = o_dask.to_dataset(name="var")
    o_dask["var2"] = o_dask["var"] ** 2
    f_prob_dask = f_prob_dask.to_dataset(name="var")
    f_prob_dask["var2"] = f_prob_dask["var"] ** 2
    actual = threshold_brier_score(o_dask, f_prob_dask, threshold)
    assert actual
def test_threshold_brier_score_dask_b_int(o_dask, f_prob_dask, keep_attrs):
    threshold = 0
    actual = threshold_brier_score(o_dask,
                                   f_prob_dask,
                                   threshold,
                                   keep_attrs=keep_attrs)
    assert actual is not None
    if keep_attrs:
        assert actual.attrs == o_dask.attrs
    else:
        assert actual.attrs == {}
def test_threshold_brier_score_accessor(o, f_prob, threshold, outer_bool):
    actual = threshold_brier_score(o, f_prob, threshold)
    ds = xr.Dataset()
    ds["o"] = o
    ds["f_prob"] = f_prob
    if outer_bool:
        ds = ds.drop_vars("f_prob")
        expected = ds.xs.threshold_brier_score("o", f_prob, threshold)
    else:
        expected = ds.xs.threshold_brier_score("o", "f_prob", threshold)
    assert_allclose(actual, expected)
def test_threshold_brier_score_multiple_thresholds_dask(
        o_dask, f_prob_dask, keep_attrs):
    threshold = xr.DataArray([0.1, 0.3, 0.5, 0.7], dims="threshold").chunk()
    actual = threshold_brier_score(o_dask,
                                   f_prob_dask,
                                   threshold,
                                   keep_attrs=keep_attrs)
    assert actual.chunks is not None
    if keep_attrs:
        assert actual.attrs == o_dask.attrs
    else:
        assert actual.attrs == {}
def test_threshold_brier_score_accessor(o, f, threshold, dask_bool,
                                        outer_bool):
    if dask_bool:
        o = o.chunk()
        f = f.chunk()
    actual = threshold_brier_score(o, f, threshold)

    ds = xr.Dataset()
    ds['o'] = o
    ds['f'] = f
    if outer_bool:
        ds = ds.drop_vars('f')
        expected = ds.xs.threshold_brier_score('o', f, threshold)
    else:
        expected = ds.xs.threshold_brier_score('o', 'f', threshold)
    assert_allclose(actual, expected)
def test_threshold_brier_score_dask(o_dask, f_prob_dask, keep_attrs):
    threshold = 0.5
    actual = threshold_brier_score(o_dask,
                                   f_prob_dask,
                                   threshold,
                                   keep_attrs=keep_attrs)
    expected = properscoring.threshold_brier_score(o_dask,
                                                   f_prob_dask,
                                                   threshold,
                                                   axis=0)
    expected = xr.DataArray(expected, coords=o_dask.coords).mean()
    # test for numerical identity of xskillscore threshold and properscorin threshold
    assert_identical(actual, expected.assign_attrs(**actual.attrs))
    # test that xskillscore crps_ensemble returns chunks
    assert actual.chunks is not None
    # show that properscoring crps_ensemble returns no chunks
    assert expected.chunks is None
    if keep_attrs:
        assert actual.attrs == o_dask.attrs
    else:
        assert actual.attrs == {}
def test_threshold_brier_score_api_and_inputs(
    o, f_prob, keep_attrs, input_type, chunk_bool
):
    """Test that threshold_brier_score keeps attributes, chunking, input types and
    equals properscoring.threshold_brier_score."""
    o, f_prob = modify_inputs(o, f_prob, input_type, chunk_bool)
    threshold = 0.5
    actual = threshold_brier_score(o, f_prob, threshold, keep_attrs=keep_attrs)
    if input_type == "DataArray":  # properscoring allows only DataArrays
        expected = properscoring.threshold_brier_score(o, f_prob, threshold, axis=0)
        expected = xr.DataArray(expected, coords=o.coords).mean()
        expected["threshold"] = threshold
        # test for numerical identity of xs threshold and properscoring threshold
        if keep_attrs:
            expected = expected.assign_attrs(**actual.attrs)
        assert_identical(actual, expected)
    # test that returns chunks
    assert_chunk(actual, chunk_bool)
    # test that attributes are kept
    assert_keep_attrs(actual, o, keep_attrs)
    # test that input types equal output types
    assign_type_input_output(actual, o)
示例#10
0
def test_threshold_brier_score_threshold(o_dask, f_prob_dask, threshold):
    """Test that threshold_brier_score accepts different kinds of thresholds."""
    actual = threshold_brier_score(o_dask, f_prob_dask, threshold)
    assert (actual.threshold == threshold).all()
示例#11
0
def test_threshold_brier_score_dim(o, f_prob, dim):
    """Check that threshold_brier_score reduces only dim."""
    actual = threshold_brier_score(o, f_prob, threshold=0.5, dim=dim)
    assert_only_dim_reduced(dim, actual, o)
示例#12
0
def test_threshold_brier_score_dask_threshold(o_dask, f_prob_dask, threshold):
    actual = threshold_brier_score(o_dask, f_prob_dask, threshold)
    assert actual.chunks is not None
示例#13
0
def test_threshold_brier_score_dim(o, f_prob, dim):
    actual = threshold_brier_score(o, f_prob, threshold=0.5, dim=dim)
    assert_only_dim_reduced(dim, actual, o)