[FieldTrip] Warning with redefining data

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Thu Mar 9 08:32:33 CET 2023


Hi Marta,

You say: "I’ve run a loop over the trial field in the output of the ft_timelockanalysis as well as ft_preprocessing to check for NaNs in my 10-second data structs, but I didn’t find any when running this loop.”

This is at odds with your earlier statement that you got a warning that the data contains NaNs.

The NaNs have probably been introduced in your attempt to ‘glue together’ the 2-second epochs into longer snippets of 10 seconds. If the time axes of the original small snippets does not entirely match up (i.e. if there were gaps) then ft_redefinetrial might have filled those gaps with NaNs, while creating the 10 second snippets.

FieldTrip functions that operate on data containing NaNs often gracefully ignore them, but in many occasions the NaNs will affect the output. For instance (as is likely in your case), I think that the computation of the covariance in ft_timelockanalysis is not NaN-aware. This may cause downstream problems, when you use an all-NaN covariance matrix for the computation of spatial filters, which consequently will by construction also be all-NaN, as will be the virtual channel data that you try to derive from it.

The relevant question to ask here is: why do you want to stitch together the 2 second snippets of data?

Good luck and best wishes,
Jan-Mathijs



On 7 Mar 2023, at 21:09, Marta Stojanović via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Hi Fieldtrip community,

I’m reaching out with a question about a warning I encountered when redefining trial length from resting-state MEG data using ft_definetrial and ft_redefine trial.

Namely, I redefined the length of input data from a resting-state MEG file from two-second trials to longer trials of 10-second length. I successfully used the ft_definetrial and ft_redefinetrial functions to do so, using the ‘trl’ field from the struct where I define the trial to input as a configuration for the ft_redefinetrial function.

With the two-second length I have 144 trials from the data, while with the ten-second length there are 28 trials.

The pipeline and structs look like the following:

%% define trials with 10-second length
clear ten_seconds;
cfg = [];
cfg.dataset = restfile;   % refers to resting-state file of a single subject
cfg.trialdef.beginning = 0; % start at the beginning of the recording
cfg.trialdef.length     = 10; % 10-second trial length
cfg.trialdef.overlap   = 0; % no overlap between trials
ten_seconds = ft_definetrial(cfg);


%% redefine trials to 10 seconds
clear redef_data;
cfg = [];
cfg.trl = ten_seconds.trl; % use trl from defined trial
redef_data = ft_redefinetrial(cfg,data);

%% preprocess redefined 10-second trials
clear ten_sec_trls;
cfg = [];
cfg.demean = 'yes';
cfg.baselinewindow = 'all';
% cfg.baselinewindow = [0 1018];
ten_sec_trls = ft_preprocessing(cfg,redef_data);


These are the associated structs with their fields:

redef_data =

fsample: 508.6275
grad: [1×1 struct]
label: {244×1 cell}
cfg: [1×1 struct]
hdr: [1×1 struct]
trial: {1×28 cell}
time: {1×28 cell}
trialinfo: [28×2 double]
sampleinfo: [28×2 double]

ten_sec_trls =

fsample: 508.6275
grad: [1×1 struct]
hdr: [1×1 struct]
trialinfo: [28×2 double]
trial: {1×28 cell}
time: {1×28 cell}
label: {244×1 cell}
cfg: [1×1 struct]

When I plug the redefined data (i.e., with redefined length, ten_sec_trls) into ft_timelockanalysis, I receive the following warning:

Warning: data contains NaN values
 In ft_preproc_polyremoval at line 75
 In ft_preproc_baselinecorrect at line 52
 In ft_timelockanalysis at line 174

the call to "ft_selectdata" took 0 seconds and required the additional allocation of an estimated 22 MB
Warning: inconsistent sampleinfo
 In makessense at line 115
 In ft_datatype_timelock at line 72
 In ft_checkdata at line 479
 In ft_timelockanalysis at line 207

I’ve run a loop over the trial field in the output of the ft_timelockanalysis as well as ft_preprocessing to check for NaNs in my 10-second data structs, but I didn’t find any when running this loop. I’ve checked the relevant lines from the Fieldtrip functions but couldn’t find a way to solve the warning from there. I’ve also checked the sampleinfo, but I sense the warning may be due to the sampleinfo in the configuration being inconsistent with the actual data due to the removal of non-MEG channels from the sampleinfo in the resting file.

The warning message might influence later analyses, so I’m wondering if anyone has faced the same and/or has an explanation.

Thanks a lot in advance!

All the best,
Marta
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!44dPKLWAx3oGspX-Q-IZx8b_gfPmQbTd45nbdyM61ROZgOiO2314lg4aY5eGcvDpKtQW3t1ilWOQcQ56Yd02ltXfOme3MNrQw0Ahfg$

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230309/608f7fb6/attachment.htm>


More information about the fieldtrip mailing list