Calculate gebco slope
Calculate slope from GEBCO bathymetry/altimetry data.
This script: 1. Reprojects GEBCO data to Mollweide (ESRI:54009) for accurate slope calculation 2. Calculates slope in percent using gdaldem 3. Reprojects slope back to EPSG:4326 for compatibility with atlite
Requires: GDAL (gdalwarp, gdaldem)
calculate_slope(input_gebco, output_slope, threads=4, log_file=None)
Calculate slope from GEBCO data.
The slope is calculated in an equal-area projection (Mollweide/ESRI:54009) to ensure accurate slope values, then reprojected to EPSG:4326 for use with atlite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_gebco
|
Path to input GEBCO GeoTIFF file. |
required | |
output_slope
|
Path to output slope NetCDF file. |
required | |
threads
|
Number of threads for gdalwarp. Default is 4. |
4
|
|
log_file
|
Path to log file for appending command output (optional). |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If input GEBCO file does not exist. |
RuntimeError
|
If any GDAL command fails. |
Source code in workflow/scripts/calculate_gebco_slope.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
check_gdal_availability()
Check if GDAL tools are available in the system.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If required GDAL tools are not found. |
Source code in workflow/scripts/calculate_gebco_slope.py
run_command(cmd, description)
Run a shell command and log the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Shell command to execute. |
required |
description
|
str
|
Human-readable description of the command. |
required |
Returns:
| Type | Description |
|---|---|
|
CompletedProcess instance from subprocess.run. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the command fails (non-zero return code). |
Source code in workflow/scripts/calculate_gebco_slope.py
setup_proj_environment()
Set up PROJ_LIB environment variable for GDAL to find projection database.