This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
covid_pipeline.m
422 lines (292 loc) · 15.6 KB
/
covid_pipeline.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
% macro to start the sequence of processing linked to the preparation of md1252 experiment scans about covid done in local tomography and hald-acquisition
% available preset are 'core_biopsies' and 'zoom6'
% origin Paul Tafforeau ESRF 2020
function covid_pipeline (radix,preset)
switch preset
case 'large_field'
do_cleaning =1 % remove all the previous reconstruction files as well as the previous references
do_proj =0 % for scans on axis, calculate the normalized projection of all the radiographs using SRCurrent
do_ref_scan =1 % uses a reference scan to generate the new references for each sub-scan
do_ref_from_scan =0 % generate off axis references from series of scans based on the radix with defined parameters for HR/LR calculations. If 1 uses all the scans, if >1 uses scans up to this number
do_ref_opt =0 % general optimization of the references for first integration of ring artefacts and eventual compensation of optic darkening
do_scan_opt =1 % starts covid_half_acquisition_master_OAR that will generate a new scan with all SRCurrent and darkening taken into account, with only two homogeneous references and back in 16 b
case 'large_field_off_axis'
do_cleaning =1
do_proj =0
do_ref_scan =0
do_ref_from_scan =1
do_ref_opt =0
do_scan_opt =1
case 'zoom6_on_axis'
do_cleaning =1
do_proj =1
do_ref_scan =0
do_ref_from_scan =0
do_ref_opt =0
do_scan_opt =1
case 'zoom6'
do_cleaning =1
do_proj =0
do_ref_scan =0
do_ref_from_scan =1
do_ref_opt =0
do_scan_opt =1
case 'zoom6_hard'
do_cleaning =1
do_proj =0
do_ref_scan =1
do_ref_from_scan =0
do_ref_opt =0
do_scan_opt =1
case 'core_biopsies'
do_cleaning =1
do_proj =0
do_ref_scan =0
do_ref_from_scan =1
do_ref_opt =1
do_scan_opt =1
case 'zoom2'
do_cleaning =1
do_proj =0
do_ref_scan =1
do_ref_from_scan =1
do_ref_opt =0
do_scan_opt =1
case 'zoom1'
do_cleaning =1
do_proj =0
do_ref_scan =0
do_ref_from_scan =1
do_ref_opt =1
do_scan_opt =1
case 'tubes' % to be used for samples scanned in tubes also in the lid, and that are reconstructed using the local tomography option of pyhst2
do_cleaning =1
do_proj =1
do_ref_scan =0 % to be tested if it is more efficient or not considering that the processing can be done with local tomo option in pyhst2
do_ref_from_scan =0
do_ref_opt =1
do_scan_opt =0
end
%%%%%%%%%%%%%%%%%%%%%
% details of preset %
%%%%%%%%%%%%%%%%%%%%%
switch preset
case 'large_field'
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=1000; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=200; % number of projections used to calculate the low frequencies in the references
HF_LF=50; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'large_field_off_axis'
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=600; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=200; % number of projections used to calculate the low frequencies in the references
HF_LF=50; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'zoom6_on_axis'
% preset for do_ref_scan
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=1000; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=500; % number of projections used to calculate the low frequencies in the references
HF_LF=100; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'zoom6'
% preset for do_ref_scan
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=100; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=400; % number of projections used to calculate the low frequencies in the references
HF_LF=100; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'zoom6_hard'
% preset for do_ref_scan
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=1000; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=200; % number of projections used to calculate the low frequencies in the references
HF_LF=100; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'core_biopsies'
% preset for do_ref_scan
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=600; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=200; % number of projections used to calculate the low frequencies in the references
HF_LF=250; % filter size to separate the LF and HF in the projections
use_med_scans=1; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'zoom2'
% preset for do_ref_scan and ref_from_scan
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=600; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=200; % number of projections used to calculate the low frequencies in the references
HF_LF=200; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'zoom1'
% preset for do_ref_scan and ref_from_scan
new_refon=100 ; % calculate new references every N projections
inscan_med_HF=600; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=200; % number of projections used to calculate the low frequencies in the references
HF_LF=400; % filter size to separate the LF and HF in the projections
use_med_scans=0; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=0; % do the integration of the projections using a median (1) or an average (0)
case 'tubes'
% preset for do_ref_scan
new_refon=500 ; % calculate new references every N projections
inscan_med_HF=1000; % number of projections used to calculated the high frequencies in the references
inscan_med_LF=500; % number of projections used to calculate the low frequencies in the references
HF_LF=250; % filter size to separate the LF and HF in the projections
use_med_scans=1; % do the integration using a median of the scans (1) or an average (0)
use_med_proj=1; % do the integration of the projections using a median (1) or an average (0)
end
dirlist=dir([radix '*_']);
dirnum=size(dirlist,1);
dirname={dirlist.name};
fprintf ('I found %1.0f scans to be processed \n',dirnum);
%% cleaning all the scans to ensure proper start
if do_cleaning==1
clean_scan_series ([radix '*'])
cmd=sprintf('rm -rf %s*_/refHST*',radix);
unix(cmd)
end
%% preparing the normalized projections of each scan and calculating the general projection and dark
if do_proj==1
covid_total_mean_master_OAR (radix)
add_ref_scan=0;
if do_ref_scan==1
disp('preparing also the projection for the reference scan')
ref_scan_list=dir([radix '*REF*'])
ref_scan_num=size(ref_scan_list,1);
if ref_scan_num==1
ref_scan_name={ref_scan_list.name};
ref_scan_name=ref_scan_name{1};
disp('I found one corresponding reference scan, I use it for the processing')
elseif ref_scan_num>1
disp('I found more than one reference scan for this series, please investigate')
return
else
disp('There is no available reference scan for this series. Either the name is not correct : radix*REF*, or it does not exists. Please rename the scan if existing, or select another strategy for the references')
return
end
covid_total_mean_master_OAR (ref_scan_name)
add_ref_scan=1;
end
projlist=dir([radix '*/proj_max_SRcur_norm.edf']);
projnum=size(projlist,1);
t=0;
pause(60)
while projnum<dirnum+add_ref_scan
projlist=dir([radix '*/proj_max_SRcur_norm.edf']);
projnum=size(projlist,1);
t=t+1;
fprintf('processing of the scans normalized projections is still running after %3.3i minutes, typical time is lower than 120 minutes, %2.2i files ready on a total of %2.2i \r',t,projnum,dirnum+add_ref_scan)
pause(60)
if t>120
disp('please check if the process is still running, I stop the processing for the moment')
return
end
end
end
%% preparing a new set of references from a reference scan whose name is using the radix
if do_ref_scan>0
ref_scan_list=dir([radix '*REF*'])
ref_scan_num=size(ref_scan_list,1);
if ref_scan_num==1
ref_scan_name={ref_scan_list.name};
ref_scan_name=ref_scan_name{1};
disp('I found one corresponding reference scan, I use it for the processing')
elseif ref_scan_num>1
disp('I found more than one reference scan for this series, please investigate')
return
else
disp('There is no available reference scan for this series. Either the name is not correct : radix*REF*, or it does not exists. Please rename the scan if existing, or select another strategy for the references')
return
end
if do_proj==0
disp('configuration for a scan off axis with partial angular projections from a reference scan')
covid_pipeline_scan_ref_master_OAR(ref_scan_name,new_refon,inscan_med_HF,inscan_med_LF,HF_LF,use_med_scans,use_med_proj,1,1,0)
reflist=dir('refHST/refHST*.edf');
refnum=size(reflist,1);
t=0;
fprintf('checking every minute if the processing is finished or not. in case of no progress, I will stop after 120 minutes without new files \r')
processed_files=refnum;
while refnum<floor(6000/new_refon+1)
pause(60)
reflist=dir('refHST/refHST*.edf');
refnum=size(reflist,1);
t=t+1;
if refnum>processed_files
t=0;
end
fprintf('processing of the references from reference scan is still running after %3.3i minutes, typical time is lower than 120 minutes, %2.2i files ready on a total of %2.2i \r',t,refnum,floor(6000/new_refon+1))
pause(60)
if t>120
disp('nothing happened during the last 120 minutes, please check if the calculation of the references from the ref scan is still running, I stop the processing for the moment')
return
end
end
else
disp ('configuration for a scan on axis with references from a reference scan using a single projection of all the angles')
covid_simple_ref_writing (ref_scan_name,new_refon)
end
covid_scan_local_tomo_ref_update (radix,new_refon)
end
%% preparing a new set of references from a reference scan whose name is using the radix
if do_ref_from_scan>0
if do_ref_from_scan==1
first_dir=1
last_dir=1
else
first_dir=1
last_dir=do_ref_from_scan
end
covid_pipeline_scan_ref_master_OAR(radix,new_refon,inscan_med_HF,inscan_med_LF,HF_LF,use_med_scans,use_med_proj,first_dir,last_dir,0)
reflist=dir('refHST/refHST*.edf');
refnum=size(reflist,1);
t=0;
fprintf('checking every minute if the processing is finished or not. in case of no progress, I will stop after 60 minutes without new files \r')
processed_files=refnum;
while refnum<floor(6000/new_refon+1)
pause(60)
reflist=dir('refHST/refHST*.edf');
refnum=size(reflist,1);
t=t+1;
if refnum>processed_files
t=0;
end
fprintf('processing of the references from reference scan is still running after %3.3i minutes, typical time is lower than 60 minutes, %2.2i files ready on a total of %2.2i \r',t,refnum,floor(6000/new_refon+1))
pause(60)
if t>60
disp('nothing happened during the last 60 minutes, please check if the calculation of the references from the ref scan is still running, I stop the processing for the moment')
return
end
end
covid_scan_local_tomo_ref_update (radix,new_refon)
end
%% starting the process of scans optimization, darkening of optic compensation and pre-correction of the rings
if do_ref_opt
disp ('starting the process of scans optimization, darkening compensation and pre-correction of the rings')
covid_general_ref_optimization (radix,preset)
end
%% preparation of corrected scans with optimization of the half-acquisition parameters
if do_scan_opt
covid_master_half_acquisition_master_OAR (radix,preset)
end
end
%
% cmd=sprintf('du -h PROCESSING/%s*',radix);
% unix(cmd)
%
% cd ('PROCESSING')
%
% fprintf('if everything is OK and all the scans are of the same size, you can start octave to prepare the reconstruction using fastsetup3_PT and ftseries3_PT followed by ftseries3_column_PT \n')
%
% ! octave
%
% fprintf('after the fasttomo/octave, you can start the reconstruction process using covid_tomo_rec_series(radix_without_star,'covid_HR')
%
%
% end