Ejemplo n.º 1
0
def test_crps_ensemble_weighted(o, f_prob, weights, keep_attrs):
    dim = ["lon", "lat"]
    actual = crps_ensemble(o,
                           f_prob,
                           dim=dim,
                           weights=weights,
                           keep_attrs=keep_attrs)
    assert_only_dim_reduced(dim, actual, o)
def test_crps_ensemble_accessor(o, f_prob, outer_bool):
    actual = crps_ensemble(o, f_prob)
    ds = xr.Dataset()
    ds["o"] = o
    ds["f_prob"] = f_prob
    if outer_bool:
        ds = ds.drop_vars("f_prob")
        expected = ds.xs.crps_ensemble("o", f_prob)
    else:
        expected = ds.xs.crps_ensemble("o", "f_prob")
    assert_allclose(actual, expected)
Ejemplo n.º 3
0
def test_crps_ensemble_dask(o_dask, f_prob_dask, keep_attrs):
    actual = crps_ensemble(o_dask, f_prob_dask, keep_attrs=keep_attrs)
    expected = properscoring.crps_ensemble(o_dask, f_prob_dask, axis=0)
    expected = xr.DataArray(expected, coords=o_dask.coords).mean()
    # test for numerical identity of xskillscore crps and properscoring crps
    assert_allclose(actual, expected)
    # 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_crps_ensemble_accessor(o, f, dask_bool, outer_bool):
    if dask_bool:
        o = o.chunk()
        f = f.chunk()
    actual = crps_ensemble(o, f)

    ds = xr.Dataset()
    ds['o'] = o
    ds['f'] = f
    if outer_bool:
        ds = ds.drop_vars('f')
        expected = ds.xs.crps_ensemble('o', f)
    else:
        expected = ds.xs.crps_ensemble('o', 'f')
    assert_allclose(actual, expected)
def test_crps_ensemble_api_and_inputs(o, f_prob, keep_attrs, input_type, chunk_bool):
    """Test that crps_ensemble keeps attributes, chunking, input types and equals
    properscoring.crps_ensemble."""
    o, f_prob = modify_inputs(o, f_prob, input_type, chunk_bool)
    actual = crps_ensemble(o, f_prob, keep_attrs=keep_attrs)
    if input_type == "DataArray":  # properscoring allows only DataArrays
        expected = properscoring.crps_ensemble(o, f_prob, axis=0)
        expected = xr.DataArray(expected, coords=o.coords).mean()
        # test for numerical identity of xskillscore crps and properscoring crps
        assert_allclose(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)
Ejemplo n.º 6
0
def test_crps_ensemble_weighted(o, f_prob, weights_cos_lat):
    """Test that weighted changes results of crps_ensemble."""
    dim = ["lon", "lat"]
    actual = crps_ensemble(o, f_prob, dim=dim, weights=weights_cos_lat)
    actual_no_weights = crps_ensemble(o, f_prob, dim=dim)
    assert not (actual_no_weights == actual).all()
Ejemplo n.º 7
0
def test_crps_ensemble_dim(o, f_prob, dim):
    """Check that crps_ensemble reduces only dim."""
    actual = crps_ensemble(o, f_prob, dim=dim)
    assert_only_dim_reduced(dim, actual, o)
Ejemplo n.º 8
0
def test_crps_ensemble_dim(o, f_prob, dim):
    actual = crps_ensemble(o, f_prob, dim=dim)
    assert_only_dim_reduced(dim, actual, o)
def test_crps_ensemble_broadcast(o, f_prob, dim):
    """Check that crps_ensemble broadcasts."""
    crps_ensemble(o, f_prob.expand_dims("model").isel(model=[0] * 2), dim=dim)
    crps_ensemble(o.expand_dims("model").isel(model=[0] * 2), f_prob, dim=dim)