User Tools

Site Tools


tutorials:radiation-model-in-crop_model2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:radiation-model-in-crop_model2 [2025/05/27 16:12] – created barley1965tutorials:radiation-model-in-crop_model2 [2025/05/27 17:53] (current) barley1965
Line 1: Line 1:
 ====== Plotting the absorbed light in a chart ====== ====== Plotting the absorbed light in a chart ======
  
-Open the file //LightChart.gsz//We now want to see model output as a chart (as you might know from R). The total light intercepted by all leaves is output into a chart, and this at every step of the simulation. +//Open the file {{ :tutorials:lightchart.gsz |lightchart.gsz}}.// We now want to see model output as a chart (as you might know from R). The total light intercepted by all leaves is output into a chart, and this at every step of the simulation. 
  
 For this, we have to declare a kind of data table in which the output is stored: For this, we have to declare a kind of data table in which the output is stored:
 +
 +<code java>
 +//insert a table here for the output:
 +const DatasetRef lightdata = new DatasetRef("Light intercepted by canopy");
 +</code>
 +
 +We then have to initiate the chart in the ''init()'' method. For this, we will use the new method ''initChart()'' that will be defined later:
  
 <code java> <code java>
Line 18: Line 25:
 ] ]
 </code> </code>
 + 
 +Note that if you want to declare imperative code in a method that also contains rules (like the present ''init()'' method), then you have to put it into a pair of curly braces, '' }''. Also, we want to update the chart at every step, so we add a new line to the ''grow()'' method:
  
- We then have to initiate the chart in the init() methodFor this, we will use the new method initChart() that will be defined later:+<code java> 
 +public void grow () 
 +
 + run(); 
 + lm.compute(); 
 + absorb(); 
 + //update the chart here 
 + updateChart()
 +
 +</code>
    
-Note that if you want to declare imperative code in a method that also contains rules (like the present init() method), then you have to put it into a pair of curly braces,  }Also, we want to update the chart at every step, so we add a new line to the grow() method:+The latter is another new method, ''updateChart()'', that we still need to define.  
 +The two new methods are defined, first ''initChart()'': 
 + 
 +<code java> 
 +//definition of the method initChart():  
 +protected void initChart() 
 +{ 
 + lightdata.clear(); 
 + chart(lightdata, XY_PLOT)
 +
 +</code>
    
-The latter is another new method, updateChart(), that we still need to define +This method does something with the data table ''lightdata''in fact it empties it at each new run, using the method ''clear()''(L. 112). The ''chart'' command does the actual plotting: It creates an XY plot with the data tableusing as x the time (simulation stepsand as y the sum of light absorbed by all leaves. The table is filled up with data by the ''updateChart()'' method: 
-The two new methods are definedfirst initChart():+ 
 +<code java> 
 +//definition of the method updateChart():  
 +protected void updateChart() 
 +
 + lightdata.addRow().set(0, sum((* Leaf *)[al])); 
 +
 +</code>
    
-This method does something with the data table lightdatain fact it empties it at each new run, using the method clear()(L. 112). The chart command does the actual plotting: It creates an XY plot with the data table, using as x the time (simulation steps) and as y the sum of light absorbed by all leaves. The table is filled up with data by the updateChart() method:+The ''addRow()'' method of ''DatasetRef'' does the actual jobmore specifically its sub-method ''set()'', which adds the data into the 0th column of the table: The data are produced by the ''sum'' method, which searches for all leaves ''(* Leaf *)'' that are already produced and then sums up their parameter ''al''. Searching for objects in the graph is a very powerful option in GroIMP. You can also do this at any time of the simulation by typing search commands in the XL Console, for instance the following command:
  
 +{{tutorials:console.png}} 
    
-The addRow() method of DatasetRef does the actual job, more specifically its sub-method set(), which adds the data into the 0th column of the table: The data are produced by the sum method, which searches for all leaves (* Leaf *) that are already produced and then sums up their parameter al. Searching for objects in the graph is a very powerful option in GroIMP. You can also do this at any time of the simulation by typing search commands in the XL Console, for instance the following command  +will search for all objects ''Leaf'' in the scene/graph (you have to write ''“Example1.Leaf”'' to indicate that the module was defined within the class ''“Example1.rgg”'') the value of the parameter ''al'' and calculate the sum of it. If you omit ''Example1'', the module ''Leaf'' cannot be found and you get an error message instead: 
-  + 
-will search for all objects Leaf in the scene/graph (you have to write “Example1.Leaf” to indicate that the module was defined within the class “Example1.rgg”) the value of the parameter al and calculate the sum of it. If you omit Example1, the module Leaf cannot be found and you get an error message instead:+{{tutorials:consoleerror.png}} 
    
 You can also have a look at the data table itself: You can also have a look at the data table itself:
-Main Menu: Panels -> Explorers -> Datasets+ 
 +//Main Menu: Panels -> Explorers -> Datasets// 
 + 
 +{{tutorials:panelsdatasets.png}} 
    
 This will give you a new window: This will give you a new window:
 +
 +{{tutorials:datasetslight.png}} 
    
-When you double-click on the Dataset “- Light intercepted…” you get the actual table, with two columns, # and A, where the first column contains the steps, the second the sum of light intercepted by the leaves:+When you double-click on the //Dataset “- Light intercepted…”// you get the actual table, with two columns, ''#'' and ''A'', where the first column contains the steps, the second the sum of light intercepted by the leaves: 
 + 
 +{{tutorials:datasetslighttable.png}}  
 + 
      
  
tutorials/radiation-model-in-crop_model2.1748355161.txt.gz · Last modified: 2025/05/27 16:12 by barley1965