Repository navigation
Refactor mesh2d_get_property and related methods #260
Copy link
Copy link
Labels
enhancementNew feature or requestNew feature or request
Description
The meshkernelpy code related to getting properties is slightly inconsistent, some example code to illustrate this:
import numpy as np
import matplotlib.pyplot as plt
plt.close('all')
from meshkernel import (
MeshKernel,
ProjectionType,
GeometryList,
MakeGridParameters,
MeshRefinementParameters,
Mesh2d,
Mesh2dLocation,
)
# create basegrid
lon_min, lon_max, lat_min, lat_max = -6, 2, 48.5, 51.2
dxy = 0.7
make_grid_parameters = MakeGridParameters(
origin_x=lon_min,
origin_y=lat_min,
upper_right_x=lon_max,
upper_right_y=lat_max,
block_size_x=dxy,
block_size_y=dxy,
)
mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d() #convert to ugrid/mesh2d
# refine with polygon
pol_x = np.array([-5,-4,0,-5], dtype=np.double)
pol_y = np.array([49,51,49.5,49], dtype=np.double)
geometry_list = GeometryList(pol_x, pol_y)
mrp = MeshRefinementParameters()
mk.mesh2d_refine_based_on_polygon(polygon=geometry_list, mesh_refinement_params=mrp)
# TODO: instead of providing property and location, just get properties FACE_CIRCUMCENTER, EDGE_ORTHOGONALITY, etc
# since getting EDGE_LENGTHS at FACES results in error anyway: "MeshKernelError: Exception of type 'MeshKernelError': Property not supported at this location"
face_circumcenters = mk.mesh2d_get_property(mesh2d_location=Mesh2dLocation.FACES, property=Mesh2d.Property.FACE_CIRCUMCENTER)
edge_orthogonality = mk.mesh2d_get_property(mesh2d_location=Mesh2dLocation.EDGES, property=Mesh2d.Property.ORTHOGONALITY)
edge_length = mk.mesh2d_get_property(mesh2d_location=Mesh2dLocation.EDGES, property=Mesh2d.Property.EDGE_LENGTHS)
# TODO: remove mesh2d_get_orthogonality() since it can be retrieved via mesh2d_get_property()
edge_orthogonality2 = mk.mesh2d_get_orthogonality()
# TODO: deprecate mesh2d_get_smoothness in favor of a EDGE_SMOOTHNESS property
edge_smoothness = mk.mesh2d_get_smoothness()
# TODO: x/y coordinates are valid for edge_orthogonality2 and face_circumcenters
# but are arrays with arbitrary values for edge_orthogonality. This is inconvenient for plotting
print(face_circumcenters.x_coordinates[:5])
print(edge_orthogonality.x_coordinates[:5]) # contains arbitrary/nan values
print(edge_orthogonality2.x_coordinates[:5])Todo:
Mesh2d.Propertyis the only IntEnum under Mesh2d. Consider moving it outside of theMesh2dclass and renaming it toMesh2dPropertyfor consistency. [Python-only, not used in dfm_tools/hydrolib-core/hydromt_delft3dfm/BaselineTools] >> Feature/gridedit 2297 rename mesh2d property and several functions #281- rename
mkernel_set_propertytomesh2d_set_property, to be consistentmesh2d_get_property. Also renamemkernel_delete_propertyandmkernel_mesh2d_casulli_refinement_based_on_depthsto havemesh2d_prefix. [Python only, but not used in dfm_tools/hydrolib-core/hydromt_delft3dfm/BaselineTools] >> Feature/gridedit 2297 rename mesh2d property and several functions #281 - smoothness can now only be retrieved via
mesh2d_get_smoothness, but this should be possible viamesh2d_get_propertyinstead. [Python and C, but adding functionality so not a problem] >> Feature/gridedit 2300 add edge smoothness to get property MeshKernel#543 and GRIDEDIT-2300 Add edge smoothness enum value #282 - deprecate
mesh2d_get_smoothnessandmesh2d_get_orthogonality>> follow-up in Deprecate/remove old APIs for smoothness and orthogonality #284 - All properties are location-specific. Therefore it does not make sense to ask the user to provide both. Instead, consider deprecating the location argument. Incorrect combinations will just raise an error anyway:
"MeshKernelError: Exception of type 'MeshKernelError': Property not supported at this location". Location is required for user-defined properties because it supports interpolation, but then it is good to split it into two APIs, one for predefined properties and one for user-defined properties. [C and Python, so first check if it is worth the API change] >> MKnet uses get_property C-API (edge_lenght/face_circumcenters/netlinkcontours/facebounds, as of 11 August 2026), also provides the location argument so would be a breaking change. >> won't do for now.
Version info
- meshkernelpy version 8.2.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
[-]Consider refactoring mesh2d_get_property and related methods[/-][+]Refactor mesh2d_get_property and related methods[/+]