Skip to main content

External Forecast Data Sources

This document provides comprehensive guidance on setting up and integrating external forecast data sources into the Rahat platform. It covers configuration, data processing, monitoring, and best practices for reliable environmental and weather data integration.

Overview

External forecast data sources provide critical real-time environmental and weather data for automated decision-making in humanitarian aid distribution. This setup enables the platform to trigger aid disbursements based on environmental conditions, weather forecasts, and climate monitoring data.

1. Department of Hydrology and Meteorology (DHM)

Purpose

DHM provides real-time hydrological data for river monitoring and flood prediction in Nepal. This service is critical for early warning systems in flood-prone regions.

API Integration

Base Configuration

// Configuration in settings
DATASOURCE: {
DHM: {
location: 'Babai at Chepang', // or 'Karnali at Chisapani'
url: 'https://bipadportal.gov.np/api/v1'
}
}

Data Synchronization

  • Frequency: Every 5 minutes
  • Method: Automated cron job (@Cron('*/5 * * * *'))
  • Process: Fetches latest water level data and stores in local database

API Endpoints Used

River Station Data
// GET /api/v1/water-levels
// Returns: Array of water level readings with timestamps
{
"data": {
"results": [
{
"station": "Babai at Chepang",
"waterLevel": 2.45,
"timestamp": "2024-01-15T10:30:00Z",
"location": "coordinates",
"status": "active"
}
]
}
}
Station Information
// GET /api/v1/stations
// Returns: List of available monitoring stations
{
"stations": [
{
"id": "BABAI_001",
"name": "Babai at Chepang",
"location": "coordinates",
"river": "Babai",
"status": "active"
}
]
}

Data Processing

Water Level Monitoring

// Trigger criteria check
async criteriaCheck(payload: AddTriggerStatement) {
const recentData = await this.prisma.sourcesData.findFirst({
where: {
location: payload.location,
source: 'DHM',
},
orderBy: { createdAt: 'desc' }
});

const currentLevel = recentData.data.waterLevel;
const threshold = payload.triggerStatement?.waterLevel;

return this.compareWaterLevels(currentLevel, threshold);
}

Threshold Comparison Logic

compareWaterLevels(currentLevel: number, threshold: number): boolean {
// Trigger when water level exceeds threshold
return currentLevel >= threshold;
}

Use Cases

1. Flood Early Warning

  • Trigger Condition: Water level > 3.5 meters
  • Response: Immediate beneficiary notification
  • Lead Time: 2-6 hours depending on river flow

2. River Monitoring

  • Continuous Monitoring: 24/7 water level tracking
  • Data Storage: Historical data for trend analysis
  • Alert System: Automated notifications for threshold breaches

2. Global Flood Awareness System (GLOFAS)

Purpose

GLOFAS provides global flood forecasting data with probability assessments and lead time analysis. This service enables advanced flood prediction with longer lead times than local monitoring.

API Integration

Base Configuration

// Configuration in settings
DATASOURCE: {
GLOFAS: {
location: 'Babai at Chepang',
url: "https://ows.globalfloods.eu/glofas-ows/ows.py",
bbox: "9066450.71499904,3117815.425733483,9405627.288509797,3456991.999244238",
i: "89", // coordinate for station
j: "409"
}
}

Data Synchronization

  • Frequency: Every hour
  • Method: Automated cron job (@Cron('0 * * * *'))
  • Process: Fetches forecast data and stores with date tracking

GLOFAS Data Processing

Flood Probability Assessment

async assessFloodProbability(location: string): Promise<number> {
const glofasData = await this.getGLOFASData(location);
return this.calculateFloodProbability(glofasData);
}

Forecast Lead Time Analysis

async analyzeLeadTime(location: string): Promise<number> {
const forecastData = await this.getGLOFASForecast(location);
return this.calculateLeadTime(forecastData);
}

3. Data Validation and Quality Control

Data Validation Schema

interface ForecastDataValidation {
required: boolean;
dataType: 'number' | 'string' | 'object' | 'array';
minValue?: number;
maxValue?: number;
format?: string;
customValidation?: (data: any) => boolean;
}

const validationSchemas = {
waterLevel: {
required: true,
dataType: 'number',
minValue: 0,
maxValue: 50
},
floodProbability: {
required: true,
dataType: 'number',
minValue: 0,
maxValue: 1
},
leadTime: {
required: true,
dataType: 'number',
minValue: 0,
maxValue: 168 // 7 days in hours
}
};

Quality Control Checks

async validateForecastDataQuality(sourceName: string, data: any): Promise<boolean> {
// Check for missing data
if (!data || Object.keys(data).length === 0) {
return false;
}

// Check for stale data
const dataAge = Date.now() - new Date(data.timestamp).getTime();
if (dataAge > this.getMaxDataAge(sourceName)) {
return false;
}

// Check for reasonable values
return this.validateDataRange(data);
}

4. Trigger System Integration

Forecast-Based Triggers

interface ForecastTrigger {
sourceName: string;
condition: 'greater_than' | 'less_than' | 'equals' | 'contains';
threshold: number | string;
field: string;
action: 'disburse_aid' | 'send_alert' | 'activate_protocol';
leadTime?: number; // hours
}

async evaluateForecastTrigger(trigger: ForecastTrigger): Promise<boolean> {
const forecastData = await this.getLatestForecastData(trigger.sourceName);
const currentValue = this.extractFieldValue(forecastData, trigger.field);

return this.compareValues(currentValue, trigger.condition, trigger.threshold);
}

Multi-Source Forecast Triggers

async evaluateMultiSourceForecastTrigger(triggers: ForecastTrigger[]): Promise<boolean> {
const results = await Promise.all(
triggers.map(trigger => this.evaluateForecastTrigger(trigger))
);

// All triggers must be true for multi-source trigger
return results.every(result => result === true);
}

Combined Trigger Assessment

// Combined trigger assessment
async assessTriggerConditions(location: string, triggerConfig: TriggerConfig) {
const dhmData = await this.getDHMData(location);
const glofasData = await this.getGLOFASData(location);

// DHM immediate trigger
const dhmTriggered = this.checkDHMThreshold(dhmData, triggerConfig.dhmThreshold);

// GLOFAS probability trigger
const glofasTriggered = this.checkGLOFASProbability(glofasData, triggerConfig.probabilityThreshold);

return {
immediateTrigger: dhmTriggered,
forecastTrigger: glofasTriggered,
combinedRisk: this.calculateCombinedRisk(dhmData, glofasData)
};
}

Fallback Data Sources

async getDataWithFallback(primarySource: string, fallbackSource: string): Promise<any> {
try {
return await this.fetchForecastData(primarySource);
} catch (error) {
this.logger.warn(`Primary source ${primarySource} failed, using fallback`);
return await this.fetchForecastData(fallbackSource);
}
}

This documentation provides a comprehensive guide for setting up and maintaining external forecast data sources (DHM and GLOFAS) in the Rahat platform, ensuring reliable and secure environmental data processing for automated humanitarian aid distribution.