Overview
The terrain engine provides real topographic horizon profile computation by loading ICGC 5×5 DEM tiles (ESRI ASCII Grid .txt), caching them as .npy files, and computing multi-band horizon silhouettes via raycasting with Earth curvature correction.Constants
Earth radius in meters used for curvature correction
Functions
generate_bands
Zones
- Near zone (0 → 5km): 2/3 of the N bands. Captures foreground detail (hills, cliffs, passes).
- Far zone (5km → max): 1/3 of the N bands. Represents atmospheric haze with fewer bands.
Total number of bands
- 10 = Low quality
- 20 = Normal quality
- 40 = High quality
- 60 = Ultra quality
- 80 = Extreme quality
Maximum calculation distance in meters
Returns
List of dictionaries with:id(str): Band identifier (e.g., “gnd_0_71”, “near_144_208”, “far_25k_38k”)min(float): Minimum distance in metersmax(float): Maximum distance in meters
Example
bake_and_save
Observer latitude (WGS84)
Observer longitude (WGS84)
Directory containing DEM tiles
Path to save the .npz profile file
Maximum raycasting distance in meters
Raycasting step size in meters
Azimuth resolution in degrees
Observer eye height above ground in meters
Optional custom band definitions. If None, uses DEFAULT_BANDS (20 bands)
Returns
HorizonProfile object containing the baked profile data.load_profile
Path to the .npz profile file
Returns
HorizonProfile object or None if the file is missing or invalid.Classes
HorizonProfile
Serializable horizon profile result.Attributes
Array of azimuths in degrees (0-360), shape (N,)
List of band dictionaries, each containing:
id(str): Band identifierangles(np.ndarray): Elevation angles in radiansdists(np.ndarray): Distances in metersheights(np.ndarray): Terrain heights in meters
Observer latitude in degrees
Observer longitude in degrees
Light pollution dome values per azimuth
Distances of maximum light source per azimuth
Methods
get_band_points
Band identifier (e.g., “near_144_208”)
save
Output file path
load (static)
Path to the .npz file
HorizonBaker
Raycasts from observer position to compute horizon elevation angles. When a ray exits available DEM coverage, it stops and keeps whatever silhouette data was already gathered.Constructor
DEM elevation provider with get_elevation(x, y) method
Observer eye height above ground in meters
Earth radius in meters for curvature correction
Methods
bake
Observer X coordinate in projected CRS (e.g., UTM)
Observer Y coordinate in projected CRS
Observer ground elevation. If None, sampled from DEM
Initial raycasting step size in meters. Adaptive stepping is used: starts at 0.5m, grows to step_m, then multiplies for distant ranges
Maximum raycasting distance in meters
Azimuth resolution in degrees
Custom band definitions. If None, uses DEFAULT_BANDS
Optional callback(percent: int, msg: str) for progress updates
Optional light pollution sampler with get_radiance_utm(x, y) method
Optional callable() -> bool to check for abort requests
TileIndex
Indexes DEM tiles by bounding box in projected coordinates.Constructor
Directory containing DEM tiles
File patterns to search for
Optional progress callback(current, total, message)
Attributes
List of indexed tile dictionaries with ‘path’, ‘header’, and ‘bbox’
Global bounding box [xmin, ymin, xmax, ymax] covering all tiles
Methods
find_tile
get_overlapping_tiles
Center X coordinate
Center Y coordinate
Search radius in meters
TileCache
LRU cache for loaded DEM grids with .npy binary caching on disk. Thread-safe.Constructor
Maximum number of tiles to keep in memory
Methods
load
Tile dictionary from TileIndex with ‘path’ and ‘header’ keys
DemSampler
Samples elevation from DEM tiles with bilinear interpolation.Constructor
TileIndex instance for finding tiles
TileCache instance for loading tiles
Methods
sample / get_elevation
X coordinate in projected CRS
Y coordinate in projected CRS
transform_coordinates_inverse
UTM X coordinate
UTM Y coordinate