diff --git a/meshkernel/__init__.py b/meshkernel/__init__.py index ec7100d4..c05ce298 100644 --- a/meshkernel/__init__.py +++ b/meshkernel/__init__.py @@ -17,6 +17,7 @@ Mesh1d, Mesh2d, Mesh2dLocation, + Mesh2dProperty, MeshRefinementParameters, OrthogonalizationParameters, ProjectionType, diff --git a/meshkernel/meshkernel.py b/meshkernel/meshkernel.py index e89bee75..1fb824c2 100644 --- a/meshkernel/meshkernel.py +++ b/meshkernel/meshkernel.py @@ -49,6 +49,7 @@ Mesh1d, Mesh2d, Mesh2dLocation, + Mesh2dProperty, MeshRefinementParameters, OrthogonalizationParameters, ProjectionType, @@ -515,13 +516,13 @@ def mesh2d_get_face_polygons(self, num_edges: int) -> GeometryList: return face_polygons def mesh2d_get_filtered_face_polygons( - self, property: Mesh2d.Property, min_value: float, max_value: float + self, property: Mesh2dProperty, min_value: float, max_value: float ) -> GeometryList: """Gets the polygons matching the metric value within the minimum and maximum value. Args: - property (Mesh2d.Property): The property used to filter the locations + property (Mesh2dProperty): The property used to filter the locations min_value(float): The minimum value of the metric. max_value(float): The maximum value of the metric. @@ -1657,20 +1658,20 @@ def mesh2d_casulli_derefinement_on_polygon( byref(c_polygon), ) - def mkernel_delete_property(self, propertyId: int): + def mesh2d_delete_property(self, property_id: int): """ Deletes a property and its calculator. Args: - propertyId (int): The property id. + property_id (int): The property id. """ self._execute_function( self.lib.mkernel_deallocate_property, self._meshkernelid, - c_int(propertyId), + c_int(property_id), ) - def mkernel_set_property( + def mesh2d_set_property( self, interpolation_parameters: InterpolationParameters, sample_data: GeometryList, @@ -1691,21 +1692,21 @@ def mkernel_set_property( ) c_sample_data = CGeometryList.from_geometrylist(sample_data) - propertyId = c_int() + property_id = c_int() self._execute_function( self.lib.mkernel_mesh2d_set_property, self._meshkernelid, byref(c_interpolation_parameters), byref(c_sample_data), - byref(propertyId), + byref(property_id), ) - return propertyId.value + return property_id.value - def mkernel_mesh2d_casulli_refinement_based_on_depths( + def mesh2d_casulli_refinement_based_on_depths( self, polygons: GeometryList, - propertyId: int, + property_id: int, meshRefinementParameters: MeshRefinementParameters, minimumRefinementDepth: float, ) -> None: @@ -1713,7 +1714,7 @@ def mkernel_mesh2d_casulli_refinement_based_on_depths( Refine mesh using the Casulli refinement algorithm based on the depth values. Args: polygons (GeometryList): The polygon within which the refinement is computed. - propertyId (int): The identifier of the interpolator to be used. + property_id (int): The identifier of the interpolator to be used. meshRefinementParameters (MeshRefinementParameters): Parameters indicating how the mesh is to be refined. minimumRefinementDepth (float): Nodes with depth value less than this value will not be marked for refinement. """ @@ -1726,7 +1727,7 @@ def mkernel_mesh2d_casulli_refinement_based_on_depths( self.lib.mkernel_mesh2d_casulli_refinement_based_on_depths, self._meshkernelid, byref(c_polygons), - c_int(propertyId), + c_int(property_id), byref(c_refinement_params), c_double(minimumRefinementDepth), ) @@ -1821,12 +1822,12 @@ def mesh2d_get_orthogonality(self) -> GeometryList: return geometry_list_out def mesh2d_get_property( - self, mesh2d_location: Mesh2dLocation, property: Mesh2d.Property + self, mesh2d_location: Mesh2dLocation, property: Mesh2dProperty ) -> GeometryList: """Gets the polygons matching the metric value within the minimum and maximum value. Args: mesh2d_location (Mesh2dLocation): The property location - property (Mesh2d.Property): The property to retrieve + property (Mesh2dProperty): The property to retrieve Returns: GeometryList: The resulting geometry list containing the value of the properties """ diff --git a/meshkernel/py_structures.py b/meshkernel/py_structures.py index f40d0e0c..3ca9323b 100644 --- a/meshkernel/py_structures.py +++ b/meshkernel/py_structures.py @@ -58,6 +58,17 @@ class Mesh2dLocation(IntEnum): EDGES = 2 +@unique +class Mesh2dProperty(IntEnum): + """Different properties on a 2D mesh.""" + + ORTHOGONALITY = 0 + EDGE_LENGTHS = 1 + FACE_CIRCUMCENTER = 2 + NETLINK_CONTOUR_POLYGON = 3 + FACE_BOUNDS = 4 + + @unique class AveragingMethod(IntEnum): """The averaging methods.""" @@ -126,16 +137,6 @@ class Mesh2d: """ - @unique - class Property(IntEnum): - """Different properties on a 2D mesh.""" - - ORTHOGONALITY = 0 - EDGE_LENGTHS = 1 - FACE_CIRCUMCENTER = 2 - NETLINK_CONTOUR_POLYGON = 3 - FACE_BOUNDS = 4 - def __init__( self, node_x=np.empty(0, dtype=np.double), diff --git a/tests/test_mesh2d_basics.py b/tests/test_mesh2d_basics.py index 645a2c2a..9616b87b 100644 --- a/tests/test_mesh2d_basics.py +++ b/tests/test_mesh2d_basics.py @@ -15,6 +15,7 @@ MakeGridParameters, Mesh2d, Mesh2dLocation, + Mesh2dProperty, MeshKernel, MeshKernelError, MeshRefinementParameters, @@ -2342,7 +2343,7 @@ def test_mesh2d_deletion_and_get_orthogonality( cases_get_property = [ ( - Mesh2d.Property.ORTHOGONALITY, + Mesh2dProperty.ORTHOGONALITY, Mesh2dLocation.EDGES, np.array( [ @@ -2375,7 +2376,7 @@ def test_mesh2d_deletion_and_get_orthogonality( ), ), ( - Mesh2d.Property.EDGE_LENGTHS, + Mesh2dProperty.EDGE_LENGTHS, Mesh2dLocation.EDGES, np.array( [ @@ -2416,7 +2417,7 @@ def test_mesh2d_deletion_and_get_orthogonality( ) def test_mesh2d_get_property( meshkernel_with_mesh2d: MeshKernel, - property: Mesh2d.Property, + property: Mesh2dProperty, location: Mesh2dLocation, expected_values: ndarray, ): @@ -2449,7 +2450,7 @@ def test_mesh2d_get_circumcentre_property(): mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters) mk.curvilinear_convert_to_mesh2d() - property = Mesh2d.Property.FACE_CIRCUMCENTER + property = Mesh2dProperty.FACE_CIRCUMCENTER location = Mesh2dLocation.FACES property_list = mk.mesh2d_get_property(location, property) @@ -2479,7 +2480,7 @@ def test_mesh2d_get_netlink_countour_polygon_property(): mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters) mk.curvilinear_convert_to_mesh2d() - property = Mesh2d.Property.NETLINK_CONTOUR_POLYGON + property = Mesh2dProperty.NETLINK_CONTOUR_POLYGON location = Mesh2dLocation.EDGES property_list = mk.mesh2d_get_property(location, property) @@ -2505,7 +2506,7 @@ def test_mesh2d_get_filtered_face_polygons(): mk.mesh2d_set(input_mesh2d) face_polygons = mk.mesh2d_get_filtered_face_polygons( - Mesh2d.Property.ORTHOGONALITY, 0.04, 1.0 + Mesh2dProperty.ORTHOGONALITY, 0.04, 1.0 ) expected_coordinates_x = np.array([57.0, 49.1, 58.9, 66.7, 57.0], dtype=np.double) @@ -2531,11 +2532,11 @@ def test_mesh2d_get_filtered_face_polygons_full_and_empty(): mk.curvilinear_convert_to_mesh2d() orthogonality = mk.mesh2d_get_filtered_face_polygons( - Mesh2d.Property.ORTHOGONALITY, 0.0, 1.0 + Mesh2dProperty.ORTHOGONALITY, 0.0, 1.0 ) assert orthogonality.x_coordinates.shape[0] == 503 orthogonality = mk.mesh2d_get_filtered_face_polygons( - Mesh2d.Property.ORTHOGONALITY, 0.1, 10.0 + Mesh2dProperty.ORTHOGONALITY, 0.1, 10.0 ) assert orthogonality.x_coordinates.shape[0] == 0 @@ -2577,7 +2578,7 @@ def test_mesh2d_casulli_refinement_based_on_depths(): interpolationParameters = InterpolationParameters() - property_id = mk.mkernel_set_property(interpolationParameters, samples) + property_id = mk.mesh2d_set_property(interpolationParameters, samples) polygons = GeometryList( x_coordinates=np.empty(0, dtype=np.double), @@ -2586,10 +2587,10 @@ def test_mesh2d_casulli_refinement_based_on_depths(): meshRefinementParameters = MeshRefinementParameters() minimumRefinementDepth = 0.0 - mk.mkernel_mesh2d_casulli_refinement_based_on_depths( + mk.mesh2d_casulli_refinement_based_on_depths( polygons, property_id, meshRefinementParameters, minimumRefinementDepth ) - mk.mkernel_delete_property(property_id) + mk.mesh2d_delete_property(property_id) mesh2d_refined = mk.mesh2d_get() # new mesh has more nodes and edges than the starting mesh, it has been refined diff --git a/tests/test_py_structures.py b/tests/test_py_structures.py index 022d18a6..82313122 100644 --- a/tests/test_py_structures.py +++ b/tests/test_py_structures.py @@ -7,6 +7,7 @@ GeometryList, Mesh2d, Mesh2dLocation, + Mesh2dProperty, MeshRefinementParameters, OrthogonalizationParameters, ProjectToLandBoundaryOption,