How digitalearthafrica/deafrica_water_quality works
This repository is a Python-based water quality processing package with two distinct layers:
1. a reusable runtime library and CLI in src/water_quality
2. a set of research/prototyping notebooks organized by work package (WP1.x, WP2.x, SDG6.6.1, FAI_notebook)
The runtime library is the part that matters for system architecture; the notebooks are largely development artifacts and workflow notebooks that document or prototype the processing chain.
1) High-level system shape
The project implements an Earth-observation water-quality pipeline that:
• prepares processing tasks for spatial tiles and years
• distributes those tasks across parallel workers/pods
• loads sensor and ancillary data
• computes water-quality and related indicators
• writes outputs as geospatial products, likely Cloud Optimized GeoTIFFs and tabular metadata
• supports QA/monitoring and SDG 6.6.1 reporting
A key operational assumption is that processing is tiled and parallelized. The CLI takes a list of tasks and splits them by worker index, so the architecture is designed for batch execution on multiple pods rather than a single monolithic run.
2) Main runtime subsystems
A. Command-line orchestration layer
Located under src/water_quality/cli.
This is the entry boundary for operational runs. The CLI includes commands for:
• generating task lists
• generating tile lists
• processing annual water-quality variables
• processing short-term water-quality variables
• listing test areas
• generating metadata
• reporting the package version
This layer does not appear to implement domain logic itself; it orchestrates the lower-level modules and provides the execution interface for batch jobs.
Important architectural implication:
• the CLI is the control plane
• processing logic lives in library modules, not in notebooks or scripts
B. Tasking, tiling, and spatial partitioning
Core modules:
• tasks.py
• tiling.py
• grid.py
• waterbodies.py
• africa_extent.py
• scripts/get_bbox.py
This subsystem handles the spatial decomposition of the problem:
• defining Africa-wide extent and tile geometry
• mapping waterbodies to tiles
• enumerating task identifiers such as year/x##/y##
• selecting tiles by test area or by geographic bounds
The README explicitly describes task generation as a prerequisite step, and the repository contains tile/waterbody lookup data, indicating that this is a first-class boundary in the architecture.
Data flow:
• spatial extent / tile definitions
• tile selection or tile lookup
• generation of task IDs
• downstream processing workers consume only their assigned subset
C. EO data loading and preprocessing
Core modules:
• mapping/load_data.py
• io.py
• dates.py
• magics.py
• logs.py
This layer appears to centralize:
• reading input datasets
• managing time/date logic
• IO helpers for input/output formats
• logging and possibly notebook “magic” helpers
The presence of mapping/load_data.py suggests data ingestion is tightly coupled to the mapping/algorithm layer, likely loading sensor observations, masks, and ancillary layers for a tile/time slice.
D. Water-quality mapping and retrieval algorithms
Core package:
• src/water_quality/mapping
Files here indicate the main scientific processing chain:
• algorithms.py — central algorithm orchestration
• config.py — analysis configuration
• instruments.py — sensor-specific handling
• fai.py, ndvi.py, hue.py, temperature.py — derived indicators/features
• water_detection.py — water masking/detection
• pixel_correction.py — pixel-level corrections
• optical_water_type.py — optical water type classification
• load_data.py — input assembly for mapping
• ...
This is the computational core of the service. It likely transforms EO observations into water-quality variables by:
• loading calibrated imagery
• applying water detection and masking
• computing spectral indices/features
• applying sensor-specific logic
• applying corrections or classifications
• generating per-pixel water-quality outputs
The repository includes sensor band reference CSVs for MSI, OLI, and TM, and OWT vector tables, so sensor-specific branching is an explicit design feature.
Data and model assets supporting this layer:
• src/water_quality/data/
• reference_data/
These contain sensor-band definitions, optical-water-type vectors, measurement distributions, normalization parameters, lookup tables, and place metadata. This means the algorithm layer depends on packaged static reference data rather than hard-coded constants.
E. Metadata and product assembly
Core modules:
• metadata/easi_assemble.py
• metadata/prepare_metadata.py
• cli/metadata_generator.py
This subsystem likely assembles metadata needed for publishing or cataloging outputs. It is distinct from the raw numeric processing and seems to bridge generated products into a metadata/publishing format.
F. Monitoring, QA, and change analysis
Core modules:
• monitoring/change.py
• monitoring/load_data.py
• monitoring/plotting.py
• monitoring/qa.py
• monitoring/state.py
This subsystem appears to provide:
• change detection or temporal comparison
• QA logic for processed outputs
• plotting/reporting utilities
• state management for monitoring workflows
This is conceptually separate from the production mapping pipeline and likely consumes processed outputs to assess quality or change over time.
G. SDG reporting
Module:
• sdg_reporting.py
This is a dedicated reporting boundary for SDG 6.6.1-related outputs. The repo has a dedicated SDG6.6.1 notebook directory with country reporting and time series analysis, reinforcing that reporting is a downstream consumer of the core water-quality outputs.
3) Data and artifact boundaries
Packaged runtime data
src/water_quality/data/ contains files bundled with the Python package. These are part of the runtime dependency set and are likely accessed by the algorithms and CLI at execution time.
Examples:
• sensor band tables
• OWT vectors
• normalization parameters
• measurement distributions
• place metadata
• waterbody UID lists
• tile/waterbody lookup tables
This packaged data is a stable reference layer for computation.
External/reference data
reference_data/ contains similar CSVs outside the package tree. This looks like a source-of-truth or development copy of reference assets, separate from the packaged runtime data.
Intermediate and derived datasets
The repo includes some NetCDF artifacts and JSON/CSV outputs in the work-package directories, for example:
• WP1.3/wp13_ds.nc
• WP1.4/wp12_ds.nc
• WP1.4/wq_normalisation_parameters.json
• WP2.2/distributions.nc
These are likely intermediate research artifacts, not core runtime dependencies, but they show that the workflow uses tabular and array-based geospatial intermediates.
4) Execution model
The README describes a two-step operational workflow:
Step 1: task generation
A task list is created for a year range and a tile set. Tile selection can be:
• all tiles
• explicit tile IDs
• tile IDs from a file
• a predefined test area
This suggests a pre-processing stage that prepares a deterministic batch plan.
Step 2: distributed processing
Workers/pods process a shard of tasks based on:
• output directory
• maximum number of parallel steps
• worker index
• analysis config YAML
• task list
This is a horizontally scalable batch architecture. Each worker processes only its own slice of the task list, avoiding coordination-heavy distributed execution.
Outputs are written per task, likely as COGs or other geospatial files. The design is therefore:
• stateless workers
• shared task list input
• isolated per-task output
• configuration-driven behavior
5) Configuration and control files
Operational behavior is controlled by YAML/config files rather than code changes.
Relevant files:
• example_config.yaml
• docker/environment_dev.yaml
• docker/environment_prod.yaml
• compose_dev.yaml
• compose_prod.yaml
The sample config in the README shows key scientific parameters:
• resolution
• instrument enable/disable flags
• water frequency thresholds
• permanent water threshold
• sigma coefficient
This indicates the service is parameterized for different sensor combinations and threshold regimes, which is important for any architecture diagram: configuration is a first-class input to the processing pipeline.
6) Development, packaging, and deployment boundary
Python package layout
The actual package is under src/water_quality, following a modern src/ layout. This is the primary deployable codebase.
Containerized runtime
The repository has:
• docker/Dockerfile
• dev/prod environment files
• Jupyter Lab config
• entrypoint script
• Docker Compose files
This shows that the package is intended to run in a containerized environment, likely both for local development and for production/batch execution.
Reproducibility tooling
There is also:
• flake.nix / flake.lock
• .devcontainer
• pre-commit and lint configs
• GitHub Actions workflow for publishing Docker images
This suggests the project is meant to be reproducible across environments and shipped as a container image.
7) Notebook/work-package structure
The notebook directories are domain-facing workspaces rather than the runtime architecture itself:
• WP1.2
• WP1.3
• WP1.4
• WP2.1
• WP2.2
• SDG6.6.1
• FAI_notebook
These likely correspond to research or product-development tracks such as:
• annual dataset building
• tile/task generation
• per-waterbody statistics
• QA analysis
• feature computation such as FAI
There are also some helper .py files in these folders, which appear to be extracted notebook logic used during development.
For architecture purposes, treat these as:
• analysis/prototyping layer
• not the core runtime service
• consumers or predecessors of the reusable library
8) Likely data flow through the system
A reasonable architectural data flow is:
1. Spatial and reference data define tiles, waterbodies, sensor characteristics, and thresholds.
2. The task generator creates year/tile work items.
3. Parallel workers consume a subset of tasks using the analysis config.
4. The mapping subsystem loads EO data and ancillary inputs for each tile/time slice.
5. Sensor-specific and water-detection logic computes water-quality variables.
6. Outputs are written to geospatial files in the target output directory.
7. Metadata assembly and reporting modules consume these outputs for publishing, QA, and SDG reporting.
8. Monitoring/QA tools operate on generated outputs for quality assessment or trend analysis.
9) Key architectural boundaries to show in a diagram
If you are drawing this repository, the most important boundaries are:
• CLI / orchestration boundary
• core scientific processing boundary (mapping)
• spatial tasking and tiling boundary
• static reference data boundary
• metadata/reporting boundary
• monitoring/QA boundary
• notebook/prototyping boundary
• container/runtime boundary
The core message is that this repository is not a single script; it is a modular batch-processing library plus CLI for tiled EO-derived water-quality computation, with separate downstream paths for metadata, QA, monitoring, and SDG reporting.
Main entry points: algorithms.py Processing core · tasks.py Task planner · generate_tasks.py CLI · load_data.py Data loader
Components 24
Control plane
Command-line entry points and batch orchestration
- CLI · Operational command-line interface for batch runs and task generation
src/water_quality/cli/generate_tasks.py
Spatial planning
Tiling, extents, and task decomposition
- Task planner · Builds year/tile task lists and worker shards
src/water_quality/tasks.py - Tile grid · Defines tile geometry and tile enumeration
src/water_quality/tiling.py - Africa extent · Africa-wide spatial boundary definitions
src/water_quality/africa_extent.py - Waterbodies · Waterbody-to-tile and area lookup logic
src/water_quality/waterbodies.py - Grid utils · Supporting grid helpers for spatial partitioning
src/water_quality/grid.py
Mapping engine
Core water-quality processing and retrieval logic
- Processing core · Coordinates the main water-quality computation chain
src/water_quality/mapping/algorithms.py - Analysis config · Runtime parameters and instrument selection
src/water_quality/mapping/config.py - Data loader · Assembles EO and ancillary inputs for a tile/time slice
src/water_quality/mapping/load_data.py - Sensor logic · Sensor-specific branching and band handling
src/water_quality/mapping/instruments.py - Water mask · Detects or filters water pixels before retrieval
src/water_quality/mapping/water_detection.py - Spectral features · Derived indices and feature calculations
src/water_quality/mapping/fai.py - OWT classify · Optical water type classification and lookup
src/water_quality/mapping/optical_water_type.py - Pixel correction · Per-pixel correction and adjustment logic
src/water_quality/mapping/pixel_correction.py
Outputs and QA
Metadata assembly, monitoring, and reporting
- Metadata prep · Prepares product metadata for publishing and cataloging
src/water_quality/metadata/prepare_metadata.py - EASI assemble · Assembles metadata into EASI-facing structures
src/water_quality/metadata/easi_assemble.py - Monitoring · Change detection, QA, and monitoring workflows
src/water_quality/monitoring/qa.py - State · Stores monitoring workflow state and comparisons
src/water_quality/monitoring/state.py - SDG reporting · SDG 6.6.1 reporting outputs and summaries
src/water_quality/sdg_reporting.py
Reference data
Packaged and external lookup assets used by runtime code
- Packaged data · Bundled lookup tables and reference assets shipped with the package
src/water_quality/data - Reference data · Source reference tables used during development and runtime preparation
reference_data
Notebooks
Research and prototyping workspaces
- WP notebooks · Work-package notebooks for development and analysis
WP1.2 - SDG notebooks · Country reporting and waterbody time-series notebooks
SDG6.6.1 - FAI notebook · Feature and index prototyping workspace
FAI_notebook
Connections 26
- CLI → Task planner: generate tasks · Creates worker-sharded task lists
- CLI → Tile grid: generate tiles · Enumerates spatial tiles for processing
- CLI → Processing core: run processing · Invokes annual and short-term processing flows
- CLI → Metadata prep: metadata · Exposes metadata generation commands
- Task planner → Africa extent: boundaries · Uses Africa extent definitions
- Task planner → Tile grid: tiles · Builds tasks from tile geometry
- Task planner → Waterbodies: lookup · Maps waterbodies into task scope
- Tile grid → Grid utils: helpers · Relies on shared grid helpers
- Processing core → Analysis config: configured by · Uses YAML-driven analysis parameters
- Processing core → Data loader: load inputs · Loads EO and ancillary data for each task
- Data loader → Sensor logic: sensor branch · Selects instrument-specific handling
- Data loader → Water mask: mask water · Prepares water pixels for retrieval
- Data loader → Spectral features: features · Computes or assembles derived indicators
- Processing core → OWT classify: classify · Applies optical water type logic
- Processing core → Pixel correction: correct · Applies pixel-level adjustments
- Processing core → Packaged data: reference tables · Consumes packaged sensor and lookup assets
- Metadata prep → EASI assemble: assemble · Builds publication-oriented metadata products
- Monitoring → State: state · Uses stored monitoring state and comparisons
- Monitoring → Processing core: assess outputs · Consumes processed products for QA and change analysis
- SDG reporting → Processing core: summaries · Consumes core outputs for SDG reporting
- SDG reporting → Metadata prep: catalog · Reuses metadata prepared for reporting outputs
- WP notebooks → Task planner: prototype · Notebook workflows mirror task generation and processing
- WP notebooks → Processing core: experiment · Research notebooks exercise the mapping pipeline
- SDG notebooks → SDG reporting: analyze · Notebook analysis feeds SDG reporting workflows
- FAI notebook → Spectral features: feature study · FAI prototype focuses on spectral feature computation
- Reference data → Packaged data: curate · Development reference tables are packaged for runtime use