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

Sparse regridding without using ESMF #130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TomNicholas
Copy link
Contributor

@TomNicholas TomNicholas commented Jun 3, 2024

This PR shows how one can avoid using xESMF for the application of the regridding weights, by using sparse matrix multiplication instead. The motivation for this is errors when using ndpyramid with a dask PBSCluster at scale due to ESMF not being thread-safe (see pangeo-data/xESMF#307 (comment)).

To be clear: This still uses xESMF to generate the regridding weights, it just allows you to generate them once outside of dask and then use them repeatedly without invoking xESMF on you dask cluster, which is enough to get around the threading errors (because you can completely avoid importing xESMF on the dask worker at all).

This notebook shows that this function gives the same results as using xESMF for the application of the weights.

I'm not expecting this to be merged - I just wanted to put it up here in case it's useful to anyone.

Comment on lines +314 to +320
def xr_regridder(
ds: xr.Dataset,
grid: xr.Dataset,
weights: xr.DataArray,
out_grid_shape: tuple[int, int],
) -> xr.Dataset:
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very neat, @TomNicholas! thank you for this addition.

we should definitely figure out how to generalize this...

Cc @norlandrhagen / @maxrjones

latlon_dims = ['nlat', 'nlon']

shape_in = (ds.sizes['nlat'], ds.sizes['nlon'])
shape_out = out_grid_shape
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This out_grid_shape argument is probably superfluous - you could just read it from the grid object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants