Skip to content

Commit

Permalink
ENH - also support the ICA/PCA mixing and unmixing matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoostenveld committed Apr 25, 2017
1 parent 3ecee68 commit 8f8bc01
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ft_appenddata.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
% check if the input data is valid for this function
for i=1:length(varargin)
% FIXME: raw+comp is not always dealt with correctly
varargin{i} = ft_checkdata(varargin{i}, 'datatype', {'raw+comp', 'raw'}, 'feedback', 'no');
varargin{i} = ft_checkdata(varargin{i}, 'datatype', {'raw', 'raw+comp'}, 'feedback', 'no');
end

% set the defaults
Expand Down
2 changes: 1 addition & 1 deletion ft_appendfreq.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
% check if the input data is valid for this function
for i=1:length(varargin)
% FIXME: what about freq+comp?
varargin{i} = ft_checkdata(varargin{i}, 'datatype', 'freq', 'feedback', 'yes');
varargin{i} = ft_checkdata(varargin{i}, 'datatype', {'freq', 'freq+comp'}, 'feedback', 'yes');
end

% set the defaults
Expand Down
2 changes: 1 addition & 1 deletion ft_appendtimelock.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
% check if the input data is valid for this function
for i=1:length(varargin)
% FIXME: what about timelock+comp?
varargin{i} = ft_checkdata(varargin{i}, 'datatype', 'timelock', 'feedback', 'yes', 'hassampleinfo', 'ifmakessense');
varargin{i} = ft_checkdata(varargin{i}, 'datatype', {'timelock', 'timelock+comp'}, 'feedback', 'yes', 'hassampleinfo', 'ifmakessense');
end

% set the defaults
Expand Down
24 changes: 21 additions & 3 deletions private/append_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,28 @@
hasfreq = isfield(varargin{1}, 'freq');
hastrialinfo = isfield(varargin{1}, 'trialinfo');
hassampleinfo = isfield(varargin{1}, 'sampleinfo');
hastopolabel = isfield(varargin{1}, 'topolabel');
hastopo = isfield(varargin{1}, 'topo');
hasunmixing = isfield(varargin{1}, 'topo');
for i=2:numel(varargin)
hastime = hastime && isfield(varargin{i}, 'time');
hasfreq = hasfreq && isfield(varargin{i}, 'freq');
hastrialinfo = hastrialinfo && isfield(varargin{i}, 'trialinfo');
hassampleinfo = hassampleinfo && isfield(varargin{i}, 'sampleinfo');
hastopolabel = hastopolabel && isfield(varargin{i}, 'topolabel');
hastopo = hastopo && isfield(varargin{i}, 'topo');
hasunmixing = hasunmixing && isfield(varargin{i}, 'unmixing');
end

if (hastopolabel || hastopo || hasunmixing) && ~strcmp(cfg.appenddim, 'chan')
% only proceed if the ICA/PCA mixing and/or unmixing matrix is identical in all datasets
identical = true;
for i=2:numel(varargin)
if hastopolabel, identical = identical && isequal(varargin{1}.topolabel, varargin{i}.topolabel); end
if hastopo, identical = identical && isequal(varargin{1}.topo, varargin{i}.topo); end
if hasunmixing, identical = identical && isequal(varargin{1}.unmixing, varargin{i}.unmixing); end
end
assert(identical, 'cannot append data from different ICA/PCA decompositions');
end

switch cfg.appenddim
Expand Down Expand Up @@ -123,9 +140,10 @@
end

% start with the union of all input data
data = keepfields(varargin{1}, {'label', 'time', 'freq', 'dimord'});
data = keepfields(varargin{1}, {'label', 'time', 'freq', 'dimord', 'topo', 'unmixing', 'topolabel'});

% keep the trialinfo (when identical)
% note that we are NOT keeing the sampleinfo
fn = {'trialinfo'};
for i=1:numel(fn)
keepfield = isfield(varargin{1}, fn{i});
Expand Down Expand Up @@ -195,7 +213,7 @@

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'rpt'

% determine the intersection of all input data
tmpcfg = keepfields(cfg, {'tolerance', 'channel'});
tmpcfg.select = 'intersect';
Expand All @@ -205,7 +223,7 @@
end

% start with the intersection of all input data
data = keepfields(varargin{1}, {'label', 'time', 'freq', 'dimord'});
data = keepfields(varargin{1}, {'label', 'time', 'freq', 'dimord', 'topo', 'unmixing', 'topolabel'});
if numel(cfg.parameter)>0
% this check should not be done if there is no data to append, this happens when called from ft_appenddata
assert(numel(data.label)>0);
Expand Down

0 comments on commit 8f8bc01

Please sign in to comment.