def test_map_over_tiles(tmpdir, fn, buffer): tile_path = tmpdir / 'tiles' chunks = {'y': 10, 'x': 10} tiling.tile(ds, str(tile_path), chunks=chunks, buffer=buffer) files = str(tile_path / '*.nc') mapped = tiling.map_over_tiles(files, fn) xr_assert_equal(mapped, fn(ds))
def test_tile(tmpdir, chunks, buffer): tile_path = tmpdir / 'tiles' tiling.tile(ds, str(tile_path), chunks=chunks, buffer=buffer) if isinstance(buffer, int): buffer_dict = {dim: buffer for dim in ds.dims.keys()} else: buffer_dict = { dim: buffer[dim] if dim in buffer else 0 for dim in chunks.keys() } # Check whether the correct number of tiles has been created nchunks = np.prod([ int(np.ceil(ds.dims[dim] / n)) # - np.floor(buffer_dict[dim] / n)) for dim, n in chunks.items() ]) tile_files = list(map(str, tile_path.listdir())) assert len(tile_files) == nchunks for f in tile_files: t = open_dataset(f) assert_equal(ds.attrs, t.attrs) for dim, val in chunks.items(): assert t.dims[dim] <= val + 2 * buffer_dict[dim] if buffer == 0 and len(chunks) == 1: mf_data = xr.open_mfdataset(tile_files, engine='h5netcdf').compute() assert_equal_data(ds, mf_data) else: merged = tiling.auto_merge(tile_files) assert_equal_data(ds, merged)
def test_tile_and_merge(tmpdir, chunks, buffer): tile_path = tmpdir / 'tiles' tiling.tile(ds, str(tile_path), chunks=chunks, buffer=buffer) merged = tiling.auto_merge(str(tile_path / '*.nc')) xr_assert_equal(merged, ds)