-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyResults.m
104 lines (98 loc) · 3.11 KB
/
copyResults.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
function copyResults(folder, varargin)
if nargin < 1 || exist(folder, 'dir')~=7
[folder] = uigetdir('', 'Select the folder that contains the experiment');
if folder == 0
return;
end
end
p = inputParser;
p.addParameter('Config', fullfile(folder,'config.mat'), @ischar);
p.addParameter('TargetResultField', 'RectPos', @ischar);
p.addParameter('DeleteResultField', '', @ischar);
p.addParameter('AddResultFields', {}, @iscellstr);
p.addParameter('AddResultFieldValues', struct(), @isstruct);
p.parse(varargin{:});
%define and clear the logfile
log = fullfile(folder, 'AutoTipTrack_log.txt');
warning off MATLAB:DELETE:FileNotFound
delete(log);
warning on MATLAB:DELETE:FileNotFound
if exist(p.Results.Config, 'file') ~= 2
%try to read experiment default config
config_file = fullfile(folder,'config.mat');
if exist(config_file, 'file') ~= 2
%create a config file if none exists
fConfigGui('Create', folder);
end
else
config_file = p.Results.Config;
end
if ~isdeployed
addpath('assets')
end
if strendswith(folder, filesep)
folder = folder(1:end - 1);
end
%create an empty GUI handle
hEvalGui = EvalGui;
%create the root node here
rootNode = hEvalGui.createNode(folder, true);
%recursively scan the directory structure for stacks and add them to the
%queue
queue = enqueueManyExperiments(rootNode, config_file, hEvalGui);
%start the timer that watches the progress
hEvalGui.addTree(rootNode);
hEvalGui.expandAllNodes;
drawnow;
timer = hEvalGui.watchProgress;
hEvalGui.Log = log;
numFiles = length(queue);
%load one image from each stack for the figures
for n = 1:numFiles
try
trackStatus(queue(n).StatusFolder, 'Loading old data', '', 0, 1, 1);
queue(n).reloadResults('Results', p.Results.TargetResultField);
if ~isfield(queue(n).Results, p.Results.TargetResultField)
queue(n).abort('Did not find suitable results');
break
end
OldResults = queue(n).Results;
if ~isempty(p.Results.DeleteResultField) && isfield(OldResults, p.Results.DeleteResultField)
OldResults = rmfield(OldResults, p.Results.DeleteResultField);
end
if ~isempty(p.Results.AddResultFields)
for k = 1:length(p.Results.AddResultFields)
OldResults.(p.Results.AddResultFields{k}) = p.Results.AddResultFieldValues.(p.Results.AddResultFields{k});
end
end
trackStatus(queue(n).StatusFolder, 'Loading old data', '', 1, 1, 1);
trackStatus(queue(n).StatusFolder, 'Copying results', '', 0, 1, 1);
queue(n).reloadResults;
queue(n).Results = OldResults;
queue(n).saveFiestaCompatibleFile;
trackStatus(queue(n).StatusFolder, 'Copying results', '', 1, 1, 1);
queue(n).deleteDuplicateResults;
trackStatus(queue(n).StatusFolder, 'All done', '', 1, 1, 1);
queue(n).finish;
catch ME
queue(n).abort(sprintf('%s | see %s for more details.', ME.message, log));
appendLog(log, ME.getReport('extended', 'hyperlinks', 'off'));
end
end
uiwait(hEvalGui.fig);
hEvalGui.close;
%clean up
if ~isdeployed
rmpath('assets')
end
allMsg=[queue.Message];
queue.delete;
%make sure the timer is stopped
try
stop(timer);
delete(timer);
catch
end
if ~isempty(allMsg)
warning(allMsg);
end