-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_example_data_fn.m
65 lines (53 loc) · 2.35 KB
/
test_example_data_fn.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
function test_example_data_fn(rec_date, channel, mt_file_paths, lfp_inds)
% Check whether the segments found by
% plot_example_data_from_classes are actually from the intended classes.
Fs = 1000;
[~, input_s_all] = gather_exp_info;
this_input_s = input_s_all(strcmp(rec_date, {input_s_all.name}));
nmf_mfile = matfile(this_input_s.nmf_res_out);
bChan = strcmp(channel, nmf_mfile.chan_names);
classes_all = nmf_mfile.nmf_classes;
classes_all = classes_all{1};
chan_classes = classes_all{bChan};
% construct a vector of selected class inds
n_files = length(this_input_s.mt_res_in);
taken_class = cell(n_files, 1);
seg_startsamples = cell(n_files, 1);
seg_endsamples = cell(n_files, 1);
for kF = 1:n_files
mt_mfile = matfile(this_input_s.mt_res_in{kF});
opts = mt_mfile.options;
step_samps = opts.winstep * Fs;
seg_samples = mt_mfile.seg_samples;
seg_startsamples{kF} = cellfun(@(segsamps) segsamps(1), seg_samples);
seg_endsamples{kF} = cellfun(@(segsamps) segsamps(end), seg_samples);
seg_nwindows = cellfun('length', mt_mfile.seg_windows);
% seg_cum_nwindows{kF} = cumsum(seg_nwindows);
taken_class{kF} = arrayfun(@(nsamp) zeros(nsamp, 1), seg_nwindows(:), 'uni', false);
end
[n_samples, n_classes] = size(mt_file_paths);
for kK = 1:n_classes
for kS = 1:n_samples
bfile = strcmp(mt_file_paths{kS, kK}, this_input_s.mt_res_in);
start_samp = lfp_inds(1, kS, kK);
end_samp = lfp_inds(2, kS, kK);
% locate the windows
kseg = find(start_samp >= seg_startsamples{bfile}, 1, 'last');
assert(find(end_samp <= seg_endsamples{bfile}, 1) == kseg, ...
'Hmm, sample crosses segment boundary');
kwin_first = floor((start_samp - seg_startsamples{bfile}(kseg)) / step_samps);
kwin_last = floor((seg_endsamples{bfile}(kseg) - end_samp) / step_samps);
taken_class{bfile}{kseg}(1+kwin_first:end-kwin_last) = kK;
end
end
% concatenate, then compare to saved classes
taken_classes_perseg = vertcat(taken_class{:});
taken_classes_all = vertcat(taken_classes_perseg{:});
assert(length(taken_classes_all) == length(chan_classes), 'Hmm, class vectors are of different lengths');
btaken = taken_classes_all ~= 0;
if all(taken_classes_all(btaken) == chan_classes(btaken))
disp('All good, the classes match');
else
error('Class mismatch - investigate.');
end
end