apsimNGpy: The Next-Generation Agro-ecosystem Simulation Library
Introduction
apsimNGpy is a cutting-edge, open-source Python framework designed for advanced modeling with APSIM process-based model. Built on object-oriented principles. apsimNGpy extends and augments APSIM Next Generation functionalities within the Python scientific ecosystem, turning GUI-centric workflows into scriptable, reproducible, and scalable pipelines. apsimNGpy functionalities include, but not limited to the following:
Scalable performance. Run large experiment sets efficiently via
multiprocessing/multithreading(e.g., factorials, ensembles, calibrations) using a clean, high-level API.Spatial & data integration. Leverage Python’s geospatial stack and built-in helpers to fetch and manage soil/weather inputs, enabling landscape-scale analyses.
Optimization & calibration. Access multi-objective optimization and sensitivity analysis to quantify trade-offs (e.g., yield vs. nitrate loss/GHG) and calibrate parameters.
Reproducible automation. Run
APSIMusing Jupyter/CLI/scripts; outputs land inpandas DataFramesfor downstream analysis, plotting, and reporting.Full model manipulation. A modular,
object-orienteddesign supports inspection, editing, experiments, and custom reports without manual GUI interface.Version resilience. rather than tying
apsimNGpyto a fixed APSIM version,apsimNGpyis developed with forward- and backward-compatibility in mind and is actively synchronized with upstream APSIM.Open and extensible.
Apache-2.0licensing, clear abstractions, and a plug-friendly architecture make it easy to extend and integrate into existing research pipelines.Diverse model evaluation metrics. Built-in model prediction evaluation metrics: RMSE, RRMSE, Willmott’s Index of Agreement (WIA), Bias, MAE, Lin’s CCC, and R2
Table of Contents
Getting Started
VERSION CONTROL
EDITING & INSPECTION
DISTRIBUTED COMPUTING
OPTIMIZATION & TRADE-OFF ANALYSIS
- Single-Objective Optimization with apsimNGpy
- Mixed-Variable Optimization in apsimNGpy
- Multi-Objective Optimization with apsimNGpy- Step 1: Import required modules
- Step 2: Initialize the APSIM model runner
- Step 3: Define Objective Functions
- Step 4a: Define decision variables (Approach 1 - direct List)
- Step 3b: Define decision variables (Approach 2 - using add_control())
- Step 5: Run the NSGA-II optimizer
- Step 6: Plot the Pareto Front
- Comparing objectives without mult-objective optimization
 
SUPPORT DEVELOPMENT
CHEATSHEET
SIMULATED DATA PLOTTING & VISUALIZATION
- Plotting and Visualizing Simulated Output
- Moving average plots
- Categorical Plots- Box plots
- Maize yield variability by population density (mva plot).
- Maize yield variability by population density and nitrogen fertilizer (box plot).
- Bar Plots
- Maize yield variability by population density (bar plot).
- Maize yield variability by population density (bar plot, estimator =sum).
- Maize yield variability by population density in Mg (bar plot, estimator =sum).
 
- Tidy up the plots for reporting
- Passing a custom dataset
- Meta info
API REFERENCE
- apsimNGpy: API Reference- apsimNGpy.core.apsim
- apsimNGpy.core.config
- apsimNGpy.core.experimentmanager
- apsimNGpy.core.mult_cores
- apsimNGpy.core.pythonet_config
- apsimNGpy.core.runner
- apsimNGpy.core_utils.database_utils
- apsimNGpy.exceptions
- apsimNGpy.optimizer.moo
- apsimNGpy.optimizer.single
- apsimNGpy.parallel.process
- apsimNGpy.validation.evaluator