Script check inquiry

Dear Raymundo,

Thank you for all your help in my learning of brainstorm.

I was able to create a script to loop through all my participants and the process was amazingly user friendly (again thanks to you and brainstorm).

While the data look great and I didn't get overt errors, I was wondering if you could skim my brief script to see if you notice any mistakes.

In short, every participant has a single MRI but multiple EEG recordings (epoched, previously preprocessed working memory task trials). I'm hoping to extract raw voltage time series of some dlpfc and ppc scouts.

I'm particularly curious if my covariance format was correct. The data was already baseline corrected in eeglab.

Thanks for considering, Raymundo!

Brian

Brian Kavanaugh, PsyD, ABPP, Board Certified Pediatric Neuropsychologist, E. P. Bradley Hospital, Assistant Professor, Warren Alpert Medical School of Brown University

brainstorm_multipleparticipants_032724.m (8.5 KB)

thanks for considering!

Hi Brian, at first glance the code looks fine, a FOR loop across subjects with a nested FOR loop for EEG sessions. Here some comments:

  • Every time that you call a process be sure that the sFiles is necessary, if it is not, just replace it with an empty array []. This will help you to have clarity avoid unintended processing in files.

  • Not sure why EEG raw is imported if it not used.

  • BEM surfaces only depend on the Anatomy which is unique per subject, thus compute them in the Subject loop, not in the inner EEG loop

As recommendation, before running the script on all your subjects, run in in at least 2 Subjects with 2 EEG sessions manually, and then with the script. By doing so, you will test that the loop nesting is working fine, as well and the processing of the Anatomies and EEG recordings.

In addition, Matlab offers great tools to analyze the code while running and debug it if needed:
https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
https://www.youtube.com/watch?v=PdNY9n8lV1Y

Also, in the folder brainstorm3/toolbox/scripts you can find scripts to reproduce most of the tutorials in the Brainstorm page, you could use those scripts as references.

EDIT: and of course the tutorial page exclusively focused on Scripting:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting

1 Like

Wonderful, thank you Raymundo! These resources are fantastic. Have a great weekend

Sorry, one quick, concrete question:

  1. in my final output, columns are time points and rows are scouts and epochs. If row 1 is epoch 1 - scout 1, is row 2 epoch 1 - scout 2, 3? I.e., does it process all scouts within the first epoch before moving to the next epoch? I assume it would process all scouts within epoch 1 before moving to epoch 2. but I couldn't find confirmation.

brian

This is correct, when the process process_extract_scout is called with the option concatenate equal to 1 (concatenate output in one unique matrix), the result has the shape [nFilesĂ—nScouts , nTime].

The output is the concatenation (on rows) of the files that would result if the process were run in individual files. Thus for N Files (epochs/trials) and M scouts, the rows are ordered as: File1-Scout1, File1-Scout2, ..., File1-ScoutM, File2-Scout1, ..., FileN-ScoutM. This is indicated in the names of the rows, located in the Description field of the matrix file.

thanks Raymundo!