def test_filter_mutable_dimension(f): # Check that changing the order of dimensions doesn't change # the outcome up to numeric precision. xr_assert_allclose( f(dims=('y', 'x')).apply(ds), f(dims=('x', 'y')).apply(ds) )
def test_apply_with_vars_keep_vars(): ds = generate_test_dataset() ref = ds.mean('time') result = utils.apply(ds, lambda a: a.mean(axis=0), signature='(time,var)->(var)') xr_assert_allclose(result.transpose(*ref.nd.dims), ref.transpose(*ref.nd.dims))
def test_apply_with_vars(): ds = generate_test_dataset() ref = ds.to_array(dim='var').mean('var') result = utils.apply(ds, lambda a: a.mean(axis=1), signature='(time,var)->(time)') xr_assert_allclose(result.transpose(*ref.nd.dims), ref.transpose(*ref.nd.dims))
def test_apply(dims): ds = generate_test_dataset() ref = ds.mean(dims) result = utils.apply(ds, np.mean, signature='({})->()'.format(",".join(dims))) xr_assert_allclose(result.transpose(*ref.nd.dims), ref.transpose(*ref.nd.dims))
def test_parallel_merge(): dims = dict(x=50, y=50, time=50) ds = generate_test_dataset(dims=dims) def _fn(ds): return (ds - ds.mean('time')) / ds.std('time') result = _fn(ds) result_1 = utils.parallel(_fn, 'x')(ds) result_2 = utils.xr_merge(utils.parallel(_fn, 'x', merge=False)(ds), dim='x') xr_assert_allclose(result, result_1) xr_assert_allclose(result_1, result_2)
def test_generate_covariance_matrix(): ds = generate_test_dataset(var=['VV__im', 'VV__re', 'VH__im', 'VH__re']) assemble_complex(ds, inplace=True) cov = generate_covariance_matrix(ds) xr_assert_allclose(np.abs(ds.VV)**2, cov.C11) xr_assert_allclose(np.abs(ds.VH)**2, cov.C22) xr_assert_allclose(ds.VV * np.conj(ds.VH), cov.C12)
def test_parallelized_filter(f, dims): xr_assert_allclose( f(dims=dims).apply(ds), f(dims=dims).apply(ds, njobs=2) )