forked from rigelfalcon/LeadField-Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripted_fs_lf_ppl.m
108 lines (90 loc) · 4.16 KB
/
scripted_fs_lf_ppl.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
% Scripted leadfield pipeline for Freesurfer anatomy files
% Brainstorm (24-Feb-2019)
% Andy Hu, Feb. 24, 2019
clc; clear; close all;
addpath('./brainstorm3');
if ~brainstorm('status')
brainstorm nogui
end
ProtocolName = 'Leadfield_Pipeline';
% Delete existing protocol
gui_brainstorm('DeleteProtocol', ProtocolName);
% Create new protocol
gui_brainstorm('CreateProtocol', ProtocolName, 0, 0);
% Input files
sFiles = [];
SubjectNames = {'MC0000010'};
% RawFiles = {fullfile(pwd,'example data\MC0000010_EEG_anatomy_t13d_anatVOL_20060115002658_2.nii_out\mri\T1.mgz'), ...
% fullfile(pwd,'example data\MC0000010_EEG_anatomy_t13d_anatVOL_20060115002658_2.nii_out'), ...
% fullfile(pwd,'example data\MC0000010_EEG_data.mat'), ''};
RawFiles = {'F:\MEEGfMRI\Data\andy\MC0000010_EEG_anatomy_t13d_anatVOL_20060115002658_2.nii_out\mri\T1.mgz', ...
'F:\MEEGfMRI\Data\andy\MC0000010_EEG_anatomy_t13d_anatVOL_20060115002658_2.nii_out', ...
'F:\MEEGfMRI\Data\andy\MC0000010_EEG_data.mat', ''};
% Start a new report
bst_report('Start', sFiles);
% Process: Import MRI
sFiles = bst_process('CallProcess', 'process_import_mri', sFiles, [], 'subjectname', SubjectNames{1}, 'mrifile', {RawFiles{1}, 'MGH'});
% Process: Compute MNI transformation
sFiles = bst_process('CallProcess', 'process_mni_affine', sFiles, [], 'subjectname', SubjectNames{1});
% Check Fiducials
Fiducial = load('F:\Data\brainstorm_db\Leadfield_Pipeline\anat\MC0000010\subjectimage_T1.mat');
% Process: Import anatomy folder
sFiles = bst_process('CallProcess', 'process_import_anatomy', sFiles, [], 'subjectname', SubjectNames{1}, 'mrifile', {RawFiles{2}, 'FreeSurfer'}, 'nvertices', 6001, ...
'nas', Fiducial.SCS.NAS, 'lpa', Fiducial.SCS.LPA, 'rpa', Fiducial.SCS.RPA, 'ac', Fiducial.NCS.AC, 'pc', Fiducial.NCS.PC, 'ih', Fiducial.NCS.IH, 'aseg', 1);
% Process: Generate BEM surfaces
sFiles = bst_process('CallProcess', 'process_generate_bem', sFiles, [], ...
'subjectname', SubjectNames{1}, ...
'nscalp', 1922, ...
'nouter', 1922, ...
'ninner', 1922, ...
'thickness', 4);
% Process: Create link to raw file
sFiles = bst_process('CallProcess', 'process_import_data_raw', sFiles, [], ...
'subjectname', SubjectNames{1}, ...
'datafile', {RawFiles{3}, 'EEG-MAT'}, ...
'channelreplace', 1, ...
'channelalign', 1, ...
'evtmode', 'value');
% Process: Set channel file
sFiles = bst_process('CallProcess', 'process_import_channel', sFiles, [], ...
'channelfile', {RawFiles{4}, RawFiles{4}}, ...
'usedefault', 43, ... % ICBM152: 10-20 19
'channelalign', 1, ...
'fixunits', 1, ...
'vox2ras', 1);
% Process: Refine registration
sFiles = bst_process('CallProcess', 'process_headpoints_refine', sFiles, []);
% Process: Project electrodes on scalp
sFiles = bst_process('CallProcess', 'process_channel_project', sFiles, []);
% Process: Compute head model
sFiles = bst_process('CallProcess', 'process_headmodel', sFiles, [], ...
'Comment', '', ...
'sourcespace', 1, ... % Cortex surface
'volumegrid', struct(...
'Method', 'isotropic', ...
'nLayers', 17, ...
'Reduction', 3, ...
'nVerticesInit', 4000, ...
'Resolution', 0.005, ...
'FileName', ''), ...
'eeg', 3, ... % OpenMEEG BEM
'openmeeg', struct(...
'BemSelect', [1, 1, 1], ...
'BemCond', [1, 0.0125, 1], ...
'BemNames', {{'Scalp', 'Skull', 'Brain'}}, ...
'BemFiles', {{}}, ...
'isAdjoint', 0, ...
'isAdaptative', 1, ...
'isSplit', 0, ...
'SplitLength', 4000));
% Save lead field
load('F:\Data\brainstorm_db\Leadfield_Pipeline\data\MC0000010\@rawMC0000010_EEG_data\headmodel_surf_openmeeg.mat');
Gain3d=Gain; Gain = bst_gain_orient(Gain3d, GridOrient);
save Gain Gain Gain3d;
% Save patch
load('F:\Data\brainstorm_db\Leadfield_Pipeline\anat\MC0000010\tess_cortex_pial_low.mat');
save patch Vertices Faces;
% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);