Back to the main page.
Bug 3214 - ft_selectdata fails to select trials from freq due to unsupported cumtapcnt
Status | CLOSED FIXED |
Reported | 2016-11-30 15:16:00 +0100 |
Modified | 2017-01-17 11:29:47 +0100 |
Product: | FieldTrip |
Component: | preproc |
Version: | unspecified |
Hardware: | PC |
Operating System: | Windows |
Importance: | P5 minor |
Assigned to: | Robert Oostenveld |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
Tobias - 2016-11-30 15:16:37 +0100
ft_selectdata, used on output from ft_freqanalysis: ****************************** Error using ft_selectdata>getselection_rpt (line 1135) FIXME this is not yet implemented for mtmconvol with keeptrials and varying number of tapers per frequency Error in ft_selectdata (line 302) [selrpt{i}, dum, rptdim{i}, selrpttap{i}] = getselection_rpt(cfg, varargin{i}, dimord{j}); ****************************** Error occurs although 1 Hanning taper was used for freqanalysis. Error occurs only, if number of trials == number of frequencies. if number of trials == number of frequencies in ft_selectdata, line 1130: dimtok = 'rpttap' 'chan' 'freq' 'time' if number of trials ~= number of frequencies in ft_selectdata, line 1130: dimtok = 'rpt' 'chan' 'freq' 'time' %%% code used in fieldtrip@dccn: cfg = []; cfg.output = 'fourier'; cfg.channel = 'MEG'; cfg.method = 'mtmconvol'; cfg.taper = 'hanning'; cfg.keeptrials = 'yes' cfg.foi = 0:2:40; %%20 freqs! cfg.t_ftimwin = ones(length(cfg.foi),1).*.5; cfg.toi = 0:0.05:2; tfr = ft_freqanalysis(cfg, data); %%data has 20 trials! cfg=[]; cfg.trials = 1:5; tfr_sel=ft_selectdata(cfg,tfr);
Robert Oostenveld - 2016-12-01 15:18:52 +0100
This reproduces it %% try to simulate some data data = []; data.label = {'1', '2', '3'}; for i=1:20 data.trial{i} = randn(3,2000); data.time{i} = (1:2000)/1000; end %% this is what was done according to the bug report cfg = []; cfg.output = 'fourier'; cfg.channel = 'all'; cfg.method = 'mtmconvol'; cfg.taper = 'hanning'; cfg.keeptrials = 'yes'; cfg.foi = 0:2:40; %% 20 freqs! cfg.t_ftimwin = ones(length(cfg.foi),1).*.5; cfg.toi = 0:0.05:2; tfr = ft_freqanalysis(cfg, data); %% data has 20 trials! %% and here is the bug cfg = []; cfg.trials = 1:5; tfr_sel = ft_selectdata(cfg,tfr);
Robert Oostenveld - 2016-12-01 15:19:47 +0100
The error is due to cumtapcnt being a ones(20,20) matrix, whereas it should have been a ones(20,1) vector. tfr = struct with fields: label: {'1' '2' '3'} dimord: 'rpttap_chan_freq_time' freq: [2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40] time: [1×41 double] fourierspctrm: [20×3×20×41 double] cumtapcnt: [20×20 double] cfg: [1×1 struct]
Robert Oostenveld - 2016-12-01 15:23:48 +0100
(In reply to Robert Oostenveld from comment #2) sorry, my previous comment is incorrect. It should be a ntrials * nfoi matrix. In this case it happens to be 20*20, but the error also persists with a different number of trials (or frequencies), i.e. when not equal.
Robert Oostenveld - 2016-12-01 15:27:58 +0100
(In reply to Robert Oostenveld from comment #3) ... I should be more careful before typing. The problem only happens when nfreq==ntrial. I will not type anything more until I figured out what is really the problem.
Robert Oostenveld - 2016-12-01 15:59:28 +0100
(In reply to Robert Oostenveld from comment #4) ok, I figured it out and fixed it. mac011> git push upstream master Counting objects: 17, done. Delta compression using up to 4 threads. Compressing objects: 100% (17/17), done. Writing objects: 100% (17/17), 2.90 KiB | 0 bytes/s, done. Total 17 (delta 12), reused 0 (delta 0) remote: Resolving deltas: 100% (12/12), completed with 7 local objects. To github.com:fieldtrip/fieldtrip.git 9df289a..cf9f395 master -> master this involves the following smaller changes. commit cf9f3955b0b777829f7f8ed5ab018bd22c159020 added test script, see http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3214 commit 670506dd83c2701ba25c6353fd549cdde4f63a2f improve the dimord detection for cumtapcnt and cumsumcnt, see http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3214 commit e7075a18ed1313f2618cf708c902d3cf0fb0527e FIX - always pass the data through ft_checkdata, don't assume the length ot be the number of trials, but explicitly take cumtapcnt as ntrl*nfreq or ntrl*1. See http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3214 commit 607cb9221c9cfa001e0c4b3b42e5b97a3ab53f9d ensure that cumtapcnt and cumsumcnt are column vectors, consistent with the implementation in freqanalysis
Robert Oostenveld - 2016-12-01 16:09:33 +0100
I hope it now works.