Skip to main content
Glama

Axion Planetary MCP

by Dhenenjay
geospatial-models.jsβ€’29.7 kB
/** * REUSABLE GEOSPATIAL ANALYSIS MODELS * ==================================== * Production-ready models for complex geospatial analysis * Can be imported and customized for various use cases */ // Import consolidated tools directly const { callTool } = require('../mcp/server-consolidated'); // Helper function for Earth Engine API calls async function callEarthEngine(tool, args) { try { // Call the consolidated tools directly without going through SSE const result = await callTool(tool, args); return result; } catch (error) { console.error(`Error calling ${tool}:`, error); return { success: false, error: error.message }; } } /** * WILDFIRE RISK ASSESSMENT MODEL * Analyzes multiple factors to assess wildfire risk * * @param {Object} options Configuration options * @param {string} options.region - Area to analyze (place name or geometry) * @param {string} options.startDate - Start date (YYYY-MM-DD) * @param {string} options.endDate - End date (YYYY-MM-DD) * @param {number} options.scale - Analysis scale in meters (default 100) * @param {Array} options.indices - Vegetation indices to calculate (default: ['NDVI', 'NDWI', 'NBR']) * @param {boolean} options.includeTimeSeries - Include temporal analysis (default: true) * @param {boolean} options.exportMaps - Generate visualization maps (default: true) * @returns {Object} Risk assessment results */ async function wildfireRiskAssessment(options = {}) { const config = { region: options.region || 'California', startDate: options.startDate || '2023-06-01', endDate: options.endDate || '2023-10-31', scale: options.scale || 100, indices: options.indices || ['NDVI', 'NDWI', 'NBR', 'SAVI'], includeTimeSeries: options.includeTimeSeries !== false, exportMaps: options.exportMaps !== false, dataset: options.dataset || 'COPERNICUS/S2_SR_HARMONIZED' }; const results = { metadata: config, riskFactors: {}, indices: {}, statistics: {}, maps: {}, riskScore: 0, recommendations: [] }; try { // Calculate vegetation indices for (const indexType of config.indices) { console.log(`Calculating ${indexType}...`); const indexResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: indexType, datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (indexResult.success) { results.indices[indexType] = indexResult; // Interpret index values for risk if (indexType === 'NDVI' && indexResult.value < 0.3) { results.riskFactors.dryVegetation = 'HIGH'; results.riskScore += 25; } if (indexType === 'NDWI' && indexResult.value < 0) { results.riskFactors.lowMoisture = 'HIGH'; results.riskScore += 25; } } } // Terrain analysis console.log('Analyzing terrain...'); const slopeResult = await callEarthEngine('earth_engine_process', { operation: 'terrain', terrainType: 'slope', region: config.region }); if (slopeResult.success) { results.riskFactors.slope = slopeResult; if (slopeResult.mean > 15) { results.riskScore += 15; results.riskFactors.steepTerrain = 'MODERATE'; } } // Precipitation analysis console.log('Analyzing precipitation...'); const precipResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'statistics', datasetId: 'UCSB-CHG/CHIRPS/DAILY', reducer: 'sum', startDate: config.startDate, endDate: config.endDate, region: config.region, scale: 5000 }); if (precipResult.success) { results.statistics.precipitation = precipResult; if (precipResult.value < 100) { results.riskFactors.lowPrecipitation = 'HIGH'; results.riskScore += 20; } } // Time series analysis if (config.includeTimeSeries) { console.log('Performing time series analysis...'); const timeSeriesResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'timeseries', datasetId: config.dataset, band: 'B4', reducer: 'mean', startDate: config.startDate, endDate: config.endDate, region: config.region, scale: config.scale }); if (timeSeriesResult.values) { results.statistics.timeSeries = timeSeriesResult; // Analyze trend const values = timeSeriesResult.values.map(v => v.value); const trend = values[values.length - 1] - values[0]; if (trend < 0) { results.riskFactors.decliningVegetation = 'WARNING'; results.riskScore += 15; } } } // Export visualization maps if (config.exportMaps) { console.log('Generating risk visualization map...'); const mapResult = await callEarthEngine('earth_engine_export', { operation: 'thumbnail', datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region, dimensions: 800, visParams: { bands: ['B12', 'B8', 'B4'], // SWIR-NIR-Red for fire min: 0, max: 3000, gamma: 1.5 } }); if (mapResult.url) { results.maps.fireRiskVisualization = mapResult.url; } } // Generate recommendations based on risk score if (results.riskScore >= 75) { results.riskLevel = 'EXTREME'; results.recommendations = [ 'Immediate evacuation planning required', 'Deploy additional fire suppression resources', 'Issue red flag warnings', 'Implement strict fire restrictions' ]; } else if (results.riskScore >= 50) { results.riskLevel = 'HIGH'; results.recommendations = [ 'Increase monitoring frequency', 'Prepare evacuation routes', 'Alert fire departments', 'Restrict outdoor burning' ]; } else if (results.riskScore >= 25) { results.riskLevel = 'MODERATE'; results.recommendations = [ 'Continue regular monitoring', 'Maintain fuel reduction efforts', 'Public awareness campaigns', 'Review emergency plans' ]; } else { results.riskLevel = 'LOW'; results.recommendations = [ 'Routine monitoring sufficient', 'Focus on prevention measures' ]; } results.success = true; } catch (error) { results.success = false; results.error = error.message; } return results; } /** * FLOOD RISK ASSESSMENT MODEL * Analyzes hydrological and terrain factors for flood risk * * @param {Object} options Configuration options * @param {string} options.region - Area to analyze * @param {string} options.startDate - Start date * @param {string} options.endDate - End date * @param {string} options.floodType - Type of flooding to analyze (urban/coastal/riverine/snowmelt) * @param {boolean} options.analyzeWaterChange - Analyze water body changes * @returns {Object} Flood risk assessment results */ async function floodRiskAssessment(options = {}) { const config = { region: options.region || 'Houston', startDate: options.startDate || '2023-01-01', endDate: options.endDate || '2023-06-30', floodType: options.floodType || 'urban', scale: options.scale || 100, analyzeWaterChange: options.analyzeWaterChange !== false, dataset: options.dataset || 'COPERNICUS/S2_SR_HARMONIZED' }; const results = { metadata: config, riskFactors: {}, waterIndices: {}, terrain: {}, precipitation: {}, floodRisk: 0, vulnerableAreas: [], mitigationStrategies: [] }; try { // Water detection indices const waterIndices = ['NDWI', 'MNDWI']; for (const index of waterIndices) { console.log(`Calculating ${index} for water detection...`); const waterResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: index, datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (waterResult.success) { results.waterIndices[index] = waterResult; if (waterResult.value > 0.3) { results.floodRisk += 20; results.riskFactors.highWaterContent = true; } } } // Terrain analysis for drainage console.log('Analyzing terrain and drainage...'); const elevationResult = await callEarthEngine('earth_engine_process', { operation: 'terrain', terrainType: 'elevation', region: config.region }); if (elevationResult.success) { results.terrain.elevation = elevationResult; if (elevationResult.min < 10) { results.floodRisk += 30; results.riskFactors.lowElevation = 'HIGH_RISK'; results.vulnerableAreas.push('Low-lying areas below 10m elevation'); } } const slopeResult = await callEarthEngine('earth_engine_process', { operation: 'terrain', terrainType: 'slope', region: config.region }); if (slopeResult.success) { results.terrain.slope = slopeResult; if (slopeResult.mean < 2) { results.floodRisk += 15; results.riskFactors.poorDrainage = 'FLAT_TERRAIN'; } } // Precipitation analysis console.log('Analyzing precipitation patterns...'); const precipResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'statistics', datasetId: 'UCSB-CHG/CHIRPS/DAILY', reducer: 'max', startDate: config.startDate, endDate: config.endDate, region: config.region, scale: 5000 }); if (precipResult.success) { results.precipitation = precipResult; if (precipResult.value > 50) { results.floodRisk += 25; results.riskFactors.heavyRainfall = true; } } // Urban development analysis (for urban flooding) if (config.floodType === 'urban') { console.log('Analyzing urban imperviousness...'); const ndbiResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: 'NDBI', datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (ndbiResult.success) { results.urbanization = ndbiResult; if (ndbiResult.value > 0.2) { results.floodRisk += 20; results.riskFactors.highImperviousness = true; results.vulnerableAreas.push('Highly urbanized areas with poor drainage'); } } } // Snow analysis (for snowmelt flooding) if (config.floodType === 'snowmelt') { console.log('Analyzing snow cover...'); const ndsiResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: 'NDSI', datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (ndsiResult.success) { results.snowCover = ndsiResult; if (ndsiResult.value > 0.4) { results.floodRisk += 15; results.riskFactors.snowmeltRisk = true; } } } // Water change detection if (config.analyzeWaterChange) { console.log('Analyzing water extent changes...'); const changeResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'change', datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (changeResult.success) { results.waterChange = changeResult; results.riskFactors.waterExpansion = changeResult.change > 0; } } // Determine flood risk level and mitigation strategies if (results.floodRisk >= 70) { results.riskLevel = 'CRITICAL'; results.mitigationStrategies = [ 'Immediate flood warnings required', 'Evacuate low-lying areas', 'Deploy emergency pumping stations', 'Open flood gates and diversions', 'Activate emergency response teams' ]; } else if (results.floodRisk >= 50) { results.riskLevel = 'HIGH'; results.mitigationStrategies = [ 'Issue flood watches', 'Prepare evacuation routes', 'Clear storm drains', 'Sand bag vulnerable areas', 'Monitor water levels closely' ]; } else if (results.floodRisk >= 30) { results.riskLevel = 'MODERATE'; results.mitigationStrategies = [ 'Continue monitoring', 'Maintain drainage systems', 'Public awareness campaigns', 'Review flood plans' ]; } else { results.riskLevel = 'LOW'; results.mitigationStrategies = [ 'Routine monitoring', 'Preventive maintenance' ]; } results.success = true; } catch (error) { results.success = false; results.error = error.message; } return results; } /** * AGRICULTURAL MONITORING MODEL * Comprehensive crop health and yield prediction * * @param {Object} options Configuration options * @returns {Object} Agricultural analysis results */ async function agriculturalMonitoring(options = {}) { const config = { region: options.region || 'Sacramento Valley', cropType: options.cropType || 'general', startDate: options.startDate || '2023-03-01', endDate: options.endDate || '2023-09-30', scale: options.scale || 30, indices: options.indices || ['NDVI', 'EVI', 'SAVI', 'NDWI'], dataset: options.dataset || 'COPERNICUS/S2_SR_HARMONIZED' }; const results = { metadata: config, cropHealth: {}, vegetationIndices: {}, waterStress: {}, soilConditions: {}, yieldPrediction: null, recommendations: [] }; try { // Calculate vegetation indices for (const index of config.indices) { console.log(`Calculating ${index} for crop monitoring...`); const indexResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: index, datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (indexResult.success) { results.vegetationIndices[index] = indexResult; // Interpret for crop health if (index === 'NDVI') { if (indexResult.value > 0.6) { results.cropHealth.status = 'HEALTHY'; results.cropHealth.vigorScore = 85; } else if (indexResult.value > 0.4) { results.cropHealth.status = 'MODERATE'; results.cropHealth.vigorScore = 60; } else { results.cropHealth.status = 'STRESSED'; results.cropHealth.vigorScore = 30; } } if (index === 'NDWI' && indexResult.value < 0) { results.waterStress.level = 'HIGH'; results.recommendations.push('Increase irrigation frequency'); } } } // Time series for growth monitoring console.log('Analyzing crop growth patterns...'); const growthResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'timeseries', datasetId: config.dataset, band: 'B8', // NIR band reducer: 'mean', startDate: config.startDate, endDate: config.endDate, region: config.region, scale: config.scale }); if (growthResult.values) { results.growthPattern = growthResult; // Simple yield prediction based on peak NDVI const peakValue = Math.max(...growthResult.values.map(v => v.value)); results.yieldPrediction = { estimated: peakValue * 100, // Simplified calculation confidence: 'MODERATE', unit: 'relative_units' }; } // Soil moisture analysis console.log('Analyzing soil conditions...'); const saviResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: 'SAVI', datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (saviResult.success) { results.soilConditions.moisture = saviResult; if (saviResult.value < 0.3) { results.recommendations.push('Soil moisture critically low - immediate irrigation needed'); } } // Generate crop-specific recommendations if (results.cropHealth.status === 'STRESSED') { results.recommendations.push( 'Apply fertilizer to boost crop health', 'Check for pest infestations', 'Consider foliar nutrient application' ); } if (results.cropHealth.status === 'HEALTHY') { results.recommendations.push( 'Maintain current management practices', 'Monitor for optimal harvest timing' ); } results.success = true; } catch (error) { results.success = false; results.error = error.message; } return results; } /** * DEFORESTATION DETECTION MODEL * Monitors forest loss and degradation * * @param {Object} options Configuration options * @returns {Object} Deforestation analysis results */ async function deforestationDetection(options = {}) { const config = { region: options.region || 'Amazon', baselineStart: options.baselineStart || '2023-01-01', baselineEnd: options.baselineEnd || '2023-03-31', currentStart: options.currentStart || '2023-10-01', currentEnd: options.currentEnd || '2023-12-31', scale: options.scale || 30, dataset: options.dataset || 'COPERNICUS/S2_SR_HARMONIZED' }; const results = { metadata: config, forestCover: {}, deforestation: {}, degradation: {}, carbonLoss: null, alerts: [] }; try { // Calculate baseline forest cover console.log('Analyzing baseline forest cover...'); const baselineNDVI = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: 'NDVI', datasetId: config.dataset, startDate: config.baselineStart, endDate: config.baselineEnd, region: config.region }); // Calculate current forest cover console.log('Analyzing current forest cover...'); const currentNDVI = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: 'NDVI', datasetId: config.dataset, startDate: config.currentStart, endDate: config.currentEnd, region: config.region }); if (baselineNDVI.success && currentNDVI.success) { results.forestCover.baseline = baselineNDVI.value; results.forestCover.current = currentNDVI.value; const loss = baselineNDVI.value - currentNDVI.value; results.deforestation.percentLoss = (loss / baselineNDVI.value) * 100; if (results.deforestation.percentLoss > 10) { results.alerts.push({ type: 'CRITICAL', message: 'Significant forest loss detected', action: 'Immediate investigation required' }); } // Estimate carbon loss (simplified) results.carbonLoss = { estimated: results.deforestation.percentLoss * 100, unit: 'tons CO2', confidence: 'LOW' }; } // Change detection console.log('Performing change detection...'); const changeResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'change', datasetId: config.dataset, startDate: config.baselineStart, endDate: config.currentEnd, region: config.region }); if (changeResult.success) { results.changeDetection = changeResult; } // Generate alerts and recommendations if (results.deforestation.percentLoss > 5) { results.recommendations = [ 'Deploy ground teams for verification', 'Increase monitoring frequency', 'Alert local authorities', 'Document affected areas' ]; } results.success = true; } catch (error) { results.success = false; results.error = error.message; } return results; } /** * WATER QUALITY MONITORING MODEL * Analyzes water bodies for quality indicators * * @param {Object} options Configuration options * @returns {Object} Water quality analysis results */ async function waterQualityMonitoring(options = {}) { const config = { region: options.region || 'Lake Tahoe', startDate: options.startDate || '2023-06-01', endDate: options.endDate || '2023-08-31', waterBody: options.waterBody || 'lake', scale: options.scale || 30, dataset: options.dataset || 'COPERNICUS/S2_SR_HARMONIZED' }; const results = { metadata: config, waterIndices: {}, turbidity: null, algaeBloom: null, temperature: null, qualityScore: 0, warnings: [] }; try { // Water detection console.log('Detecting water bodies...'); const mndwiResult = await callEarthEngine('earth_engine_process', { operation: 'index', indexType: 'MNDWI', datasetId: config.dataset, startDate: config.startDate, endDate: config.endDate, region: config.region }); if (mndwiResult.success) { results.waterIndices.MNDWI = mndwiResult; // Estimate turbidity from band ratios results.turbidity = { level: mndwiResult.value < 0.3 ? 'HIGH' : 'LOW', value: (1 - mndwiResult.value) * 100, unit: 'NTU_estimate' }; if (results.turbidity.level === 'HIGH') { results.warnings.push('High turbidity detected - possible sediment influx'); results.qualityScore -= 30; } else { results.qualityScore += 30; } } // Chlorophyll/algae detection (using green band) console.log('Detecting algae blooms...'); const greenBandAnalysis = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'statistics', datasetId: config.dataset, band: 'B3', // Green band reducer: 'mean', startDate: config.startDate, endDate: config.endDate, region: config.region, scale: config.scale }); if (greenBandAnalysis.success) { // High green reflectance may indicate algae results.algaeBloom = { risk: greenBandAnalysis.value > 0.15 ? 'HIGH' : 'LOW', chlorophyllEstimate: greenBandAnalysis.value * 100, unit: 'relative_units' }; if (results.algaeBloom.risk === 'HIGH') { results.warnings.push('Potential algae bloom detected'); results.qualityScore -= 25; } else { results.qualityScore += 25; } } // Time series for trend analysis console.log('Analyzing water quality trends...'); const trendResult = await callEarthEngine('earth_engine_process', { operation: 'analyze', analysisType: 'timeseries', datasetId: config.dataset, band: 'B2', // Blue band for water clarity reducer: 'mean', startDate: config.startDate, endDate: config.endDate, region: config.region, scale: config.scale }); if (trendResult.values) { results.clarityTrend = trendResult; // Check if water clarity is declining const values = trendResult.values.map(v => v.value); const trend = values[values.length - 1] - values[0]; if (trend < 0) { results.warnings.push('Water clarity declining over time'); results.qualityScore -= 20; } else { results.qualityScore += 20; } } // Overall water quality assessment results.qualityScore = Math.max(0, Math.min(100, results.qualityScore + 50)); if (results.qualityScore >= 70) { results.qualityLevel = 'GOOD'; results.recommendations = ['Continue regular monitoring']; } else if (results.qualityScore >= 40) { results.qualityLevel = 'MODERATE'; results.recommendations = [ 'Increase monitoring frequency', 'Investigate pollution sources', 'Test water samples' ]; } else { results.qualityLevel = 'POOR'; results.recommendations = [ 'Immediate water quality testing required', 'Issue health advisories', 'Investigate contamination sources', 'Implement remediation measures' ]; } results.success = true; } catch (error) { results.success = false; results.error = error.message; } return results; } // Export all models - CommonJS only for Next.js compatibility module.exports = { wildfireRiskAssessment, floodRiskAssessment, agriculturalMonitoring, deforestationDetection, waterQualityMonitoring, callEarthEngine };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Dhenenjay/axion-planetary-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server