Supprimer les RuntimeWarnings: NaN dans nanmean et cast uint8

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jacquin Antoine
2026-05-10 01:29:03 +02:00
parent a654ff5964
commit bf4e42d571

View File

@ -391,6 +391,7 @@ def generate_mslrm(dem_file, basename, vis_dir, resolution):
lrm_stack.append(lrm_norm.astype(np.float32)) lrm_stack.append(lrm_norm.astype(np.float32))
lrm_array = np.array(lrm_stack) lrm_array = np.array(lrm_stack)
with np.errstate(invalid='ignore'):
mslrm = np.sqrt(np.nanmean(lrm_array ** 2, axis=0)) mslrm = np.sqrt(np.nanmean(lrm_array ** 2, axis=0))
mslrm[nan_mask] = np.nan mslrm[nan_mask] = np.nan
_save_tif(output, mslrm.astype(np.float32), transform, crs) _save_tif(output, mslrm.astype(np.float32), transform, crs)
@ -658,6 +659,7 @@ def generate_wavelet(dem_file, basename, vis_dir, resolution):
response = response / std_val response = response / std_val
wavelet_stack.append(response) wavelet_stack.append(response)
with np.errstate(invalid='ignore'):
combined = np.sqrt(np.nanmean(np.array(wavelet_stack) ** 2, axis=0)) combined = np.sqrt(np.nanmean(np.array(wavelet_stack) ** 2, axis=0))
combined[nan_mask] = np.nan combined[nan_mask] = np.nan
@ -714,7 +716,8 @@ def generate_texture(dem_file, basename, vis_dir, resolution):
# Entropy — compute bin-by-bin to avoid large 3D allocation # Entropy — compute bin-by-bin to avoid large 3D allocation
n_bins = 16 n_bins = 16
img_uint8 = np.clip(img * 255, 0, 255).astype(np.uint8) img_clean = np.nan_to_num(img, nan=0.0)
img_uint8 = np.clip(img_clean * 255, 0, 255).astype(np.uint8)
quantized = (img_uint8 // (256 // n_bins)).astype(np.int32) quantized = (img_uint8 // (256 // n_bins)).astype(np.int32)
entropy = np.zeros_like(img, dtype=np.float64) entropy = np.zeros_like(img, dtype=np.float64)
win_area = max(window * window, 1) win_area = max(window * window, 1)