Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option for parallel weight generation with xESMF #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ndpyramid/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def pyramid_regrid(
target_pyramid: dt.DataTree = None,
levels: int = None,
weights_pyramid: dt.DataTree = None,
parallel_weights: bool = True,
method: str = 'bilinear',
regridder_kws: dict = None,
regridder_apply_kws: dict = None,
Expand All @@ -216,6 +217,8 @@ def pyramid_regrid(
Number of levels in pyramid, by default None
weights_pyramid : dt.DataTree, optional
pyramid containing pregenerated weights
parallel_weights : Bool
Use dask to generate parallel weights
method : str, optional
Regridding method. See :py:class:`~xesmf.Regridder` for valid options, by default 'bilinear'
regridder_kws : dict
Expand Down Expand Up @@ -283,7 +286,7 @@ def pyramid_regrid(
grid = target_pyramid[str(level)].ds.load()
# get the regridder object
if weights_pyramid is None:
regridder = xe.Regridder(ds, grid, method, **regridder_kws)
regridder = xe.Regridder(ds, grid, method, parallel=parallel_weights, **regridder_kws)
else:
# Reconstruct weights into format that xESMF understands
# this is a hack that assumes the weights were generated by
Expand Down
6 changes: 5 additions & 1 deletion tests/test_pyramid_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def test_regridded_pyramid(temperature, regridder_apply_kws, benchmark):
temperature = temperature.isel(time=slice(0, 5))
pyramid = benchmark(
lambda: pyramid_regrid(
temperature, levels=2, regridder_apply_kws=regridder_apply_kws, other_chunks={'time': 2}
temperature,
levels=2,
parallel_weights=False,
regridder_apply_kws=regridder_apply_kws,
other_chunks={'time': 2},
)
)
verify_bounds(pyramid)
Expand Down