Skip to content

Commit

Permalink
add contiguous_chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikKok committed Jul 18, 2023
1 parent 573ef66 commit 1fa665f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions xugrid/regrid/regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import dask.array

DaskArray = dask.array.Array
DaskRechunk = dask.array.rechunk
except ImportError:
DaskArray = ()
DaskRechunk = ()

import xugrid
from xugrid.constants import FloatArray
Expand Down Expand Up @@ -148,9 +146,14 @@ def _regrid_array(self, source):
size = self._target.size

if isinstance(source, DaskArray):
# for DaskArray's from multiple partitions, rechunk first to single size per dimension
# for now always rechunk, could be optional only when explicit chunks in single dimension
source = DaskRechunk(source, source.shape)
# It's possible that the topology dimensions are chunked (e.g. from
# reading multiple partitions). The regrid operation does not
# support this, since we might need multiple source chunks for a
# single target chunk, which destroys the 1:1 relation between
# chunks. Here we ensure that the topology dimensions are contained
# in a single contiguous chunk.
contiguous_chunks = (source.chunks[0], (source.shape[-1],))
source = source.rechunk(contiguous_chunks)
chunks = source.chunks[: -source_grid.ndim] + (self._target.shape)
out = dask.array.map_blocks(
self._regrid, # func
Expand All @@ -161,9 +164,6 @@ def _regrid_array(self, source):
chunks=chunks,
meta=np.array((), dtype=source.dtype),
)
# TODO: for now we compute first, since .reshape and dask.array.reshape
# does not reshapes the underlying data somehow. This need to be evaluated.
out = out.compute()
elif isinstance(source, np.ndarray):
out = self._regrid(source, self._weights, size)
else:
Expand Down

0 comments on commit 1fa665f

Please sign in to comment.