diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 56195616..3430b3a2 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-07T00:32:45","documenter_version":"1.3.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-07T05:45:22","documenter_version":"1.3.0"}} \ No newline at end of file diff --git a/dev/faq/index.html b/dev/faq/index.html index c09d387e..3a3d9d99 100644 --- a/dev/faq/index.html +++ b/dev/faq/index.html @@ -3,4 +3,4 @@ function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-192782823-1', {'page_path': location.pathname + location.search + location.hash}); -
+
diff --git a/dev/gallery/index.html b/dev/gallery/index.html index faaf94ce..4306da5d 100644 --- a/dev/gallery/index.html +++ b/dev/gallery/index.html @@ -3,4 +3,4 @@ function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-192782823-1', {'page_path': location.pathname + location.search + location.hash}); -
+
diff --git a/dev/guide/configuration/index.html b/dev/guide/configuration/index.html index bf6d886d..f02493f4 100644 --- a/dev/guide/configuration/index.html +++ b/dev/guide/configuration/index.html @@ -101,4 +101,4 @@

context=<Context> config=<Config> D=3×2 DataFrame… - + diff --git a/dev/guide/inspection/index.html b/dev/guide/inspection/index.html index d871ae66..29670fd8 100644 --- a/dev/guide/inspection/index.html +++ b/dev/guide/inspection/index.html @@ -34,4 +34,4 @@ S → context = <Context> config = <Config> - a = 1.0 + a = 1.0 diff --git a/dev/guide/simulation/index.html b/dev/guide/simulation/index.html index f17a2e3f..1f54446c 100644 --- a/dev/guide/simulation/index.html +++ b/dev/guide/simulation/index.html @@ -79,4 +79,4 @@ a=20.0 - + diff --git a/dev/guide/system/index.html b/dev/guide/system/index.html index 265c5566..70a6fb26 100644 --- a/dev/guide/system/index.html +++ b/dev/guide/system/index.html @@ -66,4 +66,4 @@ (last - init) / step end end ~ preserve::int(round, optional) -end +end diff --git a/dev/guide/variable/index.html b/dev/guide/variable/index.html index a8a07788..5189f65b 100644 --- a/dev/guide/variable/index.html +++ b/dev/guide/variable/index.html @@ -589,4 +589,4 @@ b(a) => a ~ track(when=flag) end -simulate(S; stop=3u"hr")
4×4 DataFrame
Rowtimeaflagb
Quantity…Float64BoolFloat64
10.0 hr0.0false0.0
21.0 hr1.0false0.0
32.0 hr2.0true2.0
43.0 hr3.0true3.0
+simulate(S; stop=3u"hr")
4×4 DataFrame
Rowtimeaflagb
Quantity…Float64BoolFloat64
10.0 hr0.0false0.0
21.0 hr1.0false0.0
32.0 hr2.0true2.0
43.0 hr3.0true3.0
diff --git a/dev/guide/visualization/caf83c2c.svg b/dev/guide/visualization/79260e4f.svg similarity index 66% rename from dev/guide/visualization/caf83c2c.svg rename to dev/guide/visualization/79260e4f.svg index 346526d6..03766432 100644 --- a/dev/guide/visualization/caf83c2c.svg +++ b/dev/guide/visualization/79260e4f.svg @@ -14,13 +14,13 @@ - + - - + + 1 @@ -47,140 +47,140 @@ - - - + + + #1 - - - + + + - - + + - - - - + + + + - - + + - + - + - + - + - - + + - + - + - + - + - + - - - - + + + + - - + + 5,10 - - - + + + - - + + 4,8 - - - + + + - - + + 3,6 - - - + + + - - + + 2,4 - - - + + + - - + + 1,2 @@ -191,28 +191,28 @@ - - + + 2 - + 4 - + 6 - + 8 - + 10 @@ -220,7 +220,7 @@ - + diff --git a/dev/guide/visualization/a44821a2.svg b/dev/guide/visualization/c16341b3.svg similarity index 61% rename from dev/guide/visualization/a44821a2.svg rename to dev/guide/visualization/c16341b3.svg index 51bd5207..621fc038 100644 --- a/dev/guide/visualization/a44821a2.svg +++ b/dev/guide/visualization/c16341b3.svg @@ -14,20 +14,20 @@ - + - - + + x - + 0 @@ -44,222 +44,222 @@ - - - + + + y1 - + y2 - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - - - - + + + + - - + + 10.0,20.0 - - - + + + - - + + 9.0,18.0 - - - + + + - - + + 8.0,16.0 - - - + + + - - + + 7.0,14.0 - - - + + + - - + + 6.0,12.0 - - - + + + - - + + 5.0,10.0 - - - + + + - - + + 4.0,8.0 - - - + + + - - + + 3.0,6.0 - - - + + + - - + + 2.0,4.0 - - - + + + - - + + 1.0,2.0 - - - + + + - - + + 0.0,0.0 @@ -267,155 +267,155 @@ - - - - + + + + - - + + 10.0,100.0 - - - + + + - - + + 9.0,81.0 - - - + + + - - + + 8.0,64.0 - - - + + + - - + + 7.0,49.0 - - - + + + - - + + 6.0,36.0 - - - + + + - - + + 5.0,25.0 - - - + + + - - + + 4.0,16.0 - - - + + + - - + + 3.0,9.0 - - - + + + - - + + 2.0,4.0 - - - + + + - - + + 1.0,1.0 - - - + + + - - + + 0.0,0.0 @@ -426,18 +426,18 @@ - - + + 0 - + 50 - + 100 @@ -445,7 +445,7 @@ - + diff --git a/dev/guide/visualization/af33780a.svg b/dev/guide/visualization/cb2e2afa.svg similarity index 61% rename from dev/guide/visualization/af33780a.svg rename to dev/guide/visualization/cb2e2afa.svg index 57c875bb..df337861 100644 --- a/dev/guide/visualization/af33780a.svg +++ b/dev/guide/visualization/cb2e2afa.svg @@ -14,20 +14,20 @@ - + - - + + x - + 0 @@ -44,232 +44,232 @@ - - - + + + y1 - + y2 - + y3 - - - + + + - - + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - - - - + + + + - - + + 10.0,20.0 - - - + + + - - + + 9.0,18.0 - - - + + + - - + + 8.0,16.0 - - - + + + - - + + 7.0,14.0 - - - + + + - - + + 6.0,12.0 - - - + + + - - + + 5.0,10.0 - - - + + + - - + + 4.0,8.0 - - - + + + - - + + 3.0,6.0 - - - + + + - - + + 2.0,4.0 - - - + + + - - + + 1.0,2.0 - - - + + + - - + + 0.0,0.0 @@ -277,155 +277,155 @@ - - - - + + + + - - + + 10.0,100.0 - - - + + + - - + + 9.0,81.0 - - - + + + - - + + 8.0,64.0 - - - + + + - - + + 7.0,49.0 - - - + + + - - + + 6.0,36.0 - - - + + + - - + + 5.0,25.0 - - - + + + - - + + 4.0,16.0 - - - + + + - - + + 3.0,9.0 - - - + + + - - + + 2.0,4.0 - - - + + + - - + + 1.0,1.0 - - - + + + - - + + 0.0,0.0 @@ -433,155 +433,155 @@ - - - - + + + + - - + + 10.0,30.0 - - - + + + - - + + 9.0,27.0 - - - + + + - - + + 8.0,24.0 - - - + + + - - + + 7.0,21.0 - - - + + + - - + + 6.0,18.0 - - - + + + - - + + 5.0,15.0 - - - + + + - - + + 4.0,12.0 - - - + + + - - + + 3.0,9.0 - - - + + + - - + + 2.0,6.0 - - - + + + - - + + 1.0,3.0 - - - + + + - - + + 0.0,0.0 @@ -592,18 +592,18 @@ - - + + 0 - + 50 - + 100 @@ -611,7 +611,7 @@ - + diff --git a/dev/guide/visualization/ebe62115.svg b/dev/guide/visualization/f59ffcee.svg similarity index 63% rename from dev/guide/visualization/ebe62115.svg rename to dev/guide/visualization/f59ffcee.svg index e6230ada..f47ae112 100644 --- a/dev/guide/visualization/ebe62115.svg +++ b/dev/guide/visualization/f59ffcee.svg @@ -14,13 +14,13 @@ - + - - + + 1 @@ -47,165 +47,165 @@ - - - + + + #1 - + #2 - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - - - - + + + + - - + + 5,5 - - - + + + - - + + 4,4 - - - + + + - - + + 3,3 - - - + + + - - + + 2,2 - - - + + + - - + + 1,1 @@ -213,71 +213,71 @@ - - - - + + + + - - + + 5,10 - - - + + + - - + + 4,8 - - - + + + - - + + 3,6 - - - + + + - - + + 2,4 - - - + + + - - + + 1,2 @@ -288,53 +288,53 @@ - - + + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 - + 10 @@ -342,7 +342,7 @@ - + diff --git a/dev/guide/visualization/index.html b/dev/guide/visualization/index.html index f468526e..0728b793 100644 --- a/dev/guide/visualization/index.html +++ b/dev/guide/visualization/index.html @@ -6,7 +6,7 @@

Visualization

There are three main functions in Cropbox used for visualization. For information regarding syntax, please check the reference.

plot()

The plot() function is used to plot two-dimensional graphs.

Two Vectors

Let's start by making a simple plot by using two vectors of discrete values.

x = [1, 2, 3, 4, 5]
 y = [2, 4, 6, 8, 10]
 
-plot(x, y)
Example block output


Multiple Vectors

You can also plot multiple series, by using a vector of vectors.

plot(x, [x, y])
Example block output


DataFrame

We can also make a plot using a DataFrame and its columns. Recall that the simulate() function provides a DataFrame.

@system S(Controller) begin
+plot(x, y)
Example block output


Multiple Vectors

You can also plot multiple series, by using a vector of vectors.

plot(x, [x, y])
Example block output


DataFrame

We can also make a plot using a DataFrame and its columns. Recall that the simulate() function provides a DataFrame.

@system S(Controller) begin
     x ~ advance
     y1(x) => 2x ~ track
     y2(x) => x^2 ~ track
@@ -14,14 +14,14 @@
 
 df = simulate(S; stop=10)
 
-p = plot(df, :x, [:y1, :y2])
Example block output

plot!()

plot!() is an extension of the plot() function used to update an existing Plot object p by appending a new graph made with plot()

Example

@system S(Controller) begin
+p = plot(df, :x, [:y1, :y2])
Example block output

plot!()

plot!() is an extension of the plot() function used to update an existing Plot object p by appending a new graph made with plot()

Example

@system S(Controller) begin
     x ~ advance
     y3(x) => 3x ~ track
 end
 
 df = simulate(S; stop=10)
 
-plot!(p, df, :x, :y3)
Example block output

visualize()

The visualize() function is used to make a plot from an output collected by running simulations. It is essentially identical to running the plot() function with a DataFrame from the simulate() function, and can be seen as a convenient function to run both plot() and simulate() together.

Example

@system S(Controller) begin
+plot!(p, df, :x, :y3)
Example block output

visualize()

The visualize() function is used to make a plot from an output collected by running simulations. It is essentially identical to running the plot() function with a DataFrame from the simulate() function, and can be seen as a convenient function to run both plot() and simulate() together.

Example

@system S(Controller) begin
     x ~ advance
     y1(x) => 2x ~ track
     y2(x) => x^2 ~ track
@@ -43,20 +43,20 @@
     
   
 
-
+
   
     
   
 
-
-  
+
+  
     
       
         x
       
     
   
-  
+  
     
       
         0
@@ -73,83 +73,83 @@
       
     
   
-  
-    
-      
+  
+    
+      
         
           y1
         
       
-      
+      
         
           y2
         
       
     
-    
-      
-        
+    
+      
+        
           
         
       
-      
-        
+      
+        
           
         
       
     
-    
-      
+    
+      
         
           
         
       
     
   
-  
-    
-      
-        
+  
+    
+      
+        
           
         
       
-      
-        
+      
+        
           
         
-        
+        
           
         
-        
+        
           
         
       
-      
-        
+      
+        
           
         
-        
+        
           
         
-        
+        
           
         
       
-      
+      
         
           
           
         
-        
-          
-            
+        
+          
+            
               
             
           
         
-        
-          
-            
+        
+          
+            
               
             
           
@@ -157,18 +157,18 @@
       
     
   
-  
-    
+  
+    
       
         0
       
     
-    
+    
       
         50
       
     
-    
+    
       
         100
       
@@ -176,7 +176,7 @@
   
 
 
-  
+  
     
   
 
@@ -202,20 +202,20 @@ 

- + - - + + x - + 0 @@ -232,90 +232,90 @@

- - - + + + y1 - + y2 - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - - - + + + - - - + + + - - - + + + @@ -323,18 +323,18 @@

- - + + 0 - + 50 - + 100 @@ -342,9 +342,9 @@

- + -

manipulate()

The manipulate function has two different methods for creating an interactive plot.

manipulate(f::Function; parameters, config=())

Create an interactive plot updated by callback f. Only works in Jupyter Notebook.

manipulate(args...; parameters, kwargs...)

Create an interactive plot by calling manipulate with visualize as a callback.

+

manipulate()

The manipulate function has two different methods for creating an interactive plot.

manipulate(f::Function; parameters, config=())

Create an interactive plot updated by callback f. Only works in Jupyter Notebook.

manipulate(args...; parameters, kwargs...)

Create an interactive plot by calling manipulate with visualize as a callback.

diff --git a/dev/index.html b/dev/index.html index eede9c0a..500d5fb8 100644 --- a/dev/index.html +++ b/dev/index.html @@ -3,4 +3,4 @@ function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-192782823-1', {'page_path': location.pathname + location.search + location.hash}); -

Cropbox

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

Getting started

Citation

When using Cropbox in your work, please cite the following paper:

Yun K, Kim S-H (2023) Cropbox: a declarative crop modelling framework. in silico Plants 5(1), diac021 (https://doi.org/10.1093/insilicoplants/diac021)
+

Cropbox

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

Getting started

Citation

When using Cropbox in your work, please cite the following paper:

Yun K, Kim S-H (2023) Cropbox: a declarative crop modelling framework. in silico Plants 5(1), diac021 (https://doi.org/10.1093/insilicoplants/diac021)
diff --git a/dev/installation/index.html b/dev/installation/index.html index 0d5733bf..7b7eee2a 100644 --- a/dev/installation/index.html +++ b/dev/installation/index.html @@ -15,4 +15,4 @@ _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | -julia>

Using Binder

The docker image can be also launched via Binder without installing anything locally. This method is the least recommended due to its timeout duration.

Binder

+julia>

Using Binder

The docker image can be also launched via Binder without installing anything locally. This method is the least recommended due to its timeout duration.

Binder

diff --git a/dev/objects.inv b/dev/objects.inv index c1db4f0a..2a2a1499 100644 Binary files a/dev/objects.inv and b/dev/objects.inv differ diff --git a/dev/reference/declaration/index.html b/dev/reference/declaration/index.html index e6bf7b37..8a35b7e0 100644 --- a/dev/reference/declaration/index.html +++ b/dev/reference/declaration/index.html @@ -7,7 +7,7 @@ a => 1 ~ preserve(parameter) b(a) ~ accumulate end -Ssource
Cropbox.@configMacro
@config c.. -> Config | Vector{Config}

Construct a set or multiple sets of configuration.

A basic unit of configuration for a system S is represented by a pair in the form of S => pv. System name S is expressed in a symbol. If actual type of system is used, its name will be automatically converted to a symbol.

A parameter name and corresponding value is then represented by another pair in the form of p => v. When specifiying multiple parameters, a tuple of pairs like (p1 => v1, p2 => v2) or a named tuple like (p1 = v1, p2 = v2) can be used. Parameter name must be a symbol and should indicate a variable declared with parameter tag as often used by preserve state variable. For example, :S => (:a => 1, :b => 2) has the same meaning as S => (a = 1, b = 2) in the same scope.

Configurations for multiple systems can be concatenated by a tuple. Multiple elements in c separated by commas implicitly forms a tuple. For example, :S => (:a => 1, :b => 2), :T => :x => 1 represents a set of configuration for two systems S and T with some parameters. When the same names of system or variable appears again during concatenation, it will be overriden by later ones in an order appeared in a tuple. For example, :S => :a => 1, :S => :a => 2 results into :S => :a => 2. Instead of commas, + operator can be used in a similar way as (:S => :a => 1) + (:S => :a => 2). Note parentheses placed due to operator precedence.

When multiple sets of configurations are needed, as in configs for simulate, a vector of Config is used. This macro supports some convenient ways to construct a vector by composing simpler configurations. Prefix operator ! allows expansion of any iterable placed in the configuration value. Infix operator * allows multiplication of a vector of configurations with another vector or a single configuration to construct multiple sets of configurations. For example, !(:S => :a => 1:2) is expanded into two sets of separate configurations [:S => :a => 1, :S => :a => 2]. (:S => :a => 1:2) * (:S => :b => 0) is multiplied into [:S => (a = 1, b = 0), :S => (a = 2, b = 0)].

Examples

julia> @config :S => (:a => 1, :b => 2)
+S
source
Cropbox.@configMacro
@config c.. -> Config | Vector{Config}

Construct a set or multiple sets of configuration.

A basic unit of configuration for a system S is represented by a pair in the form of S => pv. System name S is expressed in a symbol. If actual type of system is used, its name will be automatically converted to a symbol.

A parameter name and corresponding value is then represented by another pair in the form of p => v. When specifiying multiple parameters, a tuple of pairs like (p1 => v1, p2 => v2) or a named tuple like (p1 = v1, p2 = v2) can be used. Parameter name must be a symbol and should indicate a variable declared with parameter tag as often used by preserve state variable. For example, :S => (:a => 1, :b => 2) has the same meaning as S => (a = 1, b = 2) in the same scope.

Configurations for multiple systems can be concatenated by a tuple. Multiple elements in c separated by commas implicitly forms a tuple. For example, :S => (:a => 1, :b => 2), :T => :x => 1 represents a set of configuration for two systems S and T with some parameters. When the same names of system or variable appears again during concatenation, it will be overriden by later ones in an order appeared in a tuple. For example, :S => :a => 1, :S => :a => 2 results into :S => :a => 2. Instead of commas, + operator can be used in a similar way as (:S => :a => 1) + (:S => :a => 2). Note parentheses placed due to operator precedence.

When multiple sets of configurations are needed, as in configs for simulate, a vector of Config is used. This macro supports some convenient ways to construct a vector by composing simpler configurations. Prefix operator ! allows expansion of any iterable placed in the configuration value. Infix operator * allows multiplication of a vector of configurations with another vector or a single configuration to construct multiple sets of configurations. For example, !(:S => :a => 1:2) is expanded into two sets of separate configurations [:S => :a => 1, :S => :a => 2]. (:S => :a => 1:2) * (:S => :b => 0) is multiplied into [:S => (a = 1, b = 0), :S => (a = 2, b = 0)].

Examples

julia> @config :S => (:a => 1, :b => 2)
 Config for 1 system:
   S
     a = 1
@@ -20,4 +20,4 @@
  <Config>
julia> @config (:S => :a => 1:2) * (:S => :b => 0)
 2-element Vector{Config}:
  <Config>
- <Config>
source
+ <Config>source diff --git a/dev/reference/index.html b/dev/reference/index.html index f9acb402..c8fb8afd 100644 --- a/dev/reference/index.html +++ b/dev/reference/index.html @@ -3,4 +3,4 @@ function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-192782823-1', {'page_path': location.pathname + location.search + location.hash}); - + diff --git a/dev/reference/inspection/index.html b/dev/reference/inspection/index.html index 344ed9e0..6a08225e 100644 --- a/dev/reference/inspection/index.html +++ b/dev/reference/inspection/index.html @@ -15,7 +15,7 @@ a param [code] - a => 1 ~ preserve(parameter)source
Cropbox.diveFunction
dive(s)

Inspect an instance of system s by navigating hierarchy of variables displayed in a tree structure.

Pressing up/down arrow keys allows navigation. Press 'enter' to dive into a deeper level and press 'q' to come back. A leaf node of the tree shows an output of look regarding the variable. Pressing 'enter' again would return a variable itself and exit to REPL.

Only works in a terminal environment; not working on Jupyter Notebook.

See also: look

Arguments

  • s::System: instance of target system.

Examples

julia> @system S(Controller) begin
+  a => 1 ~ preserve(parameter)
source
Cropbox.diveFunction
dive(s)

Inspect an instance of system s by navigating hierarchy of variables displayed in a tree structure.

Pressing up/down arrow keys allows navigation. Press 'enter' to dive into a deeper level and press 'q' to come back. A leaf node of the tree shows an output of look regarding the variable. Pressing 'enter' again would return a variable itself and exit to REPL.

Only works in a terminal environment; not working on Jupyter Notebook.

See also: look

Arguments

  • s::System: instance of target system.

Examples

julia> @system S(Controller) begin
            a => 1 ~ preserve(parameter)
        end;
 
@@ -25,4 +25,4 @@
 S
  → context = <Context>
    config = <Config>
-   a = 1.0
source
+ a = 1.0source diff --git a/dev/reference/simulation/index.html b/dev/reference/simulation/index.html index 2135c44a..a03ee7e5 100644 --- a/dev/reference/simulation/index.html +++ b/dev/reference/simulation/index.html @@ -13,7 +13,7 @@ context = <Context> config = <Config> a = 1.0 - b = 0.0source
Cropbox.simulateFunction
simulate([f,] S[, layout, [configs]]; <keyword arguments>) -> DataFrame

Run simulations by making instance of system S with given configuration to generate an output in the form of DataFrame. layout contains a list of variables to be saved in the output. A layout of single simulation can be specified in the layout arguments placed as keyword arguments. configs contains a list of configurations for each run of simulation. Total number of simulation runs equals to the size of configs. For a single configuration, config keyword argument may be preferred. Optional callback function f allows do-block syntax to specify snatch argument for finer control of output format.

See also: instance, @config

Arguments

  • S::Type{<:System}: type of system to be simulated.
  • layout::Vector: list of output layout definition in a named tuple (; base, index, target, meta).
  • configs::Vector: list of configurations for defining multiple runs of simluations.

Keyword Arguments

Layout

  • base=nothing: base system where index and target are populated; default falls back to the instance of S.
  • index=nothing: variables to construct index columns of the output; default falls back to context.clock.time.
  • target=nothing: variables to construct non-index columns of the output; default includes most variables in the root instance.
  • meta=nothing: name of systems in the configuration to be included in the output as metadata.

Configuration

  • config=(): a single configuration for the system, or a base for multiple configurations (when used with configs).
  • configs=[]: multiple configurations for the system.
  • seed=nothing: random seed for resetting each simulation run.

Progress

  • stop=nothing: condition checked before calling updates for the instance; default stops with no update.
  • snap=nothing: condition checked to decide if a snapshot of current update is saved in the output; default snaps all updates.
  • snatch=nothing: callback for modifying intermediate output; list of DataFrame D collected from current update and the instance of system s are provided.
  • verbose=true: shows a progress bar.

Format

  • nounit=false: remove units from the output.
  • long=false: convert output table from wide to long format.

Examples

julia> @system S(Controller) begin
+  b = 0.0
source
Cropbox.simulateFunction
simulate([f,] S[, layout, [configs]]; <keyword arguments>) -> DataFrame

Run simulations by making instance of system S with given configuration to generate an output in the form of DataFrame. layout contains a list of variables to be saved in the output. A layout of single simulation can be specified in the layout arguments placed as keyword arguments. configs contains a list of configurations for each run of simulation. Total number of simulation runs equals to the size of configs. For a single configuration, config keyword argument may be preferred. Optional callback function f allows do-block syntax to specify snatch argument for finer control of output format.

See also: instance, @config

Arguments

  • S::Type{<:System}: type of system to be simulated.
  • layout::Vector: list of output layout definition in a named tuple (; base, index, target, meta).
  • configs::Vector: list of configurations for defining multiple runs of simluations.

Keyword Arguments

Layout

  • base=nothing: base system where index and target are populated; default falls back to the instance of S.
  • index=nothing: variables to construct index columns of the output; default falls back to context.clock.time.
  • target=nothing: variables to construct non-index columns of the output; default includes most variables in the root instance.
  • meta=nothing: name of systems in the configuration to be included in the output as metadata.

Configuration

  • config=(): a single configuration for the system, or a base for multiple configurations (when used with configs).
  • configs=[]: multiple configurations for the system.
  • seed=nothing: random seed for resetting each simulation run.

Progress

  • stop=nothing: condition checked before calling updates for the instance; default stops with no update.
  • snap=nothing: condition checked to decide if a snapshot of current update is saved in the output; default snaps all updates.
  • snatch=nothing: callback for modifying intermediate output; list of DataFrame D collected from current update and the instance of system s are provided.
  • verbose=true: shows a progress bar.

Format

  • nounit=false: remove units from the output.
  • long=false: convert output table from wide to long format.

Examples

julia> @system S(Controller) begin
            a => 1 ~ preserve(parameter)
            b(a) ~ accumulate
        end;
@@ -24,7 +24,7 @@
      │ Quantity…  Float64  Float64
 ─────┼─────────────────────────────
    1 │    0.0 hr      1.0      0.0
-   2 │    1.0 hr      1.0      1.0
source
Cropbox.evaluateFunction
evaluate(S, obs; <keyword arguments>) -> Number | Tuple

Compare output of simulation results for the given system S and observation data obs with a choice of evaluation metric.

Arguments

  • S::Type{<:System}: type of system to be evaluated.
  • obs::DataFrame: observation data to be used for evaluation.

Keyword Arguments

Configuration

  • config=(): a single configuration for the system (can't be used with configs).
  • configs=[]: multiple configurations for the system (can't be used with config).

Layout

  • index=nothing: variables to construct index columns of the output; default falls back to context.clock.time.
  • target: variables to construct non-index columns of the output.

Evaluation

  • metric=nothing: evaluation metric (:rmse, :nrmse, :mae, :mape, :ef, :dr); default is RMSE.

Remaining keyword arguments are passed down to simulate with regard to running system S.

See also: simulate, calibrate, @config

Examples

julia> @system S(Controller) begin
+   2 │    1.0 hr      1.0      1.0
source
Cropbox.evaluateFunction
evaluate(S, obs; <keyword arguments>) -> Number | Tuple

Compare output of simulation results for the given system S and observation data obs with a choice of evaluation metric.

Arguments

  • S::Type{<:System}: type of system to be evaluated.
  • obs::DataFrame: observation data to be used for evaluation.

Keyword Arguments

Configuration

  • config=(): a single configuration for the system (can't be used with configs).
  • configs=[]: multiple configurations for the system (can't be used with config).

Layout

  • index=nothing: variables to construct index columns of the output; default falls back to context.clock.time.
  • target: variables to construct non-index columns of the output.

Evaluation

  • metric=nothing: evaluation metric (:rmse, :nrmse, :mae, :mape, :ef, :dr); default is RMSE.

Remaining keyword arguments are passed down to simulate with regard to running system S.

See also: simulate, calibrate, @config

Examples

julia> @system S(Controller) begin
            a => 19 ~ preserve(u"m/hr", parameter)
            b(a) ~ accumulate(u"m")
        end;
@@ -34,7 +34,7 @@
 julia> configs = @config !(:S => :a => [19, 21]);
 
 julia> evaluate(S, obs; configs, target=:b, stop=10u"hr")
-10.0 m
source
evaluate(obs, est; <keyword arguments>) -> Number | Tuple

Compare observation data obs and estimation data est with a choice of evaluation metric.

Arguments

  • obs::DataFrame: observation data to be used for evaluation.
  • est::DataFrame: estimated data from simulation.

Keyword Arguments

Layout

  • index: variables referring to index columns of the output.
  • target: variables referring to non-index columns of the output.

Evaluation

  • metric=nothing: evaluation metric (:rmse, :nrmse, :mae, :mape, :ef, :dr); default is RMSE.

See also: evaluate

Examples

julia> obs = DataFrame(time = [1, 2, 3]u"hr", b = [10, 20, 30]u"g");
+10.0 m
source
evaluate(obs, est; <keyword arguments>) -> Number | Tuple

Compare observation data obs and estimation data est with a choice of evaluation metric.

Arguments

  • obs::DataFrame: observation data to be used for evaluation.
  • est::DataFrame: estimated data from simulation.

Keyword Arguments

Layout

  • index: variables referring to index columns of the output.
  • target: variables referring to non-index columns of the output.

Evaluation

  • metric=nothing: evaluation metric (:rmse, :nrmse, :mae, :mape, :ef, :dr); default is RMSE.

See also: evaluate

Examples

julia> obs = DataFrame(time = [1, 2, 3]u"hr", b = [10, 20, 30]u"g");
 
 julia> est = DataFrame(time = [1, 2, 3]u"hr", b = [10, 20, 30]u"g", c = [11, 19, 31]u"g");
 
@@ -42,7 +42,7 @@
 0.0 g
 
 julia> evaluate(obs, est; index = :time, target = :b => :c)
-1.0 g
source
Cropbox.calibrateFunction
calibrate(S, obs; <keyword arguments>) -> Config | OrderedDict

Obtain a set of parameters for the given system S that simulates provided observation obs closely as possible. A multitude of simulations are conducted with a differing combination of parameter sets specified by the range of possible values and the optimum is selected based on a choice of evaluation metric. Internally, differential evolution algorithm from BlackboxOptim.jl is used.

Arguments

  • S::Type{<:System}: type of system to be calibrated.
  • obs::DataFrame: observation data to be used for calibration.

Keyword Arguments

Configuration

  • config=(): a single base configuration for the system (can't be used with configs).
  • configs=[]: multiple base configurations for the system (can't be used with config).

Layout

  • index=nothing: variables to construct index columns of the output; default falls back to context.clock.time.
  • target: variables to construct non-index columns of the output.

Calibration

  • parameters: parameters with a range of boundary values to be calibrated within.
  • metric=nothing: evaluation metric (:rmse, :nrmse, :mae, :mape, :ef, :dr); default is RMSE.

Multi-objective

  • weight=nothing: weights for calibrating multiple targets; default assumes equal weights.
  • pareto=false: returns a dictionary containing Pareto frontier instead of a single solution satisfying multiple targets.

Advanced

  • optim=(): extra options for BlackBoxOptim.bboptimize.

Remaining keyword arguments are passed down to simulate with regard to running system S.

See also: simulate, evaluate, @config

Examples

julia> @system S(Controller) begin
+1.0 g
source
Cropbox.calibrateFunction
calibrate(S, obs; <keyword arguments>) -> Config | OrderedDict

Obtain a set of parameters for the given system S that simulates provided observation obs closely as possible. A multitude of simulations are conducted with a differing combination of parameter sets specified by the range of possible values and the optimum is selected based on a choice of evaluation metric. Internally, differential evolution algorithm from BlackboxOptim.jl is used.

Arguments

  • S::Type{<:System}: type of system to be calibrated.
  • obs::DataFrame: observation data to be used for calibration.

Keyword Arguments

Configuration

  • config=(): a single base configuration for the system (can't be used with configs).
  • configs=[]: multiple base configurations for the system (can't be used with config).

Layout

  • index=nothing: variables to construct index columns of the output; default falls back to context.clock.time.
  • target: variables to construct non-index columns of the output.

Calibration

  • parameters: parameters with a range of boundary values to be calibrated within.
  • metric=nothing: evaluation metric (:rmse, :nrmse, :mae, :mape, :ef, :dr); default is RMSE.

Multi-objective

  • weight=nothing: weights for calibrating multiple targets; default assumes equal weights.
  • pareto=false: returns a dictionary containing Pareto frontier instead of a single solution satisfying multiple targets.

Advanced

  • optim=(): extra options for BlackBoxOptim.bboptimize.

Remaining keyword arguments are passed down to simulate with regard to running system S.

See also: simulate, evaluate, @config

Examples

julia> @system S(Controller) begin
            a => 0 ~ preserve(parameter)
            b(a) ~ accumulate
        end;
@@ -53,4 +53,4 @@
 ...
 Config for 1 system:
   S
-    a = 20.0
source
+ a = 20.0source diff --git a/dev/reference/visualization/index.html b/dev/reference/visualization/index.html index 9ffb6e86..157af6dd 100644 --- a/dev/reference/visualization/index.html +++ b/dev/reference/visualization/index.html @@ -5,8 +5,8 @@ gtag('config', 'UA-192782823-1', {'page_path': location.pathname + location.search + location.hash});

Visualization

Cropbox.plotFunction
plot(df::DataFrame, x, y; <keyword arguments>) -> Plot
 plot(X::Vector, Y::Vector; <keyword arguments>) -> Plot
-plot(df::DataFrame, x, y, z; <keyword arguments>) -> Plot

Plot a graph from provided data source. The type of graph is selected based on arguments.

See also: plot!, visualize

source
plot(v::Number; kind, <keyword arguments>) -> Plot
-plot(V::Vector; kind, <keyword arguments>) -> Plot

Plot a graph of horizontal/vertical lines depending on kind, which can be either :hline or :vline. An initial plotting of hline requires xlim and vline requires ylim, respectively.

See also: plot!, visualize

source
Cropbox.plot!Function
plot!(p, <arguments>; <keyword arguments>) -> Plot

Update an existing Plot object p by appending a new graph made with plot.

See also: plot

Arguments

  • p::Union{Plot,Nothing}: plot object to be updated; nothing creates a new plot.
source
Cropbox.visualizeFunction
visualize(<arguments>; <keyword arguments>) -> Plot

Make a plot from an output collected by running necessary simulations. A convenient function to run both simulate and plot together.

See also: visualize!, simulate, plot, manipulate

Examples

julia> @system S(Controller) begin
+plot(df::DataFrame, x, y, z; <keyword arguments>) -> Plot

Plot a graph from provided data source. The type of graph is selected based on arguments.

See also: plot!, visualize

source
plot(v::Number; kind, <keyword arguments>) -> Plot
+plot(V::Vector; kind, <keyword arguments>) -> Plot

Plot a graph of horizontal/vertical lines depending on kind, which can be either :hline or :vline. An initial plotting of hline requires xlim and vline requires ylim, respectively.

See also: plot!, visualize

source
Cropbox.plot!Function
plot!(p, <arguments>; <keyword arguments>) -> Plot

Update an existing Plot object p by appending a new graph made with plot.

See also: plot

Arguments

  • p::Union{Plot,Nothing}: plot object to be updated; nothing creates a new plot.
source
Cropbox.visualizeFunction
visualize(<arguments>; <keyword arguments>) -> Plot

Make a plot from an output collected by running necessary simulations. A convenient function to run both simulate and plot together.

See also: visualize!, simulate, plot, manipulate

Examples

julia> @system S(Controller) begin
            a(a) => a ~ accumulate(init=1)
        end;
 
@@ -29,4 +29,4 @@
      1 │.........''''                           │
        └────────────────────────────────────────┘
        0                                        5
-                      time (hr)
source
Cropbox.visualize!Function
visualize!(p, <arguments>; <keyword arguments>) -> Plot

Update an existing Plot object p by appending a new graph made with visualize.

See also: visualize

Arguments

  • p::Union{Plot,Nothing}: plot object to be updated; nothing creates a new plot.
source
Cropbox.manipulateFunction
manipulate(f::Function; parameters, config=())

Create an interactive plot updated by callback f. Only works in Jupyter Notebook.

Arguments

  • f::Function: callback for generating a plot; interactively updated configuration c is provided.
  • parameters: parameters adjustable with interactive widgets; value should be an iterable.
  • config=(): a baseline configuration.
source
manipulate(args...; parameters, kwargs...)

Create an interactive plot by calling manipulate with visualize as a callback.

See also: visualize

Arguments

  • args: positional arguments for visualize.
  • parameters: parameters for manipulate.
  • kwargs: keyword arguments for visualize.
source
+ time (hr)source
Cropbox.visualize!Function
visualize!(p, <arguments>; <keyword arguments>) -> Plot

Update an existing Plot object p by appending a new graph made with visualize.

See also: visualize

Arguments

  • p::Union{Plot,Nothing}: plot object to be updated; nothing creates a new plot.
source
Cropbox.manipulateFunction
manipulate(f::Function; parameters, config=())

Create an interactive plot updated by callback f. Only works in Jupyter Notebook.

Arguments

  • f::Function: callback for generating a plot; interactively updated configuration c is provided.
  • parameters: parameters adjustable with interactive widgets; value should be an iterable.
  • config=(): a baseline configuration.
source
manipulate(args...; parameters, kwargs...)

Create an interactive plot by calling manipulate with visualize as a callback.

See also: visualize

Arguments

  • args: positional arguments for visualize.
  • parameters: parameters for manipulate.
  • kwargs: keyword arguments for visualize.
source
diff --git a/dev/tutorials/cropbox/7e47653e.svg b/dev/tutorials/cropbox/4efe7621.svg similarity index 65% rename from dev/tutorials/cropbox/7e47653e.svg rename to dev/tutorials/cropbox/4efe7621.svg index 03fb6f12..ae3677ed 100644 --- a/dev/tutorials/cropbox/7e47653e.svg +++ b/dev/tutorials/cropbox/4efe7621.svg @@ -14,20 +14,20 @@ - + - - + + time (hr) - + 0 @@ -44,212 +44,212 @@ - - - + + + x - - - + + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - - - - + + + + - - + + 10.01.628894626777442 - - - + + + - - + + 9.01.5513282159785162 - - - + + + - - + + 8.01.477455443789063 - - - + + + - - + + 7.01.4071004226562505 - - - + + + - - + + 6.01.3400956406250004 - - - + + + - - + + 5.01.2762815625000004 - - - + + + - - + + 4.01.2155062500000002 - - - + + + - - + + 3.01.1576250000000001 - - - + + + - - + + 2.0,1.1025 - - - + + + - - + + 1.0,1.05 - - - + + + - - + + 0.0,1.0 @@ -260,18 +260,18 @@ - - + + 1.0 - + 1.5 - + 2.0 @@ -279,7 +279,7 @@ - + diff --git a/dev/tutorials/cropbox/793bd1fd.svg b/dev/tutorials/cropbox/d64b2213.svg similarity index 62% rename from dev/tutorials/cropbox/793bd1fd.svg rename to dev/tutorials/cropbox/d64b2213.svg index ecf16d35..336ba1f5 100644 --- a/dev/tutorials/cropbox/793bd1fd.svg +++ b/dev/tutorials/cropbox/d64b2213.svg @@ -14,20 +14,20 @@ - + - - + + time (hr) - + 0 @@ -44,222 +44,222 @@ - - - + + + x - + x - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - - - - + + + + - - + + 10.01.628894626777442 - - - + + + - - + + 9.01.5513282159785162 - - - + + + - - + + 8.01.477455443789063 - - - + + + - - + + 7.01.4071004226562505 - - - + + + - - + + 6.01.3400956406250004 - - - + + + - - + + 5.01.2762815625000004 - - - + + + - - + + 4.01.2155062500000002 - - - + + + - - + + 3.01.1576250000000001 - - - + + + - - + + 2.0,1.1025 - - - + + + - - + + 1.0,1.05 - - - + + + - - + + 0.0,1.0 @@ -267,155 +267,155 @@ - - - - + + + + - - + + 10.0,1.68 - - - + + + - - + + 9.0,1.53 - - - + + + - - + + 8.0,1.76 - - - + + + - - + + 7.0,1.34 - - - + + + - - + + 6.0,1.24 - - - + + + - - + + 5.0,1.17 - - - + + + - - + + 4.0,1.14 - - - + + + - - + + 3.0,1.15 - - - + + + - - + + 2.0,1.06 - - - + + + - - + + 1.0,0.985 - - - + + + - - + + 0.0,1.0 @@ -426,18 +426,18 @@ - - + + 1.0 - + 1.5 - + 2.0 @@ -445,7 +445,7 @@ - + diff --git a/dev/tutorials/cropbox/index.html b/dev/tutorials/cropbox/index.html index 7d56e720..3103651e 100644 --- a/dev/tutorials/cropbox/index.html +++ b/dev/tutorials/cropbox/index.html @@ -36,7 +36,7 @@

Named a=1 b=2 -

Simulation

The simulate function will create an instance of the system and update the values of all the variables in it at each time step until it reaches the stop time. By default, simulations in Cropbox use a time step of one hour.

Let's use Cropbox to simulate the system for ten time steps.

df = simulate(S, config = config, stop = 10)
11×5 DataFrame
Rowtimeiarx
Quantity…Float64Float64Float64Float64
10.0 hr1.00.050.051.0
21.0 hr1.00.050.05251.05
32.0 hr1.00.050.0551251.1025
43.0 hr1.00.050.05788131.15763
54.0 hr1.00.050.06077531.21551
65.0 hr1.00.050.06381411.27628
76.0 hr1.00.050.06700481.3401
87.0 hr1.00.050.0703551.4071
98.0 hr1.00.050.07387281.47746
109.0 hr1.00.050.07756641.55133
1110.0 hr1.00.050.08144471.62889

This will output the values of all the variables in the system as a DataFrame where each row represents one time step.

Visualization

Once we have simulated the system, we may want to visualize the resulting data by creating a graph. This can be done by using the plot() function, specifying the name of the dataframe as the first argument and then the names of variables we want to plot on the x and y axes.

p = plot(df, :time, :x)
Example block output

The visualize() function can also be used to run a simulation and plot the results using one command.

v = visualize(S, :time, :x ; stop=50, kind=:line)
+

Simulation

The simulate function will create an instance of the system and update the values of all the variables in it at each time step until it reaches the stop time. By default, simulations in Cropbox use a time step of one hour.

Let's use Cropbox to simulate the system for ten time steps.

df = simulate(S, config = config, stop = 10)
11×5 DataFrame
Rowtimeiarx
Quantity…Float64Float64Float64Float64
10.0 hr1.00.050.051.0
21.0 hr1.00.050.05251.05
32.0 hr1.00.050.0551251.1025
43.0 hr1.00.050.05788131.15763
54.0 hr1.00.050.06077531.21551
65.0 hr1.00.050.06381411.27628
76.0 hr1.00.050.06700481.3401
87.0 hr1.00.050.0703551.4071
98.0 hr1.00.050.07387281.47746
109.0 hr1.00.050.07756641.55133
1110.0 hr1.00.050.08144471.62889

This will output the values of all the variables in the system as a DataFrame where each row represents one time step.

Visualization

Once we have simulated the system, we may want to visualize the resulting data by creating a graph. This can be done by using the plot() function, specifying the name of the dataframe as the first argument and then the names of variables we want to plot on the x and y axes.

p = plot(df, :time, :x)
Example block output

The visualize() function can also be used to run a simulation and plot the results using one command.

v = visualize(S, :time, :x ; stop=50, kind=:line)
Simulation - + - - + + time (hr) - + 0 @@ -97,49 +97,49 @@

Simulation - - - - + + + + - - + + - + - - + + - + - + - + - + - + - + - - - + + + @@ -147,20 +147,20 @@

Simulation - - + + 50 - + 100 - - + + x @@ -168,11 +168,11 @@

Simulation - +

Evaluation

The evaluate() function can be used to compare two datasets with a choice of evaluation metric, such as root-mean-square error. For instance, we could compare a dataset of the observed values from an experiment to the estimated values from a simulation. To do this, we would enter in the observed dataset as a DataFrame.

using DataFrames
 obs = DataFrame(time = [0.0 ,1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]u"hr", x = [1, .985, 1.06, 1.15, 1.14, 1.17, 1.24, 1.34, 1.76, 1.53, 1.68])
-est = simulate(S, config = config, stop = 10)
11×5 DataFrame
Rowtimeiarx
Quantity…Float64Float64Float64Float64
10.0 hr1.00.050.051.0
21.0 hr1.00.050.05251.05
32.0 hr1.00.050.0551251.1025
43.0 hr1.00.050.05788131.15763
54.0 hr1.00.050.06077531.21551
65.0 hr1.00.050.06381411.27628
76.0 hr1.00.050.06700481.3401
87.0 hr1.00.050.0703551.4071
98.0 hr1.00.050.07387281.47746
109.0 hr1.00.050.07756641.55133
1110.0 hr1.00.050.08144471.62889

We compare this dataset to the results of the simulation visually by adding it to the our previous plot p using the plot!() function.

plot!(p,obs, :time, :x)
Example block output

Then, we can use the evaluate() function to calculate the error between the observed and simulated values. The index will be time by default and the target will be the variables we want to compare.

evaluate(obs, df; index = :time, target = :x, metric = :rmse)
0.10466658629266519

In addition to being able to compare two DataFrames, the evaluate() function can also be used to compare a system to a DataFrame.

evaluate(S, est; target = :a, stop = 10)
0.05000000000000001
+est = simulate(S, config = config, stop = 10)
11×5 DataFrame
Rowtimeiarx
Quantity…Float64Float64Float64Float64
10.0 hr1.00.050.051.0
21.0 hr1.00.050.05251.05
32.0 hr1.00.050.0551251.1025
43.0 hr1.00.050.05788131.15763
54.0 hr1.00.050.06077531.21551
65.0 hr1.00.050.06381411.27628
76.0 hr1.00.050.06700481.3401
87.0 hr1.00.050.0703551.4071
98.0 hr1.00.050.07387281.47746
109.0 hr1.00.050.07756641.55133
1110.0 hr1.00.050.08144471.62889

We compare this dataset to the results of the simulation visually by adding it to the our previous plot p using the plot!() function.

plot!(p,obs, :time, :x)
Example block output

Then, we can use the evaluate() function to calculate the error between the observed and simulated values. The index will be time by default and the target will be the variables we want to compare.

evaluate(obs, df; index = :time, target = :x, metric = :rmse)
0.10466658629266519

In addition to being able to compare two DataFrames, the evaluate() function can also be used to compare a system to a DataFrame.

evaluate(S, est; target = :a, stop = 10)
0.05000000000000001
diff --git a/dev/tutorials/julia/index.html b/dev/tutorials/julia/index.html index d60aed60..47c5b870 100644 --- a/dev/tutorials/julia/index.html +++ b/dev/tutorials/julia/index.html @@ -5,4 +5,4 @@ gtag('config', 'UA-192782823-1', {'page_path': location.pathname + location.search + location.hash});

Getting Started with Julia

Julia is a relatively new programming language designed for scientific computing in mind. It is a dynamic programming language as convenient as Python and R, but also provides high performance and extensibility as C/C++ and Fortran. Check the chart here to see where Julia stands as a programming language among other languages today; its position has been rising fast.

If you already have a fair understanding of Julia or would like to skip ahead to learning about Cropbox, please go to Getting Started With Cropbox.

Installing Julia

You can download and install Julia from the official Julia downloads page. For new users, it is recommended to install the "Current stable release" for Julia. In general, you will want to install the 64-bit version. If you run into an issue installing the 64-bit version, you can try the 32-bit version. During installation, select "Add Julia to PATH". You can also add Julia to PATH after installation using the command-line interface (CLI).

For more detailed platform-specific instructions, you can check the official Julia instructions.

If you are new to coding and require a development environment, check the Installation section for more information.

The Julia REPL

The quickest way to start using Julia is by opening the Julia executable or by running the command [julia] in your terminal or command prompt. In order to run [julia] from your terminal or command prompt, make sure that Julia is added to your PATH.

By doing so, you can start an interactive session of Julia, also known as the REPL, which stands for "Read-Eval-Print Loop".

Using the REPL, you can start running simple commands like the following:

julia> a = 11
julia> b = 22
julia> c = a + b3

Variables

Variables in Julia refer to names that are associated with a value. The names can be associated with various different types of values. Take a look at the following example:

julia> a = 11
julia> b = "string""string"
julia> c = [a, b]2-element Vector{Any}: 1 - "string"
julia> d = @system DMain.D
Warning

Julia variables are not to be confused with Cropbox variables defined within Cropbox systems.

+ "string"
julia> d = @system DMain.D
Warning

Julia variables are not to be confused with Cropbox variables defined within Cropbox systems.

diff --git a/dev/tutorials/makingamodel/6f181cd7.svg b/dev/tutorials/makingamodel/514b84cf.svg similarity index 99% rename from dev/tutorials/makingamodel/6f181cd7.svg rename to dev/tutorials/makingamodel/514b84cf.svg index fbfc0166..88aab7cf 100644 --- a/dev/tutorials/makingamodel/6f181cd7.svg +++ b/dev/tutorials/makingamodel/514b84cf.svg @@ -14,20 +14,20 @@ - + - - + + t (yr) - + 0 @@ -44,80 +44,80 @@ - - - + + + N - + P - - - + + + - - + + - - + + - - - - + + + + - - + + - + - - + + - + - + - + - - - + + + - - - + + + @@ -125,13 +125,13 @@ - - + + 50 - + 100 @@ -139,7 +139,7 @@ - + diff --git a/dev/tutorials/makingamodel/a82485b1.svg b/dev/tutorials/makingamodel/6c82857a.svg similarity index 92% rename from dev/tutorials/makingamodel/a82485b1.svg rename to dev/tutorials/makingamodel/6c82857a.svg index a23228f9..bdc91c73 100644 --- a/dev/tutorials/makingamodel/a82485b1.svg +++ b/dev/tutorials/makingamodel/6c82857a.svg @@ -14,20 +14,20 @@ - + - - + + Year (yr) - + 1900 @@ -54,375 +54,375 @@ - - - + + + Hare - + Lynx - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - + - + - - - + + + - - - - + + + + - - + + 1920,56.6 - - - + + + - - + + 1919,11.21 - - - + + + - - + + 1918,4.5 - - - + + + - - + + 1917,4.97 - - - + + + - - + + 1916,12.59 - - - + + + - - + + 1915,24.95 - - - + + + - - + + 1914,40.97 - - - + + + - - + + 1913,57.92 - - - + + + - - + + 1912,75.58 - - - + + + - - + + 1911,68.48 - - - + + + - - + + 1910,53.1 - - - + + + - - + + 1909,26.34 - - - + + + - - + + 1908,21.54 - - - + + + - - + + 1907,23.37 - - - + + + - - + + 1906,28.68 - - - + + + - - + + 1905,57.78 - - - + + + - - + + 1904,69.72 - - - + + + - - + + 1903,37.22 - - - + + + - - + + 1902,4.73 - - - + + + - - + + 1901,4.72 - - - + + + - - + + 1900,12.82 @@ -430,302 +430,302 @@ - - - + + + - - - - + + + + - - + + 1920,3.52 - - - + + + - - + + 1919,3.19 - - - + + + - - + + 1918,6.82 - - - + + + - - + + 1917,17.18 - - - + + + - - + + 1916,30.36 - - - + + + - - + + 1915,40.83 - - - + + + - - + + 1914,43.36 - - - + + + - - + + 1913,39.55 - - - + + + - - + + 1912,32.88 - - - + + + - - + + 1911,20.35 - - - + + + - - + + 1910,11.65 - - - + + + - - + + 1909,5.44 - - - + + + - - + + 1908,3.41 - - - + + + - - + + 1907,6.3 - - - + + + - - + + 1906,54.7 - - - + + + - - + + 1905,63.51 - - - + + + - - + + 1904,60.57 - - - + + + - - + + 1903,31.47 - - - + + + - - + + 1902,14.86 - - - + + + - - + + 1901,9.47 - - - + + + - - + + 1900,7.13 @@ -733,16 +733,16 @@ - - - + + + - - - + + + @@ -750,18 +750,18 @@ - - + + 20 - + 40 - + 60 @@ -769,7 +769,7 @@ - + diff --git a/dev/tutorials/makingamodel/fb1ab15a.svg b/dev/tutorials/makingamodel/9c7da28a.svg similarity index 92% rename from dev/tutorials/makingamodel/fb1ab15a.svg rename to dev/tutorials/makingamodel/9c7da28a.svg index 020ea67d..7d0b77fc 100644 --- a/dev/tutorials/makingamodel/fb1ab15a.svg +++ b/dev/tutorials/makingamodel/9c7da28a.svg @@ -14,20 +14,20 @@ - + - - + + Year (yr) - + 1900 @@ -54,375 +54,375 @@ - - - + + + Hare - + Lynx - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - + - + - - - + + + - - - - + + + + - - + + 1920,56.6 - - - + + + - - + + 1919,11.21 - - - + + + - - + + 1918,4.5 - - - + + + - - + + 1917,4.97 - - - + + + - - + + 1916,12.59 - - - + + + - - + + 1915,24.95 - - - + + + - - + + 1914,40.97 - - - + + + - - + + 1913,57.92 - - - + + + - - + + 1912,75.58 - - - + + + - - + + 1911,68.48 - - - + + + - - + + 1910,53.1 - - - + + + - - + + 1909,26.34 - - - + + + - - + + 1908,21.54 - - - + + + - - + + 1907,23.37 - - - + + + - - + + 1906,28.68 - - - + + + - - + + 1905,57.78 - - - + + + - - + + 1904,69.72 - - - + + + - - + + 1903,37.22 - - - + + + - - + + 1902,4.73 - - - + + + - - + + 1901,4.72 - - - + + + - - + + 1900,12.82 @@ -430,302 +430,302 @@ - - - + + + - - - - + + + + - - + + 1920,3.52 - - - + + + - - + + 1919,3.19 - - - + + + - - + + 1918,6.82 - - - + + + - - + + 1917,17.18 - - - + + + - - + + 1916,30.36 - - - + + + - - + + 1915,40.83 - - - + + + - - + + 1914,43.36 - - - + + + - - + + 1913,39.55 - - - + + + - - + + 1912,32.88 - - - + + + - - + + 1911,20.35 - - - + + + - - + + 1910,11.65 - - - + + + - - + + 1909,5.44 - - - + + + - - + + 1908,3.41 - - - + + + - - + + 1907,6.3 - - - + + + - - + + 1906,54.7 - - - + + + - - + + 1905,63.51 - - - + + + - - + + 1904,60.57 - - - + + + - - + + 1903,31.47 - - - + + + - - + + 1902,14.86 - - - + + + - - + + 1901,9.47 - - - + + + - - + + 1900,7.13 @@ -733,16 +733,16 @@ - - - + + + - - - + + + @@ -750,18 +750,18 @@ - - + + 20 - + 40 - + 60 @@ -769,7 +769,7 @@ - + diff --git a/dev/tutorials/makingamodel/1b78d753.svg b/dev/tutorials/makingamodel/caa34f81.svg similarity index 76% rename from dev/tutorials/makingamodel/1b78d753.svg rename to dev/tutorials/makingamodel/caa34f81.svg index ddcc0fb9..a913ac49 100644 --- a/dev/tutorials/makingamodel/1b78d753.svg +++ b/dev/tutorials/makingamodel/caa34f81.svg @@ -14,20 +14,20 @@ - + - - + + calendar.date - + Jun @@ -49,75 +49,75 @@ - - - + + + GDD - - - + + + - - + + - - - - + + + + - - + + - + - + - + - + - - + + - + - + - + - + - - - + + + @@ -125,35 +125,35 @@ - - + + 0 - + 5 - + 10 - + 15 - + 20 - - + + (K) @@ -161,7 +161,7 @@ - + diff --git a/dev/tutorials/makingamodel/cde0c2d3.svg b/dev/tutorials/makingamodel/dafc5cdb.svg similarity index 60% rename from dev/tutorials/makingamodel/cde0c2d3.svg rename to dev/tutorials/makingamodel/dafc5cdb.svg index d8ab1586..0dcd5856 100644 --- a/dev/tutorials/makingamodel/cde0c2d3.svg +++ b/dev/tutorials/makingamodel/dafc5cdb.svg @@ -14,20 +14,20 @@ - + - - + + Year (yr) - + 1860 @@ -49,1352 +49,1352 @@ - - - + + + Hare - + Lynx - - - + + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - + - - - + + + - - - - + + + + - - + + 1935,15.76 - - - + + + - - + + 1934,81.66 - - - + + + - - + + 1933,89.76 - - - + + + - - + + 1932,82.11 - - - + + + - - + + 1931,19.52 - - - + + + - - + + 1930,4.23 - - - + + + - - + + 1929,2.39 - - - + + + - - + + 1928,1.8 - - - + + + - - + + 1927,2.54 - - - + + + - - + + 1926,4.64 - - - + + + - - + + 1925,36.93 - - - + + + - - + + 1924,73.38 - - - + + + - - + + 1923,80.53 - - - + + + - - + + 1922,77.74 - - - + + + - - + + 1921,69.63 - - - + + + - - + + 1920,56.6 - - - + + + - - + + 1919,11.21 - - - + + + - - + + 1918,4.5 - - - + + + - - + + 1917,4.97 - - - + + + - - + + 1916,12.59 - - - + + + - - + + 1915,24.95 - - - + + + - - + + 1914,40.97 - - - + + + - - + + 1913,57.92 - - - + + + - - + + 1912,75.58 - - - + + + - - + + 1911,68.48 - - - + + + - - + + 1910,53.1 - - - + + + - - + + 1909,26.34 - - - + + + - - + + 1908,21.54 - - - + + + - - + + 1907,23.37 - - - + + + - - + + 1906,28.68 - - - + + + - - + + 1905,57.78 - - - + + + - - + + 1904,69.72 - - - + + + - - + + 1903,37.22 - - - + + + - - + + 1902,4.73 - - - + + + - - + + 1901,4.72 - - - + + + - - + + 1900,12.82 - - - + + + - - + + 1899,2.3 - - - + + + - - + + 1898,6.16 - - - + + + - - + + 1897,16.59 - - - + + + - - + + 1896,56.69 - - - + + + - - + + 1895,85.81 - - - + + + - - + + 1894,70.4 - - - + + + - - + + 1893,53.78 - - - + + + - - + + 1892,52.34 - - - + + + - - + + 1891,41.65 - - - + + + - - + + 1890,24.2 - - - + + + - - + + 1889,15.03 - - - + + + - - + + 1888,46.1 - - - + + + - - + + 1887103.79 - - - + + + - - + + 1886134.86 - - - + + + - - + + 1885134.85 - - - + + + - - + + 1884,52.21 - - - + + + - - + + 1883,43.12 - - - + + + - - + + 1882,9.67 - - - + + + - - + + 1881,7.74 - - - + + + - - + + 1880,10.11 - - - + + + - - + + 1879,38.32 - - - + + + - - + + 1878,72.17 - - - + + + - - + + 1877,86.51 - - - + + + - - + + 1876,97.12 - - - + + + - - + + 1875101.25 - - - + + + - - + + 1874,50.13 - - - + + + - - + + 1873,50.12 - - - + + + - - + + 1872,70.64 - - - + + + - - + + 1871,10.44 - - - + + + - - + + 1870,9.95 - - - + + + - - + + 1869,5.91 - - - + + + - - + + 1868,2.28 - - - + + + - - + + 1867,14.75 - - - + + + - - + + 1866,41.41 - - - + + + - - + + 1865,85.81 - - - + + + - - + + 1864148.36 - - - + + + - - + + 1863152.65 - - - + + + - - + + 1862,2.18 - - - + + + - - + + 1861,30.35 - - - + + + - - + + 1860,21.49 - - - + + + - - + + 1859,12.64 - - - + + + - - + + 1858,32.19 - - - + + + - - + + 1857,68.51 - - - + + + - - + + 1856,88.06 - - - + + + - - + + 1855,74.67 - - - + + + - - + + 1854,61.28 - - - + + + - - + + 1853,88.48 - - - + + + - - + + 1852,75.09 - - - + + + - - + + 1851,74.6 - - - + + + - - + + 1850,58.0 - - - + + + - - + + 1849,28.04 - - - + + + - - + + 1848,11.99 - - - + + + - - + + 1847,19.61 - - - + + + - - + + 1846,19.6 - - - + + + - - + + 1845,19.58 @@ -1402,1282 +1402,1282 @@ - - - + + + - - - - + + + + - - + + 1935,35.4 - - - + + + - - + + 1934,29.7 - - - + + + - - + + 1933,24.82 - - - + + + - - + + 1932,16.01 - - - + + + - - + + 1931,8.31 - - - + + + - - + + 1930,6.98 - - - + + + - - + + 1929,19.14 - - - + + + - - + + 1928,37.7 - - - + + + - - + + 1927,52.25 - - - + + + - - + + 1926,53.99 - - - + + + - - + + 1925,49.08 - - - + + + - - + + 1924,42.36 - - - + + + - - + + 1923,31.99 - - - + + + - - + + 1922,20.3 - - - + + + - - + + 1921,9.94 - - - + + + - - + + 1920,3.52 - - - + + + - - + + 1919,3.19 - - - + + + - - + + 1918,6.82 - - - + + + - - + + 1917,17.18 - - - + + + - - + + 1916,30.36 - - - + + + - - + + 1915,40.83 - - - + + + - - + + 1914,43.36 - - - + + + - - + + 1913,39.55 - - - + + + - - + + 1912,32.88 - - - + + + - - + + 1911,20.35 - - - + + + - - + + 1910,11.65 - - - + + + - - + + 1909,5.44 - - - + + + - - + + 1908,3.41 - - - + + + - - + + 1907,6.3 - - - + + + - - + + 1906,54.7 - - - + + + - - + + 1905,63.51 - - - + + + - - + + 1904,60.57 - - - + + + - - + + 1903,31.47 - - - + + + - - + + 1902,14.86 - - - + + + - - + + 1901,9.47 - - - + + + - - + + 1900,7.13 - - - + + + - - + + 1899,8.86 - - - + + + - - + + 1898,18.01 - - - + + + - - + + 1897,33.68 - - - + + + - - + + 1896,46.43 - - - + + + - - + + 1895,51.41 - - - + + + - - + + 1894,46.0 - - - + + + - - + + 1893,33.33 - - - + + + - - + + 1892,20.38 - - - + + + - - + + 1891,14.12 - - - + + + - - + + 1890,16.16 - - - + + + - - + + 1889,22.45 - - - + + + - - + + 1888,32.59 - - - + + + - - + + 1887,51.65 - - - + + + - - + + 1886,79.35 - - - + + + - - + + 1885,65.69 - - - + + + - - + + 1884,43.77 - - - + + + - - + + 1883,35.14 - - - + + + - - + + 1882,18.34 - - - + + + - - + + 1881,12.6 - - - + + + - - + + 1880,12.03 - - - + + + - - + + 1879,36.33 - - - + + + - - + + 1878,44.15 - - - + + + - - + + 1877,45.77 - - - + + + - - + + 1876,46.34 - - - + + + - - + + 1875,31.18 - - - + + + - - + + 1874,30.95 - - - + + + - - + + 1873,18.91 - - - + + + - - + + 1872,5.26 - - - + + + - - + + 1871,5.8 - - - + + + - - + + 1870,9.83 - - - + + + - - + + 1869,16.39 - - - + + + - - + + 1868,42.68 - - - + + + - - + + 1867,72.77 - - - + + + - - + + 1866,70.77 - - - + + + - - + + 1865,60.78 - - - + + + - - + + 1864,38.22 - - - + + + - - + + 1863,14.33 - - - + + + - - + + 1862,4.09 - - - + + + - - + + 1861,4.08 - - - + + + - - + + 1860,7.65 - - - + + + - - + + 1859,13.69 - - - + + + - - + + 1858,21.3 - - - + + + - - + + 1857,29.59 - - - + + + - - + + 1856,34.38 - - - + + + - - + + 1855,32.91 - - - + + + - - + + 1854,19.6 - - - + + + - - + + 1853,10.17 - - - + + + - - + + 1852,5.08 - - - + + + - - + + 1851,5.56 - - - + + + - - + + 1850,8.42 - - - + + + - - + + 1849,21.23 - - - + + + - - + + 1848,39.52 - - - + + + - - + + 1847,49.15 - - - + + + - - + + 1846,45.15 - - - + + + - - + + 1845,30.09 @@ -2688,18 +2688,18 @@ - - + + 50 - + 100 - + 150 @@ -2707,7 +2707,7 @@ - + diff --git a/dev/tutorials/makingamodel/e4862aad.svg b/dev/tutorials/makingamodel/e895ae6c.svg similarity index 99% rename from dev/tutorials/makingamodel/e4862aad.svg rename to dev/tutorials/makingamodel/e895ae6c.svg index 8b5ce308..9926adfb 100644 --- a/dev/tutorials/makingamodel/e4862aad.svg +++ b/dev/tutorials/makingamodel/e895ae6c.svg @@ -14,20 +14,20 @@ - + - - + + t (yr) - + 0 @@ -44,77 +44,77 @@ - - - + + + N - + P - - - + + + - - + + - - + + - - - - + + + + - - + + - - + + - + - + - + - - - + + + - - - + + + @@ -122,8 +122,8 @@ - - + + 50 @@ -131,7 +131,7 @@ - + diff --git a/dev/tutorials/makingamodel/index.html b/dev/tutorials/makingamodel/index.html index adbfdcc1..3c79ce6c 100644 --- a/dev/tutorials/makingamodel/index.html +++ b/dev/tutorials/makingamodel/index.html @@ -130,7 +130,7 @@

Simulation target = [:GDD, :cGDD] ) -first(s, 10)
10×3 DataFrame
Rowcalendar.dateGDDcGDD
DateQuantity…Quantity…
12002-05-156.9 K0.0 d K
22002-05-1610.0 K6.9 d K
32002-05-1713.3 K16.9 d K
42002-05-184.5 K30.2 d K
52002-05-191.6 K34.7 d K
62002-05-202.1 K36.3 d K
72002-05-210.8 K38.4 d K
82002-05-223.6 K39.2 d K
92002-05-236.7 K42.8 d K
102002-05-2412.1 K49.5 d K


Visualization

To end the tutorial, let's visualize the simulation using the plot() and visualize() functions.

We can input the DataFrame from our simulation in the plot() function to create a plot.

Here is a plot of GDD over time.

plot(s, "calendar.date", :GDD; kind=:line)
Example block output

We can also simultaneously run a new simulation and plot its result using the visualize() function.

Here is a plot of cGDD over time.

visualize(GrowingDegreeDay, "calendar.date", :cGDD; config=c, stop="calendar.stop", kind=:line)
+first(s, 10)
10×3 DataFrame
Rowcalendar.dateGDDcGDD
DateQuantity…Quantity…
12002-05-156.9 K0.0 d K
22002-05-1610.0 K6.9 d K
32002-05-1713.3 K16.9 d K
42002-05-184.5 K30.2 d K
52002-05-191.6 K34.7 d K
62002-05-202.1 K36.3 d K
72002-05-210.8 K38.4 d K
82002-05-223.6 K39.2 d K
92002-05-236.7 K42.8 d K
102002-05-2412.1 K49.5 d K


Visualization

To end the tutorial, let's visualize the simulation using the plot() and visualize() functions.

We can input the DataFrame from our simulation in the plot() function to create a plot.

Here is a plot of GDD over time.

plot(s, "calendar.date", :GDD; kind=:line)
Example block output

We can also simultaneously run a new simulation and plot its result using the visualize() function.

Here is a plot of cGDD over time.

visualize(GrowingDegreeDay, "calendar.date", :cGDD; config=c, stop="calendar.stop", kind=:line)
Simulation - + - - + + calendar.date - + Jun @@ -181,52 +181,52 @@

Simulation - - - - + + + + - - + + - + - + - + - + - - + + - + - + - + - + - - - + + + @@ -234,35 +234,35 @@

Simulation - - + + 0 - + 500 - + 1000 - + 1500 - + 2000 - - + + cGDD (d K) @@ -270,7 +270,7 @@

Simulation - + @@ -345,7 +345,7 @@

N0=20 P0=30 -


Visualization

Let's visualize the LotkaVolterra system with the configuration that we just created, using the visualize() function. The visualize() function both runs a simulation and plots the resulting DataFrame.

visualize(LotkaVolterra, :t, [:N, :P]; config = lvc, stop = 100u"yr", kind = :line)
Example block output

Density-Dependent Lotka-Volterra Equations

Now let's try to make a density-dependent version of the original Lotka-Volterra model which incorporates a new term in the prey population rate. The new variable K represents the carrying capacity of the prey population.

\[\begin{align} +


Visualization

Let's visualize the LotkaVolterra system with the configuration that we just created, using the visualize() function. The visualize() function both runs a simulation and plots the resulting DataFrame.

visualize(LotkaVolterra, :t, [:N, :P]; config = lvc, stop = 100u"yr", kind = :line)
Example block output

Density-Dependent Lotka-Volterra Equations

Now let's try to make a density-dependent version of the original Lotka-Volterra model which incorporates a new term in the prey population rate. The new variable K represents the carrying capacity of the prey population.

\[\begin{align} \frac{dN}{dt} &= bN-\frac{b}{K}N^2-aNP \\ \frac{dP}{dt} &= caNP-mP \\ \end{align}\]

System

We will call this new system LotkaVolterraDD.

@system LotkaVolterraDD(Controller)


Since we already defined the LotkaVolterra system, which already has most of the variables we require, we can use LotkaVolterra as a mixin for LotkaVolterraDD. This makes our task a lot simpler, as all that remains is to declare the variable K for carrying capacity and redeclare the variable N for prey population. The variable N in the new system will automatically overwrite the N from LotkaVolterra.

@system LotkaVolterraDD(LotkaVolterra, Controller) begin
@@ -380,10 +380,10 @@ 

K=1000 -


Visualization

Once again, let's visualize the system using the visualize() function.

visualize(LotkaVolterraDD, :t, [:N, :P]; config = lvddc, stop = 100u"yr", kind = :line)
Example block output


Calibration

If you want to calibrate the parameters according to a particular dataset, Cropbox provides the calibrate() function, which relies on BlackBoxOptim.jl for global optimization methods. If you are interested in local optimization methods, refer to Optim.jl package for more information.

For this tutorial, we will use a dataset containing the number of pelts (in thousands) of Canadian lynx and snowshoe hare traded by the Hudson Bay Trading Company in Canada from 1845 to 1935. The data is available here.

If you are unsure how to read CSV files, check the following documentation. You can also follow the template below (make sure path corresponds to the path to your data file).

using CSV, DataFrames
+


Visualization

Once again, let's visualize the system using the visualize() function.

visualize(LotkaVolterraDD, :t, [:N, :P]; config = lvddc, stop = 100u"yr", kind = :line)
Example block output


Calibration

If you want to calibrate the parameters according to a particular dataset, Cropbox provides the calibrate() function, which relies on BlackBoxOptim.jl for global optimization methods. If you are interested in local optimization methods, refer to Optim.jl package for more information.

For this tutorial, we will use a dataset containing the number of pelts (in thousands) of Canadian lynx and snowshoe hare traded by the Hudson Bay Trading Company in Canada from 1845 to 1935. The data is available here.

If you are unsure how to read CSV files, check the following documentation. You can also follow the template below (make sure path corresponds to the path to your data file).

using CSV, DataFrames
 
 pelts = CSV.read(path, DataFrame)

The data should look something like the this:

first(pelts, 3)
3×3 DataFrame
RowYear (yr)HareLynx
Int64Float64Float64
1184519.5830.09
2184619.645.15
3184719.6149.15


Recall that we can use the unitfy() function in Cropbox to automatically assign units when they are specified in the column headers.

pelts = unitfy(pelts)
-first(pelts, 3)
3×3 DataFrame
RowYearHareLynx
Quantity…Float64Float64
11845 yr19.5830.09
21846 yr19.645.15
31847 yr19.6149.15


Let's plot the data and see what it looks like.

visualize(pelts, :Year, [:Hare, :Lynx], kind = :scatterline)
Example block output


For our calibration, we will use a subset of the data covering years 1900 to 1920.

pelts_subset = @subset(pelts, 1900u"yr" .<= :Year .<= 1920u"yr")
21×3 DataFrame
RowYearHareLynx
Quantity…Float64Float64
11900 yr12.827.13
21901 yr4.729.47
31902 yr4.7314.86
41903 yr37.2231.47
51904 yr69.7260.57
61905 yr57.7863.51
71906 yr28.6854.7
81907 yr23.376.3
91908 yr21.543.41
101909 yr26.345.44
111910 yr53.111.65
121911 yr68.4820.35
131912 yr75.5832.88
141913 yr57.9239.55
151914 yr40.9743.36
161915 yr24.9540.83
171916 yr12.5930.36
181917 yr4.9717.18
191918 yr4.56.82
201919 yr11.213.19
211920 yr56.63.52


Before we calibrate the parameters for LotkaVolterra, let's add one new variable to the system. We will name this variable y for year. The purpose of y is to keep track of the year in the same manner as the dataset.

@system LotkaVolterra(Controller) begin
+first(pelts, 3)
3×3 DataFrame
RowYearHareLynx
Quantity…Float64Float64
11845 yr19.5830.09
21846 yr19.645.15
31847 yr19.6149.15


Let's plot the data and see what it looks like.

visualize(pelts, :Year, [:Hare, :Lynx], kind = :scatterline)
Example block output


For our calibration, we will use a subset of the data covering years 1900 to 1920.

pelts_subset = @subset(pelts, 1900u"yr" .<= :Year .<= 1920u"yr")
21×3 DataFrame
RowYearHareLynx
Quantity…Float64Float64
11900 yr12.827.13
21901 yr4.729.47
31902 yr4.7314.86
41903 yr37.2231.47
51904 yr69.7260.57
61905 yr57.7863.51
71906 yr28.6854.7
81907 yr23.376.3
91908 yr21.543.41
101909 yr26.345.44
111910 yr53.111.65
121911 yr68.4820.35
131912 yr75.5832.88
141913 yr57.9239.55
151914 yr40.9743.36
161915 yr24.9540.83
171916 yr12.5930.36
181917 yr4.9717.18
191918 yr4.56.82
201919 yr11.213.19
211920 yr56.63.52


Before we calibrate the parameters for LotkaVolterra, let's add one new variable to the system. We will name this variable y for year. The purpose of y is to keep track of the year in the same manner as the dataset.

@system LotkaVolterra(Controller) begin
     t(context.clock.time) ~ track(u"yr")
     y(t): year            ~ track::Int(u"yr", round)
 
@@ -430,7 +430,7 @@ 


Now let's try calibrating the density-dependent version of the model. Since we made a slight change to LotkaVolterra, let's make sure to define LotkaVolterraDD again.

@system LotkaVolterraDD(LotkaVolterra, Controller) begin
+)
Example block output


Now let's try calibrating the density-dependent version of the model. Since we made a slight change to LotkaVolterra, let's make sure to define LotkaVolterraDD again.

@system LotkaVolterraDD(LotkaVolterra, Controller) begin
     N(N, P, K, b, a): prey_population => begin
         b*N - b/K*N^2 - a*N*P
     end ~ accumulate(init = N0)
@@ -471,7 +471,7 @@ 


Evaluation

We have visualized how the simulated LotkaVolterra and LotkaVolterraDD systems compare to the the original dataset. Let us obtain a metric for how well the simulations fit the original dataset using the evaluate() function in Cropbox. The evaluate() function supports numerous different metrics for evaluation. Here, we will calculate the root-mean-square error (RMSE) and modeling efficiency (EF).

Here are the evaluation metrics for LotkaVolterra. The numbers in the tuples correspond to hare and lynx, respectively.

evaluate(LotkaVolterra, pelts_subset;
+)
Example block output


Evaluation

We have visualized how the simulated LotkaVolterra and LotkaVolterraDD systems compare to the the original dataset. Let us obtain a metric for how well the simulations fit the original dataset using the evaluate() function in Cropbox. The evaluate() function supports numerous different metrics for evaluation. Here, we will calculate the root-mean-square error (RMSE) and modeling efficiency (EF).

Here are the evaluation metrics for LotkaVolterra. The numbers in the tuples correspond to hare and lynx, respectively.

evaluate(LotkaVolterra, pelts_subset;
     index = :Year => :y,
     target = [:Hare => :N, :Lynx => :P],
     config = (lvcc, :Clock => (:init => 1900u"yr", :step => 1u"d")),
@@ -499,4 +499,4 @@ 

(0.5237949169511267, 0.6375697135890357)

+)
(0.5237949169511267, 0.6375697135890357)
diff --git a/dev/tutorials/usingamodel/8b657f72.svg b/dev/tutorials/usingamodel/326f6154.svg similarity index 86% rename from dev/tutorials/usingamodel/8b657f72.svg rename to dev/tutorials/usingamodel/326f6154.svg index d79f2d7e..ab622d8b 100644 --- a/dev/tutorials/usingamodel/8b657f72.svg +++ b/dev/tutorials/usingamodel/326f6154.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,109 +49,109 @@ - - - + + + ETp - + ESa - + EPa - - - + + + - - + + - - + + - - + + - - - - + + + + - - + + - + - + - + - + - - + + - + - + - + - + - - - + + + - - - + + + - - - + + + @@ -159,35 +159,35 @@ - - + + 0 - + 2 - + 4 - + 6 - + 8 - - + + (mm d^-1) @@ -195,7 +195,7 @@ - + diff --git a/dev/tutorials/usingamodel/dbc3f21b.svg b/dev/tutorials/usingamodel/49fa6705.svg similarity index 81% rename from dev/tutorials/usingamodel/dbc3f21b.svg rename to dev/tutorials/usingamodel/49fa6705.svg index e43f930e..8e4f8066 100644 --- a/dev/tutorials/usingamodel/dbc3f21b.svg +++ b/dev/tutorials/usingamodel/49fa6705.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,72 +49,72 @@ - - - + + + N - - - + + + - - + + - - - - + + + + - - + + - + - + - + - - + + - + - + - + - + - - - + + + @@ -122,23 +122,23 @@ - - + + 0 - + 5 - + 10 - + 15 @@ -146,7 +146,7 @@ - + diff --git a/dev/tutorials/usingamodel/882f6984.svg b/dev/tutorials/usingamodel/5860d546.svg similarity index 80% rename from dev/tutorials/usingamodel/882f6984.svg rename to dev/tutorials/usingamodel/5860d546.svg index 72fb9528..ecab4375 100644 --- a/dev/tutorials/usingamodel/882f6984.svg +++ b/dev/tutorials/usingamodel/5860d546.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,72 +49,72 @@ - - - + + + INT - - - + + + - - + + - - - - + + + + - - + + - + - + - + - - + + - + - + - + - + - - - + + + @@ -122,30 +122,30 @@ - - + + 0 - + 100 - + 200 - + 300 - - + + (d K) @@ -153,7 +153,7 @@ - + diff --git a/dev/tutorials/usingamodel/1d19e477.svg b/dev/tutorials/usingamodel/6585e7ad.svg similarity index 81% rename from dev/tutorials/usingamodel/1d19e477.svg rename to dev/tutorials/usingamodel/6585e7ad.svg index 4c3f37a9..6ba62de1 100644 --- a/dev/tutorials/usingamodel/1d19e477.svg +++ b/dev/tutorials/usingamodel/6585e7ad.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,72 +49,72 @@ - - - + + + LAI - - - + + + - - + + - - - - + + + + - - + + - + - + - + - - + + - + - + - + - + - - - + + + @@ -122,23 +122,23 @@ - - + + 0 - + 1 - + 2 - + 3 @@ -146,7 +146,7 @@ - + diff --git a/dev/tutorials/usingamodel/205f9dcd.svg b/dev/tutorials/usingamodel/84af4d74.svg similarity index 87% rename from dev/tutorials/usingamodel/205f9dcd.svg rename to dev/tutorials/usingamodel/84af4d74.svg index d978bd3f..b0e59ef0 100644 --- a/dev/tutorials/usingamodel/205f9dcd.svg +++ b/dev/tutorials/usingamodel/84af4d74.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,120 +49,120 @@ - - - + + + Total - + Canopy - + Root - + Fruit - - - + + + - - + + - - + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - + - - - + + + - - - + + + - - - + + + - - - + + + @@ -170,25 +170,25 @@ - - + + 0 - + 500 - + 1000 - - + + (g m^-2) @@ -196,7 +196,7 @@ - + diff --git a/dev/tutorials/usingamodel/59058d68.svg b/dev/tutorials/usingamodel/99b9d474.svg similarity index 80% rename from dev/tutorials/usingamodel/59058d68.svg rename to dev/tutorials/usingamodel/99b9d474.svg index 55550f1a..8780b212 100644 --- a/dev/tutorials/usingamodel/59058d68.svg +++ b/dev/tutorials/usingamodel/99b9d474.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,75 +49,75 @@ - - - + + + SWC - - - + + + - - + + - - - - + + + + - - + + - + - + - + - + - - + + - + - + - + - + - - - + + + @@ -125,35 +125,35 @@ - - + + 0 - + 100 - + 200 - + 300 - + 400 - - + + (mm) @@ -161,7 +161,7 @@ - + diff --git a/dev/tutorials/usingamodel/30fe5b16.svg b/dev/tutorials/usingamodel/9a2b8975.svg similarity index 86% rename from dev/tutorials/usingamodel/30fe5b16.svg rename to dev/tutorials/usingamodel/9a2b8975.svg index 915363c4..9e39a61a 100644 --- a/dev/tutorials/usingamodel/30fe5b16.svg +++ b/dev/tutorials/usingamodel/9a2b8975.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,100 +49,100 @@ - - - + + + ROF - + INF - + DRN - - - + + + - - + + - - + + - - + + - - - - + + + + - - + + - + - - + + - + - + - + - + - - - + + + - - - + + + - - - + + + @@ -150,20 +150,20 @@ - - + + 0 - + 50 - - + + (mm d^-1) @@ -171,7 +171,7 @@ - + diff --git a/dev/tutorials/usingamodel/58efc436.svg b/dev/tutorials/usingamodel/aa7321fa.svg similarity index 86% rename from dev/tutorials/usingamodel/58efc436.svg rename to dev/tutorials/usingamodel/aa7321fa.svg index 4635a9ba..7c1780c6 100644 --- a/dev/tutorials/usingamodel/58efc436.svg +++ b/dev/tutorials/usingamodel/aa7321fa.svg @@ -14,20 +14,20 @@ - + - - + + DATE - + Jan 1, 1987 @@ -49,103 +49,103 @@ - - - + + + SWFAC - + SWFAC1 - + SWFAC2 - - - + + + - - + + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - + - + - + - - - + + + - - - + + + - - - + + + @@ -153,18 +153,18 @@ - - + + 0.0 - + 0.5 - + 1.0 @@ -172,7 +172,7 @@ - + diff --git a/dev/tutorials/usingamodel/index.html b/dev/tutorials/usingamodel/index.html index c4bc0c95..21f26e98 100644 --- a/dev/tutorials/usingamodel/index.html +++ b/dev/tutorials/usingamodel/index.html @@ -166,5 +166,5 @@

r = simulate(SimpleCrop.Model; config, stop = :endsim)


Iterations: 2    Time: 0:00:03 ( 1.73  s/it)
Iterations: 242    Time: 0:00:07 (29.04 ms/it)
Iterations: 293    Time: 0:00:07 (25.98 ms/it)

Visualizing the Results

The output of simulation is now contained in a data frame from which we generate multiple plots. The number of leaf (N) went from initial_leaf_number (= 2) to maximum_leaf_number (= 12) as indicated in the default set of parameters.

visualize(r, :DATE, :N; ylim = (0, 15), kind = :line)
Example block output

Thermal degree days (INT) started accumulating from mid-August with the onset of reproductive stage until late-October when it reaches the maturity indicated by duration_of_reproductive_stage (= 300 K d).

visualize(r, :DATE, :INT; kind = :line)
Example block output

Assimilated carbon (W) was partitioned into multiple parts of the plant as shown in the plot of dry biomass.

visualize(r, :DATE, [:W, :Wc, :Wr, :Wf];
-    names = ["Total", "Canopy", "Root", "Fruit"], kind = :line)
Example block output

Leaf area index (LAI) reached its peak at the end of vegetative stage then began declining throughout reproductive stage.

visualize(r, :DATE, :LAI; kind = :line)
Example block output

For soil water balance, here is a plot showing water runoff (ROF), infiltration (INF), and vertical drainage (DRN).

visualize(r, :DATE, [:ROF, :INF, :DRN]; kind = :line)
Example block output

Soil water status has influence on potential evapotranspiration (ETp), actual soil evaporation (ESa), and actual plant transpiration (ESp).

visualize(r, :DATE, [:ETp, :ESa, :EPa]; kind = :line)
Example block output

The resulting soil water content (SWC) is shown here.

visualize(r, :DATE, :SWC; ylim = (0, 400), kind = :line)
Example block output

Which, in turn, determines soil water stress factor (SWFAC) in this model.

visualize(r, :DATE, [:SWFAC, :SWFAC1, :SWFAC2]; ylim = (0, 1), kind = :line)
Example block output +)

Let's run a simulation with the model using configuration we just created. Stop condition for simulation is defined in a flag variable named endsim which coincides with plant maturity or the end of reproductive stage.

r = simulate(SimpleCrop.Model; config, stop = :endsim)

Iterations: 2    Time: 0:00:03 ( 1.61  s/it)
Iterations: 258    Time: 0:00:07 (27.36 ms/it)
Iterations: 293    Time: 0:00:07 (25.48 ms/it)

Visualizing the Results

The output of simulation is now contained in a data frame from which we generate multiple plots. The number of leaf (N) went from initial_leaf_number (= 2) to maximum_leaf_number (= 12) as indicated in the default set of parameters.

visualize(r, :DATE, :N; ylim = (0, 15), kind = :line)
Example block output

Thermal degree days (INT) started accumulating from mid-August with the onset of reproductive stage until late-October when it reaches the maturity indicated by duration_of_reproductive_stage (= 300 K d).

visualize(r, :DATE, :INT; kind = :line)
Example block output

Assimilated carbon (W) was partitioned into multiple parts of the plant as shown in the plot of dry biomass.

visualize(r, :DATE, [:W, :Wc, :Wr, :Wf];
+    names = ["Total", "Canopy", "Root", "Fruit"], kind = :line)
Example block output

Leaf area index (LAI) reached its peak at the end of vegetative stage then began declining throughout reproductive stage.

visualize(r, :DATE, :LAI; kind = :line)
Example block output

For soil water balance, here is a plot showing water runoff (ROF), infiltration (INF), and vertical drainage (DRN).

visualize(r, :DATE, [:ROF, :INF, :DRN]; kind = :line)
Example block output

Soil water status has influence on potential evapotranspiration (ETp), actual soil evaporation (ESa), and actual plant transpiration (ESp).

visualize(r, :DATE, [:ETp, :ESa, :EPa]; kind = :line)
Example block output

The resulting soil water content (SWC) is shown here.

visualize(r, :DATE, :SWC; ylim = (0, 400), kind = :line)
Example block output

Which, in turn, determines soil water stress factor (SWFAC) in this model.

visualize(r, :DATE, [:SWFAC, :SWFAC1, :SWFAC2]; ylim = (0, 1), kind = :line)
Example block output