-
Notifications
You must be signed in to change notification settings - Fork 7
/
bf_inverse.m
83 lines (64 loc) · 2.1 KB
/
bf_inverse.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
function out = bf_inverse
% Computes inverse projectors
% Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
% $Id$
% dir Directory
% ---------------------------------------------------------------------
BF = cfg_files;
BF.tag = 'BF';
BF.name = 'BF.mat file';
BF.filter = '^BF.mat$';
BF.num = [1 1];
BF.help = {'Select BF.mat file.'};
%--------------------------------------------------------------------------
% method
%--------------------------------------------------------------------------
plugin = cfg_choice;
plugin.tag = 'plugin';
plugin.name = 'Inverse method';
inverse_funs = spm_select('List', fileparts(mfilename('fullpath')), '^bf_inverse_.*\.m$');
inverse_funs = cellstr(inverse_funs );
for i = 1:numel(inverse_funs)
plugin.values{i} = feval(spm_file(inverse_funs{i},'basename'));
end
out = cfg_exbranch;
out.tag = 'inverse';
out.name = 'Inverse solution';
out.val = {BF, plugin};
out.help = {'Compute inverse projectors'};
out.prog = @bf_inverse_run;
out.vout = @bf_inverse_vout;
out.modality = {'EEG'};
end
function out = bf_inverse_run(job)
outdir = spm_file(job.BF{1}, 'fpath');
cd(outdir);
BF = bf_load('BF.mat', {'data', 'sources', 'features'});
plugin_name = cell2mat(fieldnames(job.plugin));
S = job.plugin.(plugin_name);
if ~isa(S, 'struct')
S = [];
end
modalities = intersect(fieldnames(BF.features), {'MEG', 'MEGPLANAR', 'MEGMAG', 'EEG'});
for m = 1:numel(modalities)
S(1).modality = modalities{m};
[S.L, channels] = bf_fuse_lf(BF, S.modality);
BF.inverse.(modalities{m}) = feval(['bf_inverse_' plugin_name], BF, S);
BF.inverse.(modalities{m}).channels = channels;
if ~isfield(BF.inverse.(modalities{m}), 'L')
BF.inverse.(modalities{m}).L = S.L;
end
end
bf_save(BF);
out.BF{1} = fullfile(outdir, 'BF.mat');
end
function dep = bf_inverse_vout(job)
% Output is always in field "D", no matter how job is structured
dep = cfg_dep;
dep.sname = 'BF.mat file';
% reference field "B" from output
dep.src_output = substruct('.','BF');
% this can be entered into any evaluated input
dep.tgt_spec = cfg_findspec({{'filter','mat'}});
end