- Updated all CI maps to use tm_scale_continuous() for proper tmap v4 compatibility - Added fixed color scale limits (1-8 for CI, -3 to +3 for differences) for consistent field comparison - Fixed YAML header formatting issues in CI_report_dashboard_planet.Rmd - Positioned RGB map before CI overview map as requested - Removed all obsolete use_breaks parameter references - Enhanced error handling and logging throughout the pipeline - Added new experimental analysis scripts and improvements to mosaic creation
22 KiB
SmartCane System Architecture
Overview
The SmartCane system is a comprehensive agricultural intelligence platform that processes satellite imagery and farm data to provide agronomic insights for sugarcane farmers. The system architecture follows a modular, layered approach with clear separation of concerns between data acquisition, processing, and presentation.
Architectural Layers
The SmartCane system follows a layered architecture pattern, which is a standard approach in software engineering for organizing complex systems. This architecture divides the system into distinct functional layers, each with specific responsibilities. While these layers aren't explicitly shown as separate visual elements in the diagrams, they help conceptualize how components are organized by their function:
1. Data Acquisition Layer
- Role: Responsible for fetching raw data from external sources and user inputs
- Components: Manual Sentinel Hub Requests, Python API Downloader, User Input Interface
- Functions: Manual request setup on Sentinel Hub Requests Builder for specific client fields, connects to satellite data providers, downloads imagery, manages API credentials, performs preliminary data validation
2. Processing Layer (SmartCane Engine)
- Role: Core analytical engine that transforms raw data into actionable insights
- Components: Python API Downloader (pre-processing), R Processing Engine (analytics)
- Functions: Image processing, cloud masking, crop index calculation, field boundary processing, statistical analysis, report generation
3. Presentation Layer
- Role: Delivers insights to end users in accessible formats
- Components: Laravel Web App, Email Delivery System
- Functions: Interactive dashboards, visualization, report delivery, user management, project scheduling
4. Data Storage Layer
- Role: Persists system data across processing cycles
- Components: File System, Database
- Functions: Stores raw imagery, processed rasters, analytical results, user data, configuration
Key Subsystems
1. Python API Downloader
- Role: Acquires and pre-processes satellite imagery
- Inputs: API credentials, field boundaries, date parameters, evaluation scripts
- Outputs: Raw satellite images, merged GeoTIFFs, virtual rasters
- Interfaces: External satellite APIs (Planet via Sentinel Hub), file system
- Orchestration: Triggered by shell scripts from the Laravel application
2. R Processing Engine
- Role: Performs advanced analytics and generates insights
- Inputs: Processed satellite imagery, field boundaries, harvest data, project parameters
- Outputs: Crop indices, mosaics, RDS data files, agronomic reports
- Interfaces: File system, report templates
- Orchestration: Triggered by shell scripts from the Laravel application
3. Laravel Web Application
- Role: Provides operator interface and orchestrates the overall system
- Inputs: User data, configuration settings
- Outputs: Web interface, scheduling, report delivery
- Interfaces: Users, database, file system
- Orchestration: Controls execution of the SmartCane Engine via shell scripts
4. Shell Script Orchestration
- Role: Bridges between web application and processing components
- Functions: Triggers processing workflows, manages execution environment, handles errors
- Examples: runcane.sh, runpython.sh, build_mosaic.sh, build_report.sh
Data Flow
-
Input Stage:
- Operators (internal team) manually prepare and submit requests on Sentinel Hub Requests Builder for the specific fields of a client.
- Operators (internal team) provide farm data (field boundaries, harvest data) via the Laravel Web App.
- System schedules data acquisition for specific dates/regions
-
Acquisition Stage:
- Laravel triggers Python API Downloader via shell scripts
- Python connects to satellite data providers and downloads raw imagery
- Downloaded data is stored in the file system
-
Processing Stage:
- Laravel triggers R Processing Engine via shell scripts
- R scripts read satellite imagery and farm data
- Processing produces crop indices, analytics, and reports
- Results are stored in the file system
-
Output Stage:
- Laravel Web App accesses processed results
- Reports are delivered to users via email
System Integration Points
- Python-R Integration: Data handover via file system (GeoTIFF, virtual rasters)
- Engine-Laravel Integration: Orchestration via shell scripts, data exchange via file system and database
- User-System Integration: Web interface, file uploads, email notifications
Developed/Customized Elements
- Custom Cloud Masking Algorithm: Specialized for agricultural applications in tropical regions
- Crop Index Extraction Pipeline: Tailored to sugarcane spectral characteristics
- Reporting Templates: Designed for agronomic decision support
- Shell Script Orchestration: Custom workflow management for the system's components
Strategic Role of Satellite Data
Satellite data is central to the SmartCane system, providing:
- Regular, non-invasive field monitoring
- Detection of spatial patterns not visible from ground level
- Historical analysis of crop performance
- Early warning of crop stress or disease
- Quantification of field variability for precision agriculture
Pilot Utilization Sites
The SmartCane system is currently operational in Mozambique, Kenya, and Tanzania. Future pilot deployments and expansions are planned for Uganda, Colombia, Mexico, Guatemala, South Africa, and Zambia.
System Architecture Diagrams
Below are diagrams illustrating the system architecture from different perspectives.
Overall System Architecture
This diagram provides a high-level overview of the complete SmartCane system, showing how major components interact. It focuses on the system boundaries and main data flows between the Python API Downloader, R Processing Engine, Laravel Web App, and data storage components. This view helps understand how the system works as a whole.
graph TD
A["fa:fa-satellite External Satellite Data Providers API"] --> PyDL["fa:fa-download Python API Downloader"];
C["fa:fa-users Users: Farm Data Input e.g., GeoJSON, Excel"] --> D{"fa:fa-laptop-code Laravel Web App"};
subgraph SmartCane System
PyDL --> G["fa:fa-folder-open File System: Raw Satellite Imagery, Rasters, RDS, Reports, Boundaries"];
E["fa:fa-cogs R Processing Engine"] -- Reads --> G;
E -- Writes --> G;
D -- Manages/Triggers --> F["fa:fa-terminal Shell Script Orchestration"];
F -- Executes --> PyDL;
F -- Executes --> E;
D -- Manages/Accesses --> G;
D -- Reads/Writes --> H["fa:fa-database Database: Project Metadata, Users, Schedules"];
E -- Generates --> I["fa:fa-file-alt Agronomic Reports: DOCX, HTML"];
D -- Accesses/Delivers --> I;
end
D --> J["fa:fa-desktop Users: Web Interface (future)"];
I -- Via Email (SMTP) --> K["fa:fa-envelope Users: Email Reports"];
style E fill:#f9f,stroke:#333,stroke-width:2px
style D fill:#bbf,stroke:#333,stroke-width:2px
style PyDL fill:#ffdd57,stroke:#333,stroke-width:2px
R Processing Engine Detail
This diagram zooms in on the R Processing Engine subsystem, detailing the internal components and data flow. It shows how raw satellite imagery and field data progress through various R scripts to produce crop indices and reports. The diagram highlights the data transformation pipeline within this analytical core of the SmartCane system.
graph TD
subgraph R Processing Engine
direction TB
subgraph Inputs
SatelliteImages["fa:fa-image Raw Satellite Imagery"]
FieldBoundaries["fa:fa-map-marker-alt Field Boundaries .geojson"]
HarvestData["fa:fa-file-excel Harvest Data .xlsx"]
ProjectParams["fa:fa-file-code Project Parameters .R"]
end
subgraph Core R Scripts & Processes
ParamConfig("fa:fa-cogs parameters_project.R")
MosaicScript("fa:fa-images mosaic_creation.R")
CIExtractionScript("fa:fa-microscope ci_extraction.R")
ReportUtils("fa:fa-tools executive_report_utils.R")
DashboardRmd("fa:fa-tachometer-alt CI_report_dashboard_planet_enhanced.Rmd")
SummaryRmd("fa:fa-list-alt CI_report_executive_summary.Rmd")
end
subgraph Outputs
WeeklyMosaics["fa:fa-file-image Weekly Mosaics .tif"]
CIDataRDS["fa:fa-database CI Data .rds"]
CIRasters["fa:fa-layer-group CI Rasters .tif"]
DashboardReport["fa:fa-chart-bar Dashboard Report .docx/.html"]
SummaryReport["fa:fa-file-invoice Executive Summary .docx/.html"]
end
%% Data Flow
ProjectParams --> ParamConfig;
SatelliteImages --> MosaicScript;
FieldBoundaries --> MosaicScript;
ParamConfig --> MosaicScript;
MosaicScript --> WeeklyMosaics;
WeeklyMosaics --> CIExtractionScript;
FieldBoundaries --> CIExtractionScript;
ParamConfig --> CIExtractionScript;
CIExtractionScript --> CIDataRDS;
CIExtractionScript --> CIRasters;
CIDataRDS --> ReportUtils;
CIRasters --> ReportUtils;
HarvestData --> ReportUtils;
ParamConfig --> ReportUtils;
ReportUtils --> DashboardRmd;
ReportUtils --> SummaryRmd;
ParamConfig --> DashboardRmd;
ParamConfig --> SummaryRmd;
DashboardRmd --> DashboardReport;
SummaryRmd --> SummaryReport;
end
ShellOrchestration["fa:fa-terminal Shell Scripts e.g., build_mosaic.sh, build_report.sh"] -->|Triggers| R_Processing_Engine["fa:fa-cogs R Processing Engine"]
style R_Processing_Engine fill:#f9f,stroke:#333,stroke-width:2px
style Inputs fill:#ccf,stroke:#333,stroke-width:1px
style Outputs fill:#cfc,stroke:#333,stroke-width:1px
style Core_R_Scripts_Processes fill:#ffc,stroke:#333,stroke-width:1px
Python API Downloader Detail
This diagram focuses on the Python API Downloader subsystem, showing its internal components and workflow. It illustrates how API credentials, field boundaries, and other inputs are processed through various Python functions to download, process, and prepare satellite imagery. This view reveals the technical implementation details of the data acquisition layer.
graph TD
subgraph Python API Downloader
direction TB
subgraph Inputs_Py [Inputs]
APICreds["fa:fa-key API Credentials (SH_CLIENT_ID, SH_CLIENT_SECRET)"]
DateRangeParams["fa:fa-calendar-alt Date Range Parameters (days_needed, specific_date)"]
GeoJSONInput["fa:fa-map-marker-alt Field Boundaries (pivot.geojson)"]
ProjectConfig["fa:fa-cogs Project Configuration (project_name, paths)"]
EvalScripts["fa:fa-file-code Evalscripts (JS for cloud masking & band selection)"]
end
subgraph Core_Python_Logic_Py [Core Python Logic & Libraries]
SetupConfig["fa:fa-cog SentinelHubConfig & BYOC Definition"]
DateSlotGen["fa:fa-calendar-check Date Slot Generation (slots)"]
GeoProcessing["fa:fa-map GeoJSON Parsing & BBox Splitting (geopandas, BBoxSplitter)"]
AvailabilityCheck["fa:fa-search-location Image Availability Check (SentinelHubCatalog)"]
RequestHandler["fa:fa-paper-plane Request Generation (SentinelHubRequest, get_true_color_request_day)"]
DownloadClient["fa:fa-cloud-download-alt Image Download (SentinelHubDownloadClient, download_function)"]
MergeUtility["fa:fa-object-group Tile Merging (gdal.BuildVRT, gdal.Translate, merge_files)"]
CleanupUtility["fa:fa-trash-alt Intermediate File Cleanup (empty_folders)"]
end
subgraph Outputs_Py [Outputs]
RawSatImages["fa:fa-file-image Raw Downloaded Satellite Imagery Tiles (response.tiff in dated subfolders)"]
MergedTifs["fa:fa-images Merged TIFs (merged_tif/{slot}.tif)"]
VirtualRasters["fa:fa-layer-group Virtual Rasters (merged_virtual/merged{slot}.vrt)"]
DownloadLogs["fa:fa-file-alt Console Output Logs (print statements)"]
end
ExternalSatAPI["fa:fa-satellite External Satellite Data Providers API (Planet via Sentinel Hub)"]
%% Data Flow for Python Downloader
APICreds --> SetupConfig;
DateRangeParams --> DateSlotGen;
GeoJSONInput --> GeoProcessing;
ProjectConfig --> SetupConfig;
ProjectConfig --> GeoProcessing;
ProjectConfig --> MergeUtility;
ProjectConfig --> CleanupUtility;
EvalScripts --> RequestHandler;
DateSlotGen -- Available Slots --> AvailabilityCheck;
GeoProcessing -- BBox List --> AvailabilityCheck;
SetupConfig --> AvailabilityCheck;
AvailabilityCheck -- Filtered Slots & BBoxes --> RequestHandler;
RequestHandler -- Download Requests --> DownloadClient;
SetupConfig --> DownloadClient;
DownloadClient -- Downloads Data From --> ExternalSatAPI;
ExternalSatAPI -- Returns Image Data --> DownloadClient;
DownloadClient -- Writes --> RawSatImages;
DownloadClient -- Generates --> DownloadLogs;
RawSatImages --> MergeUtility;
MergeUtility -- Writes --> MergedTifs;
MergeUtility -- Writes --> VirtualRasters;
end
ShellOrchestratorPy["fa:fa-terminal Shell Scripts (e.g., runpython.sh triggering planet_download.ipynb)"] -->|Triggers| Python_API_Downloader["fa:fa-download Python API Downloader"];
style Python_API_Downloader fill:#ffdd57,stroke:#333,stroke-width:2px
style Inputs_Py fill:#cdeeff,stroke:#333,stroke-width:1px
style Outputs_Py fill:#d4efdf,stroke:#333,stroke-width:1px
style Core_Python_Logic_Py fill:#fff5cc,stroke:#333,stroke-width:1px
style ExternalSatAPI fill:#f5b7b1,stroke:#333,stroke-width:2px
SmartCane Engine Integration Diagram
This diagram illustrates the integration of Python and R components within the SmartCane Engine. Unlike the first diagram that shows the overall system, this one specifically focuses on how the two processing components interact with each other and the rest of the system. It emphasizes the orchestration layer and data flows between the core processing components and external systems.
graph TD
%% External Systems & Users
Users_DataInput["fa:fa-user Users: Farm Data Input (GeoJSON, Excel, etc.)"] --> Laravel_WebApp;
ExternalSatAPI["fa:fa-satellite External Satellite Data Providers API"];
%% Main Application Components
Laravel_WebApp["fa:fa-globe Laravel Web App (Frontend & Control Plane)"];
Shell_Orchestration["fa:fa-terminal Shell Script Orchestration (e.g., runcane.sh, runpython.sh, build_mosaic.sh)"]; subgraph SmartCane_Engine ["SmartCane Engine (Data Processing Core)"]
direction TB
Python_Downloader["fa:fa-download Python API Downloader"];
R_Engine["fa:fa-chart-line R Processing Engine"];
end
%% Data Storage
FileSystem["fa:fa-folder File System (Raw Imagery, Rasters, RDS, Reports, Boundaries)"];
Database["fa:fa-database Database (Project Metadata, Users, Schedules)"];
%% User Outputs
Users_WebView["fa:fa-desktop Users: Web Interface (future)"];
Users_EmailReports["fa:fa-envelope Users: Email Reports (Agronomic Reports)"];
AgronomicReports["fa:fa-file-alt Agronomic Reports (DOCX, HTML)"];
%% --- Data Flows & Interactions ---
%% Laravel to Orchestration & Engine
Laravel_WebApp -- Manages/Triggers --> Shell_Orchestration;
Shell_Orchestration -- Executes --> Python_Downloader;
Shell_Orchestration -- Executes --> R_Engine;
%% Python Downloader within Engine
ExternalSatAPI -- Satellite Data --> Python_Downloader;
Python_Downloader -- Writes Raw Data --> FileSystem;
%% Inputs to Python (simplified for this view - details in Python-specific diagram)
%% Laravel_WebApp -- Provides Config/Boundaries --> Python_Downloader;
%% R Engine within Engine
%% Inputs to R (simplified - details in R-specific diagram)
%% Laravel_WebApp -- Provides Config/Boundaries --> R_Engine;
R_Engine -- Reads Processed Data/Imagery --> FileSystem;
R_Engine -- Writes Derived Products --> FileSystem;
R_Engine -- Generates --> AgronomicReports;
%% Laravel interaction with Data Storage
Laravel_WebApp -- Manages/Accesses --> FileSystem;
Laravel_WebApp -- Reads/Writes --> Database;
%% Output Delivery
Laravel_WebApp --> Users_WebView;
AgronomicReports --> Users_EmailReports;
%% Assuming a mechanism like SMTP, potentially triggered by Laravel or R-Engine completion
Laravel_WebApp -- Delivers/Displays --> AgronomicReports;
%% Styling
style SmartCane_Engine fill:#e6ffe6,stroke:#333,stroke-width:2px
style Python_Downloader fill:#ffdd57,stroke:#333,stroke-width:2px
style R_Engine fill:#f9f,stroke:#333,stroke-width:2px
style Laravel_WebApp fill:#bbf,stroke:#333,stroke-width:2px
style Shell_Orchestration fill:#f0ad4e,stroke:#333,stroke-width:2px
style FileSystem fill:#d1e0e0,stroke:#333,stroke-width:1px
style Database fill:#d1e0e0,stroke:#333,stroke-width:1px
style ExternalSatAPI fill:#f5b7b1,stroke:#333,stroke-width:2px
style AgronomicReports fill:#d4efdf,stroke:#333,stroke-width:1px
Future Directions
The SmartCane platform is poised for significant evolution, with several key enhancements and new capabilities planned to further empower users and expand its utility:
- Advanced Management Dashboard: Development of a more comprehensive and interactive management dashboard to provide users with deeper insights and greater control over their operations.
- Enhanced Yield Prediction Models: Improving the accuracy and granularity of yield predictions by incorporating more variables and advanced machine learning techniques.
- Integrated Weather and Irrigation Advice: Leveraging weather forecast data and soil moisture information (potentially from new data sources) to provide precise irrigation scheduling and weather-related agronomic advice.
- AI-Guided Agronomic Advice: Implementing sophisticated AI algorithms to analyze integrated data (satellite, weather, soil, farm practices) and offer tailored, actionable agronomic recommendations.
- Automated Advice Generation: Developing capabilities for the system to automatically generate and disseminate critical advice and alerts to users based on real-time data analysis.
- Expanded Data Source Integration:
- Radar Data: Incorporating radar satellite imagery (e.g., Sentinel-1) for all-weather monitoring capabilities, particularly useful during cloudy seasons for assessing crop structure, soil moisture, and biomass.
- IoT and Ground Sensors: Integrating data from in-field IoT devices and soil sensors for highly localized and continuous monitoring of environmental and soil conditions.
- Client-Facing Portal: Exploration and potential development of a client-facing portal to allow end-users direct access to their data, dashboards, and reports, complementing the current internal management interface.
These future developments aim to transform SmartCane into an even more powerful decision support system, fostering sustainable and efficient agricultural practices.
Conclusion and Integration Summary
The SmartCane system architecture demonstrates a well-integrated solution that combines different technologies and subsystems to solve complex agricultural challenges. Here is a summary of how the key subsystems work together:
Subsystem Integration
-
Data Flow Sequence
- The Laravel Web App initiates the workflow and manages user interactions
- Shell scripts orchestrate the execution sequence of the processing subsystems
- The Python API Downloader acquires raw data from external sources
- The R Processing Engine transforms this data into actionable insights
- Results flow back to users through the web interface and email reports
-
Technology Integration
- Python + R: Different programming languages are leveraged for their respective strengths—Python for API communication and data acquisition, R for statistical analysis and report generation
- Laravel + Processing Engine: Clear separation between web presentation layer and computational backend
- File System + Database: Hybrid data storage approach with file system for imagery and reports, database for metadata and user information
-
Key Integration Mechanisms
- File System Bridge: The different subsystems primarily communicate through standardized file formats (GeoTIFF, GeoJSON, RDS, DOCX)
- Shell Script Orchestration: Acts as the "glue" between subsystems, ensuring proper execution sequence and environment setup
- Standardized Data Formats: Use of widely-accepted geospatial and data formats enables interoperability
-
Extensibility and Scalability
- The modular architecture allows for replacement or enhancement of individual components
- The clear subsystem boundaries enable parallel development and testing
- Standard interfaces simplify integration of new data sources, algorithms, or output methods
The SmartCane architecture balances complexity with maintainability by using well-established technologies and clear boundaries between subsystems. The separation of concerns between data acquisition, processing, and presentation layers ensures that changes in one area minimally impact others, while the consistent data flow pathways ensure that information moves smoothly through the system.