Skip to content

Add HSAE adapter: Transboundary Water Law Compliance tools for 26 river basins #78

@saifeldinkhedir-coder

Description

@saifeldinkhedir-coder

Summary

This issue proposes adding a new package adapter for the HydroSovereign AI Engine (HSAE) — a free, open-source Python package and QGIS plugin that automates satellite-based compliance assessment for transboundary river basins under the UN Watercourses Convention 1997 (UNWC).

Prof. Wu kindly responded to my outreach email and suggested submitting a pull request. I am opening this issue first to confirm the integration approach before writing the code, so the PR follows your contributing guidelines precisely.


What HSAE does

HSAE integrates 9 Google Earth Engine satellite sensors (GPM IMERG, GRACE-FO, SMAP, Sentinel-1/2, GloFAS ERA5 v4, Open-Meteo, MODIS, VIIRS) with an HBV-96 rainfall-runoff model and 6 original hydro-governance indices, producing legally interpretable compliance assessments in under 2 minutes per basin.

Key validated results for the Blue Nile (GERD):

  • ATDI = 43.5% → Article 7 UNWC triggered
  • HIFD = 20.0% → 20% downstream flow withheld
  • NSE = 0.63, KGE = 0.74 (pre-calibration vs GloFAS ERA5 v4)
  • AI negotiation engine trained on 478 historical TFDD/ICJ cases (GBM accuracy: 71.4%)

Platform:


The 6 Original HSAE Hydro-Governance Indices

All 6 indices are fully implemented, tested (56 pytest), and scientifically validated:

# Index Formula Source module
1 ATDI — Alkhedir Transparency Deficit Index mean(TDI) × 100 [%] hsae_tdi.py
2 AFSF — Alkhedir Forensic Signal Factor max(rolling₃₀(TDI)) × 100 [%] hsae_tdi.py
3 AHIFD — Alkhedir Human-Induced Flow Deficit flow withheld downstream [%] conflict_index.py
4 ATCI — Alkhedir Treaty Compliance Index GBM composite score [0–100] negotiation_ai.py
5 CI — Composite Conflict Index 0.40·TDI + 0.20·N_states + 0.25·dispute + 0.15·UN_articles [0–100] conflict_index.py
6 ADTS — Alkhedir Digital Transparency Score 100 − ATDI [%] hsae_v990.py

Canonical TDI formula (Alkhedir 2026):

I_adj  = max(0, I_in − α·(ET_PM + ET_MODIS))    α = 0.30
TDI    = max(0, (I_adj − Q_out) / (I_adj + ε))   ε = 0.001 BCM/day
ATDI   = mean(TDI) × 100                          [%]
AFSF   = max(rolling₃₀(TDI)) × 100               [% peak — legal trigger]
ADTS   = 100 − ATDI                               [% transparency achieved]

Proposed GeoAgent integration

8 tools via @geo_tool decorator — one per index + 2 composite tools:

# geoagent/tools/hsae.py

@geo_tool(category="hydrology",
          description="Run full HSAE compliance analysis on a transboundary river basin")
def analyze_basin_compliance(basin_name: str) -> dict:
    """Analyze UNWC 1997 compliance for a named basin (e.g. 'Blue Nile', 'Mekong').
    Returns all 6 indices + legal status + triggered UN articles."""
    ...

# ── Index 1: ATDI ─────────────────────────────────────────────────────────────
@geo_tool(category="hydrology",
          description="Compute Alkhedir Transparency Deficit Index (ATDI) — primary legal index")
def compute_atdi(basin_name: str) -> float:
    """ATDI = mean(TDI) × 100 [%]. Triggers Art.7 UNWC when ATDI ≥ 40%."""
    ...

# ── Index 2: AFSF ─────────────────────────────────────────────────────────────
@geo_tool(category="hydrology",
          description="Compute Alkhedir Forensic Signal Factor (AFSF) — peak legal trigger")
def compute_afsf(basin_name: str) -> float:
    """AFSF = max(rolling₃₀(TDI)) × 100 [%].
    Captures worst-case 30-day deficit window — used in ICJ dossier evidence."""
    ...

# ── Index 3: AHIFD ────────────────────────────────────────────────────────────
@geo_tool(category="hydrology",
          description="Compute Alkhedir Human-Induced Flow Deficit (AHIFD) — downstream harm")
def compute_ahifd(basin_name: str) -> float:
    """AHIFD = % of natural downstream flow withheld by upstream operations.
    Blue Nile (GERD) = 20.0% — exceeds Art.5 equitable utilization threshold."""
    ...

# ── Index 4: ATCI ─────────────────────────────────────────────────────────────
@geo_tool(category="hydrology",
          description="Compute Alkhedir Treaty Compliance Index (ATCI) — institutional score")
def compute_atci(basin_name: str) -> float:
    """ATCI = GBM-derived composite score [0–100] combining treaty ratification,
    data-sharing behavior, and institutional cooperation indicators.
    Blue Nile (GERD) = 70% — partial compliance with UNWC obligations."""
    ...

# ── Index 5: CI ───────────────────────────────────────────────────────────────
@geo_tool(category="hydrology",
          description="Compute HSAE Composite Conflict Index (CI) — multi-factor risk score")
def compute_conflict_index(basin_name: str) -> dict:
    """CI = 0.40·TDI_score + 0.20·N_states + 0.25·dispute_level + 0.15·UN_articles.
    Returns score [0–100], level (MINIMAL/LOW/MEDIUM/HIGH/CRITICAL),
    triggered UN articles, and relevant ICJ/TFDD precedents.
    Blue Nile (GERD): CI = 44 → HIGH."""
    ...

# ── Index 6: ADTS ─────────────────────────────────────────────────────────────
@geo_tool(category="hydrology",
          description="Compute Alkhedir Digital Transparency Score (ADTS) — positive compliance metric")
def compute_adts(basin_name: str) -> float:
    """ADTS = 100 − ATDI [%]. Measures data-sharing achievement under Art.9 UNWC.
    Complementary framing to ATDI — useful for reporting cooperative basins."""
    ...

# ── Composite tool 1: UNWC compliance screen ─────────────────────────────────
@geo_tool(category="hydrology",
          description="Run UNWC 1997 compliance screen for all 10 key obligations")
def run_unwc_compliance(basin_name: str) -> dict:
    ...

# ── Composite tool 2: AI negotiation recommendation ──────────────────────────
@geo_tool(category="hydrology",
          description="Get AI-based negotiation pathway recommendation (Art.17 vs Art.33)",
          confirmation_required=True)
def get_negotiation_recommendation(basin_name: str) -> dict:
    """Returns P(Negotiation) [%], recommended pathway (Art.17 vs Art.33),
    and precedent cases from 478 TFDD/ICJ training cases.
    Blue Nile (GERD): P(Negotiation) = 58%."""
    ...

Example natural language trigger in QGIS:

"Analyze Blue Nile GERD compliance"
→ GeoAgent calls analyze_basin_compliance("Blue Nile")
→ Returns all 6 indices: ATDI=43.5%, AFSF=peak, AHIFD=20%, ATCI=70%, CI=44 HIGH, ADTS=56.5%
→ Legal conclusion: Art. 5 + 7 triggered → Art.33 dispute resolution recommended
→ Renders compliance map on QGIS canvas


Why this fits GeoAgent

  • HSAE uses GEE — the same infrastructure as geemap and leafmap — making it a natural fit for the opengeos ecosystem
  • All 6 indices are modular Python functions — ready for @geo_tool registration
  • Adds a legal compliance layer not currently present in any opengeos package
  • Covers 26 globally contested river basins across all inhabited continents
  • Fully open-source, GPL-3.0

Questions before writing the PR

  1. Is geoagent/tools/hsae.py the correct file location for a new adapter?
  2. Should the tools return raw Python dicts, or is there a preferred GeoAgent return schema?
  3. Should I mark get_negotiation_recommendation as confirmation_required=True given the legal sensitivity?
  4. Is there a preferred way to handle the optional hydrosovereign dependency (lazy import vs extras_require)?

References

Seifeldin M.G. Alkhedir · University of Khartoum · ORCID: 0000-0003-0821-2991

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions