Stimulus Field

Note

For an overview of the ScanImage® Roi concept, please review the page Scanfields, ROIs, ROI Groups.

For an overview of the RoiGroup and Roi API, please review the article RoiGroup & Roi API

Stimulus Scanfield

A stimulus scanfield is defined by the following properties

Definition of a StimulusField
hSf = scanimage.mroi.scanfield.fields.StimulusField();  % create a stimulus Scanfield
hSf.centerXY = [0.5,0.5];                               % define the [x,y] center of the stimulus pattern (in reference space)
hSf.sizeXY = [0.5,0.5];                                 % define the [x,y] size stimulus pattern (in reference space)
hSf.rotationDegrees = 0;                                % define the rotation of the stimulus pattern (in reference space)
hSf.stimfcnhdl = @scanimage.mroi.stimulusfunctions.logspiral; % define the function handle used to generate the stimulus pattern
hSf.stimparams = {'revolutions',10};                    % additional parameters passed to the function generating the stimulus pattern
hSf.duration = 0.01;                                    % define the duration of the stimulus in seconds
hSf.repetitions = 1;                                    % define the number of repeats of the stimulus
hSf.powers = [1];                                       % define the power for each beam delivered during the stimulus in percent

hRoi = scanimage.mroi.Roi();                            % create an empty Roi
hRoi.add(0,hSf);                                        % add the stimulus Scanfield to the Roi

Stimulus Sequence

To create a stimulus sequence, multiple stimulus rois can be added to a RoiGroup.

Note

Add a pause before each stimulus to allow the galvo mirrors to fly to the stimulus position. End each stimulus sequence with a ‘park’ stimulus to park the galvo mirrors outside the field of view.

Tip

RoiGroups, Rois and Scanfields are handle objects. To stimulate the same target multiple times during a sequence, add the same stimulus Roi multiple times to the RoiGroup. This is faster than creating multiple instances of the Roi

Setup of a Stimulation Sequence

 1%% create template Stimulation Roi
 2hSf = scanimage.mroi.scanfield.fields.StimulusField();  % create a stimulus Scanfield
 3hRoi = scanimage.mroi.Roi();                            % create an empty Roi
 4hRoi.add(0,hSf);                                        % add the scanfield to the Roi; Currently ScanImage® only supports stimulation at z=0
 5
 6
 7%% create multiple stimulus Rois from template
 8hRoi1 = hRoi.copy();                          % create deep copy of template Roi
 9hRoi1.scanfields(1).centerXY = [0.25,0.5];    % change the position of the stimulus
10hRoi2 = hRoi.copy();                          % create deep copy of template Roi
11hRoi2.scanfields(1).centerXY = [0.5,0.5];     % change the position of the stimulus
12hRoi3 = hRoi.copy();                          % create deep copy of template Roi
13hRoi3.scanfields(1).centerXY = [0.75,0.5];    % change the position of the stimulus
14
15stimRois = [hRoi1 hRoi2 hRoi3];               % collect the position of the stimulus Rois in array
16
17
18%% create pause Roi
19hSfPause = scanimage.mroi.scanfield.fields.StimulusField();     % create a stimulus Scanfield
20hSfPause.stimfcnhdl = @scanimage.mroi.stimulusfunctions.pause;  % the pause stimulus function allow for a smooth transition between stimuli
21hSfPause.duration = 0.01;                                       % allow enough time for the mirrors to transition in between stimuli
22
23hRoiPause = scanimage.mroi.Roi();                               % create an empty Roi
24hRoiPause.add(0,hSfPause);                                      % add 'pause' stimulus to Roi
25
26
27%% create park Roi
28hSfPark = scanimage.mroi.scanfield.fields.StimulusField();      % create a stimulus Scanfield
29hSfPark.stimfcnhdl = @scanimage.mroi.stimulusfunctions.park;    % the park stimulus function moves the mirrors to the park position
30hSfPark.duration = 0.01;                                        % allow enough time for the mirrors to traverse to the park position
31
32hRoiPark = scanimage.mroi.Roi();                                % create an empty Roi
33hRoiPark.add(0,hSfPark);                                        % add 'park' stimulus to Roi
34
35
36%% create roiGroup containing sequence of stimuli
37hRoiGroup = scanimage.mroi.RoiGroup();
38
39% add all stimuli, interleave with pauses
40for idx = 1:length(stimRois)
41    hRoiGroup.add(hRoiPause);
42    hRoiGroup.add(stimRois(idx));
43end
44hRoiGroup.add(hRoiPark);  % transition to park position at end of sequence
45
46hSI.hPhotostim.stimRoiGroups(end+1) = hRoiGroup;  % add sequence to array of stimRoiGroups