From 8e4b4bb10b2043ab86c388d383c28d9bdebff934 Mon Sep 17 00:00:00 2001 From: Jacquin Antoine Date: Sun, 10 May 2026 11:42:21 +0200 Subject: [PATCH] Fix crash quand valid_data est vide dans _apply_colormap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lidar_pipeline/rendering.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lidar_pipeline/rendering.py b/lidar_pipeline/rendering.py index eaae0c0..626ce34 100644 --- a/lidar_pipeline/rendering.py +++ b/lidar_pipeline/rendering.py @@ -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()