Skip to main content

python interface to the gcn10 executable for curve number generation

Project description

GCN10Py

GCN10py is a Python interface to the high-performance C-based gcn10 executable for generating Curve Number (CN) rasters using MPI. It enables block-based, parallel generation of CN maps from global soil and land cover datasets.


Prerequisites

Ensure the following dependencies are installed and available in your system PATH:

  • gcn10 (compiled C executable with MPI and GDAL)
  • MPI implementation (e.g., MPICH, OpenMPI)
  • GDAL runtime libraries (CLI + C bindings)

Installation

Install via pip:

pip install gcn10py

Note: This package requires a working build of the gcn10 executable, compiled with MPI and GDAL support.


Building from Source

  1. Compile the C binary and place it into:

    src/gcn10py/gcn10      # or gcn10.exe on Windows
    

Follow the instructions here

  1. Install the build tools:

    pip install hatchling
    
  2. Build the wheel package:

    python -m build
    
  3. Install locally for testing:

    pip install dist/gcn10py-0.1.0-py3-none-any.whl
    

Usage

command-line (required -c, optional -l and -o)

  • -c <path>: required. path to the config.txt used by the C backend.
  • -l <path>: optional. text file containing block ids (one per line).
  • -o: optional. overwrite existing outputs.

basic examples:

# minimal: run using config only
gcn10py -c config.txt

# run and overwrite any existing outputs
gcn10py -c config.txt -o

# run a specific block list
gcn10py -c config.txt -l blocks.txt

# run a specific block list and overwrite outputs
gcn10py -c config.txt -l blocks.txt -o

mpi examples:

# 10 mpi processes, config only
mpirun -n 10 gcn10py -c config.txt

# 10 mpi processes, block list + overwrite
mpirun -n 10 gcn10py -c config.txt -l blocks.txt -o

(optional) call the C binary directly:

mpirun -n 10 ./gcn10 -c config.txt -l blocks.txt -o

python api

from gcn10py import run

# run with config only
run(["-c", "config.txt"])

# run with overwrite
run(["-c", "config.txt", "-o"])

# run with a block list
run(["-c", "config.txt", "-l", "blocks.txt"])

# run with a block list and overwrite
run(["-c", "config.txt", "-l", "blocks.txt", "-o"])

you can wrap this in your own scripts, add logging, or integrate with job schedulers.


Generate all 18 rasters for an aoi (yaml-driven execution)

a ready-to-use driver and example config live in the testing/ directory:

  • testing/gcn10_driver.py — orchestrates the full pipeline (discover blocks for your aoi, launch mpi, mosaic, clip)
  • testing/config.yaml — example configuration (aoi, blocks, mpi settings, mosaic patterns, gdal options)
  • test data under testing/ for quick validation

run it like this:

# from the project root
cd testing
python gcn10_driver.py -y config.yaml

# or make it executable
chmod a+x gcn10_driver.py
./gcn10_driver.py -y testing/config.yaml

what it does:

  • reads your aoi (gpkg/shp)
  • finds intersecting block ids from esa_extent_blocks.shp (or uses a provided list)
  • launches gcn10 via mpi (or uses the python api) to generate per-block cn rasters
  • mosaics each of the 18 combinations (hc × arc × drainage) and clips to the aoi
  • writes all 18 final geotiffs to the output directory defined in the yaml

notes:

  • the driver normalizes paths to absolute and runs with cwd set to the directory of config.txt so relative paths inside the config resolve consistently
  • set run.cli_cmd: gcn10 or copy the gcn10 in testing/config.yaml if you prefer calling the C binary directly

Project Structure

gcn10py/
├── LICENSE
├── README.md
├── pyproject.toml
├── src/
│   └── gcn10py/
│       ├── __init__.py
│       ├── cli.py
│       └── gcn10         # compiled C executable (excluded from repo)
└── testing/
    └── gcn10_driver.py
    

Testing & Benchmarks

testing

  • unit tests (if provided) under tests/:
    pytest -q
    
  • functional check:
    • edit testing/config.yaml to point to your AOI and inputs
    • run testing/gcn10_driver.py -y testing/config.yaml
    • verify 18 outputs appear in io.output_dir

benchmarks (reference)

measured on:

OS: Slackware 15.0+, x86_64
Kernel: 6.12.39
CPU: Intel(R) Core(TM) Ultra 7 165U
CPU(s): 14
Memory: 64 GiB
  • gcn10 C binary: 4 blocks, 4 MPI processes → 4 min 15 s
  • gcn10py CLI (python wrapper only): same 4 blocks → 5 min 40 s
  • YAML driver (same 4 blocks) + build VRTs + 18 mosaics clipped to AOI → 6 min 34 s
    (GDAL threads: GDAL_NUM_THREADS=ALL_CPUS, creation options: TILED=YES, COMPRESS=LZW, BIGTIFF=YES)

performance will vary with I/O bandwidth, MPI binding, GDAL config, OS and most importantly internet connection. For best performance, use linux native utilities.


License

Copyright (C) 2025
Abdullah Azzam (mabdazzam)

Released under the GNU General Public License v3.0.
See the LICENSE file for full terms.


Contact

Questions, bug reports, or contributions? Open an issue or pull request on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcn10py-0.1.0.tar.gz (164.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcn10py-0.1.0-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file gcn10py-0.1.0.tar.gz.

File metadata

  • Download URL: gcn10py-0.1.0.tar.gz
  • Upload date:
  • Size: 164.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for gcn10py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 277e2e19705abb451f1fdfa9fb6c7bca808aa92f9c44f384e64227364f1434c8
MD5 d3fc46f826316606cd5dd2992eb26e92
BLAKE2b-256 6eaa7bf79bbbfe5587e90028d83f15e7a52cc08ca9b1fead5e4c7f7d2aee6aa4

See more details on using hashes here.

File details

Details for the file gcn10py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gcn10py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for gcn10py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd4f55011f04cc504edf4faac4fe6e77f82537327c67d8fd7ab922950d25c61c
MD5 04e7c66e1a62e37d30d64eb32d5d4c02
BLAKE2b-256 1d903ae14d4b675329fbed7d64ee5645a499755434ca33e5f7192652f5df5e70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page