Terrain¶
- clear_localdem_cache(confirm=True)[source]¶
Clears the local DEM cache directory.
This removes all files in the ‘localdem’ subdirectory of the cache root, which stores downloaded DEM tiles.
- Parameters:
confirm (bool) – If True, prompt the user for confirmation before clearing the cache.
- build_tile_index(tile_list_file)[source]¶
Build an R-tree spatial index for DEM tiles from a tile list file.
Each line in the file is a tile name encoding lat/lon in the filename. Tiles are parsed into 1x1 degree bounding boxes and indexed spatially.
- download_dem_files(lon_min, lat_min, lon_max, lat_max, aws_dir)[source]¶
Download DEM tile files covering a geographic bounding box.
Tiles are downloaded from the specified AWS directory and cached locally. Already-downloaded tiles are reused from the cache.
- Parameters:
- Returns:
List of local file paths to the downloaded DEM tiles.
- Return type:
List[str]
- merge_tiles(output_filename, tile_file_list)[source]¶
Merge multiple DEM tile files into a single GeoTIFF using GDAL Warp.
- Parameters:
- Raises:
ValueError – If tile_file_list is empty or contains invalid paths.
RuntimeError – If GDAL merge operation fails.
- generate_demfile(latitude, longitude, aws_dir='https://copernicus-dem-30m.s3.amazonaws.com/')[source]¶
Generate a DEM file covering the specified latitude and longitude extents.
- get_elevations(lats, lons, dem_file)[source]¶
Extract elevation values for given latitudes and longitudes from a DEM file.
Reads the entire raster band once and indexes it in bulk, rather than querying pixel-by-pixel, for efficient batch lookups.
- get_min_max_elevations(dem_file)[source]¶
Get the minimum and maximum elevation values from a DEM file.
- ray_terrain_intersection(lat0, lon0, h0, az, tilt, precision=10.0, dem_file=None)[source]¶
Batch computation of ray-terrain intersections using a DEM for multiple observer positions. Vectorized to handle multiple observers efficiently.
- Parameters:
lat0 (np.ndarray) – Array of observer latitudes (degrees).
lon0 (np.ndarray) – Array of observer longitudes (degrees).
h0 (float) – Altitude of the observer above the ellipsoid (meters).
az (np.ndarray) – Azimuth angle of the ray (degrees).
tilt (np.ndarray) – Tilt angle of the ray below horizontal (degrees, 0–90).
precision (float) – Precision of the slant range sampling (meters).
dem_file (str) – Path to the DEM file. If None, one will be generated.
- Returns:
- (intersection_lats, intersection_lons,
intersection_alts). Observers with no terrain intersection have NaN in all three arrays.
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray]
- Raises:
ValueError – If tilt or azimuth values are out of range, or if tilt is too close to horizontal (±90°) where slant-range geometry is undefined.