Precipitation Downloader Module
Download precipitation data for rainfall-weighted flow accumulation.
This module provides functions to download precipitation data (e.g., PRISM) for use in hydrological analysis. Precipitation data enables rainfall-weighted flow accumulation, which produces more realistic discharge estimates than simple cell-count accumulation.
API Reference
Precipitation data downloader module.
Downloads and manages precipitation data from various sources (PRISM, WorldClim, etc.) for hydrological analysis and terrain visualization.
Supports: - PRISM (Parameter-elevation Regressions on Independent Slopes Model) - WorldClim (global climate data) - CHELSA (high-resolution climate data)
- src.terrain.precipitation_downloader.download_precipitation(bbox, output_dir, dataset='prism', force_download=False, use_real_data=True)[source]
Download precipitation data for bounding box.
- Parameters:
bbox (tuple) – Bounding box (min_lat, min_lon, max_lat, max_lon) in WGS84
output_dir (str) – Directory to save downloaded data
dataset (str, default 'prism') – Dataset to download (‘prism’, ‘worldclim’, ‘chelsa’)
force_download (bool, default False) – Force re-download even if cached
use_real_data (bool, default True) – If True, download real data from servers. If False, generate synthetic data for testing.
- Returns:
Path to downloaded precipitation GeoTIFF
- Return type:
Path
- Raises:
ValueError – If bbox is invalid or dataset not supported
- src.terrain.precipitation_downloader.download_real_worldclim_annual(bbox, output_dir)[source]
Download real WorldClim annual precipitation data.
WorldClim provides global climate data at ~4.5km resolution (2.5 arc-minutes). This function downloads BIO12 (annual precipitation) for the specified bbox.
Uses 2.5m resolution instead of 30s for reasonable download size (~10MB vs 9.7GB).
- src.terrain.precipitation_downloader.download_real_worldclim_30s_annual(bbox, output_dir)[source]
Download real WorldClim 30-second (~1km) annual precipitation data.
Downloads monthly precipitation data and sums to annual total. File size: ~1GB download for global coverage.
- src.terrain.precipitation_downloader.download_real_prism_annual(bbox, output_dir)[source]
Download real PRISM annual precipitation data from FTP server.
IMPORTANT: PRISM only covers continental USA. For areas outside USA (e.g., Mexico, Canada), use WorldClim instead via download_real_worldclim_annual().
- src.terrain.precipitation_downloader.get_prism_annual_precip(bbox, output_dir, use_real_data=False)[source]
Download PRISM annual precipitation for bounding box.
By default, creates synthetic orographic precipitation model for testing. Set use_real_data=True to download actual PRISM data from Oregon State servers.
- Parameters:
- Returns:
np.ndarray – Precipitation data (mm/year)
Affine – Geographic transform
- Return type:
- src.terrain.precipitation_downloader.validate_precipitation_alignment(dem, precip, dem_shape=None, dem_crs=None, precip_crs=None)[source]
Validate that precipitation data aligns with DEM.
- Parameters:
- Raises:
ValueError – If shapes or CRS don’t match
- Return type:
None
See Also
Flow Pipeline Module - Flow computation pipeline using precipitation
Flow Accumulation Module - Upstream rainfall weighting