See ScanImage Setup for installation etc.,

Triggering ScanImage from another computer#

(As of 2023 this note does not currently outline the newest way to remotely configure scanimage, but should still be functional).

If you’re triggering ScanImage acquisition from a different computer (e.g. a computer that monitors and controls behavior), you’ll need two things:

  1. TCP/IP connection between the two computers.
  2. The computer that’s sending the trigger will need to specify the correct IP address of the scan image computer in connect_to_scanimage.m. Make sure to request a static IP from HMS IT (and name your computer) for the ScanImage computer if you haven’t done so already.
  3. ScanImage computer will need to be running fly_tracker_server_v2.m so that it’s port is ready to receive the message. The file name name will be send from the behavior computer to the scanimage controller, and will extract the trial duration from the file name, and set the number of volumes to be acquired.
  4. Triggering through the NI system.
  5. Make sure to generate imaging trigger (HIGH during the entire duration of the trial) in your behavior program and send this trigger through a digital output channel.
  6. This imaging trigger needs to be fed into one of the PFI channels in a NI-DAQ breakout panel (e.g. one associated with Pockels cell control). Make sure to specify this panel as digitalIODeviceName in the Machine Data File of ScanImage.
  7. Specify the PFI channel in the Trigger Controls in ScanImage. Select the appropriate PFI in the “Terminal” and choose “rising” Edge.

Acquire imaging data#

Setting up the scope#

To acquire imaging data, open MATLAB and type ‘scanimage’. This should open a small prompt asking you for a ‘machine data file’ and a ‘user settings file’.

You will likely use the same files every time you image. The ‘machine data file’ is a .mat file that contains data specific to the set up you are using to image, like the objective resolution, the scanner types, etc. The ‘user settings file’ has default parameters that might be variable for each user, like the default laser power, frame rolling average factor, etc. These can be easily adjusted once you start imaging though.

Once you select the files you want to use and click on ‘continue’, this will open scanimage.

The first thing scanimage will do is calibrate the laser and make sure that it looks ok. If things are ok, you should see a sigmoid curve like the following appear.

If you get a message saying ‘Beam calibration data for ‘Coherent’ appears suspect.’, and the following figure:

it probably means you didn’t turn the shutter on, which you can do by going to the ‘Chamaleon’ software or by pressing the “Shutter” button on the laser control box.

To be able to image, you will need to have the flipper mirrors set in the appropriate configuration. This can be changed in the ‘BSCOPE2 CONTROLS’ window, and will depend on the set up you are using. If using Berg1, ‘PMT’ and ‘Out’ will position the mirrors in the appropriate configuration. If using Berg2, select ‘In Path’ and ‘PMT’ instead.

Finally, you’ll need to open the shutter than protects the PMTs from being damaged by ambient light sources. This is controlled by a weird circular switch with a ring that lights up blue when the shutter is closed and turns off when the shutter is open (on Berg1 this is located above the panels controller and on Berg2 it’s on one of the shelves to the right of the box).

Setting up the imaging volume#

Once the mirrors are positioned appropriately, clicking on ‘FOCUS’ will open the second shutter (a shutter associated with your specific set up), and start the imaging. At 2x zoom, you should get an image of the full head. You will be able to see part of the cuticle at the edges, and the GCaMP labelled regions. In Berg1, with a GMR-60D05 (EPG) / GCaMP7f fly, this looks like this:

***Note: It is recommeneded that the Thorlabs Piezo Controller is turned off after every imaging session. It MUST be turned off before swapping objectives or putting any manual strain on the objective, otherwise the piezo can break!
*

Note: *Ensure that ‘Closed Loop’ is ON on the Thorlabs piezo controller. This is indicated by an illuminated orange LED under ‘Closed Loop’, and toggled on/off using the button beneath. Note that when the Piezo controller is turned on, ‘closed loop’ will be by default OFF unless manually activated. Having closed-loop OFF is not always apparent when imaging: you will get a linear calibration curve, be able to optimize the waveform, and sometimes see planes that look to tbe the correct spacing, but there can be strange non-flat plane artifacts, shearing, and non-uniform plane spacing even under waveform optimized conditions. These are not alway apparent until post processing, especially when imaging dimmer lines, so please be aware! *

Note: Because of the disposition of the mirrors in Berg1, the most anterior part of the prep is at the bottom of the image. In Berg2, it is at the top.

You will now want to focus on your area of interest, and adjust the settings to get a better quality imaging. For this, you will:

  1. Zoom in as much as you can depending on the area you are imaging (if imaging the PB, as in this example, you would go to 6x or 6.5x).
  2. Adjust the channel settings in the ‘IMAGE CONTROLS’ window. This won’t change the characteristics of the image you acquire, but will change the visualization and allow you to see your neurons’ responses better. Decreasing the ‘white’ channel values will increase the brightness of the areas with signal. Increasing the ‘black’ channel values will decrease the brightness of the background. The ‘average rolling frames’ will change the number of consecutive frames that are averages to show you the image. Increasing it will give you a less noisy signal, but increasing it too much might make you miss the responses you are trying to pick up (for example a moving bump in the PB).

  1. If you are doing volumetric imaging, you will want to image across several z slices. The number you choose will depend on the z span of the area you are imaging. This can be selected in the ‘FAST Z CONTROLS’ window.

Note: the number of slices you are acquiring, and the step between them will determine the imaging rate, which you can see in the ‘Volume Rate’ field.

To image at different depths, the scope images the first slice, starting from the top, and then the stage is moved up, such that the scope can image the next slice, etc..When it reaches the last slice, it needs to go back to the first one. Ideally, this would happen almost instantaneously, but realistically, it doesn’t. To figure out how the stage actually moves, you can click on ‘Actuator Tuning’, and then click on ‘Test Actuator’ in the pop up window.

This figure is showing that during the first 4 slices, the stage is still moving. These are what we call ‘Flyback frames’, and they will need to be removed from the analysis later (see Two-photon analysis pipeline note).

For this reason, you want to set your slices such that the top of the structure you are imaging starts ~ slice 5. I also add 2 or 3 slices after the bottom of the structure, in case the imaging session is long and there is some downward drift of the brain. For PB imaging, I take 12 slices, spaced by 5 um.

Once you have selected your settings, you should ’enable’ them, select ‘Tiled’ as the ‘Volume Display Style’ in the ‘IMAGE CONTROLS’ window, and click on ‘GRAB’ in the ‘MAIN CONTROLS’ window to visualize the slices. This is what the images with those settings look like for PB imaging:

  1. There is an additional step that you might want to take (not everyone in lab does it, and it might depend on the structure you are imaging, and your type of prep). As you can deeper into the brain, the tissue scatters the light, and so the signal you collect is usually dimmer. You can correct for this by adjusting the laser power as it goes down. This can be done in the ‘POWER CONTROLS’ window (Power/Depth Adjust).

Starting the acquisition#

Now that you have selected your settings, you are ready to start acquiring!

  1. You first need to set the directory where you data will be saved, using the ‘DIR’ button in the ‘MAIN CONTROLS’ window.

Note: don’t try to acquire the data directly on the server because it might be very slow and cause scanimage to fail. Instead, save the data locally and then move it to your folder of interest.

  1. Check the ‘Save’ box.

  2. If you are running and acquiring behavior simultaneously, you need to start the communication between the imaging and behavior computer. There is a code we use for this (‘fly_tracker_server_v2.m’ in Berg1 and modified versions of the same function for each individual user in Berg2). This code starts ’listening’ to the behavior computer, and waits for a trigger coming from it, which will synchronize the data acquisition. Once you’ve started this it will be executing in the foreground and you won’t be able to use most ScanImage controls, so don’t start it until you’re ready to start imaging.

Compensating for drift#

Once the imaging has started, you’ll usually need to watch out for drift in the imaging volume caused by movements of the brain or thermal expansion of the holder, etc. Drift in the XY dimensions is usually less problematic than drift in the Z-dimension, which can make motion correction and ROI analysis difficult later on. A good way to prevent this problem is to open the Windows Snipping/Snip and Sketch tool and take a snip of the entire tiled imaging display window shortly after you start the acquisition. You can use this as a reference image throughout the experiment for identifying and managing drift. For slight adjustments in Z it’s okay (and recommended) to do it during an active acquisition, but it’s best to wait to make larger corrections in between trials (you can start a manual grab and make your adjustments, then abort and go back to the normal triggering protocol).

Note: a good technique for monitoring Z-drift is to focus on individual neurites that travel diagonally or almost laterally through the imaging volume, such that small changes in Z will cause that section of neurite to appear to move laterally in the plane. That way it’s easy to tell when drift has occurred and also which direction it needs to be moved to correct it.

Troubleshooting#

Many (most?) hardware/software problems and errors you might encounter while imaging can be solved by closing and restarting ScanImage, so you should always try that first.

Occasionally there can be a failure in the communication between ScanImage and the PMTs that can only be fixed by restarting the entire computer. Vidrio customer support has assured us that this is just a thing that happens sometimes and there’s not a less inconvenient way to fix it.

If everything is black in the tiled panel display window when you start imaging, you most likely either 1) forgot to open the PMT shutter with the weird circular switch, or 2) forgot to set the GR mirror and/or flipper mirror to the correct position in the BSCOPE2 CONTROLS window.

If things look unexpectedly dim in your imaging volume, the first thing you should do is check the the laser pre-compensation GDD value under the “curves” tab of the Chameleon Vision software on the Berg1 computer, which should be set to a value somewhere around 9000 (determined empirically by Sasha). However, this value is sometimes reset to zero for reasons that are not entirely clear (possibly every time the computer restarts?). When it is at zero, GCaMP fluorescence will appear much dimmer than expected for a given laser power.

Safety#

Take care to make sure that the box is closed before opening the laser shutter and imaging. This is especially important if you use the eyepieces in any way (i.e. to find your prep using the LEDs before 2P imaging). If you need to do any laser alignment or will need to open the shutter while the scope box is open, you need to be wearing proper eyewear and follow appropriate laser safety protocol.

ScanImage Warranty#

Can be found here.