Skip to content

Commit

Permalink
SPM8 r5236
Browse files Browse the repository at this point in the history
  • Loading branch information
SPMcentral committed Feb 4, 2013
1 parent 46909bf commit 1de68e0
Show file tree
Hide file tree
Showing 1,518 changed files with 66,390 additions and 36,491 deletions.
14 changes: 7 additions & 7 deletions @gifti/private/isintent.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: isintent.m 4382 2011-07-06 14:59:41Z guillaume $
% $Id: isintent.m 4717 2012-04-19 11:02:50Z guillaume $

a = [];
b = [];
Expand Down Expand Up @@ -51,12 +51,12 @@
fprintf('Intent %s is ignored.\n',this.data{i}.attributes.Intent);
end
end
[d,i] = unique(a);
if length(d) < length(a)
warning('Several fields match intent type. Using first.');
a = a(i);
b = b(i);
end
%[d,i] = unique(a);
%if length(d) < length(a)
% warning('Several fields match intent type. Using first.');
% a = a(i);
% b = b(i);
%end

function c = cdata

Expand Down
3 changes: 2 additions & 1 deletion @gifti/struct.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: struct.m 2076 2008-09-10 12:34:08Z guillaume $
% $Id: struct.m 4717 2012-04-19 11:02:50Z guillaume $

names = fieldnames(this);
names = unique(names);
values = cell(length(names), length(this(:)));

for i=1:length(names)
Expand Down
42 changes: 42 additions & 0 deletions @meeg/badtrials.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function res = badtrials(this, varargin)
% Method for getting/setting bad trials
% FORMAT res = badtrials(this)
% _______________________________________________________________________
% Copyright (C) 2011-2012 Wellcome Trust Centre for Neuroimaging

% Christophe Phillips
% $Id: badtrials.m 5059 2012-11-15 13:48:35Z vladimir $


if length(varargin) == 2 && ~isempty(varargin{1})
% make sure that the two inputs for set are the same length
if ~(length(varargin{2}) == 1 || (length(varargin{1}) == length(varargin{2})))
error('Use either same vector length or scalar for value');
end
end

if numel(varargin) >= 1 && ~isempty(varargin{1})
if ~(all(varargin{1} >= 1) && all(varargin{1} <= ntrials(this)))
error('Trial number out of range.');
end
end

if numel(varargin) >= 2
ubad = unique(varargin{2});
if isempty(ubad) || ~all(ismember(ubad, [0 1]))
error('Illegal bad flags (should be 0 or 1)');
end
end

res = getset(this, 'trials', 'bad', varargin{:});


% Return trial indices if called without arguments and [0, 1] if called
if numel(varargin) <= 1 % get
if iscell(res)
res = [res{:}];
end
if isempty(varargin)
res = find(res);
end
end
4 changes: 2 additions & 2 deletions @meeg/clone.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Stefan Kiebel, Vladimir Litvak
% $Id: clone.m 4207 2011-02-22 10:48:36Z christophe $
% $Id: clone.m 4781 2012-07-10 15:59:45Z vladimir $

if nargin < 4
reset = 0;
end

if nargin < 3
if ~strcmp(transformtype(this), 'TF')
if ~strncmpi(transformtype(this), 'TF', 2)
dim = [nchannels(this), nsamples(this), ntrials(this)];
else
dim = [nchannels(this), nfrequencies(this), nsamples(this), ntrials(this)];
Expand Down
113 changes: 58 additions & 55 deletions @meeg/ftraw.m
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
function raw = ftraw(this, memmap)
function raw = ftraw(this, chanind, timeind, trialind)
% Method for converting meeg object to Fieldtrip raw struct
% FORMAT raw = ftraw(this, memmap)
% memmap - 1 (default) memory map the data with file_array
% 0 load the data into memory
% FORMAT raw = ftraw(this, chanind, timeind, trialind)
% _______________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging

% Vladimir Litvak
% $Id: ftraw.m 1742 2008-05-28 11:58:04Z vladimir $
% $Id: ftraw.m 5063 2012-11-16 12:10:41Z vladimir $

if nargin < 2
memmap = 1;
if ~isequal(transformtype(this), 'time')
raw = fttimelock(this, chanind, timeind, trialind);
return;
end

nchans = nchannels(this);
ntime = nsamples(this);
ntrl = ntrials(this);
% chanind == 0 is accepted for backward compatibility
if nargin < 2 || isempty(chanind) || chanind == 0
chanind = 1:nchannels(this);
end

if nargin < 3 || isempty(timeind)
timeind = 1:nsamples(this);
end

if nargin < 4 || isempty(trialind)
trialind = 1:ntrials(this);
end

raw = [];
raw.fsample = fsample(this);
raw.label = chanlabels(this)';

wsize=wordsize(this.data.datatype);

for i=1:ntrl
if memmap
offset = (i-1)*nchans*ntime*wsize;
trialdim = [nchans ntime];
raw.trial{i} = file_array(fullfile(this.path, this.data.fnamedat),trialdim,this.data.datatype,offset,1,0,'ro');
else
raw.trial{i} = this.data.y(:, :, i);
end

raw.label = chanlabels(this, chanind)';

raw.trial = cell(1, length(trialind));

for i = 1:length(trialind)
raw.trial{i} = this.data.y(chanind, timeind, trialind(i));
end

raw.time = repmat({time(this, timeind)}, 1, length(trialind));

clist = condlist(this);

condlabels = conditions(this, trialind);

raw.trialinfo = 0*trialind;
for k = 1:numel(clist)
fprintf('mapping condition label "%s" to condition code %d\n', clist{k}, k);
sel = strcmp(clist{k}, condlabels);
raw.trialinfo(sel) = k;
end

if ~isempty(sensors(this, 'MEG'))
raw.grad = sensors(this, 'MEG');
end

if ~isempty(sensors(this, 'EEG'))
raw.elec = sensors(this, 'EEG');
end

if isfield(this.other, 'origheader')
raw.hdr = this.other.origheader;
end

onsets = trialonset(this, trialind);

if all(onsets>0)
onsets = round(onsets(:)*fsample(this));
raw.sampleinfo = [onsets+timeind(1) onsets+timeind(end)]-1;
end

raw.time = repmat({time(this)}, 1, ntrl);

function s = wordsize(datatype)

datatype = strtok(datatype, '-');

switch datatype
case 'int8'
s = 1;
case 'int16'
s = 2;
case 'int32'
s = 4;
case 'uint8'
s = 1;
case 'uint16'
s = 2;
case 'uint32'
s = 4;
case 'float'
s = 4;
case 'double'
s = 8;
case 'float32'
s = 4;
case 'float64'
s = 8;
otherwise
error('unrecognized datatype');
% FIXME, add support for le and be versions
end
99 changes: 84 additions & 15 deletions @meeg/fttimelock.m
Original file line number Diff line number Diff line change
@@ -1,26 +1,95 @@
function timelock = fttimelock(this)
function timelock = fttimelock(this, chanind, timeind, trialind, freqind)
% Method for converting meeg object to Fieldtrip timelock/freq struct
% FORMAT timelock = fttimelock(this)
% FORMAT timelock = fttimelock(this, chanind, timeind, trialind, freqind)
%
% The method support both time and TF data and outputs different variants
% of timelock or freq FT struct depending on the dataset type and requested
% data dimensions.
% _______________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging

% Vladimir Litvak
% $Id: fttimelock.m 3210 2009-06-17 13:46:25Z vladimir $
% $Id: fttimelock.m 5063 2012-11-16 12:10:41Z vladimir $

if nargin < 2 || isempty(chanind)
chanind = 1:nchannels(this);
end

if nargin < 3 || isempty(timeind)
timeind = 1:nsamples(this);
end

if nargin < 4 || isempty(trialind)
trialind = 1:ntrials(this);
end

if strncmpi(transformtype(this),'TF',2) && ...
(nargin < 5 || isempty(freqind))
freqind = 1:nfrequencies(this);
end

timelock = [];
timelock.label = chanlabels(this);
timelock.label = timelock.label(:);
timelock.label = chanlabels(this, chanind)';

if isequal(transformtype(this), 'time')
timelock.dimord = 'rpt_chan_time';
timelock.fsample = fsample(this);
timelock.trial = permute(this.data.y(:, :, :), [3 1 2]);
timelock.dimord = 'rpt_chan_time';
if isequal(type(this), 'continuous')
error('For continuous data use ftraw method');
end

if isequal(type(this), 'single') || length(trialind)>1
timelock.dimord = 'rpt_chan_time';
timelock.trial = permute(this.data.y(chanind, timeind, trialind), [3 1 2]);
else
timelock.dimord = 'chan_time';
timelock.avg = spm_squeeze(this.data.y(chanind, timeind, trialind), 3);
end

timelock.time = time(this, timeind);

elseif strncmpi(transformtype(this),'TF',2)
timelock.dimord = 'rpt_chan_freq_time';
timelock.powspctrm = permute(this.data.y(:, :, :, :), [4 1 2 3]);
timelock.freq = frequencies(this);
if length(timeind)>1
if isequal(type(this), 'single') || length(trialind)>1
timelock.dimord = 'rpt_chan_freq_time';
timelock.powspctrm = permute(this.data.y(chanind, freqind, timeind, trialind), [4 1 2 3]);
else
timelock.dimord = 'chan_freq_time';
timelock.powspctrm = spm_squeeze(this.data.y(chanind, freqind, timeind, trialind), 3);
end

timelock.time = time(this, timeind);
else
if isequal(type(this), 'single') || length(trialind)>1
timelock.dimord = 'rpt_chan_freq';
timelock.powspctrm = spm_squeeze(permute(this.data.y(chanind, freqind, timeind, trialind), [4 1 2 3]), 4);
else
timelock.dimord = 'chan_freq';
timelock.powspctrm = spm_squeeze(this.data.y(chanind, freqind, timeind, trialind), [3 4]);
end
end

timelock.freq = frequencies(this, freqind);
else
error('Unknown transform type.');
error('Unknown transform type.');
end

if length(trialind)>1

clist = condlist(this);
condlabels = conditions(this, trialind);
timelock.trialinfo = 0*trialind;

for k = 1:numel(clist)
fprintf('mapping condition label "%s" to condition code %d\n', clist{k}, k);
sel = strcmp(clist{k}, condlabels);
timelock.trialinfo(sel) = k;
end

end

timelock.time = time(this);
if ~isempty(sensors(this, 'MEG'))
timelock.grad = sensors(this, 'MEG');
end

if ~isempty(sensors(this, 'EEG'))
timelock.elec = sensors(this, 'EEG');
end
Loading

0 comments on commit 1de68e0

Please sign in to comment.