From d9a4ea9a4ea87ab3afd36f3429a42a7e91835490 Mon Sep 17 00:00:00 2001 From: Antoine Jacquin Date: Mon, 7 Sep 2026 21:23:52 +0200 Subject: [PATCH] Add tests for priority-flood numba/Python parity and _strip_lidar_ext --- lidar_pipeline/tests/test_dtm.py | 19 ++++++++++ lidar_pipeline/tests/test_visualizations.py | 41 +++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/lidar_pipeline/tests/test_dtm.py b/lidar_pipeline/tests/test_dtm.py index 72a2ef1..86db990 100644 --- a/lidar_pipeline/tests/test_dtm.py +++ b/lidar_pipeline/tests/test_dtm.py @@ -548,3 +548,22 @@ class TestPureDtm: vals = sorted(float(v) for v in arr.flatten()) assert len(vals) == 4 assert vals[-1] == 10.0 + + +class TestStripLidarExt: + def test_copc_laz(self): + from lidar_pipeline.dtm import _strip_lidar_ext + assert _strip_lidar_ext("LHD_FXX_1000_6881_PTS_LAMB93_IGN69.copc.laz") == "LHD_FXX_1000_6881_PTS_LAMB93_IGN69" + + def test_laz(self): + from lidar_pipeline.dtm import _strip_lidar_ext + assert _strip_lidar_ext("file.laz") == "file" + + def test_las(self): + from lidar_pipeline.dtm import _strip_lidar_ext + assert _strip_lidar_ext("file.las") == "file" + + def test_path_object(self): + from lidar_pipeline.dtm import _strip_lidar_ext + from pathlib import Path + assert _strip_lidar_ext(Path("/data/input/file.copc.laz")) == "file" diff --git a/lidar_pipeline/tests/test_visualizations.py b/lidar_pipeline/tests/test_visualizations.py index 0af1a43..7e0319d 100644 --- a/lidar_pipeline/tests/test_visualizations.py +++ b/lidar_pipeline/tests/test_visualizations.py @@ -326,3 +326,44 @@ def test_ray_trace_horizons_reraises_non_oom(monkeypatch): assert False, "ValueError attendue" except ValueError: pass + + +class TestPriorityFlood: + def test_numba_matches_python(self): + """Le résultat numba et python sont identiques sur un DEM avec un puits.""" + from lidar_pipeline.visualizations import _priority_flood_numba, _priority_flood_python + + dem = np.zeros((20, 20), dtype=np.float64) + dem[10, 10] = -5.0 + dem[9:12, 9:12] = -3.0 + nodata = np.zeros((20, 20), dtype=bool) + + result_numba = _priority_flood_numba(dem.copy(), nodata) + result_python = _priority_flood_python(dem.copy(), nodata) + + if result_numba is not None: + assert np.allclose(result_numba, result_python) + + def test_pit_is_filled(self): + """Un puits isolé est ramené au niveau de son bord.""" + from lidar_pipeline.visualizations import _priority_flood + + dem = np.full((10, 10), 5.0, dtype=np.float64) + dem[5, 5] = 1.0 + nodata = np.zeros((10, 10), dtype=bool) + + result = _priority_flood(dem, nodata) + assert result[5, 5] == 5.0 + + def test_nodata_cells_untouched(self): + """Les cellules nodata ne sont jamais modifiées.""" + from lidar_pipeline.visualizations import _priority_flood + + dem = np.full((10, 10), 5.0, dtype=np.float64) + dem[5, 5] = 1.0 + nodata = np.zeros((10, 10), dtype=bool) + nodata[2, 2] = True + dem[2, 2] = 999.0 + + result = _priority_flood(dem, nodata) + assert result[2, 2] == 999.0