Fix crash quand valid_data est vide dans _apply_colormap
np.percentile crash avec IndexError quand valid_data est vide (TIF entièrement NaN). Ajout d'un guard qui retourne une colormap par défaut si aucune donnée valide n'existe. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -200,6 +200,10 @@ def _apply_colormap(data, tif_file):
|
||||
valid_data = np.asarray(data.compressed() if hasattr(data, 'compressed') else data.flatten())
|
||||
valid_data = valid_data[~np.isnan(valid_data)]
|
||||
|
||||
if len(valid_data) == 0:
|
||||
logger.warning(f" Aucune donnée valide pour {Path(tif_file).name} — colormap ignorée")
|
||||
return data, 'terrain', Path(tif_file).stem.replace('_', ' ').title(), '', '', False
|
||||
|
||||
vmin = vmax = None
|
||||
|
||||
# Compute vmin/vmax based on mode
|
||||
@ -234,6 +238,8 @@ def _apply_colormap(data, tif_file):
|
||||
# Default: terrain colormap with percentile stretch
|
||||
valid_data = np.asarray(data.compressed() if hasattr(data, 'compressed') else data.flatten())
|
||||
valid_data = valid_data[~np.isnan(valid_data)]
|
||||
if len(valid_data) == 0:
|
||||
return data, 'terrain', Path(tif_file).stem.replace('_', ' ').title(), '', '', False
|
||||
p2, p98 = np.percentile(valid_data, (2, 98))
|
||||
data = np.clip((data - p2) / (p98 - p2), 0, 1)
|
||||
title = Path(tif_file).stem.replace('_', ' ').title()
|
||||
|
||||
Reference in New Issue
Block a user