https://github.com/csdms/bmi-example-pynetlogo
An example of wrapping a model written in NetLogo with a Python BMI
https://github.com/csdms/bmi-example-pynetlogo
bmi csdms netlogo python
Last synced: 4 months ago
JSON representation
An example of wrapping a model written in NetLogo with a Python BMI
- Host: GitHub
- URL: https://github.com/csdms/bmi-example-pynetlogo
- Owner: csdms
- License: mit
- Created: 2023-11-08T18:34:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-18T02:47:44.000Z (4 months ago)
- Last Synced: 2025-02-18T03:28:13.320Z (4 months ago)
- Topics: bmi, csdms, netlogo, python
- Language: NetLogo
- Homepage: https://bmi.csdms.io
- Size: 68.4 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://bmi.readthedocs.io/)
[](https://github.com/csdms/bmi-example-pynetlogo/actions/workflows/test.yml)# bmi-example-pynetlogo
An example of using the
[Python bindings](https://github.com/csdms/bmi-python)
for the CSDMS
[Basic Model Interface](https://bmi.readthedocs.io) (BMI)
to wrap a model written in [NetLogo](https://ccl.northwestern.edu/netlogo/).## Overview
This is an example of implementing a BMI for a simple model of temperature diffusion
on a uniform rectangular plate
with Dirichlet boundary conditions.
The model, [HeatDiffusion](https://ccl.northwestern.edu/netlogo/models/HeatDiffusion),
is written in NetLogo,
and is a part of the standard NetLogo distribution.This repository is organized with the following directories:
- heat
- Source for the model and a BMI implementation for the model
- examples
- Python scripts and Jupyter Notebooks that demonstrate how to run the model standalone and through its BMI
- tests
- Tests that cover the BMI of the model
## Build/Install
This example can be built and installed on Linux, macOS, and Windows.
**Prerequisites:**
* Java Runtime Environment (JRE). NetLogo is build on Java, and it needs a JRE to run.
* NetLogo. Instructions for downloading and installing NetLogo can be found [here](https://ccl.northwestern.edu/netlogo/download.shtml). NetLogo 6.1.1 was used to build, test, and run this example.
* Python BMI mappings. Follow the [build and install directions](https://github.com/csdms/bmi-python#install) given in that repository. You can choose to install them from source, or through `pip` or `conda`.
* PyNetLogo and Jpype. These are the key software packages that allow communication between NetLogo and Python.
We recommend setting up a virtual environment--e.g., through `venv` or `conda`--to install the packages required for this example.
For `conda`,
we've included an environment file.
```
conda env create --file environment.yml
```
This creates the *logo* environment,
which you can activate to have access to all the dependent packages needed to build and use this example.
Install the example with `pip`.
```
pip install -e .
```
### Note on Java install location
Jpype tries to guess where Java is installed.
If Java is installed in a non-standard location,
set the `JAVA_HOME` environment variable.
As an example,
I installed Java through Homebrew on my Mac,
so I set `JAVA_HOME` to its install location:
```bash
export JAVA_HOME=/opt/homebrew/opt/openjdk
```
## Use
Try the example notebooks and scripts in the [examples](./examples/) directory.
## Acknowledgments
The model of temperature diffusion used in this example.
> Wilensky, U. (1998). NetLogo Heat Diffusion model. http://ccl.northwestern.edu/netlogo/models/HeatDiffusion. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
The NetLogo software.
> Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
CSDMS is supported with funding from the U.S. National Science Foundation.