Section 3. Some examples
Record and replay a time series
This example has two parts. In Part 1, the objective is to record a time series of
light intensity to a file. This would be useful, for example, in an understory with
passing sunflecks. In Part 2, use that file to drive a light source through the same
time series of light intensities.
For the data recording part, we won’t use normal logging, as we just need a time
stamp and light sensor value. A BP can do this for us easily, and Figure 3-22 below
illustrates a test version, since it outputs to the run log, and only runs for 10
seconds.
Figure 3-22. Program to record a light time series.
A discussion of the program steps follows:
1
Use ASSIGN to open a file (using the Python expression for this), assigning f to the file object.
2
Use ASSIGN to track the external quantum sensor with a variable named q.
3
Write a header (“Time,Light”) to the file using a Python print statement inside of an EXEC step.
Note the reference to the file (file=f) in the print.
4
Use ASSIGN to make a variable hhmmss that captures current time in hh:mm:ss format. (The
Python datetime module is available and is used for this.
5
Use ASSIGN to build the observation line for the file, held in variable line.
6
Use SHOW puts the line in the run log. (Strictly for debugging - we’ll get rid of this in the final
version.)
7
Write the line to the file using print(), putting it all in an EXEC statement.
8
When the loop is done, close the file with f.close(), inside an EXEC.
3-20 Using LI-6800 Background Programs