prepare: add index module, update pipeline, tests, Dockerfile, and run.sh
This commit is contained in:
@ -16,7 +16,7 @@ from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import rasterio
|
||||
from .gpu import HAS_GPU, to_gpu, to_cpu, xp_gaussian_filter, xp_uniform_filter, xp_minimum_filter, xp_maximum_filter, gpu_cleanup
|
||||
from .gpu import to_gpu, to_cpu, xp_gaussian_filter, xp_uniform_filter, gpu_cleanup
|
||||
from . import gpu as _gpu_mod
|
||||
|
||||
logger = logging.getLogger("lidar")
|
||||
@ -37,7 +37,6 @@ class _XPProxy:
|
||||
|
||||
def __getattr__(self, name):
|
||||
global _cp
|
||||
from . import gpu as _gpu_mod
|
||||
if _gpu_mod.HAS_GPU:
|
||||
if _cp is None:
|
||||
try:
|
||||
@ -272,20 +271,21 @@ def _filter_nanaware(arr, filter_func, *args, use_gpu=True, **kwargs):
|
||||
def _prepare_dem_for_raycast(dem_file, shared, resolution):
|
||||
"""Load DEM and prepare padded array for ray-tracing.
|
||||
|
||||
Returns (dem_gpu_or_cpu, dem_np, rows, cols, res, nan_mask,
|
||||
transform, crs, padded) ready for ray-tracing.
|
||||
Returns (dem_filled, dem_np, rows, cols, res, nan_mask,
|
||||
transform, crs) ready for ray-tracing.
|
||||
dem_filled is a CPU numpy array (filled, no NaN).
|
||||
"""
|
||||
if shared:
|
||||
dem_np = shared.dem_np
|
||||
nan_mask = shared.nan_mask
|
||||
transform = shared.transform
|
||||
crs = shared.crs
|
||||
dem = to_gpu(shared.filled) if _gpu_mod.HAS_GPU else shared.filled
|
||||
dem = shared.filled
|
||||
else:
|
||||
dem_np, transform, crs = _read_dem(dem_file)
|
||||
nan_mask = np.isnan(dem_np)
|
||||
filled, _ = _fill_nans(dem_np)
|
||||
dem = to_gpu(filled) if _gpu_mod.HAS_GPU else filled
|
||||
dem = filled
|
||||
res = resolution
|
||||
rows, cols = dem_np.shape
|
||||
return dem, dem_np, rows, cols, res, nan_mask, transform, crs
|
||||
@ -304,7 +304,7 @@ def _ray_trace_horizons(dem, rows, cols, res, n_dirs, max_dist, radii_m=None):
|
||||
processed and results are streamed back to CPU.
|
||||
|
||||
Args:
|
||||
dem: GPU or CPU filled DEM array (rows, cols).
|
||||
dem: CPU numpy array — filled DEM (no NaN), shape (rows, cols).
|
||||
rows, cols: dimensions.
|
||||
res: resolution in m/px.
|
||||
n_dirs: number of directions.
|
||||
@ -329,13 +329,14 @@ def _ray_trace_horizons(dem, rows, cols, res, n_dirs, max_dist, radii_m=None):
|
||||
|
||||
# Pad on CPU (numpy) — avoids GPU memory pressure and
|
||||
# pre-compiled kernel issues (NO_BINARY_FOR_GPU on sm_89).
|
||||
dem_np = to_cpu(dem)
|
||||
padded_np = np.pad(dem_np, max_dist, mode='constant', constant_values=np.nan)
|
||||
padded_np = np.pad(dem, max_dist, mode='constant', constant_values=np.nan)
|
||||
|
||||
# Transfer padded DEM to GPU for computation
|
||||
padded = to_gpu(padded_np)
|
||||
# GPU view of central region — reference elevation for ray-tracing
|
||||
dem = padded[max_dist:max_dist+rows, max_dist:max_dist+cols]
|
||||
# Free the CPU copy — we don't need it anymore
|
||||
del dem_np, padded_np
|
||||
del padded_np
|
||||
|
||||
# Process one direction at a time to limit GPU memory.
|
||||
# Store results as flat CPU arrays — transfer back to GPU at the end.
|
||||
|
||||
Reference in New Issue
Block a user