pyissm.tools.interp
Interpolation functions for ISSM
This module contains various interpolation functions that can be used in conjunction with ISSM models.
Functions
|
Smooth input data over a mesh using area/volume-weighted nodal averaging. |
|
Transfer element-defined values to vertices. |
|
Transfer vertex-defined values to mesh elements. |
- pyissm.tools.interp.averaging(md, data, iterations, layer=0)
Smooth input data over a mesh using area/volume-weighted nodal averaging.
This function performs an iterative smoothing of data defined either on mesh elements or on mesh vertices. For element-defined data, it first distributes element values to nodes using element areas/volumes as weights. For vertex- defined data, it uses the provided nodal values as the starting point. Each iteration computes element-averaged values from current nodal values and then recomputes nodal values as the area/volume-weighted average of adjacent element averages. The algorithm supports 2-D meshes, full 3-D meshes (using element volumes), and extraction of a single 2-D layer from a 3-D mesh.
- Parameters:
md (ISSM model object)
data (array_like) – 1-D array-like of scalar values defined either on elements or on vertices. Its length must be equal to either: - md.mesh.numberofelements (data on elements), or - md.mesh.numberofvertices (data on vertices). If layer is provided for a 3-D mesh, the vertex-based length should be md.mesh.numberofvertices2d and element-based length md.mesh.numberofelements2d.
iterations (int) – Number of smoothing iterations to perform. Must be a non-negative integer. A value of 0 will still perform the initial element->node distribution if data is provided on elements.
layer (int, optional) – Layer index to extract when working with a 3-D mesh. Default is 0, meaning operate on the full mesh. If non-zero, it must satisfy 1 <= layer <= md.mesh.numberoflayers and the function will operate on the corresponding 2-D layer (using mesh.elements2d, x2d, y2d, etc.).
- Returns:
average – Dense column vector containing the smoothed nodal values. The length n is md.mesh.numberofvertices when layer == 0, or md.mesh.numberofvertices2d when a 2-D layer is extracted.
- Return type:
numpy.ndarray, shape (n, 1)
- Raises:
Exception – If the length of data does not match the expected number of elements or vertices for the mesh/layer combination.
ValueError – If a non-zero layer is provided for a 3-D mesh but is outside the valid range (not in 1..md.mesh.numberoflayers).
Notes
Weighting: element areas (2-D) or volumes (3-D) are used to weight the contribution of each element to its corner nodes when distributing element values to nodes and when recomputing nodal values from element averages.
Indexing: mesh connectivity arrays are expected to be 1-based in the model and are converted to 0-based indices internally.
Output is returned as a dense array (not a sparse matrix) for compatibility with downstream code (e.g. C routines) that expect full arrays.
Examples
>>> # Smooth element data on a 2-D mesh for 5 iterations >>> avg = averaging(md, element_data, iterations=5) >>> # Smooth nodal data on layer 2 of a 3-D mesh >>> avg2d = averaging(md, vertex_data_2d, iterations=3, layer=2)
- pyissm.tools.interp.element_to_vertex(md, values, layer=0)
Transfer element-defined values to vertices.
- Parameters:
md (
pyissm.model) – ISSM model object containing mesh connectivity inmd.mesh.elementsand vertex count inmd.mesh.numberofvertices.values (
numpy.ndarray) – Element-defined field of shape(md.mesh.numberofelements,).layer (
int, optional) – Layer index to extract when working with a 3-D mesh. Default is 0, meaning operate on the full mesh. If non-zero, it must satisfy 1 <= layer <= md.mesh.numberoflayers and the function will operate on the corresponding 2-D layer (using mesh.elements2d, x2d, y2d, etc.).
- Returns:
Vertex-defined field of shape
(md.mesh.numberofvertices,).- Return type:
numpy.ndarray
- pyissm.tools.interp.vertex_to_element(md, values, method='mean')
Transfer vertex-defined values to mesh elements.
- Parameters:
md (
pyissm.model) – ISSM model object containing mesh connectivity inmd.mesh.elementsand vertex count inmd.mesh.numberofvertices.values (
array_like) – Vertex-defined field of shape(md.mesh.numberofvertices,).method (
str, optional) –Aggregation method used to combine vertex values within each element. Available options:
"mean","min","max". Default is"mean"."mean": Compute the average of vertex values for each element."min": Take the minimum vertex value for each element."max": Take the maximum vertex value for each element.
- Returns:
Element-defined field of shape
(md.mesh.numberofelements,).- Return type:
numpy.ndarray
- Raises:
ValueError – If
valuesis not vertex-defined for the mesh or ifmethodis unsupported.