# aquacropos/aquacrop architecture

> Architecture diagram of the GitHub repository aquacropos/aquacrop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aquacropos/aquacrop
- Repository: https://github.com/aquacropos/aquacrop

## Overview

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: [`aquacrop/core.py`](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/core.py) (Core API), [`aquacrop/initialize/__init__.py`](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/__init__.py) (Initialize), [`aquacrop/solution/__init__.py`](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/__init__.py) (Solvers), [`aquacrop/initialize/read_weather_inputs.py`](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/read_weather_inputs.py) (Input readers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public_api["Public API"]
  node_pkg_root["Package root<br/>api<br/>[__init__.py]"]
  node_core_api["Core API<br/>model orchestration<br/>[core.py]"]
  node_weather_utils["Weather prep<br/>[prepare_weather.py]"]
  node_gdd_utils["GDD prep<br/>[prepare_gdd.py]"]
end

subgraph group_pipeline["Simulation pipeline"]
  node_init_pipeline["Initialize<br/>setup pipeline<br/>[__init__.py]"]
  node_clock_reader["Input readers<br/>setup stages"]
  node_soil_builder["Soil builder<br/>setup stage"]
  node_daily_loop["Timestep loop<br/>runtime loop<br/>[__init__.py]"]
  node_single_step["Run day<br/>runtime step"]
  node_solver_bundle["Solvers<br/>physics engine<br/>[__init__.py]"]
  node_hydro_solver["Water fluxes<br/>solver<br/>[infiltration.py]"]
  node_crop_solver["Crop growth<br/>solver<br/>[canopy_cover.py]"]
end

subgraph group_domain["Domain state"]
  node_entity_bundle["Model state<br/>entities<br/>[__init__.py]"]
  node_soil_entity["Soil profile<br/>entity<br/>[soil.py]"]
  node_crop_entity["Crop params<br/>entity<br/>[crop.py]"]
  node_water_entity["Water state<br/>entity"]
  node_management_entity["Mgmt settings<br/>entity"]
  node_output_entity["Outputs<br/>entity<br/>[output.py]"]
end

subgraph group_support["Support assets"]
  node_data_bundle["Bundled data<br/>reference data<br/>[__init__.py]"]
  node_tests_bundle["Regression tests<br/>validation<br/>[__init__.py]"]
  node_docs_site["Docs<br/>documentation<br/>[index.md]"]
end

node_pkg_root -->|"exports"| node_core_api
node_core_api -->|"prepares"| node_weather_utils
node_core_api -->|"prepares"| node_gdd_utils
node_core_api -->|"builds state"| node_entity_bundle
node_weather_utils -->|"feeds"| node_init_pipeline
node_gdd_utils -->|"feeds"| node_init_pipeline
node_init_pipeline -->|"reads"| node_clock_reader
node_init_pipeline -->|"derives"| node_soil_builder
node_clock_reader -->|"uses"| node_soil_entity
node_clock_reader -->|"uses"| node_crop_entity
node_soil_builder -->|"initializes"| node_water_entity
node_soil_builder -->|"initializes"| node_management_entity
node_init_pipeline -->|"hands off"| node_daily_loop
node_daily_loop -->|"advances"| node_single_step
node_single_step -->|"calls"| node_solver_bundle
node_solver_bundle -->|"runs"| node_hydro_solver
node_solver_bundle -->|"runs"| node_crop_solver
node_hydro_solver -->|"updates"| node_water_entity
node_crop_solver -->|"updates"| node_crop_entity
node_crop_solver -->|"records"| node_output_entity
node_single_step -->|"appends"| node_output_entity
node_data_bundle -->|"supplies examples"| node_init_pipeline
node_tests_bundle -->|"validates"| node_core_api
node_tests_bundle -->|"compares"| node_output_entity
node_docs_site -->|"documents"| node_core_api
node_docs_site -->|"documents"| node_solver_bundle

click node_pkg_root "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/__init__.py"
click node_core_api "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/core.py"
click node_weather_utils "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/utils/prepare_weather.py"
click node_gdd_utils "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/utils/prepare_gdd.py"
click node_entity_bundle "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/__init__.py"
click node_soil_entity "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/soil.py"
click node_crop_entity "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/crop.py"
click node_water_entity "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/rootZoneWaterContent.py"
click node_management_entity "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/irrigationManagement.py"
click node_output_entity "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/output.py"
click node_init_pipeline "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/__init__.py"
click node_clock_reader "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/read_weather_inputs.py"
click node_soil_builder "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/create_soil_profile.py"
click node_daily_loop "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/timestep/__init__.py"
click node_single_step "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/timestep/run_single_timestep.py"
click node_solver_bundle "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/__init__.py"
click node_hydro_solver "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/infiltration.py"
click node_crop_solver "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/canopy_cover.py"
click node_data_bundle "https://github.com/aquacropos/aquacrop/blob/master/aquacrop/data/__init__.py"
click node_tests_bundle "https://github.com/aquacropos/aquacrop/blob/master/tests/__init__.py"
click node_docs_site "https://github.com/aquacropos/aquacrop/blob/master/docs/index.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pkg_root,node_core_api,node_weather_utils,node_gdd_utils toneBlue
class node_init_pipeline,node_clock_reader,node_soil_builder,node_daily_loop,node_single_step,node_solver_bundle,node_hydro_solver,node_crop_solver toneAmber
class node_entity_bundle,node_soil_entity,node_crop_entity,node_water_entity,node_management_entity,node_output_entity toneMint
class node_data_bundle,node_tests_bundle,node_docs_site toneRose
```

## Components

### Public API

User-facing entry points and convenience helpers.

- [Package root](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/__init__.py): api · Top-level import surface exposing the main model objects. · `aquacrop/__init__.py`
- [Core API](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/core.py): model orchestration · Defines AquaCropModel and user-facing simulation workflow. · `aquacrop/core.py`
- [Weather prep](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/utils/prepare_weather.py): utility · Normalizes weather and auxiliary inputs for the model. · `aquacrop/utils/prepare_weather.py`
- [GDD prep](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/utils/prepare_gdd.py): utility · Prepares growing-degree-day related inputs. · `aquacrop/utils/prepare_gdd.py`

### Simulation pipeline

Initialization, timestep control, and solver execution.

- [Initialize](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/__init__.py): setup pipeline · Reads inputs and builds derived model state. · `aquacrop/initialize/__init__.py`
- [Input readers](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/read_weather_inputs.py): setup stages · Reads clocks, weather, model parameters, and management inputs. · `aquacrop/initialize/read_weather_inputs.py`
- [Soil builder](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/initialize/create_soil_profile.py): setup stage · Creates soil profiles and derived initialization variables. · `aquacrop/initialize/create_soil_profile.py`
- [Timestep loop](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/timestep/__init__.py): runtime loop · Controls daily progression, termination, and reset behavior. · `aquacrop/timestep/__init__.py`
- [Run day](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/timestep/run_single_timestep.py): runtime step · Executes one simulation day and updates state. · `aquacrop/timestep/run_single_timestep.py`
- [Solvers](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/__init__.py): physics engine · Core agronomic and hydrologic process calculations. · `aquacrop/solution/__init__.py`
- [Water fluxes](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/infiltration.py): solver · Infiltration, drainage, evaporation, transpiration, and groundwater flow. · `aquacrop/solution/infiltration.py`
- [Crop growth](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/solution/canopy_cover.py): solver · Canopy cover, root development, biomass, and harvest index. · `aquacrop/solution/canopy_cover.py`

### Domain state

Structured entities passed through the model.

- [Model state](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/__init__.py): entities · Shared simulation entities for soil, crop, water, stress, and outputs. · `aquacrop/entities/__init__.py`
- [Soil profile](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/soil.py): entity · Soil and profile structures used throughout initialization and solvers. · `aquacrop/entities/soil.py`
- [Crop params](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/crop.py): entity · Crop parameter definitions and related structures. · `aquacrop/entities/crop.py`
- [Water state](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/rootZoneWaterContent.py): entity · Root-zone water content and depletion state. · `aquacrop/entities/rootZoneWaterContent.py`
- [Mgmt settings](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/irrigationManagement.py): entity · Irrigation, field management, and groundwater settings. · `aquacrop/entities/irrigationManagement.py`
- [Outputs](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/entities/output.py): entity · Time-series output structures produced by the run. · `aquacrop/entities/output.py`

### Support assets

Bundled data, docs, tests, and packaging.

- [Bundled data](https://github.com/aquacropos/aquacrop/blob/master/aquacrop/data/__init__.py): reference data · Example climates, benchmark inputs, and reference outputs. · `aquacrop/data/__init__.py`
- [Regression tests](https://github.com/aquacropos/aquacrop/blob/master/tests/__init__.py): validation · Behavior and comparison tests against known reference runs. · `tests/__init__.py`
- [Docs](https://github.com/aquacropos/aquacrop/blob/master/docs/index.md): documentation · MkDocs documentation and tutorial notebooks. · `docs/index.md`

## Connections

- 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.
