Importing raw data with a script

Hi Francois,

Yu-Teng has worked on the following code to automatically import raw data (== review raw data) into Brainstorm (modifying code from the script folder). However, we cannot figure out how to completely disable the gui and still load the events (triggers). The current code still pops-up the window to select the event channel. Any hints on how to automatically load the raw data without any gui?

Also, how can we then create trials out of the imported raw data using only scripts?

Thank you!
Dimitrios

% Align sensors
sProcess.options.channelalign.Comment = ‘Align sensors using headpoints’;
sProcess.options.channelalign.Type = ‘checkbox’;
sProcess.options.channelalign.Value = 1;
% Channels options
ChannelAlign = 2 * double(sProcess.options.channelalign.Value);
ImportOptions = db_template(‘ImportOptions’);
ImportOptions.ChannelReplace = 2;
ImportOptions.ChannelAlign = ChannelAlign;
ImportOptions.DisplayMessages = 0;
% ImportOptions.EventsMode = ‘ignore’;
% ImportOptions.EventsTrackMode = ‘value’;
for i=1:length(RawFiles)
OutputDataFile{i} = import_raw(RawFiles{i}, FileFormat, iSubject, ImportOptions);
end

Hi Dimitrios,

You’re going the wrong way: there are now processes to deal with all the import operations.
Do not put anything process box, select the process “Import > Create link to raw file”.
Then to read the events from a channel, use the process “Import > Events: Read from channel”.
Everything that you get from the process interface will work without any user interactions, and will just show a report if anything wrong happens during the execution.

If you want to re-use this code in custom scripts instead of running it from the interface: use the menu “Generate .m script” in the “Process selection” window.
You don’t have to write the scripts anymore, the process interface does it for you automatically. You shouldn’t have to use this “script” folder anymore, if anything is missing in the “process selection” window, let me know and I will add it.

Say hi to Yu-Teng for me.

Cheers,
Francois

Hi Francois,

That sounds great and easy. I will let Yu-Teng know!

Thank you,
Dimitrios

Hi Francois,

One more thing: Importing and creating events works well as you described. Thank you. But when calling ‘events: combine stim/response’ from the process window nothing happens. When calling it from the figure controls ‘recordings->events->combine stim/response’ it works. Can you please have a look?

Thank you,
Dimitrios

Hello Francois,

Good Evening. This is Yu-Teng.

I think i am able to run the process to combine stim/events by pipeline from the import raw data; in other words, i am calling the process box with the following processes:

process_import_data_raw
process_evt_read
process_evt_combine

however, we have problems here extracting the script or run from script.

Problem A:
say we want to do the following in the stim/event combine:
[B]
11s; ignore; 11; 254
11a; ignore; 11; 255[/B]

The script will look as follows:

[B]sFiles = bst_process(…
‘CallProcess’, ‘process_evt_combine’, …
sFiles, [], …
‘combine’, ‘11s; ignore; 11; 254
11a; ignore; 11; 255
’);[/B]

which the MATLAB will find syntax error.
I tried several ways to get around it but all failed. One leads to the next problem.

Problem B
Now i try to input only 1 criteria (combine condition) as follows:

[B]41s; ignore; 41; 254[/B]

The script looks like this

[B]sFiles = bst_process(…
‘CallProcess’, ‘process_evt_combine’, …
sFiles, [], …
‘combine’, ‘41s; ignore; 41; 254’);[/B]

It has no syntax error in MATLAB; however, the script gives the different event combination result (which is wrong) from the GUI version (which is correct). Basically, the script seems to get the other condition
[B]‘41s; ignore; 41; 255’ [/B]
also combined. That is, even the event is 255 rather than 254, it still creates a combined event in “41s”.

Could you please have a look at the previous two questions that we have here? Thank you very much for your kindly help.

Sincerely Yours,
Yu-Teng

Hi Dimitrios & Yu-Teng,

One more thing: Importing and creating events works well as you described. Thank you. But when calling 'events: combine stim/response' from the process window nothing happens. When calling it from the figure controls 'recordings->events->combine stim/response' it works. Can you please have a look?

When using the menus in the "Events" tab, the processes to detect or group events are applied on the raw file, and the raw viewer is reloaded to update the modifications.
When calling the same processes directly from the process interface, it just saves the modifications to the file but do not do anything with the currently opened figures. You have to close the viewer and re-open it to view the modifications.
It is not a bug, it is just that the process window is not meant to be an interactive tool.

The script will look as follows [...] which the MATLAB will find syntax error.

I fixed the bug with the generation of code with multi-line strings. Now, a list of different conditions will look like this in the generated code:
['evt1; ignore; A; B' 10 'evt2; ignore; A; C']

That should solve all your current problems. Please let me know if it doesn't.

Cheers,
Francois

Dear François,

Please note that the approach you are proposing here is not working (as far as I can tell) with BDF files. When using process_import_data_raw, it calls import_raw(…, ImportOptions), which call in_fopen(…, ImportOptions), which call in_fopen_edf(DataFile) [i.e., the ImportOptions structure with its field EventsTrackMode is not passed down below that point]. Then, in the in_fopen_edf(…) function, a value is set to ImportOptions using “ImportOptions = db_template(‘ImportOptions’);” which set EventsTrackMode to ‘ask’. Thus, we cannot by-pass the GUI call in this case…

I got around this limitation by making a local copy of the db_template.m in my local repertory where I changed line 430 for "‘EventsTrackMode’, ‘value’, … " instead of "‘EventsTrackMode’, ‘ask’, … "… but I guess a more elegant and permanent solution might be useful.

Best regards,

Christian O’Reilly

[QUOTE=Francois;4009]Hi Dimitrios,

You’re going the wrong way: there are now processes to deal with all the import operations.
Do not put anything process box, select the process “Import > Create link to raw file”.
Then to read the events from a channel, use the process “Import > Events: Read from channel”.
Everything that you get from the process interface will work without any user interactions, and will just show a report if anything wrong happens during the execution.

If you want to re-use this code in custom scripts instead of running it from the interface: use the menu “Generate .m script” in the “Process selection” window.
You don’t have to write the scripts anymore, the process interface does it for you automatically. You shouldn’t have to use this “script” folder anymore, if anything is missing in the “process selection” window, let me know and I will add it.

Say hi to Yu-Teng for me.

Cheers,
Francois[/QUOTE]

Hi Christian,

Good catch. I added a quick fix to force the loading of the events in “value” mode.
The correct way of fixing would be to allow the loading of the events from EDF/BDF files separately, and load them separately, as described earlier in this thread.
I won’t do right now, but I added it to my todo list…

Francois

Sounds good to me. Thanks for the feedback.

Christian