8282from typing import Any , Literal , Optional
8383
8484import numpy as np
85- from numpy .polynomial .polyutils import RankWarning # type: ignore[attr-defined]
8685from scipy .optimize import curve_fit
8786
8887# Constants
@@ -193,7 +192,8 @@ def level_plane(
193192 # ========== X DIRECTION ==========
194193 # Column-wise masked mean with NaN-outside semantics
195194 with warnings .catch_warnings ():
196- warnings .simplefilter ("ignore" , category = RuntimeWarning )
195+ warnings .simplefilter ("ignore" , RuntimeWarning )
196+ warnings .filterwarnings ("ignore" , message = ".*[Rr]ank.*" )
197197 column_means = np .nanmean (np .where (m , arr , np .nan ), axis = 0 )
198198
199199 valid_columns = ~ np .isnan (column_means )
@@ -213,7 +213,8 @@ def level_plane(
213213 standardized_columns = (column_indices - col_centroid ) / col_scale
214214
215215 with warnings .catch_warnings ():
216- warnings .simplefilter ("ignore" , RankWarning )
216+ warnings .simplefilter ("ignore" , RuntimeWarning )
217+ warnings .filterwarnings ("ignore" , message = ".*[Rr]ank.*" )
217218 x_coeffs = np .polyfit (standardized_columns , column_means [valid_columns ], polyx )
218219
219220 # Evaluate polynomial at every column (1..W) using the same mu
@@ -226,7 +227,8 @@ def level_plane(
226227 # ========== Y DIRECTION ==========
227228 # Row-wise masked mean after X subtraction (NaN-outside semantics)
228229 with warnings .catch_warnings ():
229- warnings .simplefilter ("ignore" , category = RuntimeWarning )
230+ warnings .simplefilter ("ignore" , RuntimeWarning )
231+ warnings .filterwarnings ("ignore" , message = ".*[Rr]ank.*" )
230232 row_means = np .nanmean (np .where (m , leveled , np .nan ), axis = 1 )
231233
232234 valid_rows = ~ np .isnan (row_means )
@@ -245,7 +247,8 @@ def level_plane(
245247 standardized_rows = (row_indices - row_centroid ) / row_scale
246248
247249 with warnings .catch_warnings ():
248- warnings .simplefilter ("ignore" , RankWarning )
250+ warnings .simplefilter ("ignore" , RuntimeWarning )
251+ warnings .filterwarnings ("ignore" , message = ".*[Rr]ank.*" )
249252 y_coeffs = np .polyfit (standardized_rows , row_means [valid_rows ], polyy )
250253
251254 # Evaluate polynomial at every row (1..H) with the same mu
@@ -333,7 +336,8 @@ def level_line(
333336 xs = (x_idx - mu ) / sd # xs: standardized x indices used for fitting
334337
335338 with warnings .catch_warnings ():
336- warnings .simplefilter ("ignore" , RankWarning )
339+ warnings .simplefilter ("ignore" , RuntimeWarning )
340+ warnings .filterwarnings ("ignore" , message = ".*[Rr]ank.*" )
337341 p_coeff = np .polyfit (xs , y_vals , polyx )
338342
339343 all_cols = (np .arange (img_width ) + 1 ).astype (np .float64 )
@@ -378,7 +382,8 @@ def level_line(
378382 ys = (yl - mu ) / sd # ys: standardized y indices used for fitting
379383
380384 with warnings .catch_warnings ():
381- warnings .simplefilter ("ignore" , RankWarning )
385+ warnings .simplefilter ("ignore" , RuntimeWarning )
386+ warnings .filterwarnings ("ignore" , message = ".*[Rr]ank.*" )
382387 p_coeff = np .polyfit (ys , y_vals , polyy )
383388
384389 all_rows = (np .arange (img_height ) + 1 ).astype (np .float64 )
0 commit comments