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

replace remove xu noncontiguous with mk disconnected regions #550

Closed
veenstrajelmer opened this issue Sep 30, 2023 · 0 comments · Fixed by #674
Closed

replace remove xu noncontiguous with mk disconnected regions #550

veenstrajelmer opened this issue Sep 30, 2023 · 0 comments · Fixed by #674

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Sep 30, 2023

Was implemented in meshkernelpy 3.0.0 (Deltares/MeshKernelPy#87) with mkernel_mesh2d_remove_disconnected_regions.First wait on #563

This can potentially replace this part in dfmt.meshkernel_to_UgridDataset() (and move it outside function):

def xugrid_remove_noncontiguous(grid):
#based on https://deltares.github.io/xugrid/examples/connectivity.html#connected-components
#uses https://docs.scipy.org/doc/scipy/reference/sparse.csgraph.html
#TODO: maybe replace with meshkernel?
uda = xu.UgridDataArray(
xr.DataArray(np.ones(grid.node_face_connectivity.shape[0]), dims=["face"]), grid
)
labels = uda.ugrid.connected_components()
counts = labels.groupby(labels).count()
most_frequent_label = counts["group"][np.argmax(counts.data)].item() #find largest contiguous part
labels = labels.where(labels == most_frequent_label, drop=True)
grid = labels.grid
return grid
if remove_noncontiguous:
xu_grid = xugrid_remove_noncontiguous(xu_grid)

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