Here we provide a simple timelapse script example.
Using this script we move through the list of points defined by the
user.
For each cycle of points the system will change the
cube to a position defined in the script and change the camera exposure
time for each cube.
For each point we make an adjustment to the focus position and then
snap an image.
The script filename can be anything as it is not displayed in the user
interface.
The name that is displayed in the timelapse dropdown list is taken from
the first line of the script which is a Python comment.
# Move and display
As the first line. This is the string that is used as the script
identifier the next step is to import any required Python modules.
In this case we only need access to the Python wrapper API for the
microscope so we only import the microscope module.
import microscope
Here we define a Python list of cube positions to cycle through. In
this case we wish to cycle between cube positions 2 and 3.
# Cubes that we will cycle through
# You can extend this list with any valid cube positions
# Here we have two cube positions 2 and 3
cubes = [2, 3]
For each of the cube positions defined in the list above we now define
the camera exposure that we would like.
The position of the exposure in the list corresponds to the cube
position in the cubes list.
# This is the exposure setting for each cube in the cubes list
# For example the cubes in position 2 and 3 above both should have
exposure
# set to 15 ms
exposures = [15.0, 15.0]
As with the exposure list this focus_offsets list is used to provide an
offset to the focus position for each cube.,
# These are the offsets that will be applied
to the zdrive for each cube.
focus_offsets = [0.0, 1.0]
Here we define the OnStart method that is called when the user
presses start on the timelapse panel. This method is only called once.
In this example we simply pass as we do not need to do anything at this
point.
This global variable holds the current cube index into the cubes list defined above.
current_cube_index = 0
# OnStart is called once when the user presses
start to begin the timelapse.
def OnStart():
pass
Here the OnAbort method is defined. This is called when a timelapse
experiment is stopped by a user. As
with the OnStart method we don't need to do anything here.
def OnAbort():
pass
Here OnCycleStart is defined. This is called every time a new cycle
of points is started. It is at this point that we start visiting points
after changing cubes
and setting the correct exposure.
# Called once at the start of each cycle of
points. Should contain at least one call to
microscope.MicroscopeVisitPoints() to start the cycle.
def OnCycleStart():
global current_cube_index
current_cube_index = 0
print "Back
to start."
# Here for each cube in the
cubes list we move to the cube position and set the corresponding
exposure setting. ,
for cube in cubes:
print
"Moving to cube position ", cube
microscope.MoveCubeToPosition(current_cube_index)
print
"Setting camera exposure to ", exposures[current_cube_index]
microscope.SetExposure(exposures[current_cube_index])
microscope.VisitPoints()
current_cube_index
= current_cube_index + 1
Finally we define OnNewPoint. This is called every time a new point is
reached. It is at this point that we adjust the focus position and then
snap an image..
# Called each time the stage moves to a new
point.
def OnNewPoint(x, y, z, position):
global current_cube_index
print "Setting focus
offset to ", focus_offsets[current_cube_index]
microscope.SetStagePosition(x, y, z +
focus_offsets[current_cube_index])
# Wait for stage to finish
moving (additional delay= 0.1 seconds, time out= 1.0 seconds)< /FONT
>
microscope.WaitForStage(0.0,
1.0)
microscope.SnapImage()