Example Workflows

Computation workflow with script

In this example we generate a new heatmap be performing math on two existing heatmaps with corresponding rows and columns. This workflow is not currently supported through the user interface. Non-scripting users should skip to the last section of the Looping workflow.

1. Count the number of rows and columns in a heatmap

We create two new variables, nRows and nCols, and use the phi2 heatmap's getRowCount() and getColumnCount() functions to assign numberical values to our variables.

nRows = phi2.getRowCount()
nCols = phi2.getColumnCount()

2. Extract numerical arrays to use for computation

We use getValueMatrix() to extract the measured data from the size and phi2 heatmaps, and getExtraRowValues() to extract some meta-data. We assign these large sets of numbers to three new variables.

phi2_vals = phi2.getValueMatrix()
size_vals = size.getValueMatrix()
light_vals = phi2.getExtraRowValues( "light_intensity" )

3. Compute delta-times

We use the phi2 heatmap's getTimeLabels() function to extract an array of time numbers. Then we create a new array dt, and populate it by computing the difference between each pair of adjacent time numbers within a for loop. Finally, since we have one fewer delta-times than we have timepoints, we duplicate the very first delta-time.

times = phi2.getTimeLabels()
dt = new Array(nCols)
for( col = 1 ; col < nCols ; col++ ) {
    dt[col] = times[col]-times[col-1]
}
dt[0] = dt[1]

Note that the contents of the for loop are indented and placed between curly brackets { }.

4. Prepare an empty array to contain computed results

Using new Array(), we create a new variable totalP_vals to contain computed values. Since we will have a separate results value for every row and column, totalP_vals should be 2-dimensional array (or an array of arrays). So we use a for loop to give totalP_vals an empty array for each row.

totalP_vals = new Array(nRows)
for ( row = 0 ; row < nRows ; row++) {
    totalP_vals[row] = new Array(nCols)
}

5. Start a loop to iterate through each cell

We use two for loops to accomplish this. The outer loop iterates through each row in the dataset. The inner loop iterates through the columns, and is indented to indicate that it is within the outer loop. Within these loops we will be able to use the variables row and col to keep track of the specific cell in question.

for ( row = 0; row < nRows; row++) {
    for ( col = 0; col < nCols; col++) {

Here use two left-curly-brackets { to indicate the beginning of two loops. The code below will take place within the loops, and eventually we will have to add two right curly brackets } to terminate the loops.

6. Extract raw data for a single cell

We use the row and col variables to extract a single value from each the numerical arrays we created previously.

        phi2_cell = phi2_vals[row][col]
        size_cell = size_vals[row][col]
        light_cell = light_vals[col]
        dt_cell = dt[col]

These lines are indented twice to indicate that they are within our row and column loops - they will be run multiple times.

7. Compute results for a single cell

We compute a single total photosynthesis value by multiplying the raw data together along with a constant. Then we place the computed value into the logical position in the 2-dimensional results array. Then, since we want results accumulated over time, we add the total photosynthesis value from the previous column.

        totalP_cell = phi2_cell * light_cell * .42 * size_cell * dt_cell
        totalP_vals[row][col] = totalP_cell
        if( col > 0 )
            totalP_vals[row][col] += totalP_vals[row][col-1]
    }
}
  • Again, these lines are indented twice because we are inside loops.
  • The two right-curly-brackets } at the end indicate the end of both loops.

8. Put computed results into a new heatmap, and display it

We get a set of row labels for the new heatmap using the phi2 heatmap's getRowLabels() function. Then we create the new heatmap totalP using the times we extracted in section 3, and the total photosynthesis values we computed in section 7. We give the new heatmap a title using setTitle() and display it using GLOBAL.display()

row_labels = phi2.getRowLabels(true)
totalP = new Heatmap( row_labels, times, totalP_vals )
totalP.setTitle( "Total Photosynthesis" )
GLOBAL.display( totalP )

Complete script and sample data

click here to download the full script (shown below).

click here to download the sample dataset. This file can be dragged directly into the OLIVER window.

//1 count the number of rows and columns
nRows = phi2.getRowCount()
nCols = phi2.getColumnCount()

//2 get arrays containing values for light, phi2, and reflectance
phi2_vals = phi2.getValueMatrix()
size_vals = size.getValueMatrix()
light_vals = phi2.getExtraRowValues( "light_intensity" )

//3 create an array containing delta-times for each column
times = phi2.getTimeLabels()
dt = new Array(nCols)
for( col = 1 ; col < nCols ; col++ ) {
    dt[col] = times[col]-times[col-1]
}
dt[0] = dt[1]

//4 create an empty 2D array that will eventually contain computed LEF values
totalP_vals = new Array(nRows)
for ( row = 0 ; row < nRows ; row++) {
    totalP_vals[row] = new Array(nCols)
}

//5 iterate through each cell in the phi2 data
for ( row = 0; row < nRows; row++) {
    for ( col = 0; col < nCols; col++) {

        //6 get the phi2, size, light, and delta-time values for this cell
        phi2_cell = phi2_vals[row][col]
        size_cell = size_vals[row][col]
        light_cell = light_vals[col]
        dt_cell = dt[col]
        

        //7 compute totalP for this cell and add it to the result array (as a cumulative)
        totalP_cell = phi2_cell * light_cell * .42 * size_cell * dt_cell
        totalP_vals[row][col] = totalP_cell
        if( col > 0 )
            totalP_vals[row][col] += totalP_vals[row][col-1]
    }
}

//8 display a total photosynthesis heatmap using the same times, and row labels as phi2
row_labels = phi2.getRowLabels(true)
totalP = new Heatmap( row_labels, times, totalP_vals )
totalP.setTitle( "Total Photosynthesis" )
GLOBAL.display( totalP )