[FieldTrip] Reading data and trigger events from Neuromag fif dataset sp

Niels Trusbak Haumann aestnth at hum.au.dk
Wed Nov 6 22:57:54 CET 2013


Sorry, the previously posted example was wrong. Below is a correction to the previous example.

Does the error shown below mean that you can only define trials based on the raw data files, and you can not define trials based on the data, which has already been converted to FieldTrip data?

If so, I assume that it's necessary to:
1. Apply ft_definetrial on each one of the splitted raw fif files. 
2. In the first two rows in the trial definition matrix from the second splitted file (i.e. the trial begin sample and trial end sample) add the number of samples in the preceeding raw fif file + 1. 
3. Use vertcat to concatenate the corrected trial definition matrices from both files into one trial definition.
4. Then use ft_redefinetrial to apply the concatenated trial definitions on the concatenated data.

Have anyone tried succesfully to concatenate trial definitions and apply them on concatenated data (in cases with raw fif files splitted into 2 files due to 2 GB file limitation during raw data recording)?

Greetings
Niels.

>> cfg = [];
cfg.dataset = dfull
cfg.trialfun = 'ft_trialfun_general' % this is the default
cfg.trialdef.eventtype = 'STI101'; % trigger channel
cfg.trialdef.eventvalue = [1 2 3 4 5]; % the values of the stimulus triggers
cfg.trialdef.prestim = 0.250; % time window before stimulus in seconds
cfg.trialdef.poststim = 0.500; % time window after stimulus in seconds
trl  = ft_definetrial(cfg);

cfg = 

    dataset: [1x1 struct]


cfg = 

     dataset: [1x1 struct]
    trialfun: 'ft_trialfun_general'

Warning: -clear 
> In utilities/private/warning_once at 116
  In utilities/private/ft_preamble_init at 26
  In ft_preamble at 54
  In ft_definetrial at 112 
Error using fileparts (line 31)
Input must be a row vector of characters.

Error in ft_filetype (line 146)
[p, f, x] = fileparts(filename);

Error in dataset2files (line 14)
  format = ft_filetype(filename);

Error in ft_checkconfig (line 503)
    [cfg.dataset, cfg.headerfile, cfg.datafile] = dataset2files(cfg.dataset, []);

Error in ft_definetrial (line 116)
cfg = ft_checkconfig(cfg, 'dataset2files', {'yes'});
 

FieldTrip discussion list <fieldtrip at science.ru.nl> writes:
>Thanks Peter. 
>
>The concatenation of the data by using horzcat works fine. 
>
>However, I don't know how to define the trials by refering to the concatenated data. 
>Is it possible to automatically define the trials based on trigger signals in the concatenated data by using ft_definetrial or ft_redefinetrial?
>
>I get the error message (see below) about the missing headerfile. I tried to define cfg.header = dfull.hdr and cfg.headerfile = dfull.hdr , but it didn't seem to work. 
>
>Greetings
>Niels. 
>
>>> cfg = [];
>cfg.data = dfull
>cfg.trialfun = 'ft_trialfun_general' % this is the default
>cfg.trialdef.eventtype = 'STI101'; % trigger channel
>cfg.trialdef.eventvalue = [1 2 3 4 5]; % the values of the stimulus triggers
>cfg.trialdef.prestim = 0.250; % time window before stimulus in seconds
>cfg.trialdef.poststim = 0.500; % time window after stimulus in seconds
>trl  = ft_definetrial(cfg);
>
>cfg = 
>
>Â Â Â Â data: [1x1 struct]
>
>
>cfg = 
>
>Â Â Â Â Â Â Â Â data: [1x1 struct]
> Â Â Â trialfun: 'ft_trialfun_general'
>
>evaluating trialfunction 'ft_trialfun_general'
>Reference to non-existent field 'headerfile'.
>
>Error in ft_trialfun_general (line 71)
>hdr = ft_read_header(cfg.headerfile, 'headerformat', cfg.headerformat);
>
>Error in ft_definetrial (line 162)
> Â Â Â [trl, event] = feval(cfg.trialfun, cfg);
>
>
>FieldTrip discussion list <[ mailto:fieldtrip at science.ru.nl ]fieldtrip at science.ru.nl> writes:
>Hi Neils,  
>
>
>I use the ft_preprocessing function to load  both of my fif files into memory, then use the horzcat command to concatenate the matrices together. From there I create my trialdefs and use ft_redefinetrial to create the condition epochs. 
>
>
>I haven't had a problem with dropped triggers / incorrect trial lengths etc. 
>
>
>Please find the code I use below (and excuse any clunkiness):
>
>
>As for your second question re:Â cfg.detectflank = 'up', the ft_read_event function is the one you want to look at. If your system is anything like a typical neuromag, an event can be characterised by both the up and down edges of your digital trigger channel. By specifying cfg.detectflank = 'up' in the read_even function, it will search for jumps in the channel where samples change from 0 to > 0 and classify that as an event, ignoring the down edge. Â 
>
>
>Hope the above (and below) helps and happy MEGing, 
>
>
>Peter.
>
>
>
>
>%%
>%Read data into matlab
>
>
>cfg = [];
>cfg.dataset = megdata1; %first fif file
>cfg.channel = 'MEG';
>d1 = ft_preprocessing(cfg);
>
>
>cfg = [];
>cfg.dataset = megdata2;Â %second fif file
>cfg.channel = 'MEG';
>d2 = ft_preprocessing(cfg);
>
>
>%%
>%concatenate data
>
>
>dfull = d1;
>dfull.trial{1,1} = zeros(306,length(d1.trial{1,1}) + length(d2.trial{1,1})); NOTE: The 306 refers to channels (MEG only). If you have more channels (eg. EOG, ECG) change accordingly. 
>dfull.trial{1,1} = horzcat(d1.trial{1,1}, d2.trial{1,1});
>dfull.sampleinfo = [1 length(dfull.trial{1,1})];
>
>
>for i = 2:length(dfull.time{1,1}); NOTE: Loop assumes data has yet to be downsampled and is at the base SR of 1000Hz.
>dfull.time{1,1}(1,i) = (i - 1)*.001; %Change .001 to match SR. 
>i = i + 1;
>end  
>
>
>__________________________
>Peter Goodin,   
>BSc (Hons), Ph.D Candidate.
>
>
>Brain and Psychological Sciences Research Centre (BPsych)
>Swinburne University, 
>Hawthorn, Vic, 3122
>
>
>Monash Alfred Psychiatry Research Centre (MAPrc)
>Level 4, 607 St Kilda Road, 
>Melbourne 3004
>
>
>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>-
>From: [ mailto:fieldtrip-bounces at science.ru.nl ]fieldtrip-bounces at science.ru.nl [[ mailto:fieldtrip-bounces at science.ru.nl ]fieldtrip-bounces at science.ru.nl] on behalf of Niels Trusbak Haumann [[ mailto:aestnth at hum.au.dk ]aestnth at hum.au.dk]
>Sent: Friday, 1 November 2013 3:16 AM
>To: [ mailto:fieldtrip at science.ru.nl ]fieldtrip at science.ru.nl
>Subject: [FieldTrip] Reading data and trigger events from Neuromag fif dataset splitted into 2 files
>
>
>Dear FieldTrip community. 
>
>Is it possible to read the data and trial events from a single continuous Neuromag fif dataset, which was automatically split into two separate fif files during recording, because it exceeeded the standard 2 GB file size limitation?
>
>The second of the two splitted fif files contains relevant information showing that the second file continues at the time in seconds at which the first file ended. However, if the two fif files are read separately into Field Trip format this information seems to be lost. 
>FieldTrip seems to support reading in CTF datasets, which have been split into more files due to the 2 GB file size limitation, but I don't know whether there is a method for handling this problem with Neuromag fif data. 
>( [ http://fieldtrip.fcdonders.nl/getting_started/ctf?s[]=ctf ]http://fieldtrip.fcdonders.nl/getting_started/ctf?s[]=ctf )
>
>I presume that it is a general problem that Neuromag fif datasets with 306 channel data sampled at 1 kHz 32 bit floats are splitted into more files, since only ca. 16-18 minutes raw data can be recorded before it is automatically splitted into two files. 
>The large file size is not a problem after applying MaxFilter procedures to remove high frequency cHPI signals..., etc., and thereafter downsampling e.g. to 16 bit integers sampled at 250 Hz. I see from a previous discussion in another forum that it is not possible to merge (or append) the splitted files with the MaxFilter software. 
>
>When reading triggers from splitted fif files there is usually one trial, which starts in the end of the first file and ends in the start of the second file, which cannot be correctly recognized, if the files are treated separately. This is however just a minor problem of loosing a single trial. Â 
>
>I have a few wrong detections, probably because a few trials are both defined by up-going signals and down-going signals. Would ft_preprocessing (and the sub-routines that it calls) take this into consideration, if you e.g. specificy cfg.detectflank = 'up' ?
>
>I'm looking forward to hear any comments, suggestions or solutions. 
>
>Greetings
>Niels.
>
>Niels Trusbak Haumann
>M.A. / PhD student
>Department of Aesthetic Studies / Center of Functionally Integrative Neuroscience
>Aarhus University / Aarhus University Hospital
>Denmark
>E-mail: [ mailto:aestnth at hum.au.dk ]aestnth at hum.au.dk
>_______________________________________________
>fieldtrip mailing list
>[ mailto:fieldtrip at donders.ru.nl ]fieldtrip at donders.ru.nl
>[ http://mailman.science.ru.nl/mailman/listinfo/fieldtrip ]http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
>
>Niels Trusbak Haumann
>M.A. / PhD student
>Department of Aesthetic Studies / Center of Functionally Integrative Neuroscience
>Aarhus University / Aarhus University Hospital
>E-mail: [ mailto:aestnth at hum.au.dk ]aestnth at hum.au.dk
>_______________________________________________
>fieldtrip mailing list
>fieldtrip at donders.ru.nl
>http://mailman.science.ru.nl/mailman/listinfo/fieldtrip



Niels Trusbak Haumann
M.A. / PhD student
Department of Aesthetic Studies / Center of Functionally Integrative Neuroscience
Aarhus University / Aarhus University Hospital
E-mail: aestnth at hum.au.dk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20131106/732b9a37/attachment-0002.html>


More information about the fieldtrip mailing list