def test_reproject_no_hidden_effects(): src_crs = epsg4326 dst_crs = sinusoidal ds = generate_test_dataset(crs=src_crs) ds_copy = ds.copy(deep=True) projected = _reproject(ds_copy, dst_crs=dst_crs) xr_assert_identical(ds, ds_copy)
def test_convolve_complex(): ds_complex = assemble_complex(ds) convolved_complex = ConvolutionFilter( ('y', 'x'), identity_kernel).apply(ds_complex) xr_assert_identical( ds_complex, convolved_complex )
def test_boxcar(): w = 5 dims = ('y', 'x') kernel = np.ones((w, w)) / w**2 xr_assert_identical( BoxcarFilter(dims, w).apply(ds), ConvolutionFilter(dims, kernel).apply(ds))
def test_squeeze(): a = generate_test_dataarray(dims={'y': 1}) value = a.values[0] squeezed = utils.squeeze(a) assert isinstance(squeezed, float) assert value == squeezed b = generate_test_dataarray(dims={'y': 2}) xr_assert_identical(b, utils.squeeze(b))
def test_parallel(): ds = generate_test_dataset() t = time.time() result_serial = _parallel_fn(ds) serial_time = time.time() - t t = time.time() result_parallel = utils.parallel(_parallel_fn, chunks=4)(ds) parallel_time = time.time() - t # Assert that the results are identical xr_assert_identical(result_serial, result_parallel) # Assert that the parallel execution was more than three times faster import multiprocessing as mp if mp.cpu_count() <= 1: pytest.skip("Execution time is only faster if there are " "multiple cores") assert serial_time > parallel_time
def test_convolve_dataset_identity(): dims = ('y', 'x') convolved = ConvolutionFilter(dims, identity_kernel).apply(ds) xr_assert_identical(ds, convolved)
def test_expand_variables(): ds = generate_test_dataset() da = ds.to_array(dim='new_dim') ds_new = utils.expand_variables(da, dim='new_dim') xr_assert_identical(ds, ds_new)
def test_assemble_and_dissassemble_complex(): ds_orig = generate_test_dataset(var=['a__im', 'a__re', 'b', 'c']) ds_complex = assemble_complex(ds_orig) ds_real = disassemble_complex(ds_complex) xr_assert_identical(ds_orig, ds_real)