-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageESRFunctionPool.m
More file actions
219 lines (180 loc) · 6.45 KB
/
Copy pathImageESRFunctionPool.m
File metadata and controls
219 lines (180 loc) · 6.45 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
function varargout=ImageESRFunctionPool(varargin)
switch varargin{1}
case 'Init'
Init;
case 'Run'
Run;
case 'SaveSweep'
SaveSweep;
end
function Init
% Maybe don't need this.
function Run
global gConfocal gmSEQ gESR
% Construct a questdlg
choice = questdlg('Please confirm that the average number of iterations on Experiment_PB_DAQ is set to a reasonable number.', ...
'Don''t integrate forever', ...
'OK','Cancel','OK');
% Handle response
switch choice
case 'OK'
case 'Cancel'
gESR.bGo=0;
return
end
% get the handle of Gui1
h = findobj('Tag','ExperimentGUI');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to Gui1
handles_Experiment = guidata(h);
end
% get the handle of Gui1
h2 = findobj('Tag','ImageNVCGUI');
% if exists (not empty)
if ~isempty(h2)
% get handles and other user-defined data associated to Gui1
handles_ImageNVC = guidata(h2);
end
% Get relevant sequence parameters (particularly gmSEQ.NSweepParam)
ExperimentFunctionPool('LoadUserInputs',0,0,handles_Experiment);
InitializeData(handles_Experiment);
gESR.SweepParam=gmSEQ.SweepParam;
%Consider rewriting ExperimentFunctionPool s.t. it calls InitializeData
%separately from RunSequence. Then, you can redefine the average number to
%be 1 to avoid running an infinite averaging sequence.
% Prepare vectors corresponding to X,Y,Z scan directions
planScan=PlanScan;
%
BackupImageFile=PortMap('BackupImageFile');
for k=1:gESR.NVz
ImageFunctionPool('WriteVoltage',0,0,0,3,planScan.SweepVz(k));
for j=1:gESR.NVy
if strcmp(gESR.direction,'Cartesian')
ImageFunctionPool('WriteVoltage',0,0,0,2,planScan.SweepVy(j)+gConfocal.YOffSet);
end
for i=1:gESR.NVx
ImageFunctionPool('WriteVoltage',0,0,0,1,planScan.SweepVx(i)+gConfocal.XOffSet);
if strcmp(gESR.direction,'Diagonal XY')
ImageFunctionPool('WriteVoltage',0,0,0,2,planScan.SweepVy(i)+gConfocal.YOffSet);
disp(['Sweeping sequence at location (', num2str(planScan.SweepVx(i)),', ', num2str(planScan.SweepVy(i)),', ',num2str(planScan.SweepVz(k)),')'])
else
disp(['Sweeping sequence at location (', num2str(planScan.SweepVx(i)),', ', num2str(planScan.SweepVy(j)),', ',num2str(planScan.SweepVz(k)),')'])
end
%DrawCrossHairs(handles_ImageNVC,[planScan.SweepVx(i)
%planScan.SweepVy(j) planScan.SweepVz(k)]); % This isn't
%working yet.
% Run ESR sequence
gmSEQ.bGo=0; % this is to prevent ExperimentFunctionPool from thinking a sequence already is happening
ExperimentFunctionPool('Run',0,0,handles_Experiment);
% Store data into separate global variable of size (Nx,Ny,Nz,NSweepParam)
if strcmp(gmSEQ.name,'ESR')
if strcmp(gESR.direction,'Diagonal XY')
gESR.data(i,1,k,:)=gmSEQ.signal;
else
gESR.data(i,j,k,:)=gmSEQ.signal;
end
else
gESR.data(i,j,k,:)=ExperimentFunctionPool('Normalize',0,[],[]);
if strcmp(gESR.direction,'Diagonal XY')
gESR.data(i,1,k,:)=gmSEQ.signal;
else
gESR.data(i,j,k,:)=gmSEQ.signal;
end
end
drawnow;
if ~gESR.bGo, break; end
end
Rescan;
TemporarySave(BackupImageFile);
if ~gESR.bGo || strcmp(gESR.direction,'Diagonal XY'), break; end
end
if ~gESR.bGo, break; end
end
gESR.data=squeeze(gESR.data);
%ImageFunctionPool('WriteVoltage',0,0,0,1,gConfocal.XOffSet);
%ImageFunctionPool('WriteVoltage',0,0,0,2,gConfocal.YOffSet);
%ImageFunctionPool('WriteVoltage',0,0,0,3,50);
gESR.bGo=0;
disp('ESR sweep completed.');
% ImageESR should set gESR.bGo=1; Should prepare gESR.max/min/N;
function planScan=PlanScan
global gESR gmSEQ
gESR.sweep=[];
if ~gESR.bFixVx
planScan.SweepVx=gESR.minVx:(gESR.maxVx-gESR.minVx)/(gESR.NVx-1):gESR.maxVx;
gESR.sweep=[gESR.sweep 'x'];
else
planScan.SweepVx=gESR.FixVx;
gESR.NVx=1;
end
if ~gESR.bFixVy
planScan.SweepVy=gESR.minVy:(gESR.maxVy-gESR.minVy)/(gESR.NVy-1):gESR.maxVy;
gESR.sweep=[gESR.sweep 'y'];
else
planScan.SweepVy=gESR.FixVy;
gESR.NVy=1;
end
if ~gESR.bFixVz
planScan.SweepVz=gESR.minVz:(gESR.maxVz-gESR.minVz)/(gESR.NVz-1):gESR.maxVz;
gESR.sweep=[gESR.sweep 'z'];
else
planScan.SweepVz=gESR.FixVz;
gESR.NVz=1;
end
if strcmp(gESR.direction,'Diagonal XY')
gESR.data=(NaN(gESR.NVx,1,gESR.NVz,gmSEQ.NSweepParam));
else
gESR.data=(NaN(gESR.NVx,gESR.NVy,gESR.NVz,gmSEQ.NSweepParam));
end
function DrawCrossHairs(handles, vec)
global gScan
% get the current limits of the axes1
XLimits = get(handles.axes1,'XLim');
YLimits = get(handles.axes1,'YLim');
p.x = vec(1);
p.y = vec(2);
% draw two lines
if isfield(gScan,'xLineHandle')
if ishandle(gScan.xLineHandle)
set(gScan.xLineHandle,'XData',[XLimits(1),XLimits(2)]);
set(gScan.xLineHandle,'YData',[p.y p.y]);
else
gScan.xLineHandle = line(handles.axes1,[XLimits(1),XLimits(2)],[p.y p.y],[1,1]);
end
else
gScan.xLineHandle = line(handles.axes1,[XLimits(1),XLimits(2)],[p.y p.y],[1,1]);
end
if isfield(gScan,'yLineHandle')
if ishandle(gScan.yLineHandle)
set(gScan.yLineHandle,'XData',[p.x p.x]);
set(gScan.yLineHandle,'YData',[YLimits(1),YLimits(2)]);
else
gScan.yLineHandle = line(handles.axes1,[p.x p.x],[YLimits(1),YLimits(2)],[1,1]);
end
else
gScan.yLineHandle = line(handles.axes1,[p.x p.x],[YLimits(1),YLimits(2)],[1,1]);
end
function SaveSweep
global gESR
% Map the squeezed data matrix to the corresponding
% parameters
gESR.sweep;
% Things to save: min/max/N for all spatial coordinates, NSweepParam
function Rescan
% get the handle of Gui1
h = findobj('Tag','ImageNVCGUI');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to Gui1
handles_ImageNVC = guidata(h);
end
ImageFunctionPool('Scan',0, 0, handles_ImageNVC);
ImageFunctionPool('Save',0, 0, handles_ImageNVC);
function TemporarySave(BackupFile)
global gESR gmSEQ
% convert relevant globals to a bigger structure
BackupExp.gmSEQ=gmSEQ;
BackupExp.gESR=gESR;
%save the data in matlab binary format
save(BackupFile,'BackupExp');