Spaces:
Sleeping
Sleeping
Download src/utils/geo.py from Harshilforworks/Forcast: direct link, hf CLI and curl.
- Browser
- Download file 397 Bytes
-
https://huggingface.co/spaces/Harshilforworks/Forcast/resolve/main/src/utils/geo.py
- Command line
-
hf download hf://spaces/Harshilforworks/Forcast/src/utils/geo.py
-
curl -L -o geo.py https://huggingface.co/spaces/Harshilforworks/Forcast/resolve/main/src/utils/geo.py
397 Bytes
| from __future__ import annotations | |
| import numpy as np | |
| def slope_from_dem_numpy(dem: np.ndarray, pixel_size_m: float = 10.0) -> np.ndarray: | |
| """Approximate terrain slope (degrees) from DEM using finite differences.""" | |
| dz_dy, dz_dx = np.gradient(dem, pixel_size_m, pixel_size_m) | |
| slope_rad = np.arctan(np.sqrt(dz_dx**2 + dz_dy**2)) | |
| return np.degrees(slope_rad).astype(np.float32) | |