Back to the main page.
Bug 3368 - error writing .gdf (or .eeg) data
Status | CLOSED FIXED |
Reported | 2017-11-10 20:59:00 +0100 |
Modified | 2017-11-20 20:03:47 +0100 |
Product: | FieldTrip |
Component: | fileio |
Version: | unspecified |
Hardware: | Macintosh |
Operating System: | Mac OS |
Importance: | P3 normal |
Assigned to: | Jan-Mathijs Schoffelen |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
Dora Hermes - 2017-11-10 20:59:04 +0100
I am trying to convert a dataset to a .gdf or .eeg format. However, if I write and then load the data, I get ~300 NaNs where there were numbers in the original set. An example is here, with a Fieldtrip example dataset: % load a fieldtrip dataset ieeg_name = fullfile(rootDir,'fieldtrip_examples','SubjectNY394','NY394_VisualLoc_R1.edf'); cfg = []; cfg.dataset = ieeg_name; cfg.continuous = 'yes'; cfg.channel = 'all'; ft_data = ft_preprocessing(cfg); % name to write the file ieeg_name_gdf = fullfile(rootDir,'fieldtrip_examples','SubjectNY394','NY394_VisualLoc_R1.gdf'); % fetch the header hdr_data = ft_fetch_header(ft_data); % write the data ft_write_data(ieeg_name_gdf,ft_data.trial{1},'header',hdr_data,'dataformat','gdf') % load the data back in test_ft_data = ft_read_data(ieeg_name_gdf); test_ft_header = ft_read_header(ieeg_name_gdf); % now check whether the loaded data are the same as the written data, % the following should be zero: length(find(test_ft_data-ft_data.trial{1}~=0))
Jan-Mathijs Schoffelen - 2017-11-13 09:37:23 +0100
confirmed. I created a test function that reproduces your observation
Jan-Mathijs Schoffelen - 2017-11-13 11:21:09 +0100
the error lies in the fact that the biosig reading code (sread) is replacing the data points that exceed some threshold defined in the file header. I suspect that due to numerical tolerance issues, the most extreme values are by consequence replaced by NaNs. This is upon reading, not writing. Since I am reluctant to delve into the low-level (and mostly ugly) biosig tools, even though this should be the place to fix it in a clean way, I suggest to increase the numerical tolerance in the writing code (which is in fieldtrip).
Jan-Mathijs Schoffelen - 2017-11-13 11:21:46 +0100
I'd rather have you do the work, but it'll probably take me more to explain how to do it, rather than doing it myself.
Jan-Mathijs Schoffelen - 2017-11-13 11:32:53 +0100
Fixed with github PR 575
Jan-Mathijs Schoffelen - 2017-11-20 11:13:54 +0100
Dora, zou je even kunnen bevestigen dat dit nu voor je werkt, a.u.b.? Dan weet ik in ieder geval dat ik niet voor jan joker hieraan heb gewerkt. M.v.g., JM