def test_crps_gaussian_dask_b_int(o_dask, keep_attrs): mu = 0 sig = 1 actual = crps_gaussian(o_dask, mu, sig, keep_attrs=keep_attrs) assert actual is not None if keep_attrs: assert actual.attrs == o_dask.attrs else: assert actual.attrs == {}
def test_crps_gaussian_dask(o_dask, f_prob_dask, keep_attrs): mu = f_prob_dask.mean("member") sig = f_prob_dask.std("member") actual = crps_gaussian(o_dask, mu, sig, keep_attrs=keep_attrs) expected = properscoring.crps_gaussian(o_dask, mu, sig) 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
def test_crps_gaussian_accessor(o, f_prob, outer_bool): mu = f_prob.mean("member") sig = f_prob.std("member") actual = crps_gaussian(o, mu, sig) ds = xr.Dataset() ds["o"] = o ds["mu"] = mu ds["sig"] = sig if outer_bool: ds = ds.drop_vars("mu") expected = ds.xs.crps_gaussian("o", mu, sig) else: expected = ds.xs.crps_gaussian("o", "mu", "sig") assert_allclose(actual, expected)
def test_crps_gaussian_args(o, keep_attrs, input_type): """Test that crps_gaussian accepts various data types as args.""" mu = 0 sig = 1 if "input_type" == "float": mu = float(mu) sig = float(sig) elif "input_type" == "xr.DataArray": mu = xr.DataArray(mu) sig = xr.DataArray(sig) elif "input_type" == "np.array": mu = np.array(mu) sig = np.array(sig) actual = crps_gaussian(o, mu, sig, keep_attrs=keep_attrs) assert_keep_attrs(actual, o, keep_attrs)
def test_crps_gaussian_accessor(o, f, dask_bool, outer_bool): if dask_bool: o = o.chunk() f = f.chunk() mu = f.mean('member') sig = f.std('member') actual = crps_gaussian(o, mu, sig) ds = xr.Dataset() ds['o'] = o ds['mu'] = mu ds['sig'] = sig if outer_bool: ds = ds.drop_vars('mu') expected = ds.xs.crps_gaussian('o', mu, sig) else: expected = ds.xs.crps_gaussian('o', 'mu', 'sig') assert_allclose(actual, expected)
def test_crps_gaussian_api_and_inputs(o, f_prob, keep_attrs, input_type, chunk_bool): """Test that crps_gaussian keeps attributes, chunking, input types and equals properscoring.crps_gaussian.""" o, f_prob = modify_inputs(o, f_prob, input_type, chunk_bool) mu = f_prob.mean("member") sig = f_prob.std("member") actual = crps_gaussian(o, mu, sig, keep_attrs=keep_attrs) if input_type == "DataArray": # properscoring allows only DataArrays expected = properscoring.crps_gaussian(o, mu, sig) 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)
def test_crps_gaussian_dim(o, f_prob, dim): """Check that crps_gaussian reduces only dim.""" mu = f_prob.mean("member") sig = f_prob.std("member") actual = crps_gaussian(o, mu, sig, dim=dim) assert_only_dim_reduced(dim, actual, o)