@mytec: iter3.10 start, baseline rc ready

This commit is contained in:
2026-02-04 15:56:09 +02:00
parent e392b449cc
commit 81e078e92a
17 changed files with 1486 additions and 414 deletions

View File

@@ -277,10 +277,11 @@ class GPUService:
lons: np.ndarray,
terrain_cache: dict,
) -> np.ndarray:
"""Look up elevations from cached terrain tiles.
"""Look up elevations from cached terrain tiles with bilinear interpolation.
Vectorized implementation: processes per-tile (1-4 tiles) instead of
per-point (thousands of points). Inner operations are all NumPy vectorized.
per-point (thousands of points). Uses bilinear interpolation for
sub-meter accuracy (vs 15m error with nearest-neighbor at 30m resolution).
Args:
lats, lons: Flattened arrays of coordinates
@@ -313,16 +314,39 @@ class GPUService:
tile_lons = lons[mask]
size = tile.shape[0]
# Vectorized row/col calculation
rows = ((1 - (tile_lats - lat_int)) * (size - 1)).astype(int)
cols = ((tile_lons - lon_int) * (size - 1)).astype(int)
rows = np.clip(rows, 0, size - 1)
cols = np.clip(cols, 0, size - 1)
# Vectorized lookup - single operation for ALL points in tile
tile_elevs = tile[rows, cols].astype(np.float64)
tile_elevs[tile_elevs == -32768] = 0.0
elevations[mask] = tile_elevs
# Vectorized bilinear interpolation
lat_frac = tile_lats - lat_int
lon_frac = tile_lons - lon_int
row_exact = (1.0 - lat_frac) * (size - 1)
col_exact = lon_frac * (size - 1)
r0 = np.clip(row_exact.astype(int), 0, size - 2)
c0 = np.clip(col_exact.astype(int), 0, size - 2)
r1 = r0 + 1
c1 = c0 + 1
dr = row_exact - r0
dc = col_exact - c0
# Get four corner values for all points at once
z00 = tile[r0, c0].astype(np.float64)
z01 = tile[r0, c1].astype(np.float64)
z10 = tile[r1, c0].astype(np.float64)
z11 = tile[r1, c1].astype(np.float64)
# Bilinear interpolation (vectorized)
result = (z00 * (1 - dr) * (1 - dc) +
z01 * (1 - dr) * dc +
z10 * dr * (1 - dc) +
z11 * dr * dc)
# Handle void values (-32768) - set to 0
void_mask = (z00 == -32768) | (z01 == -32768) | (z10 == -32768) | (z11 == -32768)
result[void_mask] = 0.0
elevations[mask] = result
return elevations