ETL Pipeline
This section describes the data processing pipelines that ingest, transform, and load data into the AClimate v3 database.
Pipeline Overview
The ETL layer consists of three specialized Python repositories that handle different aspects of data processing:
External Data Sources
│
▼
┌─────────────────────────────┐
│ cut_spatial_data │
│ - Spatial segmentation │
│ - Raster/vector processing │
│ - AOI extraction │
└─────────┬───────────────────┘
│
▼
┌─────────────────────────────┐
│ historical_spatial_etl │
│ - Gridded climate data │
│ - Spatial interpolation │
│ - Historical reanalysis │
└─────────┬───────────────────┘
│
▼
┌─────────────────────────────┐
│ historical_location_etl │
│ - Station-based data │
│ - Location time series │
│ - Quality control │
└─────────┬───────────────────┘
│
▼
PostgreSQL DB
1. aclimate_v3_cut_spatial_data
Purpose: Preprocesses and segments spatial data to feed ETL pipelines and downstream services.
- Inputs: Global/regional climate datasets (NetCDF, GeoTIFF), administrative boundaries
- Processing: Clipping, resampling, reprojection, AOI extraction
- Outputs: Segmented spatial files organized by region/country
Key characteristics:
- Python-based spatial processing
- Supports multiple input formats (NetCDF, GeoTIFF, shapefiles)
- Configurable AOI definitions
- Idempotent: re-runs produce same results
2. aclimate_v3_historical_spatial_etl
Purpose: Processes historical gridded climate data (e.g., ERA5, CHIRPS, AgERA5) into the AClimate database.
- Inputs: Gridded climate datasets, spatial segments from cut_spatial_data
- Processing:
- Temporal aggregation (daily → monthly → climatology)
- Spatial statistics (zonal means, point extraction)
- Variable derivation (growing degree days, precipitation anomalies)
- Outputs: ClimateHistoricalDaily, ClimateHistoricalMonthly, ClimateHistoricalClimatology records
Key characteristics:
- Handles large spatio-temporal datasets efficiently
- Parallel processing for performance
- Validates against ORM schemas
- Logs processing metrics per run
3. aclimate_v3_historical_location_etl
Purpose: Processes historical climate data from weather stations and location-specific sources.
- Inputs: Station observations, local climate records
- Processing:
- Quality control (outlier detection, gap filling)
- Homogenization checks
- Statistical summaries
- Outputs: Location-based climate records in ORM entities
Key characteristics:
- Focus on point-based (station) data
- QC/QA workflows
- Metadata preservation
Data Quality
Each ETL implements data quality controls:
| Check | Description | Action on Failure |
|---|---|---|
| Schema validation | Data matches ORM schema | Record rejected, logged |
| Range validation | Values within expected bounds | Flagged, logged |
| Completeness | Required fields present | Record rejected |
| Duplicate detection | Existing records checked | Skipped or updated |
| Temporal consistency | Dates in logical order | Flagged |
Idempotency and Reprocessing
All ETLs are designed to be idempotent:
- Same input + same configuration = same output
- Duplicate runs do not create duplicate records
- Reprocessing can be triggered for specific time ranges or locations
- Migration scripts support schema evolution
Orchestration and Scheduling
- ETLs are executed as standalone Python scripts or Docker containers
- Scheduling via cron/airflow (configurable per environment)
- Execution logs are stored for auditing and debugging
- Failed runs can be retried from the point of failure
ETL ↔ ORM Traceability
| ETL Repository | ORM Models Written | Schema Impact |
|---|---|---|
cut_spatial_data | (file-based output) | Configures spatial inputs |
historical_spatial_etl | ClimateHistoricalDaily, Monthly, Climatology, Indicator | High-volume writes |
historical_location_etl | ClimateHistoricalDaily, Monthly | Medium-volume writes |