How aquacropos/aquacrop works
1. What this repository is
- AquaCrop-OSPy is a local, file-driven crop-soil-water simulation engine in Python, based on FAO AquaCrop-OS.
- The runtime is centered around a single model object, AquaCropModel, which orchestrates initialization, daily simulation, and result collection.
2. Public API boundary
- The main user-facing entry points live at the package root and in aquacrop.core.
- Typical top-level objects are AquaCropModel, Soil, Crop, and InitialWaterContent, with utilities like prepare_weather() and get_filepath() for feeding data into the model.
- This is not a service or web app; it is a scientific computation library with a Python API.
3. Input and data layer
- The model consumes weather time series, soil definitions, crop parameters, initial water content, and optional management / groundwater / irrigation settings.
- The aquacrop/data directory contains bundled example climates, crop reference files, and benchmark outputs used for tutorials and regression tests.
- Data is primarily local files (.txt, .csv, .dat, .st, .OUT), so the architecture is dominated by in-memory computation over tabular inputs.
4. Domain entities
- aquacrop/entities contains the model’s structured state and parameter objects: clock/time structs, soil profile, crop parameters, water stress coefficients, root-zone water content, irrigation and field management, groundwater, CO2, and output structures.
- These modules form the shared data contract passed between initialization, process solvers, and timestep orchestration.
- The design strongly suggests a stateful simulation model where these entities are updated over time rather than pure stateless functions.
5. Initialization pipeline
- aquacrop/initialize turns raw inputs into a fully configured simulation.
- It reads clocks, weather, crop, soil, groundwater, irrigation, field management, and initial condition inputs, then computes derived values like crop calendars, soil profiles, and model variables.
- This is the “setup boundary” where input files and user parameters are transformed into the model state used by the timestep engine.
6. Daily simulation kernel
- aquacrop/timestep provides the loop control for advancing the model day by day.
- Key responsibilities are updating time, running a single timestep, checking whether the simulation is finished, and resetting initial conditions when needed.
- This layer is the orchestrator that wires state progression to the individual physical/process solvers.
7. Process / physics solvers
- aquacrop/solution contains the core agronomic and hydrologic process calculations: infiltration, rainfall partitioning, soil evaporation, transpiration, root development, drainage, capillary rise, groundwater inflow, water stress, temperature stress, canopy cover growth, biomass accumulation, and harvest index adjustment.
- These modules are the main computational engine of the model.
- The repository explicitly notes that some FAO AquaCrop features are not yet implemented, including salinity, fertility stress, weed management, and perennial herbaceous crops.
8. Model outputs
- Outputs are tracked in aquacrop/entities/output and produced as the simulation runs.
- The public workflow ends with tabular results returned by get_simulation_results(), which implies the final artifact is a time series result table rather than a persisted database or service response.
- Benchmark .OUT files in aquacrop/data and tests indicate the outputs are compared against known reference runs.
9. Utilities and preprocessing
- aquacrop/utils contains support functions for preparing weather data, computing growing degree days, and handling auxiliary data sources.
- These utilities sit between raw input files and the simulation setup, helping normalize external data into the model’s expected format.
- aquacrop/scripts/initiate_library.* appears to be a bootstrap step for library initialization / compilation support.
10. Performance / build boundary
- The troubleshooting notes indicate optional AOT/compiled function support and a development mode that disables some compilation for easier execution.
- That means the architecture has a small performance-oriented boundary around compiled numerical routines, but the core model remains Python-first.
11. Validation and regression structure
- tests contains a large set of comparison and behavior tests, including groundwater, irrigation, timestep termination, root growth, exceptions, and speed.
- Several tests use bundled reference files and notebooks, showing the project validates both scientific correctness and simulation lifecycle behavior.
- This is important for the architecture diagram because the reference data is part of the model’s acceptance contract.
12. Documentation and distribution
- The repo is packaged for PyPI and documented with MkDocs (docs/, mkdocs.yml), with GitHub Actions workflows for unit tests, docs builds, and publishing.
- This supports a standard open-source library lifecycle: local simulation engine, docs/tutorials, regression tests, package release.
- There is no indication of external runtime infrastructure beyond packaging and CI/CD.
Main entry points: core.py Core API · initialize/__init__.py Initialize · solution/__init__.py Solvers · read_weather_inputs.py Input readers
Components 21
Public API
User-facing entry points and convenience helpers.
- Package root · Top-level import surface exposing the main model objects.
aquacrop/__init__.py - Core API · Defines AquaCropModel and user-facing simulation workflow.
aquacrop/core.py - Weather prep · Normalizes weather and auxiliary inputs for the model.
aquacrop/utils/prepare_weather.py - GDD prep · Prepares growing-degree-day related inputs.
aquacrop/utils/prepare_gdd.py
Simulation pipeline
Initialization, timestep control, and solver execution.
- Initialize · Reads inputs and builds derived model state.
aquacrop/initialize/__init__.py - Input readers · Reads clocks, weather, model parameters, and management inputs.
aquacrop/initialize/read_weather_inputs.py - Soil builder · Creates soil profiles and derived initialization variables.
aquacrop/initialize/create_soil_profile.py - Timestep loop · Controls daily progression, termination, and reset behavior.
aquacrop/timestep/__init__.py - Run day · Executes one simulation day and updates state.
aquacrop/timestep/run_single_timestep.py - Solvers · Core agronomic and hydrologic process calculations.
aquacrop/solution/__init__.py - Water fluxes · Infiltration, drainage, evaporation, transpiration, and groundwater flow.
aquacrop/solution/infiltration.py - Crop growth · Canopy cover, root development, biomass, and harvest index.
aquacrop/solution/canopy_cover.py
Domain state
Structured entities passed through the model.
- Model state · Shared simulation entities for soil, crop, water, stress, and outputs.
aquacrop/entities/__init__.py - Soil profile · Soil and profile structures used throughout initialization and solvers.
aquacrop/entities/soil.py - Crop params · Crop parameter definitions and related structures.
aquacrop/entities/crop.py - Water state · Root-zone water content and depletion state.
aquacrop/entities/rootZoneWaterContent.py - Mgmt settings · Irrigation, field management, and groundwater settings.
aquacrop/entities/irrigationManagement.py - Outputs · Time-series output structures produced by the run.
aquacrop/entities/output.py
Support assets
Bundled data, docs, tests, and packaging.
- Bundled data · Example climates, benchmark inputs, and reference outputs.
aquacrop/data/__init__.py - Regression tests · Behavior and comparison tests against known reference runs.
tests/__init__.py - Docs · MkDocs documentation and tutorial notebooks.
docs/index.md
Connections 26
- Package root → Core API: exports · Package root exposes the main library API.
- Core API → Weather prep: prepares · Public workflow accepts normalized weather inputs.
- Core API → GDD prep: prepares · Public workflow can derive growing-degree-day inputs.
- Core API → Model state: builds state · Model construction relies on shared domain entities.
- Weather prep → Initialize: feeds · Prepared weather data enters initialization.
- GDD prep → Initialize: feeds · Auxiliary climate features enter initialization.
- Initialize → Input readers: reads · Initialization parses clocks and raw model inputs.
- Initialize → Soil builder: derives · Initialization computes soil profiles and model variables.
- Input readers → Soil profile: uses · Input readers populate soil-related structures.
- Input readers → Crop params: uses · Input readers populate crop parameter structures.
- Soil builder → Water state: initializes · Derived setup creates initial water state.
- Soil builder → Mgmt settings: initializes · Setup incorporates irrigation and groundwater settings.
- Initialize → Timestep loop: hands off · Configured state is passed to the daily engine.
- Timestep loop → Run day: advances · The loop executes one timestep at a time.
- Run day → Solvers: calls · Each day dispatches to process solvers.
- Solvers → Water fluxes: runs · Water balance and flux calculations.
- Solvers → Crop growth: runs · Crop development and yield calculations.
- Water fluxes → Water state: updates · Hydrologic processes mutate water state.
- Crop growth → Crop params: updates · Growth processes mutate crop state.
- Crop growth → Outputs: records · Solved daily values are accumulated into outputs.
- Run day → Outputs: appends · Runtime collects timestep results.
- Bundled data → Initialize: supplies examples · Bundled files are used as local inputs and references.
- Regression tests → Core API: validates · Tests exercise the public model workflow and lifecycle.
- Regression tests → Outputs: compares · Regression tests compare against known output tables.
- Docs → Core API: documents · Docs explain the main API and usage pattern.
- Docs → Solvers: documents · Docs describe the process solver layer.