Skip to content

Commit 35a8727

Browse files
aulemahalpre-commit-ci[bot]huard
authored
Add error message when output has no chunks with parallel weights generation (#304)
* Add error msg when no chunks in par=T * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix for locstreamout * add simple test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: David Huard <[email protected]>
1 parent 198d0ee commit 35a8727

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ What's new
66

77
Bug fixes
88
~~~~~~~~~
9+
* Raise a meaningful error messages when the output grid has no chunks with `parallel=True` (:issue:`299`, :pull:`304`). By `Pascal Bourgault <https://github.com/aulemahal>`_.
910
* Correct guess of output chunks for the :``SpatialAverager``.
1011

1112
0.8.1 (2023-09-05)

xesmf/frontend.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,11 @@ def _init_para_regrid(self, ds_in, ds_out, kwargs):
963963
ds_out = ds_out.set_coords(['lon_b', 'lat_b'])
964964
if 'lon_b' in ds_in.data_vars:
965965
ds_in = ds_in.set_coords(['lon_b', 'lat_b'])
966+
if not (set(self.out_horiz_dims) - {'dummy'}).issubset(ds_out.chunksizes.keys()):
967+
raise ValueError(
968+
'Using `parallel=True` requires the output grid to have chunks along all spatial dimensions. '
969+
'If the dataset has no variables, consider adding an all-True spatial mask with appropriate chunks.'
970+
)
966971
# Drop everything in ds_out except mask or create mask if None. This is to prevent map_blocks loading unnecessary large data
967972
if self.sequence_out:
968973
ds_out_dims_drop = set(ds_out.variables).difference(ds_out.data_vars)

xesmf/tests/test_frontend.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ def test_para_weight_gen():
649649
assert all(regridder_locs.w.data.data == para_regridder_locs.w.data.data)
650650

651651

652+
def test_para_weight_gen_errors():
653+
with pytest.raises(ValueError, match='requires the output grid to have chunks'):
654+
xe.Regridder(ds_in, ds_out, 'conservative', parallel=True)
655+
656+
652657
def test_regrid_dataset():
653658
# xarray.Dataset containing in-memory numpy array
654659
regridder = xe.Regridder(ds_in, ds_out, 'conservative')

0 commit comments

Comments
 (0)