[Scripting] importing volume atlas from subject anatomy as source scouts

Hello, I'm trying to script a batch to perform EEG volume source analysis. I used the following command lines to import subject01's aal3 volume atlas:

ScoutFiles = 'Subject01/subjectimage_aal3_volatlas.mat';
isNewAtlas = 1;
panel_scout('LoadScouts',ScoutFiles,isNewAtlas);


It only worked when I had the volume source maps opened (Volume 9557: aal3). Otherwise, It would create a surface atlas (From volume: aal3). I then tried to find a way to open the volume source map in the MriViewer. The following lines seem promising:

MriFile = 'Subject01/Eyec/Avg: 01515_rest_eyec pruned with ICA pruned with ICA - 2-s epochs (120)/PNAI: EEG(Unconstr) 2018 (aal3)'; 
sMri = bst_memory('LoadMri', MriFile); 
view_mri(MriFile);

However, I cannot find such a source file in the result folder (brainstorm_db). I am wondering, where is this source map file? Is it possible to open the source maps of the subject and then close such pop-up window (eg. using the MriViewer) in command lines?

Hi @Taiziliulong, you were in the good path. The required information is read from the Fig handler, so it is needed to open the figure.

The piece of information that was missing is about volume sources, while they are plotted on the MRI (Viewer or 3D) they are not MRI, they are values for a volume grid (defined in the head model), the these values are interpolated in the MRI volume. All this to say, the file that needs to be open is the volume sources, not the MRI.

Volume head models: https://neuroimage.usc.edu/brainstorm/Tutorials/TutVolSource#Compute_a_volume_head_model

Note that your sources (from the screenshot) are not files in the HDD, they are a source link to a kernel. See the section source links in here:
https://neuroimage.usc.edu/brainstorm/Tutorials/SourceEstimation#On_the_hard_drive

You can obtain the "path" for the source link by right-click on it > File > Copy file path to clipboard

To plot the source file

SourceFile = 'link|Subject01/.../*KERNEL*.mat|Subject01/.../*data*.mat';
hFig = view_mri([], SourceFile);

Then you can run the lines you posted to import the Volume atlas:

ScoutFiles = 'Subject01/subjectimage_aal3_volatlas.mat';
isNewAtlas = 1;
panel_scout('LoadScouts',ScoutFiles,isNewAtlas);
panel_scouts('SaveModifications');

And close figure

close(hFig);

:bulb: Note that the importing the Atlas just needs to be done once per Subject. These atlases are saved in the default (in green) cortex file for the Subject.


You can programmatically find the source files with the process File > Select files : Sources

Dear Raymundo,

  Thanks for your quick and patient reply! That did solve my problem. 

Best,

Greatson Wu

Dear Raymundo,

Sorry to bother you again :sweat:. After importing the volume atlas from the subject anatomy as described before, I then tried to extact the volume scouts using the command lines. The script looks like the following:

  sFiles = bst_process('CallProcess', 'process_extract_scout', sFiles, [], ...
'timewindow',     [0, 1.998], ...
'scouts',         {'Volume 9557: aal3', {'Left Amygdala', 'Left Angular gyrus', 'Left Anterior cingulate cortex-pregenual', 'Left Anterior cingulate cortex-subgenual', 'Left Anterior cingulate cortex-supracallosal', 'Left Anterior orbital gyrus', 'Left Calcarine fissure and surrounding cortex', 'Left Caudate nucleus', 'Left Crus I of cerebellar hemisphere', 'Left Cuneus', 'Left Fusiform gyrus', 'Left Gyrus rectus', 'Left Heschls gyrus', 'Left Hippocampus', 'Left IFG pars orbitalis', 'Left Inferior frontal gyrus-opercular part', 'Left Inferior frontal gyrus-triangular part', 'Left Inferior occipital gyrus', 'Left Inferior parietal gyrus-excluding supramarginal and angular gyri', 'Left Inferior temporal gyrus', 'Left Insula', 'Left Intralaminar', 'Left Lateral geniculate', 'Left Lateral orbital gyrus', 'Left Lateral posterior', 'Left Lenticular nucleus-Pallidum', 'Left Lenticular nucleus-Putamen', 'Left Lingual gyrus', 'Left Lobule VI of cerebellar hemisphere', 'Left Medial Geniculate', 'Left Medial orbital gyrus', 'Left Mediodorsal lateral parvocellular', 'Left Mediodorsal medial magnocellular', 'Left Middle cingulate & paracingulate gyri', 'Left Middle frontal gyrus', 'Left Middle occipital gyrus', 'Left Middle temporal gyrus', 'Left Nucleus accumbens', 'Left Olfactory cortex', 'Left Paracentral lobule', 'Left Parahippocampal gyrus', 'Left Postcentral gyrus', 'Left Posterior cingulate gyrus', 'Left Posterior orbital gyrus', 'Left Precentral gyrus', 'Left Precuneus', 'Left Pulvinar anterior', 'Left Pulvinar inferior', 'Left Pulvinar lateral', 'Left Pulvinar medial', 'Left Rolandic operculum', 'Left Superior frontal gyrus-dorsolateral', 'Left Superior frontal gyrus-medial', 'Left Superior frontal gyrus-medial orbital', 'Left Superior occipital gyrus', 'Left Superior parietal gyrus', 'Left Superior temporal gyrus', 'Left Supplementary motor area', 'Left SupraMarginal gyrus', 'Left Temporal pole: middle temporal gyrus', 'Left Temporal pole: superior temporal gyrus', 'Left Thalamus-Anteroventral Nucleus', 'Left Ventral anterior', 'Left Ventral lateral', 'Left Ventral posterolateral', 'Right Amygdala', 'Right Angular gyrus', 'Right Anterior cingulate cortex-pregenual', 'Right Anterior cingulate cortex-subgenual', 'Right Anterior cingulate cortex-supracallosal', 'Right Anterior orbital gyrus', 'Right Calcarine fissure and surrounding cortex', 'Right Caudate nucleus', 'Right Crus I of cerebellar hemisphere', 'Right Cuneus', 'Right Fusiform gyrus', 'Right Gyrus rectus', 'Right Heschls gyrus', 'Right Hippocampus', 'Right IFG pars orbitalis', 'Right Inferior frontal gyrus-opercular part', 'Right Inferior frontal gyrus-triangular part', 'Right Inferior occipital gyrus', 'Right Inferior parietal gyrus-excluding supramarginal and angular gyri', 'Right Inferior temporal gyrus', 'Right Insula', 'Right Intralaminar', 'Right Lateral geniculate', 'Right Lateral orbital gyrus', 'Right Lateral posterior', 'Right Lenticular nucleus-Pallidum', 'Right Lenticular nucleus-Putamen', 'Right Lingual gyrus', 'Right Lobule IV-V of cerebellar hemisphere', 'Right Lobule VI of cerebellar hemisphere', 'Right Medial Geniculate', 'Right Medial orbital gyrus', 'Right Mediodorsal lateral parvocellular', 'Right Mediodorsal medial magnocellular', 'Right Middle cingulate & paracingulate gyri', 'Right Middle frontal gyrus', 'Right Middle occipital gyrus', 'Right Middle temporal gyrus', 'Right Nucleus accumbens', 'Right Olfactory cortex', 'Right Paracentral lobule', 'Right Parahippocampal gyrus', 'Right Postcentral gyrus', 'Right Posterior cingulate gyrus', 'Right Posterior orbital gyrus', 'Right Precentral gyrus', 'Right Precuneus', 'Right Pulvinar anterior', 'Right Pulvinar inferior', 'Right Pulvinar lateral', 'Right Pulvinar medial', 'Right Rolandic operculum', 'Right Superior frontal gyrus-dorsolateral', 'Right Superior frontal gyrus-medial', 'Right Superior frontal gyrus-medial orbital', 'Right Superior occipital gyrus', 'Right Superior parietal gyrus', 'Right Superior temporal gyrus', 'Right Supplementary motor area', 'Right SupraMarginal gyrus', 'Right Temporal pole: middle temporal gyrus', 'Right Temporal pole: superior temporal gyrus', 'Right Thalamus-Anteroventral Nucleus', 'Right Ventral anterior', 'Right Ventral lateral', 'Right Ventral posterolateral'}}, ...
'flatten',        0, ...
'scoutfunc',      'mean', ...  % Mean
'pcaedit',        struct(...
     'Method',         'pca', ...
     'Baseline',       [-0.1, 0], ...
     'DataTimeWindow', [0, 1], ...
     'RemoveDcOffset', 'file'), ...
'isflip',         1, ...
'isnorm',         0, ...
'concatenate',    1, ...
'save',           1, ...
'addrowcomment',  1, ...
'addfilecomment', []);

The scout labels are just the same as those showed in the GUI. However, when I run the script, an error occurred as below:

I tried to extract the scout sources from the epoch and average files. It seems the volume atlas should have be saved in the surface to be detected?
When I did the same process in the GUI, It work successfully and generated the corresponding scout source file.

I just cann't figure out what caused the error. Should I attached the volume atlas to the surface file? If so, what can I do in the script :face_holding_back_tears:? Use the panel_scout('SaveScouts') function?

Best,

Greatson Wu

Does it give the same error if you generate a Matlab script directly from the Pipeline Editor?
(with the option: Generate .m script)
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Starting_a_new_script

Test for a simple scenario: one source file and one process (Extract > Scout time series).


Could it be that in your script the volume atlas is only added for one Subject, and the error is produced when trying to extract that Atlas:Scout for another Subject where the Atlas is not available yet?

Dear Raymundo,

The error occurred before the processing of another subject. But thank you for your suggestion. It reminded me to go checking if the volume atlas was stored in the subject's surface file. It turned out that the volume atlas imported previously was missing.

I then doubled the previous command lines used to import the volume atlas, and tested the simple scenario: one source file and one process. The double scripts by coincidence solved the problem :joy:. Now the volume atlas showed up in the cortex file. The entire process ran smoothly without any errors (for Subject01), generating the corresponding scout source.

Thanks again for your careful checking and kind reminder ! ! Though the problem was solved in an unexpected way :rofl:.

Best,

Greatson Wu

I'm glad you found a way! However, this is not an optimal solution.
The reason was that after adding the volume atlas, it was necessary to save the modifications.

panel_scouts('SaveModifications')

No need of repeated lines :wink:

* I have edited my answer above to include this.

Thank you for your reply! That is quite an elegant way.