From 796e68c8707d0538e2af0fe050c0e0baa5cff7d1 Mon Sep 17 00:00:00 2001 From: Antoine Jacquin Date: Fri, 18 Sep 2026 21:31:19 +0200 Subject: [PATCH] =?UTF-8?q?Supprimer=20le=20code=20mort=20(imports=20inuti?= =?UTF-8?q?lis=C3=A9s,=20variable=20=5Fxp,=20conseil=20GPU=20inatteignable?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lidar_pipeline/cli.py | 2 -- lidar_pipeline/dtm.py | 2 +- lidar_pipeline/gpu.py | 11 ++--------- lidar_pipeline/ign.py | 1 - lidar_pipeline/pipeline.py | 7 ++++--- lidar_pipeline/rendering.py | 11 +---------- requirements.txt | 1 - 7 files changed, 8 insertions(+), 27 deletions(-) diff --git a/lidar_pipeline/cli.py b/lidar_pipeline/cli.py index c58457f..f74f671 100644 --- a/lidar_pipeline/cli.py +++ b/lidar_pipeline/cli.py @@ -5,8 +5,6 @@ Handles argument parsing, logging configuration, and entry point. import argparse import logging -import os -import shutil import signal import sys diff --git a/lidar_pipeline/dtm.py b/lidar_pipeline/dtm.py index b57e3f4..c65aee1 100644 --- a/lidar_pipeline/dtm.py +++ b/lidar_pipeline/dtm.py @@ -457,7 +457,7 @@ def classify_ground(laz_file, temp_dir, method='auto', force=False, ign_classes= Returns: Path to classified ground LAS file, or None on failure. """ - import laspy # noqa: ensure available + import laspy # Auto-detect method if requested if method == 'auto': diff --git a/lidar_pipeline/gpu.py b/lidar_pipeline/gpu.py index 50c2efa..fe8d0a2 100644 --- a/lidar_pipeline/gpu.py +++ b/lidar_pipeline/gpu.py @@ -80,7 +80,6 @@ except Exception: # --------------------------------------------------------------------------- # Lazy CuPy initialization — tries each GPU until one works # --------------------------------------------------------------------------- -_xp = np _cp = None _cp_ndimage = None _cupy_ndarray = None # type ref qui survit à disable_gpu() pour que to_cpu() récupère les tableaux orphelins @@ -154,7 +153,7 @@ def _init_gpu(): import CuPy directly (no subprocess test needed) 3. Otherwise: test each GPU in a subprocess, pick the first that works """ - global _xp, _cp, _cp_ndimage, _cupy_ndarray, _gpu_initialized, HAS_GPU, _best_gpu_id, _gpu_name, _gpu_mem_gb + global _cp, _cp_ndimage, _cupy_ndarray, _gpu_initialized, HAS_GPU, _best_gpu_id, _gpu_name, _gpu_mem_gb if _gpu_initialized: return _gpu_initialized = True @@ -165,7 +164,6 @@ def _init_gpu(): candidates = _filter_candidates(_runtime_candidates()) if not candidates: logger.info("Pas de GPU utilisable — mode CPU uniquement") - _xp = np _cp = None _cp_ndimage = None HAS_GPU = False @@ -191,14 +189,12 @@ def _init_gpu(): _gpu_name = name _gpu_mem_gb = mem_mi // 1024 HAS_GPU = True - _xp = _real_cupy _cp = _real_cupy _cp_ndimage = _real_cupy_ndimage _cupy_ndarray = _real_cupy.ndarray return except Exception as e: logger.warning(f"GPU indisponible (CUDA_VISIBLE_DEVICES={cuda_visible}): {e}") - _xp = np _cp = None _cp_ndimage = None HAS_GPU = False @@ -230,7 +226,6 @@ def _init_gpu(): if _working_gpu is None: logger.info("Pas de GPU utilisable — mode CPU uniquement") - _xp = np _cp = None _cp_ndimage = None HAS_GPU = False @@ -248,7 +243,6 @@ def _init_gpu(): _gpu_name = name _gpu_mem_gb = mem_mi // 1024 HAS_GPU = True - _xp = _real_cupy _cp = _real_cupy _cp_ndimage = _real_cupy_ndimage _cupy_ndarray = _real_cupy.ndarray @@ -444,13 +438,12 @@ def disable_gpu(): Libère le memory pool GPU avant de nuller les références (anti-fuite VRAM). Garde _cupy_ndarray vivant pour que to_cpu() récupère les tableaux orphelins. """ - global HAS_GPU, _xp, _cp, _cp_ndimage + global HAS_GPU, _cp, _cp_ndimage if not HAS_GPU: return logger.warning("GPU désactivé — passage en mode CPU pour la suite du processus") gpu_cleanup() HAS_GPU = False - _xp = np _cp = None _cp_ndimage = None diff --git a/lidar_pipeline/ign.py b/lidar_pipeline/ign.py index f7c410d..2c9a987 100644 --- a/lidar_pipeline/ign.py +++ b/lidar_pipeline/ign.py @@ -7,7 +7,6 @@ GeoTIFF overlays matching the LiDAR DTM extent. import logging import math import time -from pathlib import Path import numpy as np import rasterio diff --git a/lidar_pipeline/pipeline.py b/lidar_pipeline/pipeline.py index 510deb5..444521d 100644 --- a/lidar_pipeline/pipeline.py +++ b/lidar_pipeline/pipeline.py @@ -243,7 +243,6 @@ class LidarArchaeoPipeline: needs_generation[name] = not expected_webp.exists() to_generate = [n for n, needed in needs_generation.items() if needed] - ign_only = all(name in ('ortho', 'topo') for name in to_generate) needs_shared = any(name not in ('ortho', 'topo') for name in to_generate) if not to_generate: @@ -574,8 +573,6 @@ class LidarArchaeoPipeline: logger.info(f"Traitement parallèle avec {self.workers} workers sur {n_gpus} GPUs...") else: logger.info(f"Traitement parallèle avec {self.workers} workers...") - if n_gpus > 1 and self.workers == 1: - logger.info(f"Conseil: utilisez -w {n_gpus} pour exploiter tous les GPUs") logger.info(f"Fichiers: {len(files)}") with ProcessPoolExecutor(max_workers=self.workers) as executor: @@ -624,6 +621,10 @@ class LidarArchaeoPipeline: return else: total = len(files) + if self.workers == 1 and len(files) > 1: + n_gpus = num_gpus() or 1 + if n_gpus > 1: + logger.info(f"Conseil : utilisez -w {n_gpus} pour exploiter tous les GPUs") for idx, laz_file in enumerate(files, 1): logger.info(f"--- Fichier {idx}/{total} ---") try: diff --git a/lidar_pipeline/rendering.py b/lidar_pipeline/rendering.py index ae3d410..3dc1ecb 100644 --- a/lidar_pipeline/rendering.py +++ b/lidar_pipeline/rendering.py @@ -28,16 +28,9 @@ import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib import rcParams -from matplotlib.patches import Polygon as MplPolygon, Rectangle as RectPatch, FancyBboxPatch -from matplotlib.colors import ListedColormap +from matplotlib.patches import Polygon as MplPolygon, Rectangle as RectPatch from matplotlib.ticker import ScalarFormatter -try: - from cmcrameri import cm as cmc - HAS_CMCRAmeri = True -except ImportError: - HAS_CMCRAmeri = False - rcParams['figure.dpi'] = 150 rcParams['savefig.dpi'] = 300 rcParams['font.size'] = 10 @@ -284,8 +277,6 @@ def _download_location_map(min_x, max_x, min_y, max_y): Tuple (image_array, bounds_dict) where bounds_dict has keys 'min_x', 'max_x', 'min_y', 'max_y' in Lambert 93, or None on failure. """ - import hashlib - # Cache key based on rounded coordinates (1km grid) cache_key = (round(min_x, -3), round(max_x, -3), round(min_y, -3), round(max_y, -3)) if cache_key in _location_map_cache: diff --git a/requirements.txt b/requirements.txt index bb926e8..046f270 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,6 @@ fastapi>=0.110 uvicorn>=0.29 pydantic>=2.6 pyproj>=3.6 -cmcrameri>=1.8 # Tests (./run.sh --test) pytest>=7.4