Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion ft_sourceanalysis.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@
assert(numel(cfg.supchan)>0, 'cfg.supchan is not present in the data');
end

% also do some checks which are conditional on the presence of spatial filters or precomputed leadfields
if isfield(cfg.sourcemodel, 'leadfield') && isempty(cfg.refdip) && isempty(cfg.supdip)
cfg = ft_checkconfig(cfg, 'unused', {'reducerank' 'backproject' 'normalize' 'normalizeparam' 'weight'});
end
if isfield(cfg.sourcemodel, 'filter') && isempty(cfg.refdip) && isempty(cfg.supdip)
% these are options for forward computation
cfg = ft_checkconfig(cfg, 'unused', {'reducerank' 'backproject' 'normalize' 'normalizeparam' 'weight'});

% these are options for inverse computation
cfg.(cfg.method) = ft_checkconfig(cfg.(cfg.method), 'unused', {'lambda' 'kappa' 'tol' 'invmethod' 'fixedori' 'weightnorm' 'subspace'});
end

% spectrally decomposed data can have label and/or labelcmb
if ~isfield(data, 'label') && isfield(data, 'labelcmb')
% the code further down assumes that data.label is present
Expand Down Expand Up @@ -477,6 +489,10 @@
end
sourcemodel = ft_prepare_leadfield(tmpcfg);

% these need to be removed from the cfg, otherwise the low-level inverse
% function may throw an error, see https://github.com/fieldtrip/fieldtrip/pull/2468
cfg = ft_checkconfig(cfg, 'unused', {'reducerank' 'backproject' 'normalize' 'normalizeparam' 'weight'});

% no further forward computations are needed, but keep them in the cfg
needheadmodel = false;
headmodel = [];
Expand Down Expand Up @@ -1122,10 +1138,13 @@
for i=1:Nrepetitions
fprintf('estimating current density distribution for repetition %d\n', i);
squeeze_avg = reshape(avg(i,:,:),[size_avg(2) size_avg(3)]);
if hascovariance
if hascovariance && ~isfield(sourcemodel, 'filter')
squeeze_Cy = reshape(Cy(i,:,:), [size_Cy(2) size_Cy(3)]);
dip(i) = ft_inverse_mne(sourcemodel, sens, headmodel, squeeze_avg, methodopt{:}, leadfieldopt{:}, 'noisecov', squeeze_Cy);
else
if isfield(sourcemodel, 'filter') && hascovariance
ft_warning('spatial filter has been provided, not using the noise covariance matrix for the computations');
end
dip(i) = ft_inverse_mne(sourcemodel, sens, headmodel, squeeze_avg, methodopt{:}, leadfieldopt{:});
end
end
Expand Down
2 changes: 1 addition & 1 deletion inverse/ft_inverse_dics.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
assert(all(cellfun(@isempty, invopt(4:2:end))) && invopt{2}==0, 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
Expand Down
2 changes: 1 addition & 1 deletion inverse/ft_inverse_lcmv.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
assert(all(cellfun(@isempty, invopt(4:2:end))) && invopt{2}==0, 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
Expand Down
2 changes: 1 addition & 1 deletion inverse/ft_inverse_pcc.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
assert(all(cellfun(@isempty, invopt(4:2:end))) && invopt{2}==0, 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
Expand Down
14 changes: 7 additions & 7 deletions inverse/ft_inverse_sam.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
invopt = ft_setopt(invopt, 'tolerance', ft_getopt(varargin, 'tol'));
invopt = ft_setopt(invopt, 'method', ft_getopt(varargin, 'invmethod'));

% construct the low-level options for the leadfield computation as key-value pairs, these are passed to FT_COMPUTE_LEADFIELD
leadfieldopt = {};
leadfieldopt = ft_setopt(leadfieldopt, 'normalize', ft_getopt(varargin, 'normalize'));
leadfieldopt = ft_setopt(leadfieldopt, 'normalizeparam', ft_getopt(varargin, 'normalizeparam'));
leadfieldopt = ft_setopt(leadfieldopt, 'weight', ft_getopt(varargin, 'weight'));

% backwards compatibility information
if ~isempty(fixedori)
switch fixedori
Expand Down Expand Up @@ -111,7 +117,7 @@
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
assert(all(cellfun(@isempty, invopt(4:2:end))) && invopt{2}==0, 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(sourcemodel.inside);
elseif hasleadfield
Expand All @@ -133,12 +139,6 @@
else
ft_info('computing forward model on the fly\n');

% construct the low-level options for the leadfield computation as key-value pairs, these are passed to FT_COMPUTE_LEADFIELD
leadfieldopt = {};
leadfieldopt = ft_setopt(leadfieldopt, 'normalize', ft_getopt(varargin, 'normalize'));
leadfieldopt = ft_setopt(leadfieldopt, 'normalizeparam', ft_getopt(varargin, 'normalizeparam'));
leadfieldopt = ft_setopt(leadfieldopt, 'weight', ft_getopt(varargin, 'weight'));

% check if a tangential orientation estimation is performed, i.e. if only orientations in the tangential plane are considered.
% if this is the case, we perform the lead field rank reduction directly in this script, since otherwise we would not
% have access to the tangential plane defined by the full leadfield
Expand Down
Loading