Back to the main page.

Bug 2440 - ft_singleplotTFR fails when plotting anything other than 'powspctrm'

Status CLOSED FIXED
Reported 2014-01-17 14:36:00 +0100
Modified 2015-07-15 13:30:49 +0200
Product: FieldTrip
Component: plotting
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to: Jim Herring
URL:
Tags:
Depends on:
Blocks:
See also:

- 2014-01-17 14:36:59 +0100

Hey guys, I have some data with dimord 'rpt_chan_freq_time' (result of freqanalysis with keeptrials='yes') and I'm trying to plot single trials from this structure. I log-transformed the power spectrum for visualisation. data.logspctrm=log10(data.powspctrm); Now if I try to plot a single trial, plotting the power spectrum works. cfg=[]; cfg.parameter='powspctrm'; (also works if nothing is specified here) cfg.trials=1; ft_singleplotTFR(cfg,data); <- this plots however if I switch cfg.parameter to 'logspctrm' I get the following error: ??? Reference to non-existent field 'time'. Error in ==> dimlength at 201 n = length(data.time); Error in ==> dimlength at 46 n{k}(i) = dimlength(data, dimtok{i}, fn{k}); Error in ==> seloverdim at 39 [reduceddim, fntmp] = dimlength(data); Error in ==> ft_selectdata_old at 599 if selectrpt, data = seloverdim(data, 'rpt', selrpt, fb); end Error in ==> ft_selectdata at 45 [varargout{1:nargout}] = ft_selectdata_old(varargin{:}); Error in ==> ft_freqdescriptives at 121 if hasrpt, if ~strcmp(cfg.trials, 'all'), freq = ft_selectdata(freq, 'rpt', cfg.trials); end; end Error in ==> ft_singleplotTFR at 181 tempdata = ft_freqdescriptives(tmpcfg, tempdata); data.logspctrm has the same dimensions as data.powspctrm so I don't know what's wrong. Help! Best, Tom


Jan-Mathijs Schoffelen - 2014-01-18 12:51:49 +0100

Seems an issue with ft_selectdata, rather than ft_singleplotTFR. Since you are fooling around manually with the data anyway, it'll likely work if you average across trials by hand. NOTE: taking the log10 per trial and averaging will be different than taking the average and then the log10. Depends on your application, but in general it is better to average first, and log10 later. If you log10 first and average later you essentially create the log10 of the product of all single trial power estimates: log(a)+log(b)=log(a*b) So, in sum I'd do data2 = ft_freqdescriptives([], data); % this averages across trials. data2.logspctrm = log10(data2.powspctrm); % better even, use ft_math for this, but I suspect that the log transformed power will then end up in the field .powspctrm then visualize


Jan-Mathijs Schoffelen - 2014-01-25 09:33:42 +0100

Hi Tom, Any new from the front?


Jim Herring - 2014-01-30 09:39:02 +0100

I've added a testscript. It only seems to fail when cfg.trials is specified. I'll see if I can fix it.


Jim Herring - 2014-01-30 09:49:21 +0100

The problem is in ft_singleplotTFR. When cfg.parameter is specified a temporary freq structure is created with the powspctrm field filled by what is specified in cfg.parameter. The 'time' field, if available, is not copied and therefor throws an error when plotting. if isfield(cfg, 'parameter') && ~strcmp(cfg.parameter,'powspctrm') % freqdesctiptives will only work on the powspctrm field % hence a temporary copy of the data is needed tempdata.dimord = data.dimord; tempdata.freq = data.freq; tempdata.label = data.label; tempdata.time = data.time; tempdata.powspctrm = data.(cfg.parameter); if isfield(data, 'cfg') tempdata.cfg = data.cfg; end tempdata = ft_freqdescriptives(tmpcfg, tempdata); data.(cfg.parameter) = tempdata.powspctrm; clear tempdata else I've fixed it by also copying the time field to the temp structure. Sending ft_singleplotTFR.m Sending test/test_bug2440.m Transmitting file data .. Committed revision 9173.