Add web map with zone generation API, side job queue, and restore historical DTM hole rendering

- webapp.py: FastAPI serving the continuous map (port 8973) with
  /api/preview, /api/generate and /api/status; tiles are downloaded
  from IGN and processed in a logged subprocess, tracked live in a
  side "File de génération" panel that survives page reloads
- fetch_ign.py: download missing 1 km LiDAR HD tiles from the IGN
  geoplateforme before processing
- index.py: tile thumbnails and 500 m subtiles are now invalidated by
  mtime so regenerating a tile refreshes its cached images; progress
  logging per tile
- dtm.py: back to the historical gap handling (small gaps filled by
  fillnodata only, larger holes left as nodata rendered black);
  lowest-return floor only via --bare-earth, IGN class selection via
  --ign-classes
- cli.py: positional input now optional (--rebuild-index works alone)
- docker-compose.yml: serve (GPU, port 8973) and process services;
  launch via docker compose only (documented in AGENTS.md/AGENTS.md)
- tests: 131 passing, incl. regressions for thumbnail staleness,
  --rebuild-index without input, and nodata rendering
This commit is contained in:
Antoine Jacquin
2026-08-31 18:07:14 +02:00
parent 35bd827790
commit 8ca65155db
19 changed files with 3676 additions and 771 deletions

View File

@ -0,0 +1,81 @@
"""Tests du serveur web de génération de zones (webapp)."""
def test_bbox_to_cells_single_km_cell():
"""Une bbox couvrant ~1 km² retourne la cellule L93 correspondante."""
from lidar_pipeline.webapp import bbox_to_cells
# Cellule 1054,6882 : X∈[1054000,1055000], Y∈[6881000,6882000] (L93)
from rasterio.warp import transform as warp_transform
lons, lats = warp_transform('EPSG:2154', 'EPSG:4326',
[1054100, 1054900], [6881100, 6881900])
cells = bbox_to_cells(min(lons), min(lats), max(lons), max(lats))
assert (1054, 6882) in cells
# La sélection reste locale : pas de cellule lointaine
for (c, r) in cells:
assert abs(c - 1054) <= 1 and abs(r - 6882) <= 1
def test_bbox_to_cells_empty_for_tiny_bbox():
"""Une bbox quasi ponctuelle ne sélectionne rien (rétrécie sous 1 m)."""
from lidar_pipeline.webapp import bbox_to_cells
assert bbox_to_cells(7.850000, 48.930000, 7.850001, 48.930001) == []
def test_processed_cells(tmp_path):
"""processed_cells lit les dossiers de visualisations."""
from lidar_pipeline.webapp import processed_cells
vis = tmp_path / "visualisations" / "LHD_FXX_1054_6882_PTS_LAMB93_IGN69_r0p2"
vis.mkdir(parents=True)
(vis / "LHD_FXX_1054_6882_PTS_LAMB93_IGN69_r0p2_aspect.avif").write_bytes(b"x")
assert processed_cells(tmp_path) == {(1054, 6882)}
def test_missing_cells_filters_processed(tmp_path):
"""Les cellules déjà traitées sont exclues, les autres gardent leurs coins."""
from lidar_pipeline.webapp import missing_cells_with_corners
vis = tmp_path / "visualisations" / "LHD_FXX_1054_6882_PTS_LAMB93_IGN69"
vis.mkdir(parents=True)
(vis / "LHD_FXX_1054_6882_PTS_LAMB93_IGN69_aspect.avif").write_bytes(b"x")
todo = missing_cells_with_corners([(1054, 6882), (1055, 6882)], tmp_path)
assert len(todo) == 1
assert todo[0]['col'] == 1055 and todo[0]['row'] == 6882
assert len(todo[0]['corners']) == 4 # SW, SE, NE, NW
def test_missing_cells_include_done(tmp_path):
"""include_done=True conserve les cellules déjà traitées (régénération)."""
from lidar_pipeline.webapp import missing_cells_with_corners
vis = tmp_path / "visualisations" / "LHD_FXX_1054_6882_PTS_LAMB93_IGN69"
vis.mkdir(parents=True)
(vis / "LHD_FXX_1054_6882_PTS_LAMB93_IGN69_aspect.avif").write_bytes(b"x")
todo = missing_cells_with_corners([(1054, 6882), (1055, 6882)], tmp_path,
include_done=True)
assert {(t['col'], t['row']) for t in todo} == {(1054, 6882), (1055, 6882)}
def test_build_command_regenerate():
"""regenerate=True ajoute --force --force-classification à la commande."""
from lidar_pipeline.webapp import _build_command
cmd = " ".join(_build_command([(1054, 6882)], regenerate=True))
assert "--force" in cmd
assert "--force-classification" in cmd
cmd = " ".join(_build_command([(1054, 6882)]))
assert "--force" not in cmd
assert "--force-classification" not in cmd
def test_build_command_ground_classification():
"""La commande utilise la méthode de classification demandée (défaut : ign)."""
from lidar_pipeline.webapp import _build_command, GROUND_CLASS_METHODS
# Défaut : ign (pré-classification)
cmd = _build_command([(1054, 6882)])
i = cmd.index("--ground-classification")
assert cmd[i + 1] == "ign"
# Chaque méthode valide est transmise telle quelle, avec ou sans régénération
for method in GROUND_CLASS_METHODS:
for regenerate in (False, True):
cmd = _build_command([(1054, 6882)], regenerate=regenerate, ground_class=method)
i = cmd.index("--ground-classification")
assert cmd[i + 1] == method
assert ("--force" in cmd) == regenerate
assert ("--force-classification" in cmd) == regenerate