pyfvcom2.mesh_reader module
- class pyfvcom2.mesh_reader.MeshData(triangle: np.ndarray, nodes: np.ndarray | None, x1: np.ndarray, x2: np.ndarray, x3: np.ndarray | None, types_bdy: np.ndarray | None, nodes_bdy: List[List[int]] | None)
Bases:
NamedTupleNamed tuple containing standardized mesh data from all readers
- Attrs:
triangles: Array of triangle vertex indices. nodes: Integer identifier for each node (one indexed). x1: Array of node x1-coordinates (x or longitude). x2: Array of node x2-coordinates (y or latitude). x3: Array of node x3-coordinates (if available). types_bdy: Array of boundary types for nodes (if available). nodes_bdy: List of lists of open boundary node indices (if available, zero-indexed).
- nodes: ndarray | None
Alias for field number 1
- nodes_bdy: List[List[int]] | None
Alias for field number 6
- triangle: ndarray
Alias for field number 0
- types_bdy: ndarray | None
Alias for field number 5
- x1: ndarray
Alias for field number 2
- x2: ndarray
Alias for field number 3
- x3: ndarray | None
Alias for field number 4
- pyfvcom2.mesh_reader.parse_obc_sections(obc_node_array, triangle)
Separate open boundary nodes into contiguous open boundary segments.
- Parameters:
obc_node_array – Open boundary node IDs, as returned by
read_fvcom_obc.triangle – Triangulation array of nodes, as returned by
read_fvcom_mesh.
- Returns:
Contiguous open boundary node sections.
- Return type:
list[np.ndarray]
- pyfvcom2.mesh_reader.read_fvcom_mesh(mesh: str, obc_filename: str | None = None, depth_filename: str | None = None) MeshData
Reads in the FVCOM unstructured grid format.
- Parameters:
mesh (str) –
Full path to the FVCOM unstructured grid file (.dat usually). The file name should also contain ‘_grd’ in the name e.g. ‘my_file_grd.dat’. The file contains information about the triangle indicies and the x, y, z coodinates of the grid nodes. The file header should be two lines:
Node Number = nnn Cell Number = eee
Followed by ‘element_index, tri1, tri2, tri3’ for eee cells Followed by ‘node_index, x, y, z’ for nnn nodes
obc_filename (str, optional) – Full path to the FVCOM OBC file. This is used to read in the open boundary node strings if provided.
depth_filename (str, optional) – Full path to the FVCOM dep file. This is used to overwrite the depth values if provided.
- Returns:
- Named tuple containing:
triangle (np.ndarray): Integer array of shape (ntri, 3). Each triangle is composed of three points and this contains the three node numbers (stored in nodes) which refer to the coordinates in
xandy(see below).nodes (np.ndarray): Integer number assigned to each node.
X (np.ndarray): X coordinates of each grid node.
Y (np.ndarray): Y coordinates of each grid node.
Z (np.ndarray): Z coordinates and any associated Z value.
types (Optional[np.ndarray]): None for FVCOM format (no type information available).
nodestrings (Optional[List]): None for FVCOM format (no nodestring information available).
- Return type:
- pyfvcom2.mesh_reader.read_fvcom_obc(obc)
Read in an FVCOM open boundary file.
- Parameters:
obc – Path to the casename_obc.dat file from FVCOM.
- Returns:
Node IDs, open boundary node types, and open boundary node numbers.
- Return type:
tuple[np.ndarray, np.ndarray, np.ndarray]
- pyfvcom2.mesh_reader.read_gmsh_mesh(mesh: str) MeshData
Reads in the GMSH unstructured grid format (version 2.2).
- Parameters:
mesh (str) – Full path to the GMSH unstructured grid file (.gmsh usually).
- Returns:
- Named tuple containing:
triangle (np.ndarray): Integer array of shape (ntri, 3). Each triangle is composed of three points and this contains the three node numbers (stored in nodes) which refer to the coordinates in
xandy(see below).nodes (np.ndarray): Integer number assigned to each node.
X (np.ndarray): X coordinates of each grid node.
Y (np.ndarray): Y coordinates of each grid node.
Z (np.ndarray): Z coordinates and any associated Z value.
types (Optional[np.ndarray]): None for GMSH format (no type information available).
nodestrings (Optional[List]): None for GMSH format (no nodestring information available).
- Return type:
- pyfvcom2.mesh_reader.read_mesh_file(filename: str, mesh_type: str, **kwargs) MeshData
Factory method to read mesh files of various formats.
- Parameters:
filename (str) – Path to the mesh file.
mesh_type (str) – Type of mesh file. Supported types are: - ‘sms’: SMS unstructured grid format (.2dm) - ‘fvcom’: FVCOM unstructured grid format (.dat) - ‘smesh’: smesh output format - ‘mike’: DHI MIKE21 unstructured grid format (.mesh) - ‘gmsh’: GMSH unstructured grid format (.gmsh)
**kwargs – Additional keyword arguments passed to the specific reader function. For ‘fvcom’: obc_filename (str) - path to FVCOM OBC file. For ‘sms’: nodestrings (bool) - whether to return nodestring information For ‘mike’: flipZ (bool) - whether to flip Z coordinates (default True)
- Returns:
Named tuple containing standardized mesh data.
- Return type:
- Raises:
PyFVCOM2ValueError – If mesh_type is not supported.
PyFVCOM2FileNotFoundError – If the mesh file cannot be found or opened.
- pyfvcom2.mesh_reader.read_mike_mesh(mesh: str, flipZ: bool = True) MeshData
Reads in the MIKE unstructured grid format.
Depth sign is typically reversed (i.e. z*-1) but can be disabled by passing flipZ=False.
- Parameters:
mesh (str) – Full path to the DHI MIKE21 unstructured grid file (.mesh usually).
flipZ (bool, optional) – DHI MIKE21 unstructured grids store the z value as positive down whereas FVCOM wants negative down. The conversion is automatically applied unless flipZ is set to False. Defaults to True.
- Returns:
- Named tuple containing:
triangle (np.ndarray): Integer array of shape (ntri, 3). Each triangle is composed of three points and this contains the three node numbers (stored in nodes) which refer to the coordinates in
xandy(see below). Given as a zero-indexed array.nodes (np.ndarray): Integer number assigned to each node.
X (np.ndarray): X coordinates of each grid node.
Y (np.ndarray): Y coordinates of each grid node.
Z (np.ndarray): Z coordinates and any associated Z value.
types (np.ndarray): Classification for each open boundary. DHI MIKE21 .mesh format requires unique IDs for each open boundary (with 0 and 1 reserved for land and sea nodes).
nodestrings (Optional[List]): None for MIKE format (no nodestring information available).
- Return type:
- pyfvcom2.mesh_reader.read_smesh_mesh(mesh: str) MeshData
Reads output of the smeshing tool. This is (close) to the fort.14 file format.
- Parameters:
mesh (str) – Full path to the smesh output file.
- Returns:
- Named tuple containing:
triangle (np.ndarray): Integer array of shape (ntri, 3). Each triangle is composed of three points and this contains the three node numbers which refer to the coordinates in
xandy(see below).nodes (Optional[np.ndarray]): None for smesh format (no node information available).
X (np.ndarray): X coordinates of each grid node.
Y (np.ndarray): Y coordinates of each grid node.
Z (Optional[np.ndarray]): None for smesh format (no Z information available).
types (Optional[np.ndarray]): None for smesh format (no type information available).
nodestrings (Optional[List]): None for smesh format (no nodestring information available).
- Return type:
- pyfvcom2.mesh_reader.read_sms_mesh(mesh: str, nodestrings: bool | None = False) MeshData
Reads in the SMS unstructured grid format. Also creates IDs for output to MIKE unstructured grid format.
- Parameters:
mesh (str) – Full path to an SMS unstructured grid (.2dm) file.
nodestrings (bool, optional) – Set to True to return the IDs of the node strings. Defaults to False.
- Returns:
- Named tuple containing:
triangle (np.ndarray): Integer array of shape (nele, 3). Each triangle is composed of three points and this contains the three node numbers (stored in nodes) which refer to the coordinates in
xandy(see below). Values are python-indexed.nodes (np.ndarray): Integer number assigned to each node.
X (np.ndarray): X coordinates of each grid node.
Y (np.ndarray): Y coordinates of each grid node.
Z (np.ndarray): Z coordinates and any associated Z value.
types (np.ndarray): Classification for each node string based on the number of node strings + 2. This is mainly for use if converting from SMS .2dm grid format to DHI MIKE21 .mesh format since the latter requires unique IDs for each boundary (with 0 and 1 reserved for land and sea nodes).
nodestrings (Optional[List]): List of lists containing the node IDs (python-indexed) of the node strings in the SMS grid if nodestrings=True, otherwise None.
- Return type: