예제 #1
0
def test_resample_iterations_dix_no_squeeze(f_prob):
    """Test _resample_iteration_idx with singular dimension."""
    da = f_prob.expand_dims("test_dim")
    actual = resample_iterations_idx(da, iterations=ITERATIONS)
    other = resample_iterations(da, iterations=ITERATIONS)
    assert "test_dim" in actual.dims
    assert actual.coords.to_dataset().equals(other.coords.to_dataset())
예제 #2
0
def test_resampling_roughly_identical_mean(f_prob):
    """check that resampling functions result in allclose iteration mean."""
    da = f_prob.isel(lon=0, lat=0, drop=True)
    iterations = 1000
    r1 = resample_iterations(da, iterations=iterations, replace=True)
    r2 = resample_iterations_idx(da, iterations=iterations, replace=True)
    xr.testing.assert_allclose(r1.mean("iteration"),
                               r2.mean("iteration"),
                               atol=0.05,
                               rtol=0.05)
예제 #3
0
def test_resampling_same_dim_coord_order_as_input(func, f_prob, iterations):
    """check whether resampling function maintain dim and coord order and add iteration
    dimension to the end."""
    da = f_prob
    r1 = resample_iterations(da, iterations=iterations)
    # same as without having iteration
    assert_dim_coords(r1.isel(iteration=0, drop=True), da)
    # same as with having iteration added in the end as in expand_dims
    assert_dim_coords(
        r1,
        da.expand_dims("iteration").transpose(
            ..., "iteration").isel(iteration=[0] * iterations).assign_coords(
                iteration=range(iterations)),
    )
예제 #4
0
def test_resampling_identical_dim(f_prob):
    """check that resampling functions have the same ordering of dims and coords."""
    da = f_prob
    r1 = resample_iterations(da, iterations=ITERATIONS)
    r2 = resample_iterations_idx(da, iterations=ITERATIONS)
    assert_dim_coords(r1, r2)