[FieldTrip] access to GDF file

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Wed May 15 09:24:24 CEST 2024


Dear all,

Following up on the below thread, I want to announce that I took the liberty of implementing my own suggestion, i.e. I added some code (inspired by EEGLAB) to extract more event information from gdf-files than before. Long story short: previously FieldTrip could only extract events as represented on a digital trigger channel (typically the STATUS channel in gdf files). With the new code in place (available as the latest tagged release https://github.com/fieldtrip/fieldtrip/releases/tag/20240514<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ffieldtrip%2Ffieldtrip%2Freleases%2Ftag%2F20240514&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=p5l8s8%2BBSk2NChjGRUoHJZPAvoFXKABV0woWeq5FnCc%3D&reserved=0>), FieldTrip’s ft_read_event function can now also harvest the events as represented in the gdf-file’s header (if present). This mimicks the behavior of similar functionality in EEGLAB, and thus takes away the need of making a detour via EEGLAB (or biosig) in order to extract this information in FieldTrip.

Happy computing,

Jan-Mathijs


On 2 May 2024, at 20:43, Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Hi,

As you may have already found in the fieldtrip documentation in https://fieldtriptoolbox.org<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Ffieldtriptoolbox.org%2F&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=C2Vo3Tr1Kn1j9l6nao%2F8bpbtOtaCI7MTD9EbCQ9srwc%3D&reserved=0>, events are read in by the function ft_read_event.

I guess you have already started inspecting the code in ft_read_event using the MATLAB debugger, and you may have found the relevant lines 484-504 dealing with the .gdf file format.

I assume (although you did not explicitly mention this) that ft_read_event in the case of the dataset that you mentioned returns an empty event structure, which means that you will have had the warning on your screen that is in line 500. In other words, based the specific data organization in the file, FieldTrip does not know how to interpret the trigger information.

Continuing the detective work, you will have noticed that in line 492 the function ft_read_header is called, producing a variable hdr, based on which consecutively a ’statusindex’ is determined, which consecutively determines whether or not the warning is thrown. Now, if we take a close look at the section in ft_read_header that deals with .gdf files, you will see in line 1545 that the read_biosig_header function is used to read in the metadata from the datafile. The read_biosig_header function uses biosig’s sopen function to do the heavy lifting.

Apparently, there has never been somebody who managed to write some ‘glue code’ that translates the events which are not represented on a digital STATUS channel into a representation that FieldTrip can work with.

We look forward to a generic implementation that broadcasts the events from the biosig header to FieldTrip as an improvement to be able to deal with a broader selection of .gdf files. Please submit your suggested code changes as a PR to our toolbox’s repository on github, which is located at https://github.com/fieldtrip/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ffieldtrip%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=wDIaOcK0fu%2BksGHF6KyUGYy2Imb%2Fwz0tluj95uh1mlM%3D&reserved=0>.

Best wishes and happy coding,
Jan-Mathijs



On 2 May 2024, at 19:04, Sina Makhdoomi Kaviri via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

I want to add this note that if I uploaded the dataset into the fieldtrip directly, it does not recognize the dataset related to specific event type. Please help me how can I access the event code in this dataset and separate it to process in the beamforming method. Here is my code:
dataset = './dataset/S03_ME/motorexecution_subject3_run1.gdf';
cfg = [];
cfg.dataset = dataset;
cfg.trialdef.eventtype = '1541'; % get a list of the available types
cfg.trialfun = 'ft_trialfun_general';
cfg.trialdef.triallength = 1; % duration in seconds
cfg = ft_definetrial(cfg);
cfg.dftfreq = [50];
cfg.channel = 'EEG';
data_segmented = ft_preprocessing(cfg);


On Thu, May 2, 2024 at 11:16 AM Sina Makhdoomi Kaviri <sinam1 at umbc.edu<mailto:sinam1 at umbc.edu>> wrote:
To whom it may concern,

I want to implement, "A novel explainable machine learning approach for EEG-based brain computer interface systems" published in Springer Nature, in fieldtrip. Regarding that they used ( http://bnci-horizon-2020.eu/database/data-sets<https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbnci-horizon-2020.eu%2Fdatabase%2Fdata-sets&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=803cwOnuUE7Qkbt3tnQC2I%2F6Zaf5MA%2Bf0Gn%2F2MyK940%3D&reserved=0> (Accession Number 001-2017)) as dataset in GDF file, I want to preprocess and use ft_definetrial, but it is not accessed to the event code. In this regard I use EEGLAB to load the dataset with biosig, after that when I convert to fieldtrip (eeglab2fieldtrip or save it and use ft_read_event,..) I face this problem as follows. Could you please help me how can I preprocess this dataset for beamforming source localization for specific event code.

Error using isfolder
Input path must be text.

Error in ft_filetype (line 166)
if isfolder(filename)

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

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

Error in ft_preprocessing (line 385)
  cfg = ft_checkconfig(cfg, 'dataset2files', 'yes');


_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=BnZcsQKXIVwm%2Fr0W%2Fjww4um7imu9qubjcko3bIDy16M%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=n%2B8LQ3Mzg%2FcSwY46fEi%2FUJTvdnjESZ2TxomgaPc5NoQ%3D&reserved=0>

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C36ee9121a8bb43fe531408dc74b00c19%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638513546684419148%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=BnZcsQKXIVwm%2Fr0W%2Fjww4um7imu9qubjcko3bIDy16M%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240515/474a173e/attachment.htm>


More information about the fieldtrip mailing list