modelbuilder: refine existing network
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 91
- Forks
- 21
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 1
Description
Often users already have a network that they want to use as the basis of the modelbuilder. Or in this example, refine an existing network with a polygon.
import dfm_tools as dfmt
import matplotlib.pyplot as plt
plt.close("all")
import numpy as np
from meshkernel import MeshRefinementParameters, GeometryList, RefinementType
# load existing grid as xugrid.UgridDataset and take left subset
netfile = dfmt.data.fm_grevelingen_net(return_filepath=True)
uds_grid = dfmt.open_partitioned_dataset(netfile)
uds_grid = uds_grid.ugrid.sel(x=slice(None,56000))
crs = "EPSG:28992"
# depending on how the grid is written, you might have to convert mesh1d to mesh2d grid
# uds_grid = dfmt.add_network_cellinfo(uds_grid)
# convert to meshkernel object
mk_object = uds_grid.grid.meshkernel
# refine grid
pol = np.array(
[[ 50886.71822346, 421431.47228723],
[ 50844.41343794, 420016.93916901],
[ 51764.54252293, 419945.01375622],
[ 51669.35675551, 421503.39770002],
[ 50886.71822346, 421431.47228723]]
)
poly_geolist = GeometryList(x_coordinates=pol[:,0], y_coordinates=pol[:,1])
mk_ref_pars = MeshRefinementParameters(
refinement_type=RefinementType.REFINEMENT_LEVELS,
connect_hanging_nodes=True,
smoothing_iterations=0,
max_refinement_iterations=1,
)
mk_object.mesh2d_refine_based_on_polygon(
polygon=poly_geolist,
mesh_refinement_params=mk_ref_pars,
)
# plot the resulting grid
fig, ax = plt.subplots()
mk_object.mesh2d_get().plot_edges(ax=ax, linewidth=1)
dfmt.plot_coastlines(ax=ax, crs=crs, zorder=2, linewidth=1)
ax.plot(pol[:,0], pol[:,1], "r")
Gives:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue demonstrates refining an existing network through the modelbuilder workflow, using uds_grid.grid.meshkernel and mesh2d_refine_based_on_polygon with MeshRefinementParameters. Start by tracing where existing grids enter this workflow and how polygon refinement is exposed. Done means the shown network can be refined from an existing grid and produces the expected refined mesh; no source file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100