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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
%% create template Stimulation Roi
hSf = scanimage.mroi.scanfield.fields.StimulusField();  % create a stimulus Scanfield
hRoi = scanimage.mroi.Roi();                            % create an empty Roi
hRoi.add(0,hSf);                                        % add the scanfield to the Roi; Currently ScanImage® only supports stimulation at z=0


%% create multiple stimulus Rois from template
hRoi1 = hRoi.copy();                          % create deep copy of template Roi
hRoi1.scanfields(1).centerXY = [0.25,0.5];    % change the position of the stimulus
hRoi2 = hRoi.copy();                          % create deep copy of template Roi
hRoi2.scanfields(1).centerXY = [0.5,0.5];     % change the position of the stimulus
hRoi3 = hRoi.copy();                          % create deep copy of template Roi
hRoi3.scanfields(1).centerXY = [0.75,0.5];    % change the position of the stimulus

stimRois = [hRoi1 hRoi2 hRoi3];               % collect the position of the stimulus Rois in array


%% create pause Roi
hSfPause = scanimage.mroi.scanfield.fields.StimulusField();     % create a stimulus Scanfield
hSfPause.stimfcnhdl = @scanimage.mroi.stimulusfunctions.pause;  % the pause stimulus function allow for a smooth transition between stimuli
hSfPause.duration = 0.01;                                       % allow enough time for the mirrors to transition in between stimuli

hRoiPause = scanimage.mroi.Roi();                               % create an empty Roi
hRoiPause.add(0,hSfPause);                                      % add 'pause' stimulus to Roi


%% create park Roi
hSfPark = scanimage.mroi.scanfield.fields.StimulusField();      % create a stimulus Scanfield
hSfPark.stimfcnhdl = @scanimage.mroi.stimulusfunctions.park;    % the park stimulus function moves the mirrors to the park position
hSfPark.duration = 0.01;                                        % allow enough time for the mirrors to traverse to the park position

hRoiPark = scanimage.mroi.Roi();                                % create an empty Roi
hRoiPark.add(0,hSfPark);                                        % add 'park' stimulus to Roi


%% create roiGroup containing sequence of stimuli
hRoiGroup = scanimage.mroi.RoiGroup();

% add all stimuli, interleave with pauses
for idx = 1:length(stimRois)
    hRoiGroup.add(hRoiPause);
    hRoiGroup.add(stimRois(idx));
end
hRoiGroup.add(hRoiPark);  % transition to park position at end of sequence

hSI.hPhotostim.stimRoiGroups(end+1) = hRoiGroup;  % add sequence to array of stimRoiGroups