Effeciantly subset existing ugrid to a smaller ugrid given a bbox or polygon #239
Replies: 2 comments 2 replies
-
The user guide part on selection should give relevant information on this: https://deltares.github.io/xugrid/examples/selection.html The Note that this currently selects by the face coordinates, which may not be what you desire. See issue #182 for a workaround (although to be clear: we should tackle it with a proper solution so it doesn't require a workaround). Selecting by polygon can be done relatively easily, but also requires more on than step. I'll open an issue for the functionality. For now, one could use this multi-step approach: import xugrid as xu
import geopandas as gpd
# Read a polygon into a geodataframe
gdf = gdp.read_file("my-polygon.shp")
# Read the ugrid file containing a single variable
uda = xu.open_dataarray("my-ugrid.nc")
# Burn the vector geometry in to the unstructured topology
burned = xu.burn_vector_geometry(gdf, uda, column="id") # let's assume there's an id colum with a value of 1
# Use the burned result to select only the values in the polygon, then drop the faces outside of the polygon
selection = uda.where(burned == 1).dropna(uda.ugrid.grid.face_dimension) There's a bit more info on "burning" vector geometries in this part of the user guide: https://deltares.github.io/xugrid/examples/vector_conversion.html In all cases, this results in a new, consistent, geometry. In case you want to preserve the original topology, you would use |
Beta Was this translation helpful? Give feedback.
-
@saeed-moghimi-noaa |
Beta Was this translation helpful? Give feedback.
-
Hi There,
Is there a suggested tool to perform efficient subset of a large ugrid data set to a new ugrid (xarray) with the consistent connectivity given a bbox or polygon as an input using xugrid tool set? I would like to retain all the properties of the parent mesh such as node coordinates and connectivity and values.
something like:
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions