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:
@ -6,6 +6,7 @@ parameters and returns the path to the output GeoTIFF file, or None on error.
|
||||
|
||||
import logging
|
||||
import time
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
@ -391,8 +392,10 @@ def generate_mslrm(dem_file, basename, vis_dir, resolution):
|
||||
lrm_stack.append(lrm_norm.astype(np.float32))
|
||||
|
||||
lrm_array = np.array(lrm_stack)
|
||||
with np.errstate(invalid='ignore'):
|
||||
mslrm = np.sqrt(np.nanmean(lrm_array ** 2, axis=0))
|
||||
with np.errstate(invalid='ignore', divide='ignore'):
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', message='Mean of empty slice')
|
||||
mslrm = np.sqrt(np.nanmean(lrm_array ** 2, axis=0))
|
||||
mslrm[nan_mask] = np.nan
|
||||
_save_tif(output, mslrm.astype(np.float32), transform, crs)
|
||||
logger.info(f" ✓ MSRM terminé ({time.time()-t0:.1f}s){gpu_tag}")
|
||||
@ -659,8 +662,10 @@ def generate_wavelet(dem_file, basename, vis_dir, resolution):
|
||||
response = response / std_val
|
||||
wavelet_stack.append(response)
|
||||
|
||||
with np.errstate(invalid='ignore'):
|
||||
combined = np.sqrt(np.nanmean(np.array(wavelet_stack) ** 2, axis=0))
|
||||
with np.errstate(invalid='ignore', divide='ignore'):
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', message='Mean of empty slice')
|
||||
combined = np.sqrt(np.nanmean(np.array(wavelet_stack) ** 2, axis=0))
|
||||
combined[nan_mask] = np.nan
|
||||
|
||||
_save_tif(output, combined.astype(np.float32), transform, crs)
|
||||
|
||||
Reference in New Issue
Block a user