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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 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 | |
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.