Month: June 2014

positioning modes

The movement of the microscope is achieved by four motors that control the position of the objective.  The motors can be independent or coupled, depending on the operating mode selected in the Position panel in the Scanbox GUI.

There are three positioning modes: normal, rotated and pivot.  To explain how these work, we need to define the coordinate system used first. So, imagine yourself standing behind the main vertical holding post of the microscope arm.

In the normal mode, moving along the positive x-axis will move the objective to the right; movement along the positive y-axis will move the objective away from you; moving along the positive z-axis will move the objective up.  There is a fourth degree of freedom that comes from the ability to rotate the objective in the (x,z) plane.  The angle between the objective and the negative z-axis is defined as a.  In the normal mode all these motors are independent of each other.  Manipulating each of the controls only changes the axis selected.

objective.001

In the rotated mode, the x and z controls move the microscope along the x’ and z’ axes, which is obtained by rotating the (x,z) plane by a degrees.  The z’  axis  is along the line of sight of the objective and x’ is normal to it.  In rotated mode, changing position of the x control will move the objective parallel to the x’ axis.  In this mode the x and z motors are coupled so that the resulting movement is restricted to the plane normal to the objective.  When changing the z control, movement will be along the z’ axis.

Finally, in the pivot move, movement of the x control will be coupled to that of z and the objective angle such that the focus point remains under focus.  To use this mode a quick calibration is required to measure the length between the focal point and the rotation axis of the objective.  To do this set your objective to be in the vertical position and zero the position counters. Image some beads at a magnification of x1 and pick one near the center of the screen. Set the mode to normal, place your mouse cursor on top of the bead, and move the it to the left or right using the ShuttleExpress wheel.  Now, switch to the a-axis and move the bead back to its original position by rotating the objective.  When the bead is in its original position you can read out the movement in the x-axis (in um) and the a-axis (in deg).  The ratio of these two numbers, in deg/um, defines  the value of ‘pivotk’ in the sbconfig structure.  In our system, we have sbconfig.pivotk = 5.9e-4 [deg/um].

Online trial averaging

It is often the case that you may want to do some quick on-line analyses on our data during the execution of an experiment.  Scanbox provides a quick way to save, at the end of each experiment, the mean image during each trial.  To use this feature do the following:
  1. Select “Accumulate” in the Image Display Panel
  2. Click the “TTL Ctrl” checkbox in the Image Display Panel
  3. Feed a TTL signal that is initially low and goes high during each stimulus trial to the AlazarTech 9440 X1 input.
  4. Start your experiment
The result will be the following:
  1. During the experiment itself the TTL Ctrl text next to the checkbox will be displayed in black when the signal is low and will be displayed in red when it is high.  You can use this feature to monitor your TTL signal. Such updates only occur when the microscope is running.
  2. At the end of the experiment there will be an additional file with _trials.mat appended at the end of the name in your data directory.
  3. The file contains two Matlab variables trials_n and trials_acc.  They are ordered sequentially by the trial #.
  4. trial_n(j) contains the number of frames that were accumulated during the j-th time the TTL pulse went high.
  5. trial_acc{j} contains the accumulated images during the j-th trial.
  6. The mean activity of the j-th trial will be trial_acc{j}/trial_n(j).
  7. If you want “blanks” you need to include them separately as trials themselves.

Happy online processing!

 

Scanbox system integration

[Updated Dec 2015]

Integrating a Scanbox-controlled microscope with your system rather pretty straightforward after you understand how the system samples external events and how it can be controlled over the network.

Monitoring external TTL events

When Scanbox runs it monitors external events on its TTL inputs.  Two TTL inputs, labeled TTL0 and TTL1, are readily available as SMA connectors on the card.  These inputs can be set to trigger an event on either rising or falling edges of the TTL signal. By default the TTL0 signal triggers events on a rising edge of the signal, while TTL1 triggers an event on both rising and falling edges. [Note: additional lines are available in the expansion header, contact me if you need more than 2.]

One simple way to monitor an external stimulus with the microscope is to have an external TTL signal that is high during the presentation of a stimulus and low otherwise.  The signal can then be connected to TTL1, which generates an event on both rising and falling edges.

The variable imask in your scanbox_config.m file allows one to select which of these TTL inputs is enabled to generate events (imask=0 disables both, imask=1 enables TTL0, imask=2 enables TTL1, and imask=3 enables both). [Let me know if you need more TTL inputs, there is one more accessible from the expansion header.]

Once you finish collecting your data Scanbox creates a file named AAA_MMM_NNN.mat in your data directory.  Here, AAA is the animal id, MMM and NNN are two 3-digit identifiers used to name your experiments. We use MMM to indicate a particular field of view and NNN one of the experiments ran at that location.  If, after running an experiment, you load one of these file you will see a Matlab variable named “info” with the following fields:

info =
frame: [1202x1 double]
line: [1202x1 double]
event_id: [1202x1 double]
resfreq: 7938
postTriggerSamples: 5000
recordsPerBuffer: 512
bytesPerBuffer: 10240000
channels: 1
ballmotion: []
abort_bit: 0
config: [1x1 struct]
messages: {0x1 cell}

The variables that code the external TTL events are frame, line and event_id. For each external event, the system time stamps the event with the frame and line at which it occurred along with its event_id.  This means that the time resolution of TTL events is the period of the resonant mirror — in our case 125us in unidirectional mode.

The events are stored in the order of arrival. Thus, frame(1), line(1) and event_id(1) contain the information for the first TTL event and so on. In this particular example the system received 1202 events. The event_id codes the TTL lines that generated the event. An event_id of 1 means that TTL0 generated the event, if event_id = 2 it means TTL1 generated an event, and if both occurred within the same frame and line the event_id will be 3. Note that by default the system TTL0 is configured to generate an event on the rising edge while TTL1 is configured to generate an event on either edge.  At the moment these choices can be changed by a firmware upgrade, but we will allow for software control soon.

Controlling the microscope over the network

A recommended experimental setup is to have 3 computers in a network:  one dedicated to the microscope, another to stimulation, and a third “master” computer that controls the entire experiment.  The master computer can tell the microscope to change the fields within the File Storage panel (animal, field and experiment ids) and instruct the microscope to start sampling.  It can then tell the stimulus computer to present the desired sequence of stimuli. The stimulus computer should be in charge of generating TTLs that represent the beginning/end of different trials or other events).  Once finished, the master computer can tell the microscope to stop sampling.

Scanbox listens to UDP network messages directed at port 7000 over the network.  In Matlab you can use the following snippet of code to open communication (replace the IP address to your own or to ‘localhost’ if you are controlling the microscope from the same machine):

sbudp = udp('192.168.1.10', 'RemotePort', 7000);
fopen(sbudp);

The microscope will now take commands that consist of a single character followed by a string.
Here is a typical sequence of commands issued by the master:

fprintf(sbudp,'Axx0'); % set animal id field
fprintf(sbudp,'U010'); % set field number to 010
fprintf(sbudp,'E002'); % set experiment number to 002
fprintf(sbudp,'G');    % Go!  Start sampling
% Master tells stimulator to present sequence of trials marked by TTLs
% ...
% Metadata, such as the order of stimuli, can be sent by including messages:
fprintf(sbudp,'MTrial #001 Orientation = 20deg");
% ....
% ... and at the end you can stop the microscope
fprintf(sbudp,'S');    % Stop sampling

There are other commands the microscope accepts over the network, such as blanking the laser in-between trials in long experiments, or some that allow one to move the position of the objective.