forked from asalmon91/ARFS-2-Batch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARFS2Batch_v1_3_3.m
134 lines (102 loc) · 3.89 KB
/
ARFS2Batch_v1_3_3.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
%% Applies the parameters in a .dmb to a user defined s+election of videos
restoredefaultpath; clear all; close all; clc; %#ok<*CLSCR>
if ~isempty(strfind(version, '2014a')) % TODO, check for other versions than 2014a
error('Please use Matlab 2014b or later');
end
%% Get fx's
addpath(fullfile(pwd,'fx'));
%% Display Instructions (todo)
%% Get .dmbs
[dmb, term] = getDmbs(pwd);
if term
clear all;
return;
end
%% Initialize master waitbar
wb = waitbar(0,'Analyzing AOSLO image sequences');
set(wb,'Resize','on');
%% Save dmb as a .mat and the stdout/stderr as a txt file for troubleshooting/debugging.
timestamp = strjoin(strread(num2str(fix(clock)),'%s')','_'); %#ok<*DSTRRD>
dmbdata_fname = [timestamp,'_dmbdata.mat'];
outerr_fname = [timestamp,'_stdout.txt'];
outerr_fid = fopen(fullfile(dmb(1).path,outerr_fname),'wt');
if outerr_fid == -1
fprintf('Unable to create %s for error documentation.\n',outerr_fname);
end
%% Log path in outerr
for i=1:numel(dmb)
fprintf(outerr_fid, '%s\n', dmb(i).path);
end
%% Get FOVs
[fov_lut, dmb] = getFOV(dmb, outerr_fid, wb);
%% Get .avi's
[dmb, term] = getAvis(dmb);
if term
clear all;
return;
end
%% Get ARFS parameters
[dmb, term] = getArfsParams(dmb);
if term
clear all;
return;
end
%% Get confirmation before running ARFS (todo)
%% Get the total number of videos to be processed
nVidsTotal = 0;
for i=1:numel(dmb)
nVidsTotal = nVidsTotal + numel(dmb(i).avis);
end
%% Determine desinusoid file properties
desinusoid_lut = getDesinusoids(dmb, wb);
%% Run ARFS and make .dmb's
n=0;
try
for i=1:numel(dmb)
for j=1:numel(dmb(i).avis)
% shortcuts
vidpath = dmb(1).aviPath;
vidname = dmb(i).avis{j};
vidnum = dmb(i).vidnums{j};
arfsParameters = dmb(i).pack;
arfsParameters.fname = vidname;
% Update waitbar and outerr
n=n+1;
set(wb, 'name', sprintf('%s (%i/%i)',vidname,n,nVidsTotal));
waitbar(n/nVidsTotal, wb, strrep(sprintf('Working on %s...',vidname),'_','\_'));
%% Read and Desinusoid video
% check if vidnum in fov_lut
if ~any(strcmp(fov_lut(:,1),vidnum))
fprintf('\nNo .mat file associated with %s\n\n',vidname);
fprintf(outerr_fid,'\nNo .mat file associated with %s\n\n',vidname);
continue;
end
fov = fov_lut{strcmp(fov_lut(:,1),vidnum),2};
des_matrix = desinusoid_lut{cellfun(@(x) x == fov, desinusoid_lut(:,1)), 3};
% Read video
images = readAndDesinusoid(vidpath, vidname, des_matrix, wb);
if isa(images,'MException')
recordErr(images,outerr_fid);
continue; % Who knows, maybe the next video will go better.
end
%% Run ARFS
dmb(i).arfs(j).data = arfsFx(images, arfsParameters, wb);
if isa(dmb(i).arfs(j).data,'MException')
recordErr(dmb(i).arfs(j).data,outerr_fid);
continue;
end
% Make .dmb's
dmb(i).arfs(j).rfList = makeDmbs(dmb(i), dmb(i).arfs(j).data);
% Save progress
save(fullfile(dmb(1).path,dmbdata_fname),'dmb');
end
end
close(wb);
fclose(outerr_fid);
catch MException
recordErr(MException,outerr_fid);
close(wb);
fclose(outerr_fid);
end
fprintf(['\nDone! If any unexpected errors occurred,\nfeel free to email these files to asalmon@mcw.edu:',...
'\n\nerror log: %s\nyour parameters and data: %s\npath: %s\n'],outerr_fname,dmbdata_fname,dmb(1).path);