μSPIM: A Software Platform for Selective Plane Illumination Microscopy

Selective Plane Illumination Microscopy (SPIM) is a fluorescence imaging technique that allows volumetric imaging at high spatio-temporal resolution to monitor neural activity in live organisms such as larval zebrafish. A major challenge in the construction of a custom SPIM microscope is the control and synchronization of the various hardware components. Here we present a control toolset, μSPIM, built around the open-source MicroManager platform that has already been widely adopted for the control of microscopy hardware. Installation of μSPIM is relatively straightforward, involving a single C++ executable and a Java-based extension to Micro-Manager. Imaging protocols are defined through the μSPIM extension to Micro-Manager. The extension then synchronizes the camera shutter with the galvanometer mirrors to create a light-sheet that is scanned in the z-dimension, in synchrony with the imaging objective, to produce volumetric recordings. A key advantage of μSPIM is that a series of calibration procedures optimizes acquisition for a given set-up making it relatively independent of the optical design of the microscope, or the hardware used to build it. Two laser illumination arms can be used while also allowing for the introduction of illumination masks. μSPIM allows imaging of calcium activity throughout the brain of larval zebrafish at rates of 100 planes per second with single cell resolution as well as slower imaging to reconstruct cell populations, for example, in the cleared brains of mice.

structure and/or function of the tissue and the images are acquired by a high-resolution camera focused on that same plane. Illuminating a single thin plane minimizes out-of-focus fluorescence to allow the visualization of individual cells and their processes at illumination intensities that minimize photobleaching and phototoxicity. Rapid movement of the sheet through the tissue then allows for collection of complete volumes at high rates. The ability to image with single-cell resolution at depth has made SPIM particularly useful for the study of developmental processes in embryos of C. elegans (Rieckher et al., 2015), Drosophila (Keller et al., 2010) and zebrafish (Kobitski et al., 2015;Wan et al., 2019), as well as imaging neural activity in Drosophila embryos and larvae (Chhetri et al., 2015;Lemon et al., 2015), C. elegans (Ardiel et al., 2017) and zebrafish (Ahrens et al., 2012;Ahrens et al., 2013;Weisenburger and Vaziri, 2018). This form of light-sheet microscopy also allows for faster imaging in fixed tissue that has been "cleared" to homogenize the refractive index and reduce scattering. Imaging through the cleared brains of mice, for instance, enables the visualization of specific neuronal circuits (Chung and Deisseroth, 2013;Mano et al., 2018).
A number of different implementations of SPIM have been developed (Keller and Ahrens, 2015), but they most commonly use an illumination arm to create a 2D plane of illumination and an orthogonal collection arm that is forming the image onto the camera. There are two main variations on this basic design: the method of light sheet formation and its movement relative to the sample.
The original approach creates a stationary light sheet using a cylindrical lens and then translates or rotates the sample with a moving stage. This implementation has been particularly useful in studies of development (Huisken and Stainier, 2009), but it is too slow to monitor the activity of neurons using, for instance, genetically-encoded calcium indicators. Applications in functional neuroscience therefore favour a configuration in which the sample is kept stationary while the light sheet is created using a fast scanning mirror that moves the light beam across a plane at least once per imaging frame, with a secondary mirror moving the beam in the z-dimension ( Figure   2B). This method has allowed "brain-wide" imaging of neural activity in live zebrafish with single neuron resolution and acquisition frequencies of ~1 Hz (Ahrens et al., 2012;Ahrens et al., 2013).
Several designs of SPIM have been published but probably the most accessible in terms of both hardware and software are the OpenSPIM (Pitrone et al., 2013) and Open SPIM microscopy (Gualda et al., 2013) projects. Both these implementations are focused on imaging of developmental processes using the slower "moving sample" configuration and therefore have limited use if the aim is to image neural activity through volumes of the brain. The "moving lightsheet" configuration is more complex to control because it requires synchronization of several hardware components with millisecond temporal accuracy. For instance, movements of the imaging objective in the z-dimension must be synchronized with movement of the light-sheet to stay focused on the plane of illumination, often involving 50-100 planes per second. Perhaps for this reason, open software tools for the control of SPIMs in functional imaging experiments are not easily available. We aim to fill this gap by providing a control toolset, µSPIM, which adopts an open software approach for control of a SPIM microscope in which the light-sheet is scanned through a stationary sample. We achieve this by building µSPIM around Micro-Manager (Edelstein et al., 2010), an open-source platform widely used for control of microscopes, to provide a comprehensive user interface (Fig 3) with a smooth learning curve. µSPIM has been designed to be used to control a range of custom-built microscopes, for which it is calibrated using semiautomated procedures. We demonstrate the utility of µSPIM for whole-brain imaging in larval zebrafish and neuron reconstruction in cleared mouse brains.

II. Design Requirements
We start by listing the basic objectives of software controlling a SPIM microscope in relation to the microscope we have constructed (shown in Figure 1, see Methods). 1. The illumination arm requires the control of the laser light-source, using either an internal and/or external shutter. Dualcolour imaging requires two independent laser sources to be combined. Depending on the laser model, power may be controlled on long time-scales using USB or RS232 interfaces and modulated on short time-scales by analogue signals, while shuttering requires digital signals. 2.
The beam has to be scanned in the x and z dimensions using fast galvanometer mirrors driven through analogue inputs. 3. The collection arm must follow the beam and collect images that are in focus at different z-positions, which is achieved by using a piezo-electric mount for the objective, again controlled through an analogue signal. Finally, 4. The camera acquisition must be accurately timed to collect frames at each z position, which in turn requires accurate calibration of the z mirror so that the z position of the light-sheet is set from the command signal. The software should then allow control of several features of the camera, including frame integration time, pixel binning and gain. Furthermore it should support saving and retrieving images and movies, zooming, defining ROIs, quick and easy changes in imaging parameters and the ability to define various imaging protocols using different sequences of laser illumination Fig. 1: Light-Sheet Microscope Implementation. (A) Diagram outlining light-sheet microscope with two mirror galvanometers and a stationary sample. The light sheet is created from a laser beam by the 'X Galvo mirror'. The 'Z Galvo mirror' then moves the sheet through the sample to create volumetric excitation. This is synchronized with a Piezoelectric stage that moves the imaging objective so that the excitation plane always coincides with the imaging plane. (B) A photo of an example light-sheet microscope setup with one light-sheet path. The main components are colour coded.
We built µSPIM around the open-source software Micro-Manager (Edelstein et al., 2010), which is based on ImageJ (Schindelin et al., 2015), because it immediately offers the ability to integrate different hardware from a wide range of manufacturers through specific plugins, including a range of cameras, light-sources and shutters required for a SPIM. It provides an integrated environment for image acquisition and a very wide range of post-acquisition processing capabilities through ImageJ. Micro-Manager does not, however, provide hardware triggering, analogue control and monitoring with the precision required for volumetric imaging of neural activity. For this purpose, we used a National Instruments DAC card (NI PCIe-6738) and wrote an executable 'µSPIM Control' to allow interaction between Micromanager and hardware through its own user interface.
µSPIM Control synchronizes internal laser shutters, x and z mirrors, the objective piezo stage and all camera triggering, leaving laser power, external mechanical shutters and camera operating properties under control of Micro-Manager, see Figure 2A. µSPIM therefore provides both accessibility and versatility, retaining the user's ability to select hardware best suited for the particular setting, as long as it supported through a Micro-Manager plug-in (The current range can be viewed at https://micro-manager.org/wiki/Device%20Support).

III. Principles of operation
The µSPIM toolset consists of two main components: a Java plugin for MicroManager which facilitates all user interaction and configuration, and a C++ control executable which interacts with the National Instruments board to produce hardware control signals (Figure 2). These support the control of two scanning X mirrors for light sheet formation, two scanning Z mirrors and one piezoelectric stage for a Z motion of the collection objective, two laser shutters for laser masking and one trigger for the camera acquisition control and synchronization with other hardware. After an appropriate setup, the Java plugin facilitates all necessary tools for calibration and control of the hardware, providing the users with an intuitive interface without requiring the need for specialized computer knowledge or programming, while allowing flexibility provided by MicroManager. Figure 2 illustrates the control diagram, outlining the interaction between the user and the light-sheet microscope hardware (Figure 2A) as well as the temporal sequence of the control signals ( Figure 2B and C).  A typical user interface for data acquisition is presented in Figure 3, with the µSPIM Control window at the top (A) and MicroManager windows below (B-D). The primary Micromanager window (C) provides access to all functionality related to the acquisition, such as live mode, binning, ROI selection or exposure time. The µSPIM plugin (A) provides access to the variables used for light-sheet formation, such as light-sheet width, volume depth or number of planes as well as providing a set of calibration procedures described in the Calibration section below. During scan mode, the image can be viewed in the classical MicroManger live window (D) which also allows the acquisition of snapshots. While acquisition can be manually started through the MicroManager interface, the µSPIM plugin interface provides an acquisition routine executing a synchronized start of acquisition and illumination, making the process of acquiring data (namely volumes) simpler and more robust.
Taking full advantage of the stationary sample and fast acquisition speeds, we used µSPIM to monitor the activity of neurons across most of the brain of larval zebrafish expressing the nuclear localised Ca2+ reporter GCaMP6f panneuronally (Tg(Huc:H2B -GCaMP6f), Fig. 4 ). Larvae were embedded so that the laser excited the sample from the side (arrows in Fig. 4A). The width of the sheet spanned 500 µm and covered the entire hindbrain, the cerebellum and parts of the optic tectum. Single planes were recorded at a frequency of 98 Hz. The volume was set to cover a distance of z = 100 µm and consisted of 50 planes with a spacing of 2 µm. The piezo returned to its original position within 10 frames yielding an overall imaging frequency of 1.6 volumes per second. Figure   Many problems in neuroscience require the mapping of neurons and their connections through large volumes of the brain and SPIM has become very useful for such applications because it allows high-speed volumetric imaging of fixed and stained tissues with two key advantages over techniques such as confocal microscopy and multiphoton microscopy -faster speed and muchreduced photobleaching (Stefaniuk et al., 2016;Tomer et al., 2014). Speed improvements of more than 100-fold derive from capturing the whole image simultaneously rather than by scanning a point source, while photobleaching is minimized by only illuminating the plane of interest. This application of SPIM has recently become more important with the development of tissue preparation techniques such as iDISCO -immunolabeling-enabled three-dimensional imaging of solvent-cleared organs . These techniques remove variations in refractive index that would normally degrade images while allowing visualization of expressed fluorescent proteins or antibody-labelling throughout intact tissues and come into their own when used with SPIM (Dodt et al., 2007;Tomer et al., 2014). µSPIM is also ideally suited to this application and example images are shown in Fig. 5, were obtained from the cleared brain of a mouse prepared by the iDISCO technique. Here we used µSPIM to control two lasers for dual-colour imaging in red and green channels. The images show excitatory neurons (pyramidal cells) in the primary visual cortex V1 expressing the green calcium reporter GCaMP6f and/or phosphorylated tau protein. Individual neurons are easily visualized and their processes can be followed. Images at this resolution, using planes just 1 m apart, could be imaged through the brain at speeds of 20 m/s. The images show excitatory neurons (pyramidal cells) in the primary visual cortex V1, either expressing the GFP-based calcium reporter GCaMP6f (green) and/or tau fibrils (red, labelled with the AT-8 antibody). The sequence of images is spaced 10 m apart and each is an average intensity projection of 2 planes 1 m apart. Individual frames were acquired with an integration time of 50 ms. Cell bodies and thin processes of pyramidal neurons can be seen. Cells expressing both GCaMP6f and tau fibrils appear yellow. The surface of the cortex is at the top.

IV. Computing Requirements
The µSPIM relies only on minimal third-party software for its operation. This includes MicroManager for integration of acquisition hardware (laser control, light path shutter and camera) and National Instruments drivers, in order to interface with the National instruments DAC card.
Naturally, drivers and accompanying software must be installed for the selected hardware (such as lasers or camera) in order to ensure MicroManager can communicate with those parts properly.
Due to the continuous high data throughput, it is recommended to use a secondary computer for stimulation and/or other intensive tasks to avoid potential performance issues.
The computer specifications necessary for optimal function and acquisition of the setup are highly dependent on the acquisition requirements. For large field of view and high acquisition speeds, the acquisition produces large datasets, making the process highly storage-dependent. State-ofthe-art acquisition cameras are able to reach 4 megapixel resolution at 100 Hz and 16 bit depth, producing a theoretical throughput of 838.9 MB/s. This poses a write speed requirement higher than that which can be satisfied by a regular SATA3 storage interface which is limited to a theoretical maximum of 600 MB/s. It is therefore highly recommended to utilize a faster storage solution, such as fast PCI-based solid state disk (SSD) storage (e.g. Intel Optane 905p) or hardware SSD RAID. The acquisition is not highly CPU dependent and neither µSPIM nor MicroManager take a significant advantage in parallel processing. A state-of-the-art consumer line 4-or 6-core CPU is sufficient for optimal performance. µSPIM supports control of two independently calibrated laser paths. Each path consists of a visible light laser, two scanning mirrors and one laser path shutter (see Fig. 1). The laser path shutter must be supported by MicroManager and is used to block light between periods of acquisition and thus reduce photo-bleaching of the sample. One of the two scanning mirrors is used for light sheet formation and the second is used for Z movement. The laser should provide digital or analogue shuttering capability. All other devices are controlled using an analogue signal produced by the National Instrument DAC adapter and should support inputs in appropriate voltage ranges (commonly ±10 V). µSPIM allows for incomplete configurations e.g. single light path with unmodulated laser and single sheet-generating scanning mirror would provide minimal functionality, however most of the features of the µSPIM toolkit would be unavailable. To support the full functionality, the National Instruments DAC card must support at least 8 analogue outputs with no need for analogue or digital inputs as the control is fully feed-forward and does not require any feedback from the hardware.

V. Calibration
The spatial scales of the signals are greatly dependent on the chosen hardware and thus require the user to perform set of calibration procedures to ensure appropriate alignment of the hardware.
Here and in Figure 6 we outline the principles of the calibration of the different components affecting the acquisition.  A) and (B) show the calibration interface for X mirror with respect to the laser shutter when using masks and for Z mirror, respectively. (C) The movement of the X mirror galvanometer lags behind the supplied signal, resulting in artefacts when using laser masks. (i.) shows the laser shutter signal (green) and (ii.) shows the X mirror signal (blue) and actual mirror movement (light blue). Black bar highlights the misalignment between the shutter signal and mirror movement when the X mirror signal is not calibrated and no delay is introduced. (iii.) shows a mask used for calibration, emphasizing the difference between uncalibrated and calibrated system.

A. X-Mirror
Proper X-plane mirror calibration is essential for the correct assessment of size of the illuminated region when starting acquisition. To calibrate the X mirror, it is necessary to know the size of the field of view (or pixel size). This can be calculated as the effective camera image sensor size divided by the magnification of the collection objective or by measuring a standard stage calibration slide under the microscope. Using this measurement, the X Mirror scale can be adjusted such that a sheet of a particular width matches the corresponding number of the pixel.
In the case of two illumination paths, this procedure should be repeated for both paths separately.
This calibration should be carried out such that the x-mirror moves around its central position when energized (i.e. with zero volts driving signal) and the illumination arm should be adjusted such that this central position is centred on the field of view.

B. Piezoelectric Stage
Piezoelectric stages are generally factory-calibrated to move a predefined distance by set voltage difference (e.g. 1 µm per 40 mV for the PIFOC model) to which the Piezo Scale setting should be set. The unit is mV/µm and for the previous example this setting would be set to 40.0. µSPIM also provides a Piezo Offset setting which can be used to adjust voltage offset in software. For optimal operation, it is suggested to adjust the offset such that a plane at 0.0 µm is near the top of the available range. Setting the offset could be beneficial, for instance, when imaging at multiple depths in a sample so that when 0.0 µm is positioned at the top of the sample it serves as a reference while allowing the full range of the piezoelectric stage to be utilized.

C. Z-Mirror
Next, it is necessary to calibrate the relative movement of the Z-plane mirror(s) with respect to the movement of the now-calibrated Piezoelectric stage. This can be done using a calibration procedure provided by µSPIM which steps the stage through a user-defined number of levels across a volume of choice and allows the user to adjusts the Z mirror voltage for each level such that the laser sheet is in focus. Finally, a Z Mirror scale is generated which can then be used to adjust settings.

D. X-Mirror Lag Compensation
The X Mirror movement lags the signal which can be problematic when using laser masks (discussed in Section VI-A1). To correct for this, µSPIM provides a simple calibration process during which a distinct mask is displayed and the mirror lag is adjusted by the user until the masks perfectly overlap as shown in Figure 7.

VI. Data Acquisition using µSPIM
For the acquisition of a single plane, the X mirror galvanometer has to be scanned at least once across the full range of the desired light sheet width and back to its original position (Figure 2, showing 3 scans per frame). To ensure uniform illumination between frames, µSPIM takes control over the camera using a rising edge trigger signal synchronized with the X mirror (Figure 2).

Generation of a volume recording is provided by a synchronous movement of the Z Mirror and
the Piezoelectric Stage between frames, acquiring consecutive frames from different heights in the samples (Figure 2). To allow for better distribution of sample illumination or illumination of occluded regions, µSPIM also supports the control of two separate paths, allowing for two light sheets of different widths.

A. Advanced Acquisition Methods
While basic acquisition described above may be sufficient for some applications, µSPIM is primarily intended for functional imaging with visible light which can disturb the live sample. To minimize the impact of the visible light, the µSPIM toolset implements several procedures which can be used in applications where this is an issue.

1) Laser Masks:
Removing parts of the light sheet can be beneficial in some acquisition settings.
µSPIM utilizes fast software shuttering to provide two main masks which may be beneficial for in vivo imaging: Edge Masks, removing the ends of the light sheet and thus reducing the regions which are over-illuminated due to slow reversion of the direction of the X mirror (Figure 7) and Eye Mask which can be used to remove illumination from a selected region in the light sheet (Figure 7), allowing for acquisition where a specific region must not be illuminated (such as the eye).
2) Light Adaptation: Zebrafish larvae have been shown to react to sudden light changes (Burgess and Granato, 2007), interfering with behaviours of interest. This proves problematic in visible light recordings as the light is commonly turned off between recordings to prevent photodamage to the sample, resulting in a sudden light change during the start of the recording. We provide a simple light adaptation functionality which places a light sheet in a position near the top of the sample prior to recording where photodamage is of less concern and then move the sheet into position as the recording is started.
3) Multi-recording sequence: Similarly, to the adaptation period, sudden light changes can be reduced by consecutive acquisition of a number of recordings without the need for user input in between the recordings. This eliminates the concern of photodamage during non-acquisition time periods, allowing the laser to be turned on for the whole sequence of the recordings.

B. Data Output Format
The image data output follows the MicroManager format with acquired image sequences being split into 4GB files accompanied by a metadata file (Metadata format can be found in the official MicroManager documentation: https://micro-manager.org/wiki/Files_and_Metadata). To accommodate for the extra information regarding the light sheet acquisition, µSPIM provides a separate metadata file which carries the information about the volume acquired as well as information about the experiment and sample provided by the user (Figure 8).

VII. Discussion
We have presented the µSPIM toolset which provides a flexible software solution for the control of SPIM microscopes and demonstrated its utility for two important applicationsbrain-wide imaging of neural activity in larval zebrafish (Ahrens et al., 2012) and visualizing neurons with cellular resolution in whole mouse brains (Tomer et al., 2014). In contrast to other open source control solutions for light sheet microscopes, such as OpenSPIM (Pitrone et al., 2013) and Open SPIM microscopy (Gualda et al., 2013), µSPIM focuses on a microscope implementation better As previously outlined, the focus of the µSPIM toolbox is primarily on the hardware flexibility aimed at a particular application (functional light sheet imaging) and thus some more complex functionality may not be supported out of the box. One notable example would be use of multiple lasers with various wavelengths which is required when imaging with multiple fluorescent reporters or markers: µSPIM is currently limited to providing support for two independent lasers.
We have not yet explored the possibility of replacing one or either of these by a multi-colour light engine, but envisage that this will be possible given that micromanager supports a number of such devices. Again, advanced users may choose to modify our solution to support this functionality if required.
Being built around MicroManager, µSPIM inherits all of its limitations. For instance, while the list of acquisition hardware supported by the MicroManager platform is extensive, it is possible that some less common devices are not supported by the platform and thus cannot be used with our toolbox. Another notable limitation is the lack of support for the "rolling shutter" mode of acquisition in which the exposure of each line of pixels on the sCMOS sensor is delayed to coincide with the time at which those pixels are parfocal with the laser beam passing through the sample (also called electronic confocal slit detection (Hu et al., 2017)). Because only that single line of pixels is activated, much background fluorescence caused by scattered illumination of neighbouring areas is rejected, thereby improving resolution. We did not implement this mode of acquisition as a standard feature of SPIM because it results in lower frame rates compared to the usual "global shutter" mode of acquisition in which all pixels are activated simultaneously.
While our framework does not support some use cases in its current implementation, it provides a comprehensive solution to the control of light sheet microscope with support for a wide range of both control and acquisition hardware while retaining a gentle learning curve supported by the well documented calibration and acquisition protocols. For this reason, we hope the µSPIM toolbox will be adopted in both standard and custom light sheet imaging use cases thanks to welldocumented open source code base. Both documentation and source code is available for free from the µSPIM git repository (https://uspim.org).

A. Optical design of SPIM used in this work
A partial parts list for the SPIM we constructed is provided in Table 1. The illumination arm ( Fig.   1) was fed by one or two lasers through optical fibres (kineflex). When using both red and green fluorophores, a long-pass dichroic mirror (Thorlabs DMLP505R) combined the beams of the blue and yellow lasers, which then passed through a mechanical shutter. The beam was reflected by a pair of X and Z Galvo scanning mirrors with 1 kHz bandwidth at deflection angles ± 0.2°. The beam was then expanded by a factor of 2.5 using a pair of achromatic lenses (f = 50 mm and 125 mm) The optimum beam parameters were calculated using calctool (http://www.calctool.org/CALC/phys/optics/f_NA). The illumination lens was f = 40 mm achromat.
The whole of the illumination arm, beginning with the combining mirror, was mounted on an optical rail which was itself mounted on two translation stages (Thorlabs XR25C/M), one of which was slaved to the other. This arrangement allowed centering of the illumination beam on the field of view when the x-mirror was set to its position of zero offset, which is especially important for calibration of x-mirror displacement described above. With the rapid scanning of the X Galvo mirror, the laser line will form an illumination plane over the integration time of a single frame. The thickness of the beam waist was ~7 µm, with a Rayleigh length of ~440 µm. We therefore achieved a relatively uniform plane of illumination across half of the total field of view, which was 810 µm wide. The specimen stage was custom-designed according to application and manufactured using a 3D printer. The stage was attached to an x-y-z translation assembly (Thorlabs PT3)

B. Imaging Brains of Larval Zebrafish
All procedures were in accordance with the UK Animal Act 1986 and were approved by the Home Office and the University of Sussex Ethical Review Committee. Transgenic zebrafish larvae of undetermined sex expressing the nuclear localised H2B-GCaMP6f calcium reporter panneuronally (Tg(elavl3:H2BGCaMP6f) (Chen et al., 2013;Dunn et al., 2016)), were imaged at 6 days-post-fertilisation (dpf). Larvae were paralysed by positioning them sideways in a small slit of PDMS (Sylgard184, Dow Crowning) on a coverslip (Pichler and Lagnado, 2019) and injecting 0.25mM a-Bungarotoxin (Tocris Bioscience) into their heart. They were then embedded dorsal side up in 2% low-melting-point agarose (Biogene) in E2 medium (Brand et al., 2002) a 22 mm x 22 mm coverslip and placed into a custom glass-walled 3D printed chamber. After filling the chamber with E2 medium, the majority of the agarose that fell between the laser source and the larva's head was removed with a scalpel to maintain sufficient stability of the sample while minimising the way the laser travelling through the agarose. The chamber was positioned underneath the objective so that upon turning on the laser, it would not hit the head, and the eyes in particular, but rather the tail of the fish. Once imaging and excitation plane were successfully aligned, the larva's brain was approached and the desired brain region was found, the size of the volume and the number of slices were chosen.
temperature (3-hour incubation with shaking). Samples were washed in 100% DCM (15min x 2 with shaking). Brains were cleared using dibenzyl ether (DBE). Tubes were filled to the top to avoid oxidation and prevent brains turning opaque. Brains were kept in DBE-filled tubes until imaged. Red emission was collected through a 607/42 filter (Edmund Optics). Laser powers were usually ~20 mW.