def test_resample_1_size(PM_da_initialized_1d): """Tests that the resampled dimensions are appropriate for a single iteration.""" dim = "member" expected = _resample(PM_da_initialized_1d, resample_dim=dim) # 1 somehow fails actual = _resample_iterations_idx(PM_da_initialized_1d, 2, dim=dim).isel(iteration=0) assert expected.size == actual.size assert expected[dim].size == actual[dim].size
def test_resample_iterations_same(PM_da_initialized_1d, chunk, replace): """Test that both `resample_iterations` functions yield same result shape.""" ds = PM_da_initialized_1d if chunk: ds = ds.chunk() ds_r_idx = _resample_iterations_idx(ds, ITERATIONS, 'member', replace=replace) ds_r = _resample_iterations(ds, ITERATIONS, 'member', replace=replace) for d in ds.dims: xr.testing.assert_identical(ds_r[d], ds_r_idx[d]) assert ds_r.size == ds_r_idx.size
def test_resample_size(PM_da_initialized_1d): """Tests that the resampled dimensions are appropriate for many iterations.""" dim = 'member' expected = xr.concat( [_resample(PM_da_initialized_1d, resample_dim=dim) for i in range(ITERATIONS)], 'iteration', ) actual = _resample_iterations_idx(PM_da_initialized_1d, ITERATIONS, dim=dim) assert expected.size == actual.size assert expected[dim].size == actual[dim].size
def test_resample_iterations_dix_no_squeeze(PM_da_initialized_1d): """Test _resample_iteration_idx with singular dimension. Currently this fails for dimensions with just a single index as we use `squeeze` in the code and not using squeeze doesnt maintain functionality. This means that _resample_iteration_idx should not be called on singleton dimension inputs (which is not critical and can be circumvented when using squeeze before climpred.). """ da = PM_da_initialized_1d.expand_dims("test_dim") print(da) actual = _resample_iterations_idx(da, iterations=ITERATIONS) assert "test_dim" in actual.dims