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

Remove non-contiguous parts of a grid #44

Closed
veenstrajelmer opened this issue Apr 18, 2023 · 1 comment · Fixed by #87
Closed

Remove non-contiguous parts of a grid #44

veenstrajelmer opened this issue Apr 18, 2023 · 1 comment · Fixed by #87
Labels
enhancement New feature or request

Comments

@veenstrajelmer
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
When generating a grid and deleting landward parts with a polygon, sometimes this results in "loose" parts of a grids. These non-contiguous parts could be lakes or just a result of a coarse polygon, but since they have no connection to the model, they can be removed. This also results in contiguous partitioning by FM, which is convenient.

image

Describe the solution you'd like
New function to delete non-contiguous parts of a grid. Maybe also an algorithm that efficiently checks if all cells are connected to each other.

@veenstrajelmer
Copy link
Collaborator Author

veenstrajelmer commented Apr 18, 2023

Possible with xugrid, which might be a working approach:

import xugrid as xu
grid = xu_grid_uds.grid
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"][counts.argmax()].item()
labels = labels.where(labels == most_frequent_label, drop=True)

fig, ax = plt.subplots(figsize=figsize)
labels.ugrid.plot(cmap="jet")

https://deltares.github.io/xugrid/examples/connectivity.html#connected-components

Applied to a grid, it results in the desired behaviour
image
Nevertheless, we might still want to implement it also in meshkernel.

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

Successfully merging a pull request may close this issue.

2 participants