Skip to content

Commit

Permalink
Fix the number of samples returned for the interpolation routines (#23
Browse files Browse the repository at this point in the history
…| GRIDEDIT-744)
  • Loading branch information
ipelupessy authored Oct 18, 2023
1 parent 91a2249 commit 6fef104
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,8 +1432,7 @@ def mesh2d_triangulation_interpolation(
"""
c_samples = CGeometryList.from_geometrylist(samples)

number_of_coordinates = c_samples.n_coordinates

number_of_coordinates = self._get_num_coordinates(location_type)
x_coordinates = np.empty(number_of_coordinates, dtype=np.double)
y_coordinates = np.empty(number_of_coordinates, dtype=np.double)
values = np.empty(number_of_coordinates, dtype=np.double)
Expand Down Expand Up @@ -1474,8 +1473,7 @@ def mesh2d_averaging_interpolation(
"""
c_samples = CGeometryList.from_geometrylist(samples)

number_of_coordinates = c_samples.n_coordinates

number_of_coordinates = self._get_num_coordinates(location_type)
x_coordinates = np.empty(number_of_coordinates, dtype=np.double)
y_coordinates = np.empty(number_of_coordinates, dtype=np.double)
values = np.empty(number_of_coordinates, dtype=np.double)
Expand Down Expand Up @@ -2215,3 +2213,26 @@ def curvilinear_delete_node(self, x_coordinate: float, y_coordinate: float) -> N
c_double(x_coordinate),
c_double(y_coordinate),
)

def _get_num_coordinates(self, location_type):
"""Get the numbers of mesh coordinates of a specific location.
Args:
location_type (Mesh2dLocation): The location type.
Raises:
Exception: This exception gets raised if an invalid location is used.
"""

mesh = self.mesh2d_get()

if location_type == Mesh2dLocation.NODES:
number_of_coordinates = len(mesh.node_x)
elif location_type == Mesh2dLocation.FACES:
number_of_coordinates = len(mesh.face_x)
elif location_type == Mesh2dLocation.EDGES:
number_of_coordinates = len(mesh.edge_x)
else:
raise Exception("wrong location_type")

return number_of_coordinates

0 comments on commit 6fef104

Please sign in to comment.