Scripting both surface and volume source reconstruction

Dear BST Community,

I have a single protocol with subjects for each of which I have calculated the surface and volume head models. I now wish to script the source reconstruction for each EEG file, for both the surface and volume. Is there any way to script this, or should I manually use the GUI to select the surface head model, and then calculate the sources?

Thank you,
Paul

Hi Paul,

In the script you need to change the HeadModel that will be used to compute the sources. See this script:

SubjectName = 'Subject02';
Condition   = 'SubjectCMC';

% === CHANGE THE DEFAULT HEAD MODEL ===
% Select the recordings within the Subject and the Study
sFilesRec = bst_process('CallProcess', 'process_select_files_data', [], [], ...
    'subjectname', SubjectName, ...
    'condition',   Condition, ...
    'includebad',  0);
% Index of the study 
iStudy = sFilesRec(1).iStudy;
% Get Study structure
sStudy = bst_get('Study', iStudy);
% List of the headmodels for this Study
HeadModels = sStudy.HeadModel;
% Change the Default head model
iHeadModel = 2;
% Save in database the sStudy with the selected iHeadModel
sStudy.iHeadModel = iHeadModel;
bst_set('Study', iStudy, sStudy);
% Repaint tree
panel_protocols('RepaintTree');

% === COMPUTE SOURCES ===
% Minimum norm options
InverseOptions = struct(...
    'Comment',        'MN: MEG', ...
    'InverseMethod',  'minnorm', ...
    'InverseMeasure', 'amplitude', ...
    'SourceOrient',   {{'free'}}, ...  % 'fixed', 'loose', 'free'
    'Loose',          0.2, ...
    'UseDepth',       1, ...
    'WeightExp',      0.5, ...
    'WeightLimit',    10, ...
    'NoiseMethod',    'reg', ...
    'NoiseReg',       0.1, ...
    'SnrMethod',      'fixed', ...
    'SnrRms',         0.001, ...
    'SnrFixed',       3, ...
    'ComputeKernel',  1, ...
    'DataTypes',      {{'MEG'}});
% Process: Compute sources [2018]
sFilesSources = bst_process('CallProcess', 'process_inverse_2018', sFilesRec, [], ...
    'output',  1, ...  % 1 Kernel only shared; 2 Kernel only: one per file; 3 Full results
    'inverse', InverseOptions);```