import os
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import zoom
import gc
from tqdm import tqdm
from zernike import RZern
def wrap_phase(phase):
"""将相位包裹到[-π, π]区间"""
return np.angle(np.exp(1j * phase))
def clean_nan_values(arr):
"""清理数组中的NaN值"""
arr_copy = arr.copy()
if np.any(np.isnan(arr_copy)):
arr_copy = np.nan_to_num(arr_copy, nan=0.0)
return arr_copy
def fit_zernike_coefficients(phase, mask, n_coef=37):
"""
使用RZern对相位进行Zernike多项式拟合
参数:
phase: 相位图
mask: 掩码
n_coef: Zernike系