fesomp.mesh

FESOM2 mesh module.

This module provides classes and functions for loading and working with FESOM2 unstructured mesh data.

class fesomp.mesh.Mesh[source]

Bases: object

Represents a FESOM2 unstructured mesh.

This class holds the core mesh data including node coordinates, element connectivity, and vertical structure. Topology, geometry, and spatial indexing are lazily computed on first access.

lon

Longitude of nodes in degrees, shape (n2d,).

Type:

np.ndarray

lat

Latitude of nodes in degrees, shape (n2d,).

Type:

np.ndarray

triangles

Triangle connectivity, shape (nelem, 3), 0-indexed.

Type:

np.ndarray

nlev

Number of vertical levels.

Type:

int

depth_levels

Depth at each level interface, shape (nlev,).

Type:

np.ndarray

depth_layers

Depth at layer centers, shape (nlev-1,).

Type:

np.ndarray

node_levels

Number of active levels at each node, shape (n2d,).

Type:

np.ndarray

elem_levels

Number of active levels at each element, shape (nelem,).

Type:

np.ndarray

node_bottom_depth

Bottom depth at each node, shape (n2d,).

Type:

np.ndarray

elem_bottom_depth

Bottom depth at each element, shape (nelem,).

Type:

np.ndarray

lon: ndarray
lat: ndarray
triangles: ndarray
nlev: int
depth_levels: ndarray
depth_layers: ndarray
node_levels: ndarray
elem_levels: ndarray
node_bottom_depth: ndarray
elem_bottom_depth: ndarray
__post_init__()[source]

Validate mesh data and ensure correct dtypes.

Return type:

None

property n2d: int

Number of 2D nodes.

property nelem: int

Number of triangular elements.

property topology: Topology

Get mesh topology (edges, neighbors, etc.).

Computed lazily on first access if not pre-loaded from NetCDF.

property geometry: Geometry

Get mesh geometry (areas, gradients, etc.).

Computed lazily on first access if not pre-loaded from NetCDF.

property spatial_index: SpatialIndex

Get spatial index for efficient point queries.

Built lazily on first access.

property lon_elem: ndarray

Longitude of element (triangle) centers in degrees.

Computed lazily on first access. Handles cyclic triangles that cross the dateline correctly.

property lat_elem: ndarray

Latitude of element (triangle) centers in degrees.

Computed lazily on first access.

find_nearest(lon, lat, k=1)[source]

Find the k nearest nodes to a given point.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

  • k (int, optional) – Number of nearest neighbors to return.

Returns:

Indices of the k nearest nodes.

Return type:

np.ndarray

find_in_radius(lon, lat, radius_km)[source]

Find all nodes within a given radius of a point.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

  • radius_km (float) – Search radius in kilometers.

Returns:

Indices of nodes within the radius.

Return type:

np.ndarray

subset_by_bbox(lon_min, lon_max, lat_min, lat_max)[source]

Find all nodes within a bounding box.

Parameters:
  • lon_min (float) – Longitude bounds in degrees.

  • lon_max (float) – Longitude bounds in degrees.

  • lat_min (float) – Latitude bounds in degrees.

  • lat_max (float) – Latitude bounds in degrees.

Returns:

Indices of nodes within the bounding box.

Return type:

np.ndarray

get_triangulation(mask_cyclic=True)[source]

Create a matplotlib Triangulation object for plotting.

Parameters:

mask_cyclic (bool, optional) – If True (default), mask triangles that cross the dateline to prevent ugly lines spanning the globe.

Returns:

Triangulation object ready for use with triplot, tripcolor, etc.

Return type:

matplotlib.tri.Triangulation

Example

>>> tri = mesh.get_triangulation()
>>> plt.triplot(tri, 'b-', linewidth=0.2)
__init__(lon, lat, triangles, nlev, depth_levels, depth_layers, node_levels, elem_levels, node_bottom_depth, elem_bottom_depth, _preloaded_topology=None, _preloaded_geometry=None, _topology=None, _geometry=None, _spatial_index=None, _lon_elem=None, _lat_elem=None)
Parameters:
Return type:

None

fesomp.mesh.load_mesh(path)[source]

Load a FESOM2 mesh from a file or directory.

Automatically detects the format based on the path: - If path is a .nc file: loads from NetCDF - If path is a directory: loads from ASCII files

Parameters:

path (str or Path) – Path to the mesh file (NetCDF) or directory (ASCII).

Returns:

The loaded mesh object.

Return type:

Mesh

Raises:
class fesomp.mesh.Topology[source]

Bases: object

Mesh topology information (edges, connectivity, neighbors).

edges

Edge node pairs, shape (nedges, 2), 0-indexed. Each row contains [node_i, node_j] where node_i < node_j.

Type:

np.ndarray

face_edges

Edge indices for each face, shape (nelem, 3). face_edges[i, j] is the edge index opposite to vertex j of face i.

Type:

np.ndarray

face_neighbors

Neighbor face indices, shape (nelem, 3). face_neighbors[i, j] is the face adjacent to face i across edge j. -1 indicates a boundary edge with no neighbor.

Type:

np.ndarray

edge_faces

Face indices for each edge, shape (nedges, 2). edge_faces[e, 0] and edge_faces[e, 1] are the faces sharing edge e. -1 indicates a boundary edge with only one adjacent face.

Type:

np.ndarray

node_elements

For each node, the list of element indices containing that node.

Type:

list[np.ndarray]

edges: ndarray
face_edges: ndarray
face_neighbors: ndarray
edge_faces: ndarray
node_elements: list[ndarray]
property nedges: int

Number of edges.

get_boundary_edges()[source]

Get indices of boundary edges.

Returns:

Indices of edges that have only one adjacent face.

Return type:

np.ndarray

get_boundary_nodes()[source]

Get indices of boundary nodes.

Returns:

Sorted unique indices of nodes on the boundary.

Return type:

np.ndarray

__init__(edges, face_edges, face_neighbors, edge_faces, node_elements)
Parameters:
Return type:

None

class fesomp.mesh.Geometry[source]

Bases: object

Mesh geometry information (areas, gradients).

elem_area

Area of each element in m^2, shape (nelem,).

Type:

np.ndarray

node_area

Area associated with each node at each level, shape (nlev, n2d).

Type:

np.ndarray

gradient_sca

Gradient operator for scalar fields (x, y components).

Type:

tuple[np.ndarray, np.ndarray] | None

gradient_vec

Gradient operator for vector fields (x, y components).

Type:

tuple[np.ndarray, np.ndarray] | None

edge_cross_dxdy

Edge crossing distances, shape (4, nedges).

Type:

np.ndarray | None

elem_area: ndarray
node_area: ndarray
gradient_sca: tuple[ndarray, ndarray] | None = None
gradient_vec: tuple[ndarray, ndarray] | None = None
edge_cross_dxdy: ndarray | None = None
__init__(elem_area, node_area, gradient_sca=None, gradient_vec=None, edge_cross_dxdy=None)
Parameters:
Return type:

None

class fesomp.mesh.SpatialIndex[source]

Bases: object

Spatial index for efficient nearest-neighbor queries on mesh nodes.

Uses a 3D KD-tree in Cartesian coordinates for accurate spherical queries.

Parameters:
  • lon (np.ndarray) – Longitude of nodes in degrees, shape (n2d,).

  • lat (np.ndarray) – Latitude of nodes in degrees, shape (n2d,).

__init__(lon, lat)[source]
Parameters:
Return type:

None

find_nearest(lon, lat, k=1)[source]

Find the k nearest nodes to given point(s).

Parameters:
  • lon (float or np.ndarray) – Longitude in degrees.

  • lat (float or np.ndarray) – Latitude in degrees.

  • k (int, optional) – Number of nearest neighbors to return.

Returns:

Indices of the k nearest nodes. If single point, shape is (k,) for k>1 or scalar for k=1. If multiple points, shape is (npoints, k).

Return type:

np.ndarray

find_in_radius(lon, lat, radius_km)[source]

Find all nodes within a given radius of point(s).

Parameters:
  • lon (float or np.ndarray) – Longitude in degrees.

  • lat (float or np.ndarray) – Latitude in degrees.

  • radius_km (float) – Search radius in kilometers.

Returns:

Indices of nodes within the radius. For single point: 1D array of indices. For multiple points: list of arrays.

Return type:

np.ndarray or list[np.ndarray]

find_containing_element(lon, lat, triangles, mesh_lon, mesh_lat)[source]

Find the element containing a given point.

Uses nearest-neighbor search followed by local search of adjacent elements.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

  • triangles (np.ndarray) – Triangle connectivity, shape (nelem, 3).

  • mesh_lon (np.ndarray) – Longitude of mesh nodes.

  • mesh_lat (np.ndarray) – Latitude of mesh nodes.

Returns:

Index of the containing element, or -1 if not found.

Return type:

int

fesomp.mesh.scalar_r2g(alpha, beta, gamma, rlon, rlat)[source]

Convert coordinates from rotated to geographical coordinate system.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • rlon (np.ndarray) – Longitudes in rotated coordinates (degrees).

  • rlat (np.ndarray) – Latitudes in rotated coordinates (degrees).

Returns:

(lon, lat) - Longitudes and latitudes in geographical coordinates (degrees).

Return type:

tuple[np.ndarray, np.ndarray]

fesomp.mesh.scalar_g2r(alpha, beta, gamma, lon, lat)[source]

Convert coordinates from geographical to rotated coordinate system.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • lon (np.ndarray) – Longitudes in geographical coordinates (degrees).

  • lat (np.ndarray) – Latitudes in geographical coordinates (degrees).

Returns:

(rlon, rlat) - Longitudes and latitudes in rotated coordinates (degrees).

Return type:

tuple[np.ndarray, np.ndarray]

fesomp.mesh.vec_rotate_r2g(alpha, beta, gamma, lon, lat, urot, vrot, flag)[source]

Rotate vectors from rotated to geographical coordinates.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • lon (np.ndarray) – Longitudes (in rotated or geographical coordinates, see flag).

  • lat (np.ndarray) – Latitudes (in rotated or geographical coordinates, see flag).

  • urot (np.ndarray) – U (eastward) component of vector in rotated coordinates.

  • vrot (np.ndarray) – V (northward) component of vector in rotated coordinates.

  • flag (int) – Coordinate system of input lon/lat: - 1: lon/lat are in geographical coordinates - 0: lon/lat are in rotated coordinates

Returns:

(u, v) - Vector components in geographical coordinates.

Return type:

tuple[np.ndarray, np.ndarray]

fesomp.mesh.vec_rotate_g2r(alpha, beta, gamma, lon, lat, ugeo, vgeo, flag)[source]

Rotate vectors from geographical to rotated coordinates.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • lon (np.ndarray) – Longitudes (in rotated or geographical coordinates, see flag).

  • lat (np.ndarray) – Latitudes (in rotated or geographical coordinates, see flag).

  • ugeo (np.ndarray) – U (eastward) component of vector in geographical coordinates.

  • vgeo (np.ndarray) – V (northward) component of vector in geographical coordinates.

  • flag (int) – Coordinate system of input lon/lat: - 1: lon/lat are in geographical coordinates - 0: lon/lat are in rotated coordinates

Returns:

(u, v) - Vector components in rotated coordinates.

Return type:

tuple[np.ndarray, np.ndarray]

Mesh Class

Core Mesh class for FESOM2 unstructured mesh data.

class fesomp.mesh.mesh.Mesh[source]

Bases: object

Represents a FESOM2 unstructured mesh.

This class holds the core mesh data including node coordinates, element connectivity, and vertical structure. Topology, geometry, and spatial indexing are lazily computed on first access.

lon

Longitude of nodes in degrees, shape (n2d,).

Type:

np.ndarray

lat

Latitude of nodes in degrees, shape (n2d,).

Type:

np.ndarray

triangles

Triangle connectivity, shape (nelem, 3), 0-indexed.

Type:

np.ndarray

nlev

Number of vertical levels.

Type:

int

depth_levels

Depth at each level interface, shape (nlev,).

Type:

np.ndarray

depth_layers

Depth at layer centers, shape (nlev-1,).

Type:

np.ndarray

node_levels

Number of active levels at each node, shape (n2d,).

Type:

np.ndarray

elem_levels

Number of active levels at each element, shape (nelem,).

Type:

np.ndarray

node_bottom_depth

Bottom depth at each node, shape (n2d,).

Type:

np.ndarray

elem_bottom_depth

Bottom depth at each element, shape (nelem,).

Type:

np.ndarray

lon: ndarray
lat: ndarray
triangles: ndarray
nlev: int
depth_levels: ndarray
depth_layers: ndarray
node_levels: ndarray
elem_levels: ndarray
node_bottom_depth: ndarray
elem_bottom_depth: ndarray
__post_init__()[source]

Validate mesh data and ensure correct dtypes.

Return type:

None

property n2d: int

Number of 2D nodes.

property nelem: int

Number of triangular elements.

property topology: Topology

Get mesh topology (edges, neighbors, etc.).

Computed lazily on first access if not pre-loaded from NetCDF.

property geometry: Geometry

Get mesh geometry (areas, gradients, etc.).

Computed lazily on first access if not pre-loaded from NetCDF.

property spatial_index: SpatialIndex

Get spatial index for efficient point queries.

Built lazily on first access.

property lon_elem: ndarray

Longitude of element (triangle) centers in degrees.

Computed lazily on first access. Handles cyclic triangles that cross the dateline correctly.

property lat_elem: ndarray

Latitude of element (triangle) centers in degrees.

Computed lazily on first access.

find_nearest(lon, lat, k=1)[source]

Find the k nearest nodes to a given point.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

  • k (int, optional) – Number of nearest neighbors to return.

Returns:

Indices of the k nearest nodes.

Return type:

np.ndarray

find_in_radius(lon, lat, radius_km)[source]

Find all nodes within a given radius of a point.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

  • radius_km (float) – Search radius in kilometers.

Returns:

Indices of nodes within the radius.

Return type:

np.ndarray

subset_by_bbox(lon_min, lon_max, lat_min, lat_max)[source]

Find all nodes within a bounding box.

Parameters:
  • lon_min (float) – Longitude bounds in degrees.

  • lon_max (float) – Longitude bounds in degrees.

  • lat_min (float) – Latitude bounds in degrees.

  • lat_max (float) – Latitude bounds in degrees.

Returns:

Indices of nodes within the bounding box.

Return type:

np.ndarray

get_triangulation(mask_cyclic=True)[source]

Create a matplotlib Triangulation object for plotting.

Parameters:

mask_cyclic (bool, optional) – If True (default), mask triangles that cross the dateline to prevent ugly lines spanning the globe.

Returns:

Triangulation object ready for use with triplot, tripcolor, etc.

Return type:

matplotlib.tri.Triangulation

Example

>>> tri = mesh.get_triangulation()
>>> plt.triplot(tri, 'b-', linewidth=0.2)
__init__(lon, lat, triangles, nlev, depth_levels, depth_layers, node_levels, elem_levels, node_bottom_depth, elem_bottom_depth, _preloaded_topology=None, _preloaded_geometry=None, _topology=None, _geometry=None, _spatial_index=None, _lon_elem=None, _lat_elem=None)
Parameters:
Return type:

None

fesomp.mesh.mesh.load_mesh(path)[source]

Load a FESOM2 mesh from a file or directory.

Automatically detects the format based on the path: - If path is a .nc file: loads from NetCDF - If path is a directory: loads from ASCII files

Parameters:

path (str or Path) – Path to the mesh file (NetCDF) or directory (ASCII).

Returns:

The loaded mesh object.

Return type:

Mesh

Raises:

Topology

Mesh topology data structures and computation.

class fesomp.mesh.topology.Topology[source]

Bases: object

Mesh topology information (edges, connectivity, neighbors).

edges

Edge node pairs, shape (nedges, 2), 0-indexed. Each row contains [node_i, node_j] where node_i < node_j.

Type:

np.ndarray

face_edges

Edge indices for each face, shape (nelem, 3). face_edges[i, j] is the edge index opposite to vertex j of face i.

Type:

np.ndarray

face_neighbors

Neighbor face indices, shape (nelem, 3). face_neighbors[i, j] is the face adjacent to face i across edge j. -1 indicates a boundary edge with no neighbor.

Type:

np.ndarray

edge_faces

Face indices for each edge, shape (nedges, 2). edge_faces[e, 0] and edge_faces[e, 1] are the faces sharing edge e. -1 indicates a boundary edge with only one adjacent face.

Type:

np.ndarray

node_elements

For each node, the list of element indices containing that node.

Type:

list[np.ndarray]

edges: ndarray
face_edges: ndarray
face_neighbors: ndarray
edge_faces: ndarray
node_elements: list[ndarray]
property nedges: int

Number of edges.

get_boundary_edges()[source]

Get indices of boundary edges.

Returns:

Indices of edges that have only one adjacent face.

Return type:

np.ndarray

get_boundary_nodes()[source]

Get indices of boundary nodes.

Returns:

Sorted unique indices of nodes on the boundary.

Return type:

np.ndarray

__init__(edges, face_edges, face_neighbors, edge_faces, node_elements)
Parameters:
Return type:

None

fesomp.mesh.topology.compute_topology(triangles)[source]

Compute mesh topology from triangle connectivity.

Parameters:

triangles (np.ndarray) – Triangle connectivity, shape (nelem, 3), 0-indexed.

Returns:

Computed topology object.

Return type:

Topology

Geometry

Mesh geometry data structures and computation.

class fesomp.mesh.geometry.Geometry[source]

Bases: object

Mesh geometry information (areas, gradients).

elem_area

Area of each element in m^2, shape (nelem,).

Type:

np.ndarray

node_area

Area associated with each node at each level, shape (nlev, n2d).

Type:

np.ndarray

gradient_sca

Gradient operator for scalar fields (x, y components).

Type:

tuple[np.ndarray, np.ndarray] | None

gradient_vec

Gradient operator for vector fields (x, y components).

Type:

tuple[np.ndarray, np.ndarray] | None

edge_cross_dxdy

Edge crossing distances, shape (4, nedges).

Type:

np.ndarray | None

elem_area: ndarray
node_area: ndarray
gradient_sca: tuple[ndarray, ndarray] | None = None
gradient_vec: tuple[ndarray, ndarray] | None = None
edge_cross_dxdy: ndarray | None = None
__init__(elem_area, node_area, gradient_sca=None, gradient_vec=None, edge_cross_dxdy=None)
Parameters:
Return type:

None

fesomp.mesh.geometry.spherical_triangle_area(lon, lat, triangles)[source]

Compute the spherical area of triangles on a sphere.

Uses the spherical excess formula for computing the area of spherical triangles. The formula is:

Area = R^2 * E

where E is the spherical excess (sum of angles - π).

Parameters:
  • lon (np.ndarray) – Longitude of nodes in degrees, shape (n2d,).

  • lat (np.ndarray) – Latitude of nodes in degrees, shape (n2d,).

  • triangles (np.ndarray) – Triangle connectivity, shape (nelem, 3), 0-indexed.

Returns:

Area of each triangle in m^2, shape (nelem,).

Return type:

np.ndarray

fesomp.mesh.geometry.compute_node_area(elem_area, triangles, node_levels, nlev)[source]

Compute the area associated with each node at each level.

Each node receives 1/3 of the area of each adjacent element. For nodes with fewer levels, deeper levels have zero area.

Parameters:
  • elem_area (np.ndarray) – Area of each element, shape (nelem,).

  • triangles (np.ndarray) – Triangle connectivity, shape (nelem, 3), 0-indexed.

  • node_levels (np.ndarray) – Number of active levels at each node, shape (n2d,).

  • nlev (int) – Total number of vertical levels.

Returns:

Area at each node and level, shape (nlev, n2d).

Return type:

np.ndarray

fesomp.mesh.geometry.compute_geometry(lon, lat, triangles, node_levels, nlev, topology)[source]

Compute mesh geometry from coordinates and connectivity.

Parameters:
  • lon (np.ndarray) – Longitude of nodes in degrees, shape (n2d,).

  • lat (np.ndarray) – Latitude of nodes in degrees, shape (n2d,).

  • triangles (np.ndarray) – Triangle connectivity, shape (nelem, 3), 0-indexed.

  • node_levels (np.ndarray) – Number of active levels at each node, shape (n2d,).

  • nlev (int) – Total number of vertical levels.

  • topology (Topology) – Pre-computed topology.

Returns:

Computed geometry object.

Return type:

Geometry

Spatial Index

Spatial indexing for efficient point queries on mesh data.

fesomp.mesh.spatial.lonlat_to_cartesian(lon, lat)[source]

Convert longitude/latitude to 3D Cartesian coordinates on unit sphere.

Parameters:
  • lon (np.ndarray) – Longitude in degrees.

  • lat (np.ndarray) – Latitude in degrees.

Returns:

Cartesian coordinates, shape (…, 3).

Return type:

np.ndarray

fesomp.mesh.spatial.chord_to_arc_distance(chord, radius=6371.0)[source]

Convert chord distance to arc (great-circle) distance.

Parameters:
  • chord (float) – Chord distance on unit sphere.

  • radius (float) – Sphere radius (default: Earth radius in km).

Returns:

Arc distance in same units as radius.

Return type:

float

fesomp.mesh.spatial.arc_to_chord_distance(arc_km, radius=6371.0)[source]

Convert arc (great-circle) distance to chord distance on unit sphere.

Parameters:
  • arc_km (float) – Arc distance in kilometers.

  • radius (float) – Sphere radius (default: Earth radius in km).

Returns:

Chord distance on unit sphere.

Return type:

float

class fesomp.mesh.spatial.SpatialIndex[source]

Bases: object

Spatial index for efficient nearest-neighbor queries on mesh nodes.

Uses a 3D KD-tree in Cartesian coordinates for accurate spherical queries.

Parameters:
  • lon (np.ndarray) – Longitude of nodes in degrees, shape (n2d,).

  • lat (np.ndarray) – Latitude of nodes in degrees, shape (n2d,).

__init__(lon, lat)[source]
Parameters:
Return type:

None

find_nearest(lon, lat, k=1)[source]

Find the k nearest nodes to given point(s).

Parameters:
  • lon (float or np.ndarray) – Longitude in degrees.

  • lat (float or np.ndarray) – Latitude in degrees.

  • k (int, optional) – Number of nearest neighbors to return.

Returns:

Indices of the k nearest nodes. If single point, shape is (k,) for k>1 or scalar for k=1. If multiple points, shape is (npoints, k).

Return type:

np.ndarray

find_in_radius(lon, lat, radius_km)[source]

Find all nodes within a given radius of point(s).

Parameters:
  • lon (float or np.ndarray) – Longitude in degrees.

  • lat (float or np.ndarray) – Latitude in degrees.

  • radius_km (float) – Search radius in kilometers.

Returns:

Indices of nodes within the radius. For single point: 1D array of indices. For multiple points: list of arrays.

Return type:

np.ndarray or list[np.ndarray]

find_containing_element(lon, lat, triangles, mesh_lon, mesh_lat)[source]

Find the element containing a given point.

Uses nearest-neighbor search followed by local search of adjacent elements.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

  • triangles (np.ndarray) – Triangle connectivity, shape (nelem, 3).

  • mesh_lon (np.ndarray) – Longitude of mesh nodes.

  • mesh_lat (np.ndarray) – Latitude of mesh nodes.

Returns:

Index of the containing element, or -1 if not found.

Return type:

int

Coordinate Transformations

Coordinate transformations between rotated and geographical coordinates.

This module provides functions for converting coordinates and vectors between rotated (model) coordinates and geographical coordinates using Euler angle rotations. These transformations are necessary when working with FESOM2 meshes that use rotated coordinate systems.

fesomp.mesh.coordinates.scalar_r2g(alpha, beta, gamma, rlon, rlat)[source]

Convert coordinates from rotated to geographical coordinate system.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • rlon (np.ndarray) – Longitudes in rotated coordinates (degrees).

  • rlat (np.ndarray) – Latitudes in rotated coordinates (degrees).

Returns:

(lon, lat) - Longitudes and latitudes in geographical coordinates (degrees).

Return type:

tuple[np.ndarray, np.ndarray]

fesomp.mesh.coordinates.scalar_g2r(alpha, beta, gamma, lon, lat)[source]

Convert coordinates from geographical to rotated coordinate system.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • lon (np.ndarray) – Longitudes in geographical coordinates (degrees).

  • lat (np.ndarray) – Latitudes in geographical coordinates (degrees).

Returns:

(rlon, rlat) - Longitudes and latitudes in rotated coordinates (degrees).

Return type:

tuple[np.ndarray, np.ndarray]

fesomp.mesh.coordinates.vec_rotate_r2g(alpha, beta, gamma, lon, lat, urot, vrot, flag)[source]

Rotate vectors from rotated to geographical coordinates.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • lon (np.ndarray) – Longitudes (in rotated or geographical coordinates, see flag).

  • lat (np.ndarray) – Latitudes (in rotated or geographical coordinates, see flag).

  • urot (np.ndarray) – U (eastward) component of vector in rotated coordinates.

  • vrot (np.ndarray) – V (northward) component of vector in rotated coordinates.

  • flag (int) – Coordinate system of input lon/lat: - 1: lon/lat are in geographical coordinates - 0: lon/lat are in rotated coordinates

Returns:

(u, v) - Vector components in geographical coordinates.

Return type:

tuple[np.ndarray, np.ndarray]

fesomp.mesh.coordinates.vec_rotate_g2r(alpha, beta, gamma, lon, lat, ugeo, vgeo, flag)[source]

Rotate vectors from geographical to rotated coordinates.

Parameters:
  • alpha (float) – Alpha Euler angle in degrees.

  • beta (float) – Beta Euler angle in degrees.

  • gamma (float) – Gamma Euler angle in degrees.

  • lon (np.ndarray) – Longitudes (in rotated or geographical coordinates, see flag).

  • lat (np.ndarray) – Latitudes (in rotated or geographical coordinates, see flag).

  • ugeo (np.ndarray) – U (eastward) component of vector in geographical coordinates.

  • vgeo (np.ndarray) – V (northward) component of vector in geographical coordinates.

  • flag (int) – Coordinate system of input lon/lat: - 1: lon/lat are in geographical coordinates - 0: lon/lat are in rotated coordinates

Returns:

(u, v) - Vector components in rotated coordinates.

Return type:

tuple[np.ndarray, np.ndarray]

Readers

Mesh file readers for different formats.

class fesomp.mesh.readers.MeshReader[source]

Bases: ABC

Abstract base class for mesh readers.

abstractmethod read(path)[source]

Read a mesh from the given path.

Parameters:

path (Path) – Path to the mesh file or directory.

Returns:

The loaded mesh object.

Return type:

Mesh

class fesomp.mesh.readers.NetCDFReader[source]

Bases: MeshReader

Reader for FESOM2 mesh diagnostic NetCDF files.

Reads from fesom.mesh.diag.nc which contains pre-computed topology and geometry information.

read(path)[source]

Read a mesh from a NetCDF file.

Parameters:

path (Path) – Path to the NetCDF mesh file (e.g., fesom.mesh.diag.nc).

Returns:

The loaded mesh object with pre-populated topology and geometry.

Return type:

Mesh

class fesomp.mesh.readers.ASCIIReader[source]

Bases: MeshReader

Reader for FESOM2 ASCII mesh files.

Reads from a directory containing: - nod2d.out: Node coordinates - elem2d.out: Triangle connectivity - aux3d.out: Vertical structure and bottom depths

read(path)[source]

Read a mesh from ASCII files in a directory.

Parameters:

path (Path) – Path to directory containing mesh files.

Returns:

The loaded mesh object.

Return type:

Mesh

Base class for mesh readers.

class fesomp.mesh.readers.base.MeshReader[source]

Bases: ABC

Abstract base class for mesh readers.

abstractmethod read(path)[source]

Read a mesh from the given path.

Parameters:

path (Path) – Path to the mesh file or directory.

Returns:

The loaded mesh object.

Return type:

Mesh

NetCDF reader for FESOM2 mesh files.

class fesomp.mesh.readers.netcdf.NetCDFReader[source]

Bases: MeshReader

Reader for FESOM2 mesh diagnostic NetCDF files.

Reads from fesom.mesh.diag.nc which contains pre-computed topology and geometry information.

read(path)[source]

Read a mesh from a NetCDF file.

Parameters:

path (Path) – Path to the NetCDF mesh file (e.g., fesom.mesh.diag.nc).

Returns:

The loaded mesh object with pre-populated topology and geometry.

Return type:

Mesh

ASCII reader for FESOM2 mesh files.

class fesomp.mesh.readers.ascii.ASCIIReader[source]

Bases: MeshReader

Reader for FESOM2 ASCII mesh files.

Reads from a directory containing: - nod2d.out: Node coordinates - elem2d.out: Triangle connectivity - aux3d.out: Vertical structure and bottom depths

read(path)[source]

Read a mesh from ASCII files in a directory.

Parameters:

path (Path) – Path to directory containing mesh files.

Returns:

The loaded mesh object.

Return type:

Mesh