"""Shared fixtures for LiDAR pipeline tests.""" import numpy as np import rasterio from rasterio.transform import from_bounds import pytest from pathlib import Path @pytest.fixture def tmp_output_dir(tmp_path): """Create a temporary output directory.""" out = tmp_path / "output" out.mkdir() return out @pytest.fixture def synthetic_dem(tmp_path): """Create a small synthetic DEM GeoTIFF with realistic terrain features. Includes: - A gaussian hill (tumulus) - A linear ridge (wall) - A depression (ditch) - Background noise """ size = 200 x = np.linspace(0, 1000, size) y = np.linspace(0, 1000, size) X, Y = np.meshgrid(x, y) # Base terrain with gentle slope dem = 100.0 + 0.01 * X + 0.005 * Y # Gaussian hill (tumulus) at center dem += 5.0 * np.exp(-((X - 500)**2 + (Y - 500)**2) / (2 * 80**2)) # Linear ridge (wall) running SW-NE dist_to_wall = np.abs((X - 200) * 0.707 + (Y - 300) * 0.707) / np.sqrt(2) dem += 1.5 * np.exp(-dist_to_wall**2 / (2 * 10**2)) # Depression (ditch) dist_to_ditch = np.abs(X - 800) dem -= 2.0 * np.exp(-dist_to_ditch**2 / (2 * 15**2)) * (Y > 300) * (Y < 700) # Small random noise rng = np.random.default_rng(42) dem += rng.normal(0, 0.05, dem.shape) # Save as GeoTIFF (Lambert 93) dem_file = tmp_path / "test_dem.tif" transform = from_bounds(660000, 6700000, 661000, 6701000, size, size) with rasterio.open( dem_file, 'w', driver='GTiff', height=size, width=size, count=1, dtype='float32', crs='EPSG:2154', transform=transform, compress='lzw' ) as dst: dst.write(dem.astype('float32'), 1) return dem_file @pytest.fixture def synthetic_dem_data(synthetic_dem): """Return (array, transform, crs) from the synthetic DEM.""" with rasterio.open(synthetic_dem) as src: return src.read(1), src.transform, src.crs