|
1 | 1 | import sys |
2 | 2 |
|
3 | 3 | import cubed |
| 4 | +import numpy as np |
4 | 5 | import pytest |
5 | 6 | import xarray as xr |
6 | 7 | from cubed.runtime.create import create_executor |
@@ -75,6 +76,29 @@ def test_to_zarr(tmpdir, executor): |
75 | 76 | assert_allclose(original, computed) |
76 | 77 |
|
77 | 78 |
|
| 79 | +# based on test_write_region |
| 80 | +def test_write_region(tmpdir): |
| 81 | + zeros = xr.Dataset({"u": (("x",), np.zeros(10))}).chunk( |
| 82 | + 2, chunked_array_type="cubed" |
| 83 | + ) |
| 84 | + nonzeros = xr.Dataset({"u": (("x",), np.arange(1, 11))}).chunk( |
| 85 | + 2, chunked_array_type="cubed" |
| 86 | + ) |
| 87 | + |
| 88 | + store = tmpdir / "out.zarr" |
| 89 | + zeros.to_zarr( |
| 90 | + store, |
| 91 | + encoding={"u": dict(chunks=2)}, |
| 92 | + ) |
| 93 | + with xr.open_zarr(store) as actual: |
| 94 | + assert_identical(actual, zeros) |
| 95 | + for i in range(0, 10, 2): |
| 96 | + region = {"x": slice(i, i + 2)} |
| 97 | + nonzeros.isel(region).to_zarr(store, region=region) |
| 98 | + with xr.open_zarr(store) as actual: |
| 99 | + assert_identical(actual, nonzeros) |
| 100 | + |
| 101 | + |
78 | 102 | def test_dataset_accessor_visualize(tmp_path): |
79 | 103 | spec = cubed.Spec(allowed_mem="200MB") |
80 | 104 |
|
|
0 commit comments