Mesh representation
- class ocsmesh.mesh.Mesh(mesh: jigsaw_msh_t, **kwargs)
Bases:
BaseMesh
Mesh object factory
Factory class that creates and returns concrete mesh object based on the input types.
- Attributes:
Methods
open(path, crs=None)
Read mesh data from a file on disk.
Construct a concrete mesh object.
- Parameters:
- meshjigsaw_msh_t
Input jigsaw mesh object
- Attributes:
Methods
open
(path[, crs])Read mesh from a file on disk
- Returns:
- MeshType
Mesh object created from the input
- Raises:
- TypeError
Input mesh is not a jigsaw_msh_t object.
- NotImplementedError
Input mesh object cannot be used to create a EuclideanMesh2D
- static open(path: str | Path, crs: CRS | None = None) EuclideanMesh2D
Read mesh from a file on disk
- Parameters:
- pathpath-like
Path to the file containig mesh.
- crsCRS or None, default=None
CRS of the mesh in the path. Overwrites any info read from file, no transformation is done.
- Returns:
- MeshType
Mesh object created by reading the file.
- Raises:
- TypeError
If cannot determine the input mesh type.
Notes
Currently only SMS-2DM and GRD formats are supported for reading.
- property coord: ndarray[Any, dtype[float32]]
Read-only property for coordinates of mesh points
- Raises:
- If the number of mesh dimensions is not 2 or 3.
Notes
The property is read-only, however the returned value is not. That means if the user mutates the returned numpy array object, it will affect the mesh.
- property msh_t: jigsaw_msh_t
Read-only property returning reference to the jigsawpy mesh object
Notes
The property is read-only, however the returned value is not. That means if the user mutates the returned jigsaw_msh_t object, it will affect the mesh.
- class ocsmesh.mesh.EuclideanMesh2D(mesh: jigsaw_msh_t, boundaries=None)
Bases:
EuclideanMesh
2D Euclidean mesh definition
- Attributes:
boundaries
Handle to boundaries calculator helper object
vert2
Reference to underlying mesh 2D vertices structure
value
Reference to underlying mesh values
bbox
Calculates and returns bounding box of the mesh hull.
Methods
get_bbox(crs=None, output_type=None)
Gets the bounding box of the mesh elements.
tricontourf(**kwargs)
Create a contour plot from the value data on the nodes of the mesh
interpolate(raster, method=’spline’, nprocs=None)
Interpolate raster date on the nodes.
get_contour(level)
Get contour lines from node value data at specified levels.
get_multipolygon(zmin=None, zmax=None)
Get multipolygon of the mesh hull.
Initialize Euclidean 2D mesh object.
- Parameters:
- meshjigsaw_msh_t
The underlying jigsaw_msh_t object to hold onto mesh data.
- boundariesdict or None, default = None
Dictionary of boundaries assignment
- Attributes:
bbox
Calculates and returns bounding box of the mesh hull.
boundaries
Handle to boundaries calculator helper object
coord
Read-only property for coordinates of mesh points
crs
Reference to underlying mesh crs
elements
Reference to element handler helper object
hull
Reference to hull calculator helper object
msh_t
Read-only property returning reference to the jigsawpy mesh object
nodes
Reference to node handler helper object
quad4
Reference to underlying mesh quadrangle element structure
quads
Reference to underlying mesh quadrangle element index array
tria3
Reference to underlying mesh tirangle element structure
triangles
Reference to underlying mesh triangle element index array
value
Reference to underlying mesh values
vert2
Reference to underlying mesh 2D vertices structure
Methods
get_bbox
([crs, output_type])Get the bounding box of mesh elements.
get_contour
(level)Extract contour lines at the specified level from mesh values
get_multipolygon
([zmin, zmax])Calculate multipolygon covering mesh elements (hull)
interpolate
(raster[, method, nprocs, ...])Interplate values from raster inputs to the mesh nodes.
tricontourf
(**kwargs)Generate contour for the data of triangular elements of the mesh
write
(path[, overwrite, format])Export the mesh object to the disk
- Raises:
- ValueError
If number of mesh dimensions is not equal to
2
.
- get_bbox(crs: str | CRS | None = None, output_type: Literal[None, 'polygon', 'bbox'] = None) Polygon | Bbox
Get the bounding box of mesh elements.
- Parameters:
- crsstr or CRS or None, default=None
CRS to transform the calculated bounding box into before returning
- output_type{ None, ‘polygon’, ‘bbox’}, default=None
Output type
- Returns:
- Polygon or Bbox
Bounding box of the mesh elements.
- property boundaries
Handle to boundaries calculator helper object
- tricontourf(**kwargs) Axes
Generate contour for the data of triangular elements of the mesh
- Parameters:
- **kwargsdict, optional
Passed to underlying matplotlib API.
- Returns:
- Axes
Axes on which the filled contour is drawn.
- interpolate(raster: Raster | List[Raster], method: Literal['spline', 'linear', 'nearest'] = 'spline', nprocs: int | None = None, info_out_path: Path | str | None = None, filter_by_shape: bool = False, band: int = 1) None
Interplate values from raster inputs to the mesh nodes.
- Parameters:
- rasterRaster or list of Raster
A single or a list of rasters from which values are interpolated onto the mesh
- method{‘spline’, ‘linear’, ‘nearest’}, default=’spline’
Method of interpolation.
- nprocsint or None, default=None
Number of workers to use when interpolating data.
- info_out_pathpathlike or str or None
Path for the output node interpolation information file
- filter_by_shapebool, default=False
Flag for node filtering based on raster bbox or shape
- bandint, default=1
The band from rasters to use for interpolation
- Returns:
- None
- get_contour(level: float) LineString
Extract contour lines at the specified level from mesh values
- Parameters:
- levelfloat
The level at which contour lines must be extracted.
- Returns:
- LineString
Extracted and merged contour lines.
- Raises:
- ValueError
If mesh has nodes that have null value np.nan.
- get_multipolygon(zmin: float | None = None, zmax: float | None = None) MultiPolygon
Calculate multipolygon covering mesh elements (hull)
- Parameters:
- zminfloat or None
Minimum elevation to consider for multipolygon extraction
- zmaxfloat or None
Maximum elevation to consider for multipolygon extraction
- Returns:
- MultiPolygon
Calculated multipolygon shape
- property vert2
Reference to underlying mesh 2D vertices structure
- property value
Reference to underlying mesh values
- property coord: ndarray[Any, dtype[float32]]
Read-only property for coordinates of mesh points
- Raises:
- If the number of mesh dimensions is not 2 or 3.
Notes
The property is read-only, however the returned value is not. That means if the user mutates the returned numpy array object, it will affect the mesh.
- property crs
Reference to underlying mesh crs
- property elements
Reference to element handler helper object
- property hull
Reference to hull calculator helper object
- property msh_t: jigsaw_msh_t
Read-only property returning reference to the jigsawpy mesh object
Notes
The property is read-only, however the returned value is not. That means if the user mutates the returned jigsaw_msh_t object, it will affect the mesh.
- property nodes
Reference to node handler helper object
- property quad4
Reference to underlying mesh quadrangle element structure
- property quads
Reference to underlying mesh quadrangle element index array
- property tria3
Reference to underlying mesh tirangle element structure
- property triangles
Reference to underlying mesh triangle element index array
- write(path: str | PathLike, overwrite: bool = False, format: Literal['grd', '2dm', 'msh', 'vtk'] = 'grd') None
Export the mesh object to the disk
- Parameters:
- pathpath-like
Path to which the mesh should be exported.
- overwritebool, default=False
Whether to overwrite, if a file already exists in path
- format{ ‘grd’, ‘2dm’, ‘msh’, ‘vtk’ }
Format of the export, SMS-2DM or GRD.
- Returns:
- None
- Raises:
- ValueError
If specified export format is not supported.