Exporting data from Brainstorm to edf file

,

Hi
I am trying to export data from Brainstorm to edf file and getting the following error message:

Error using export_data (line 206)
Subscript indices must either be real positive integers or logicals.

Error in export_data (line 58)
AllOutputs{1} = export_data(DataFile{1}, ChannelMat, ExportFile);

Error in tree_callbacks>@(h,ev)export_data(GetAllFilenames(bstNodes,'data')) (line 1455)
jMenuExport = gui_component('MenuItem', , , 'Export to file', IconLoader.ICON_SAVE, , @(h,ev)export_data(GetAllFilenames(bstNodes,
'data')));

Thank you for your report, Niko. The EDF export wasn’t fully tested for groups of files and export of negative time windows. I pushed a tentative fix in the following commit: https://github.com/brainstorm-tools/brainstorm3/commit/fa7a41c5b18d0150fbadf428823d0cb9c0b8dad6

Please update Brainstorm and let me know if it helps.

Cheers,
Martin

Thanks Martin.
Unfortunately there is still a problem after updating my Brainstorm:

Error using export_data (line 206)
Subscript indices must either be real positive integers or logicals.

Error in export_data (line 58)
AllOutputs{1} = export_data(DataFile{1}, ChannelMat, ExportFile);

Error in tree_callbacks>@(h,ev)export_data(GetAllFilenames(bstNodes,‘data’)) (line 1455)
jMenuExport = gui_component(‘MenuItem’, [], [], ‘Export to file’, IconLoader.ICON_SAVE, [], @(h,ev)export_data(GetAllFilenames(bstNodes,
‘data’)));

I’ve just updated the .zip distribution.
Please try updating Brainstorm again.

Sorry, still have error message:

Error using export_data (line 206)
Subscript indices must either be real positive integers or logicals.

Error in export_data (line 58)
AllOutputs{1} = export_data(DataFile{1}, ChannelMat, ExportFile);

Error in tree_callbacks>@(h,ev)export_data(GetAllFilenames(bstNodes,‘data’)) (line 1455)
jMenuExport = gui_component(‘MenuItem’, [], [], ‘Export to file’, IconLoader.ICON_SAVE, [], @(h,ev)export_data(GetAllFilenames(bstNodes,
‘data’)));

It is now stuck at Finding maximal values (100%)

before it was stuck at Finding maximal values (33%)

Hi Niko,

Do you think you could share with us some of the files that are not working for you? It’s working for me on my local tests.

Thanks,
Martin

Sorry Martin, for the delayed response. Which file should I send you, .set files are OK?
I have attached the photo how I export into edf, may be am doing it in a wrong way?
Thanks

Hi Niko,

The way you’re showing is the correct way to export it to EDF. I think sending me one file of the group will be fine, for example: “sb10S4_bthermode | band | time (#1)”. Right click on the first trial (#1) and select File -> Export to File, and choose the Brainstorm matrix (timeseries.mat) format.

Thanks,
Martin

Thanks Martin, I tried it again, and it is fine now.

I am getting the same kind of error using Matlab 2017b and latest (September) brainstorm
Shoul I send you file for testing @MartinC?

Error using export_data (line 244)
Subscript indices must either be real positive integers or logicals.

Error in export_data (line 58)
AllOutputs{1} = export_data(DataFile{1}, ChannelMat, ExportFile);

Error in tree_callbacks>@(h,ev)export_data(GetAllFilenames(bstNodes,'data'))
(line 1566)
jMenuExport = gui_component('MenuItem', [], [], 'Export
to file', IconLoader.ICON_SAVE, [],
@(h,ev)export_data(GetAllFilenames(bstNodes, 'data')));

Hello,

Yes, please send me your problematic file if possible. Can you briefly explain what you're doing to reproduce this issue? Are you simply right clicking on the file in Brainstorm and going to File -> Export to file -> EEG: .edf?

Thanks,
Martin

Yes, I am doing the the steps described as above, the procedure hangs when finding maximum values (50%)

Please post the file you are tying to export, so we can to reproduce this error on our end.
Thanks

The file was shared with me privately, thank you it really helped debugging.

It was hitting an unlikely precision error when computing the number of samples per EDF block during export. I added a round operation to ensure it doesn't happen again. Fixed in https://github.com/brainstorm-tools/brainstorm3/commit/f1193733f9942e0a7757013133afe3f101602ca1

Please update Brainstorm and try again, it works on my end with your file now.

Cheers,
Martin

Thanks for the help!
Now I could export but I got weird behaviour when I try to read exported files.
When I try to read edf file in Python mne I am getting the following error
ValueError: could not convert string to float: '-7.247e-'

It could be error on mne side (on EEGLAB I am getting this warning for all channels
WARNING SOPEN(GDF/BDF/EDF): Scaling factor is not defined in following channels:

But this is not that important and probably related how those libraries solve this ambiguity (so this should be not solved on brainstorm side)

But what is stranger, when I read exported file using EEGLAB, the sample has 1875 frames per epoch what gives end of the epoch at 3,123s, while orginal matlab files have length 1801 samples, which should give 3s

Could it be related to newly introduced round operation?

Hi,

For the extra samples at the end of the file, this is not a bug but rather a limitation of the EDF format. This format needs to be broken into small data records (blocks) of the same length. Because your original file had an indivisible (prime) number of samples (1801), Brainstorm cannot find a record size that fits perfectly with your data. In your case, it was chosen to split the data in blocks of 75 samples. Because of the last 1801th sample, an extra block was needed for that single sample, resulting in 74 empty samples appended at the end of your file to fill that last block.

So either remove these last 74 samples when importing that file in another software or export your file in a better format such as Fieldtrip (EDF is not a great format...)

Martin

1 Like

In general, exporting processed data as EDF files is a not a good choice.
EDF can only save 16bit integers, while your processed data is available in 64bit floating-point values. Converting back to 16bit integers causes a lot of precision to be lost, and doing this multiple times to exchange data between programs can end up damaging the signals and introduce unexpected artifacts.

Always prefer using file formats that can store floating point values instead (anything Matlab-based, or the BrainVision format.