pyinterp.fill.multi_grid#
- pyinterp.fill.multi_grid(array: _Float2DArray, first_guess: str = 'zonal_average', is_circle: bool = False, max_iterations: int | None = None, epsilon: float = 0.0001, pre_smooth: int = 2, post_smooth: int = 2, num_threads: int = 0, in_place: bool = False) tuple[int, float, _Float2DArray][source]#
Replace undefined values (NaN) in a 2-D grid using the multigrid V-cycle.
- Parameters:
array – The array to be processed.
first_guess – Method to use for the first guess. Supported values are
zero(use0.0) andzonal_average(use zonal averages along the X axis). Defaults tozonal_average.is_circle – True if the X axis of the array defines a circle.
max_iterations – Maximum number of iterations to be used by the multigrid method. If None, defaults to the product of the array dimensions.
epsilon – Tolerance for ending the multigrid method before reaching the maximum number of iterations. Defaults to
1e-4.pre_smooth – Number of smoothing iterations to perform before restriction. Defaults to
2.post_smooth – Number of smoothing iterations to perform after prolongation. Defaults to
2.num_threads – Number of threads to use for the computation. If 0 all CPUs are used. If 1 is given, no parallel computing code is used, which is useful for debugging. Defaults to
0.in_place – If True, the input array is modified in place. If False, a copy is made and filled. Defaults to
False.
- Returns:
A tuple containing the number of iterations performed, the final residual value, and the filled array.
Note
This function operates on 2D grids only. For greater dimensional data, apply this function to each 2D slice independently:
# For a 3D array with shape (ny, nx, nz) filled_3d = np.empty_like(data_3d) for iz in range(data_3d.shape[2]): iterations, residual, filled_3d[:, :, iz] = multi_grid( data_3d[:, :, iz], is_circle=True )