resqpy.surface.TriangulatedPatch¶
- class resqpy.surface.TriangulatedPatch(parent_model, patch_index=None, patch_node=None, crs_uuid=None)¶
Bases:
object
Class for RESQML TrianglePatch objects (used by Surface objects inter alia).
Methods:
__init__
(parent_model[, patch_index, ...])Create an empty TriangulatedPatch (TrianglePatch) node and optionally load from xml.
Caches uuid for coordinate reference system, as stored in geometry xml sub-tree.
Returns arrays representing the patch.
set_to_trimmed_patch
(larger_patch[, ...])Populate this (empty) patch with triangles and points that overlap with a trimming volume.
set_to_horizontal_plane
(depth, box_xyz[, ...])Populate this (empty) patch with two triangles defining a flat, horizontal plane at a given depth.
set_to_triangle
(corners)Populate this (empty) patch with a single triangle.
set_to_triangle_pair
(corners)Populate this (empty) patch with a pair of triangles.
set_from_triangles_and_points
(triangles, points)Populate this (empty) patch from triangle node indices and points from elsewhere.
set_to_sail
(n, centre, radius, azimuth, ...)Populate this (empty) patch with triangles for a big triangle wrapped on a sphere.
set_from_irregular_mesh
(mesh_xyz[, ...])Populate this (empty) patch from an untorn mesh array of shape (N, M, 3).
set_from_sparse_mesh
(mesh_xyz)Populate this (empty) patch from a mesh array of shape (N, M, 3), with some NaNs in z.
get_indices_from_sparse_meshxyz
(mesh_xyz)Update self.points and self.node_count with non-nan points in a given mesh_xyz array.
set_from_torn_mesh
(mesh_xyz[, quad_triangles])Populate this (empty) patch from a torn mesh array of shape (nj, ni, 2, 2, 3).
column_from_triangle_index
(triangle_index)For patch freshly built from fully defined mesh, returns (j, i) for given triangle index.
set_to_cell_faces_from_corner_points
(cp[, ...])Populates this (empty) patch to represent faces of a cell, from corner points of shape (2, 2, 2, 3).
Returns the triangles for corner points representing cell faces, where quad_triangles is False.
Returns the triangles for corner points representing cell faces, where quad_triangles is True.
face_from_triangle_index
(triangle_index)For patch freshly built for cell faces, returns (axis, polarity) for given triangle index.
vertical_rescale_points
(ref_depth, ...)Rescale points along vertical direction.
- __init__(parent_model, patch_index=None, patch_node=None, crs_uuid=None)[source]¶
Create an empty TriangulatedPatch (TrianglePatch) node and optionally load from xml.
Note
not usually instantiated directly by application code
- column_from_triangle_index(triangle_index)[source]¶
For patch freshly built from fully defined mesh, returns (j, i) for given triangle index.
- argument:
triangle_index (int or numpy int array): the triangle index (or array of indices) for which column(s) are being sought
- Returns
pair of ints or pair of numpy int arrays – the (j0, i0) indices of the column(s) which the triangle(s) is/are part of
Notes
this function will only work if the surface has been freshly constructed with data from a mesh without NaNs, otherwise (None, None) will be returned; if triangle_index is a numpy int array, a pair of similarly shaped numpy arrays is returned
- extract_crs_root_and_uuid()[source]¶
Caches uuid for coordinate reference system, as stored in geometry xml sub-tree.
- face_from_triangle_index(triangle_index)[source]¶
For patch freshly built for cell faces, returns (axis, polarity) for given triangle index.
- get_indices_from_sparse_meshxyz(mesh_xyz)[source]¶
Update self.points and self.node_count with non-nan points in a given mesh_xyz array.
Returns the indices of these non_nan points.
- get_triangles_for_cell_faces_quad_false(cp)[source]¶
Returns the triangles for corner points representing cell faces, where quad_triangles is False.
- get_triangles_for_cell_faces_quad_true(cp)[source]¶
Returns the triangles for corner points representing cell faces, where quad_triangles is True.
- set_from_irregular_mesh(mesh_xyz, quad_triangles=False)[source]¶
Populate this (empty) patch from an untorn mesh array of shape (N, M, 3).
- set_from_sparse_mesh(mesh_xyz)[source]¶
Populate this (empty) patch from a mesh array of shape (N, M, 3), with some NaNs in z.
- set_from_torn_mesh(mesh_xyz, quad_triangles=False)[source]¶
Populate this (empty) patch from a torn mesh array of shape (nj, ni, 2, 2, 3).
- set_from_triangles_and_points(triangles, points)[source]¶
Populate this (empty) patch from triangle node indices and points from elsewhere.
- set_to_cell_faces_from_corner_points(cp, quad_triangles=True)[source]¶
Populates this (empty) patch to represent faces of a cell, from corner points of shape (2, 2, 2, 3).
- set_to_horizontal_plane(depth, box_xyz, border=0.0, quad_triangles=False)[source]¶
Populate this (empty) patch with two triangles defining a flat, horizontal plane at a given depth.
- Parameters
depth (float) – z value to use in all points in the triangulated patch
box_xyz (float[2, 3]) – the min, max values of x, y (&z) giving the area to be covered (z ignored)
border (float) – an optional border width added around the x,y area defined by box_xyz
quad_triangles (bool, default False) – if True, 4 triangles are used instead of 2
- set_to_sail(n, centre, radius, azimuth, delta_theta)[source]¶
Populate this (empty) patch with triangles for a big triangle wrapped on a sphere.
- set_to_trimmed_patch(larger_patch, xyz_box=None, xy_polygon=None, internal=False)[source]¶
Populate this (empty) patch with triangles and points that overlap with a trimming volume.
- Parameters
larger_patch (TriangulatedPatch) – the larger patch, a copy of which is to be trimmed
xyz_box (numpy float array of shape (2, 3), optional) – if present, a cuboid in xyz space against which to trim the patch
xy_polygon (closed convex resqpy.lines.Polyline, optional) – if present, an xy boundary against which to trim
internal (bool, default False) – if True, only those triangles where all three vertices are wtihin the trimming space are kept; if False, triangles with at least one vertex within the space are kept
Notes
at least one of xyz_box or xy_polygon must be present; if both are present, a triangle must be within both boundaries to survive the trimming; xyz_box and xy_polygon must be in the same crs as the larger patch
- triangles_and_points()[source]¶
Returns arrays representing the patch.
- Returns
Tuple (triangles, points) –
triangles (int array of shape[:, 3]): integer indices into points array, being the nodes of the corners of the triangles
points (float array of shape[:, 3]): flat array of xyz points, indexed by triangles