-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathed_plot_annotation_duration_DV.m
More file actions
184 lines (149 loc) · 5.91 KB
/
ed_plot_annotation_duration_DV.m
File metadata and controls
184 lines (149 loc) · 5.91 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
%**************************************************
% Copyright 2013 by Robert Rein & Henning Holle
% gerrobrein@yahoo.com.au
%**************************************************
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%**************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% raterDisparity(anno)
% INPUT:
% anno = hierarchical annotation struct
% OUTPUT:
% None
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ed_plot_annotation_duration(anno)
noFiles = numel(anno.files);
figHeight = max(300,min(noFiles*12+100,800));
figWidth = 600;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Determining size of screen for position of figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
screen_size = get(0,'screensize');
h_root_figure = findobj('tag','EasyDIAg');
if ( isempty(h_root_figure) )
lower_left_x = 300;
lower_left_y = screen_size(4) - figHeight - 100;
else
root_pos = get(h_root_figure(end),'pos');
lower_left_x = root_pos(1) + root_pos(3);
if ( lower_left_x + figWidth > screen_size(3) )
lower_left_x = 300;
end
lower_left_y = root_pos(2);
if ( lower_left_y + figHeight > screen_size(4) )
lower_left_y = screen_size(4) - figHeight - 100;
end
end
h_fig = figure('pos',[lower_left_x lower_left_y figWidth figHeight],...
'numbertitle','off',...
'name','Rater annotation length',...
'menubar','none',...
'resize','off');
h_axes(1) = axes('unit','pixel','pos',[350 50 200 figHeight - 100],...
'ygrid','on');
setappdata(h_fig,'h_axes',h_axes);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Setting up menu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h_file = uimenu(h_fig,'label','File');
uimenu(h_file,'label','Save plot',...
'callback',{@raterAnnotationDuration_saveas,h_fig});
h_unit = uimenu(h_fig,'label','Unit');
noUnits = numel(anno.units);
h_tmp = uimenu(h_unit,'label',anno.units{1},'checked','on',...
'callback',{@raterAnnotationDuration_dispatcher,h_fig},...
'accelerator','1');
for unit = 2:noUnits
uimenu(h_unit,'label',anno.units{unit},...
'callback',{@raterAnnotationDuration_dispatcher,h_fig},...
'accelerator',num2str(unit));
end
setappdata(h_fig,'h_unit',h_unit);
h_label = uicontrol('style','text','pos',[250 figHeight - 30 300 30],...
'string','Unit','fontsize',12,'fontweight','bold','horizontalalignment','center');
setappdata(h_fig,'h_label',h_label);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Date for easy identification of print-outs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text','pos',[200,20,100,20],...
'string',date());
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Processing data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
raterAnnotationDuration_calcData(anno,h_fig);
raterAnnotationDuration_dispatcher(h_tmp,[],h_fig);
end
function raterAnnotationDuration_dispatcher(hObject,evt,h_fig)
h_unit = getappdata(h_fig,'h_unit');
units = get(h_unit,'children');
set(units,'checked','off');
set(hObject,'checked','on');
iunit = find(units(end:-1:1) == hObject);
h_label = getappdata(h_fig,'h_label');
set(h_label,'string',get(hObject,'label'));
raterAnnotationDuration_plot(h_fig,iunit);
end
function raterAnnotationDuration_calcData(anno,h_fig)
% cellstring with file names
% .data = [start end type, tier, filename, rater]
no_units = numel(anno.units);
no_files = numel(anno.files);
res.fname = anno.files;
res.mats = NaN(no_files,2,no_units);
res.units = anno.units;
duration = (anno.data(:,2) - anno.data(:,1))/1000;
for f = 1:no_files
for u = 1:no_units
idx = anno.data(:,3) == u & ...
anno.data(:,5) == f & ...
anno.data(:,6) == 1;
res.mats(f,1,u) = sum(duration(idx));
idx = anno.data(:,3) == u & ...
anno.data(:,5) == f & ...
anno.data(:,6) == 2;
res.mats(f,2,u) = sum(duration(idx));
end
end
setappdata(h_fig,'data',res);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function raterAnnotationDuration_plot(h_fig,unit)
data = getappdata(h_fig,'data');
if ( isempty(data) )
fprintf('Error couldn''t find data\n');
return
end
h_axes = getappdata(h_fig,'h_axes');
noFiles = numel(data.fname);
iid = (noFiles:-1:1)';
cla(h_axes);
set(h_fig,'currentaxes',h_axes);
barh(squeeze(data.mats(iid,:,unit)));
set(h_axes,'ytick',1:noFiles,'yticklabel',data.fname(iid),'ylim',[0 noFiles+1],'ygrid','on')
xlabel('Total duration of all annotations in seconds');
ylabel('Filename');
legend('Pri','Rel');
end
function raterAnnotationDuration_saveas(hObject,evt,h_fig)
[file,path] = uiputfile({'*.pdf';'*.png';'*.tif';'*.eps';'*.emf'},'Save figure as');
if ( file )
set(h_fig,'paperpositionmode','auto');
saveas(h_fig,[path,file]);
set(h_fig,'paperpositionmode','manual');
end
end