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

improve performance of interpolate edges/nodes to faces #649

Closed
veenstrajelmer opened this issue Nov 10, 2023 · 0 comments · Fixed by #652
Closed

improve performance of interpolate edges/nodes to faces #649

veenstrajelmer opened this issue Nov 10, 2023 · 0 comments · Fixed by #652

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Nov 10, 2023

2D indexing with face_node_connectivity or face_edge_connecitivity is terribly slow: dask/dask#10237
This is used in dfmt.uda_edges_to_faces() and dfmt.uda_nodes_to_faces(), also check whether we use it more often.

Faster example with stack and unstack:

import xugrid as xu
import xarray as xr

ds = xr.open_dataset("conv_schism_raw_2.nc").chunk({"time": 1})
grid = xu.Ugrid2d.from_dataset(xr.open_dataset("ugrid.nc"))
node_salinity = ds["salinity"]

reduce_dim = "mesh2d_nMax_face_nodes"
indexer = xr.DataArray(grid.face_node_connectivity, dims=(grid.face_dimension, reduce_dim))
valid = indexer != -2
indexer = indexer.stack(__tmp_dim__=("mesh2d_nFaces", "mesh2d_nMax_face_nodes"))
face_salinity = node_salinity.isel({"nSCHISM_hgrid_node": indexer}).unstack("__tmp_dim__")
result = face_salinity.where(valid).mean(reduce_dim)

Maybe this is a good moment to implement in xugrid instead of dfm_tools.

Other open vindex issue: dask/dask#7313

@veenstrajelmer veenstrajelmer changed the title improve performance of interpolate to faces improve performance of interpolate edges/nodes to faces Nov 10, 2023
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 a pull request may close this issue.

1 participant