-
Notifications
You must be signed in to change notification settings - Fork 24
/
writeRoastLog.m
314 lines (273 loc) · 11.6 KB
/
writeRoastLog.m
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
function opt = writeRoastLog(subject,opt,fun)
% opt = writeRoastLog(subject,opt,fun)
%
% Write logs for roast() and roast_target().
% The log file for roast() ends with '_roastLog' and the log file for
% roast_target() ends with '_targetLog'.
%
% (c) Yu (Andy) Huang, Parra Lab at CCNY
% April 2018
% August 2019 callable by roast_target()
[dirname,subjName] = fileparts(subject);
if isempty(dirname), dirname = pwd; end
switch fun
case 'roast'
fid = fopen([dirname filesep subjName '_roastLog'],'a');
if ~isempty(opt.uniqueTag)
uniqueTag = opt.uniqueTag;
else
% uniqueTag = char(datetime('now','Format','yyyy-MM-dd-HH-mm-ss')); % for Matlab 2014b and later
uniqueTag = char(datestr(now,30)); % for Matlab 2014a and earlier
opt.uniqueTag = uniqueTag;
end
if ~exist([dirname filesep subjName '_' uniqueTag '_roastOptions.mat'],'file')
save([dirname filesep subjName '_' uniqueTag '_roastOptions.mat'],'opt');
else
error('You''re about to run a simulation using options that you never used before, but forgot to use a new tag for it. ROAST will get confused when managing different simulations with the same tag. Please use a new tag.');
end
fprintf(fid,'%s:\n',uniqueTag);
fprintf(fid,'recipe:\t%s\n',opt.configTxt);
fprintf(fid,'capType:\t%s\n',opt.elecPara(1).capType);
fprintf(fid,'elecType:\t');
for i=1:length(opt.elecPara)
fprintf(fid,'%s\t',opt.elecPara(i).elecType);
end
fprintf(fid,'\n');
fprintf(fid,'elecSize:\t');
if length(opt.elecPara)==1
for i=1:size(opt.elecPara.elecSize,1)
fprintf(fid,'[');
for j=1:size(opt.elecPara.elecSize,2)
fprintf(fid,'%.1f',opt.elecPara.elecSize(i,j));
if j<size(opt.elecPara.elecSize,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<size(opt.elecPara.elecSize,1), fprintf(fid,'; '); end
end
else
for i=1:length(opt.elecPara)
fprintf(fid,'[');
for j=1:size(opt.elecPara(i).elecSize,2)
fprintf(fid,'%.1f',opt.elecPara(i).elecSize(j));
if j<size(opt.elecPara(i).elecSize,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<length(opt.elecPara), fprintf(fid,'; '); end
end
end
fprintf(fid,'\n');
fprintf(fid,'elecOri:\t');
if length(opt.elecPara)==1
if isempty(opt.elecPara.elecOri)
fprintf(fid,'N/A');
elseif ischar(opt.elecPara.elecOri)
fprintf(fid,'%s',opt.elecPara.elecOri);
else
for i=1:size(opt.elecPara.elecOri,1)
fprintf(fid,'[');
for j=1:size(opt.elecPara.elecOri,2)
fprintf(fid,'%.4f',opt.elecPara.elecOri(i,j));
if j<size(opt.elecPara.elecOri,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<size(opt.elecPara.elecOri,1), fprintf(fid,'; '); end
end
end
else
for i=1:length(opt.elecPara)
if isempty(opt.elecPara(i).elecOri)
fprintf(fid,'N/A');
elseif ischar(opt.elecPara(i).elecOri)
fprintf(fid,'%s',opt.elecPara(i).elecOri);
else
fprintf(fid,'[');
for j=1:size(opt.elecPara(i).elecOri,2)
fprintf(fid,'%.4f',opt.elecPara(i).elecOri(j));
if j<size(opt.elecPara(i).elecOri,2), fprintf(fid,','); end
end
fprintf(fid,']');
end
if i<length(opt.elecPara), fprintf(fid,'; '); end
end
end
fprintf(fid,'\n');
fprintf(fid,'T2:\t');
if ~isempty(opt.T2)
fprintf(fid,'%s',opt.T2);
else
fprintf(fid,'none');
end
fprintf(fid,'\n');
fprintf(fid,'multipriors:\t');
if opt.multipriors
fprintf(fid,'on');
else
fprintf(fid,'off');
end
fprintf(fid,'\n');
fprintf(fid,'meshOpt:\t');
fprintf(fid,'radbound: %d; angbound: %d; distbound: %.1f; reratio: %d; maxvol: %d',...
opt.meshOpt.radbound,opt.meshOpt.angbound,opt.meshOpt.distbound,opt.meshOpt.reratio,opt.meshOpt.maxvol);
fprintf(fid,'\n');
fprintf(fid,'conductivities:\t');
fprintf(fid,'white: %.3f; gray: %.3f; CSF: %.3f; bone: %.3f; skin: %.3f; air: %.1e; ',...
opt.conductivities.white,opt.conductivities.gray,opt.conductivities.csf,opt.conductivities.bone,opt.conductivities.skin,opt.conductivities.air);
fprintf(fid,'gel: ');
for i=1:length(opt.conductivities.gel), fprintf(fid,'%.3f; ',opt.conductivities.gel(i)); end
fprintf(fid,'electrode: ');
for i=1:length(opt.conductivities.electrode), fprintf(fid,'%.1e; ',opt.conductivities.electrode(i)); end
fprintf(fid,'\n');
fprintf(fid,'reSampling:\t');
if opt.resamp
fprintf(fid,'on');
else
fprintf(fid,'off');
end
fprintf(fid,'\n');
fprintf(fid,'zeroPadding:\t');
if opt.zeroPad>0
fprintf(fid,'%d',opt.zeroPad);
else
fprintf(fid,'none');
end
fprintf(fid,'\n');
fprintf(fid,'original MRI in RAS?:\t');
if opt.isNonRAS
fprintf(fid,'no, and is re-oriented into RAS');
else
fprintf(fid,'yes');
end
fprintf(fid,'\n\n');
fclose(fid);
case 'target'
fid = fopen([dirname filesep subjName '_targetLog'],'a');
if ~isempty(opt.uniqueTag)
uniqueTag = opt.uniqueTag;
else
% uniqueTag = char(datetime('now','Format','yyyy-MM-dd-HH-mm-ss')); % for Matlab 2014b and later
uniqueTag = char(datestr(now,30)); % for Matlab 2014a and earlier
opt.uniqueTag = uniqueTag;
end
if ~exist([dirname filesep subjName '_' uniqueTag '_targetOptions.mat'],'file')
save([dirname filesep subjName '_' uniqueTag '_targetOptions.mat'],'opt');
else
error('You''re about to run a targeting using options that you never used before, but forgot to use a new tag for it. ROAST-TARGET will get confused when managing different targetings with the same tag. Please use a new tag.');
end
fprintf(fid,'%s:\n',uniqueTag);
fprintf(fid,'ROAST simulation tag:\t%s\n',opt.roastTag);
fprintf(fid,'targetCoord (in MNI space):\t');
if ~isempty(opt.targetCoordMNI)
for i=1:size(opt.targetCoordMNI,1)
fprintf(fid,'[');
for j=1:size(opt.targetCoordMNI,2)
fprintf(fid,'%.1f',opt.targetCoordMNI(i,j));
if j<size(opt.targetCoordMNI,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<size(opt.targetCoordMNI,1), fprintf(fid,'; '); end
end
else
fprintf(fid,'not provided');
end
fprintf(fid,'\n');
fprintf(fid,'targetCoord (in original MRI voxel space):\t');
if ~isempty(opt.targetCoordOriginal)
for i=1:size(opt.targetCoordOriginal,1)
fprintf(fid,'[');
for j=1:size(opt.targetCoordOriginal,2)
fprintf(fid,'%d',opt.targetCoordOriginal(i,j));
if j<size(opt.targetCoordOriginal,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<size(opt.targetCoordOriginal,1), fprintf(fid,'; '); end
end
else
fprintf(fid,'not provided');
end
fprintf(fid,'\n');
fprintf(fid,'targetCoord (in model voxel space):\t');
for i=1:size(opt.targetCoord,1)
fprintf(fid,'[');
for j=1:size(opt.targetCoord,2)
fprintf(fid,'%d',opt.targetCoord(i,j));
if j<size(opt.targetCoord,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<size(opt.targetCoord,1), fprintf(fid,'; '); end
end
fprintf(fid,'\n');
fprintf(fid,'desired intensity at each target (in V/m, only for max-focality):\t');
if ~isempty(strfind(lower(opt.optType),'wls')) || ~isempty(strfind(lower(opt.optType),'lcmv'))
fprintf(fid,'%.3f',opt.desiredIntensity);
else
fprintf(fid,'N/A');
end
fprintf(fid,'\n');
fprintf(fid,'desired orientation at each target:\t');
if ~iscell(opt.orient)
for i=1:size(opt.orient,1)
fprintf(fid,'[');
for j=1:size(opt.orient,2)
fprintf(fid,'%.1f',opt.orient(i,j));
if j<size(opt.orient,2), fprintf(fid,','); end
end
fprintf(fid,']');
if i<size(opt.orient,1), fprintf(fid,'; '); end
end
else
for i=1:length(opt.orient)
if ischar(opt.orient{i})
fprintf(fid,'%s',opt.orient{i});
else
fprintf(fid,'[');
for j=1:size(opt.orient{i},2)
fprintf(fid,'%.4f',opt.orient{i}(j));
if j<size(opt.orient{i},2), fprintf(fid,','); end
end
fprintf(fid,']');
end
if i<length(opt.orient), fprintf(fid,'; '); end
end
end
fprintf(fid,'\n');
fprintf(fid,'targeting algorithm:\t%s\n',opt.optType);
fprintf(fid,'number of electrodes (only for max-l1per):\t');
if ~isempty(opt.elecNum)
fprintf(fid,'%d',opt.elecNum);
else
fprintf(fid,'N/A');
end
fprintf(fid,'\n');
fprintf(fid,'target radius (in mm):\t%d\n',opt.targetRadius);
fprintf(fid,'k (only for wls):\t');
if ~isempty(opt.k)
fprintf(fid,'%.3f',opt.k);
else
fprintf(fid,'N/A');
end
fprintf(fid,'\n');
fclose(fid);
case 'target-results'
fid = fopen([dirname filesep subjName '_targetLog'],'a');
fprintf(fid,'optimal montage:\t%s\n',opt.montageTxt);
fprintf(fid,'E-field magnitude at each target (in V/m):\t');
for i=1:length(opt.targetMag)
fprintf(fid,'%.2f',opt.targetMag(i));
if i<length(opt.targetMag), fprintf(fid,','); end
end
fprintf(fid,'\n');
fprintf(fid,'E-field intensity along the desired orientation at each target (in V/m):\t');
for i=1:length(opt.targetInt)
fprintf(fid,'%.2f',opt.targetInt(i));
if i<length(opt.targetInt), fprintf(fid,','); end
end
fprintf(fid,'\n');
fprintf(fid,'E-field focality at each target (in cm):\t');
for i=1:length(opt.targetMagFoc)
fprintf(fid,'%.2f',opt.targetMagFoc(i));
if i<length(opt.targetMagFoc), fprintf(fid,','); end
end
fprintf(fid,'\n\n');
fclose(fid);
end