Fix numpy warnings: MaskedArray partition et Mean of empty slice

- Convert MaskedArray to ndarray avant np.percentile() via
  np.asarray(data.compressed()) et np.ma.filled(data, np.nan)
- Supprimer RuntimeWarning "Mean of empty slice" dans MSRM et
  ondelette avec warnings.catch_warnings()
- Ajout import warnings dans visualizations.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jacquin Antoine
2026-05-10 03:02:36 +02:00
parent e2845b9e6d
commit 569f2e680c
2 changed files with 15 additions and 6 deletions

View File

@ -204,7 +204,7 @@ def _apply_colormap(data, tif_file):
# Find matching colormap
for key, info in COLORMAPS.items():
if key in name:
valid_data = np.asarray(data[~np.isnan(data)] if hasattr(data, 'compressed') else data.flatten())
valid_data = np.asarray(data.compressed() if hasattr(data, 'compressed') else data.flatten())
valid_data = valid_data[~np.isnan(valid_data)]
vmin = vmax = None
@ -239,7 +239,7 @@ def _apply_colormap(data, tif_file):
return data, info['cmap'], info['title'], legend, info['description'], False
# Default: terrain colormap with percentile stretch
valid_data = np.asarray(data[~np.isnan(data)] if hasattr(data, 'compressed') else data.flatten())
valid_data = np.asarray(data.compressed() if hasattr(data, 'compressed') else data.flatten())
valid_data = valid_data[~np.isnan(valid_data)]
p2, p98 = np.percentile(valid_data, (2, 98))
data = np.clip((data - p2) / (p98 - p2), 0, 1)
@ -324,6 +324,10 @@ def tif_to_png(tif_file, vis_dir, resolution):
valid_data = np.asarray(data.compressed() if hasattr(data, 'compressed') else data.flatten())
valid_data = valid_data[~np.isnan(valid_data)]
# Convert MaskedArray to plain ndarray (NaN-filled) to avoid numpy warnings
if isinstance(data, np.ma.MaskedArray):
data = np.ma.filled(data, np.nan)
# Apply colormap
data, cmap, title, legend_label, description, is_rgb_result = _apply_colormap(data, tif_file)