pysdic.workflows.compute_median_filtered_displacements#

compute_median_filtered_displacements(analysis, frames, neighborhood=None, *, max_distance=None, radius=None)[source]#

Apply a median filter to the displacements of frames: the displacement of each vertex is replaced, component by component, by the median of the displacements of its neighborhood.

The neighborhood is given in one of three ways (at most one input):

  • neighborhood: a boolean sparse matrix \((N_v, N_v)\), the neighborhood of the vertex \(i\) being neighborhood[i].indices (e.g. from pysdic.Mesh.compute_vertices_neighborhood());

  • max_distance: the vertices within a topological distance (two vertices are at distance 1 if they share an element), see pysdic.Mesh.compute_vertices_neighborhood();

  • radius: the vertices within a Euclidean distance on the reference vertices of the mesh (in the unit of the mesh), independent of the size of the elements.

By default, max_distance=1. Each vertex is in its own neighborhood with max_distance and radius.

The median removes the isolated outliers (a vertex badly measured, e.g. on a reflection) while keeping the steps of the displacement, unlike a mean.

Parameters:
  • analysis (pysdic.SDICAnalysis) – The analysis, with the displacements of frames set.

  • frames (Sequence[Integral]) – The frames to filter.

  • neighborhood (Optional[scipy.sparse.spmatrix], optional) – The neighborhood of the vertices.

  • max_distance (Optional[Integral], optional) – The topological distance of the neighborhood (at least 1).

  • radius (Optional[Real], optional) – The Euclidean distance of the neighborhood (strictly positive).

Returns:

For each frame, its filtered displacement \((N_v, E)\).

Return type:

Dict[int, numpy.ndarray]

Raises:

ValueError – If several neighborhoods are given, the neighborhood has a wrong shape, or a displacement is not set.

Examples

from pysdic.workflows import compute_median_filtered_displacements

filtered = compute_median_filtered_displacements(analysis, [3, 4, 5], radius=5.0)  # 5 mm
for frame, displacement in filtered.items():
    analysis.set_displacement(frame, displacement)