pyinterp.fill.fft_inpaint#
- pyinterp.fill.fft_inpaint(array: _Float2DArray, first_guess: str = 'zonal_average', is_circle: bool = False, max_iterations: int | None = None, epsilon: float = 0.0001, sigma: float = 10.0, num_threads: int = 0, in_place: bool = False) tuple[int, float, _Float2DArray][source]#
Fill undefined values in a grid using spectral in-painting.
Replace NaN values in a 2D array using a spectral in-painting approach. Uses a Fast Fourier Transform (FFT) for periodic boundaries (is_circle=True) or a Discrete Cosine Transform (DCT) for reflective boundaries (is_circle=False). A Gaussian low-pass filter (sigma) controls the smoothness of the fill.
- Parameters:
array – The array to be processed
first_guess – Method to use for the first guess.
is_circle – If true, uses a Fast Fourier Transform (FFT) assuming periodic boundaries. If false, uses a Discrete Cosine Transform (DCT) assuming reflective boundaries. Defaults to
False.max_iterations – Maximum number of iterations. Defaults to
500.epsilon – Tolerance for ending relaxation. Defaults to
1e-4.sigma – Standard deviation of the Gaussian low-pass filter in pixel units. Controls the smoothness of the fill. Defaults to
10.0.num_threads – The number of threads to use for the computation. 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 maximum residual value, and the filled array.
Note
This function operates on 2D arrays only and requires a C contiguous array. If you have higher 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]): c_contiguous_data = np.ascontiguousarray(data_3d[:, :, iz]) iterations, residual, filled_3d[:, :, iz] = fft_inpaint( c_contiguous_data, is_circle=True )