Cropbox

Cropbox is a declarative modeling framework specifically designed for developing crop models. The goal is to let crop modelers focus on what the model should look like rather than how the model is technically implemented under the hood.

Installation

Cropbox.jl is available through Julia package manager.

using Pkg
Pkg.add("Cropbox")

There is a Docker image with Cropbox precompiled for convenience. By default, Jupyter Lab will be launched.

$ docker run -it --rm -p 8888:8888 cropbox/cropbox

If REPL is preferred, you can directly launch an instance of Julia session.

$ docker run -it --rm cropbox/cropbox julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.1 (2021-04-23)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

The docker image can be also launched via Binder without installing anything local.

Binder

Getting Started

Let's start with Cropbox.

using Cropbox

In Cropbox, system is where the model specification is written down in a slightly repurposed Julia syntax, which is an approach generally called domain specific language (DSL).

@system S(Controller) begin
    a(a) ~ accumulate(init = 1)
end

In this simple example, our system S has a single variable named a which accumulates itself starting from an initial value of 1. Once the model is defined as a system, users can run simulations.

r = simulate(S, stop = 5)
6×2 DataFrame
 Row │ time       a
     │ Quantity…  Float64
─────┼────────────────────
   1 │    0.0 hr      1.0
   2 │    1.0 hr      2.0
   3 │    2.0 hr      4.0
   4 │    3.0 hr      8.0
   5 │    4.0 hr     16.0
   6 │    5.0 hr     32.0

Here is a line plot of the variable a after running simulation updated for five times.

visualize(r, :time, :a; kind = :line)
x 0 1 2 3 4 5 a 10 20 30 y

A more comprehensive guide in the next page will tell more about concepts and features behind Cropbox.