Skip to content

Commit

Permalink
Update lf_generate_frombrainstorm.m
Browse files Browse the repository at this point in the history
Fixed typo in  `error` , limited initial documentation to 75-character columns, reinstated "Unknown" label for uncovered dipoles
lrkrol authored Dec 8, 2022
1 parent 79150a2 commit bc572c7
Showing 1 changed file with 56 additions and 47 deletions.
103 changes: 56 additions & 47 deletions leadfield/brainstorm/lf_generate_frombrainstorm.m
Original file line number Diff line number Diff line change
@@ -20,46 +20,53 @@
% which was used to generate the BEM surfaces. These were then used to
% compute the leadfield through OpenMEEG and costraining the dipoles to
% the cortex surface. The electrodes template is the already
% co-registered EGI GSN HydroCel 256 E1 template. Finally, the default
% co-registered EGI GSN HydroCel 256 E1 template. Finally, the default
% atlas provided is the Mindboggle atalas. Please cite Brainstorm,
% OpenMEEG and Mindboggle if using this default files (see function content).
% OpenMEEG and Mindboggle if using this default files (see function
% content).
%
% Options:
% chanloc: - path + filename (.mat) of the channel location file used
% in Brainstorm to create the headmodel. You should find
% in Brainstorm to create the headmodel. You should find
% this file in:
% PATHTOBRAINSTORM\brainstorm_db\PROTOCOLNAME\data\SUBJECTNAME\@intra
% brainstorm_db\PROTOCOLNAME\data\SUBJECTNAME\@intra
% Otherwise you can open the protocol in Brainstorm and do:
% Functional Data>>Subject>>Intra-subject>>right click on the channel>>File>>Show in File Explorer
% Functional Data>>Subject>>Intra-subject>>right click on
% the channel>>File>>Show in File Explorer
% t1 - path + filename (.mat) of the structural T1 image used in
% Brainstorm to compute the headmodel. The location of the
% file depends on whether you used the default anatomy or a
% Brainstorm to compute the headmodel. The location of the
% file depends on whether you used the default anatomy or a
% subject-specific anatomy. You can find the file by:
% Anaotmy>>Subject>>right click on the T1 image (deafult=MRI:ICBM152)>>File>>Show in File Explorer
% Anaotmy>>Subject>>right click on the T1 image
% (deafult=MRI:ICBM152)>>File>>Show in File Explorer
% headmodel - path + filename (.mat) of the headmodel (leadfield)
% generated by Brainstorm. You should find this file in:
% PATHTOBRAINSTORM\brainstorm_db\PROTOCOLNAME\data\SUBJECTNAME\@intra
% brainstorm_db\PROTOCOLNAME\data\SUBJECTNAME\@intra
% Otherwise you can open the protocol in Brainstorm and do:
% Functional Data>>Subject>>Intra-subject>>right click on the headmodel>>File>>Show in File Explorer
% Functional Data>>Subject>>Intra-subject>>right click on
% the headmodel>>File>>Show in File Explorer
% atlas - This file is optional and you should use it if you wish
% to import an atlas that has been applied to the headmodel
% to import an atlas that has been applied to the headmodel
% in Brainstorm. Depending on the type of headmodel created
% (surface, volume or mixed) and how the atlas has been
% loaded and applied, there are different ways to retrieve
% the atlas. For consistency, please follow these
% instructions, which apply independently from the type of
% headmodel. With the protocol open in Brainstorm:
% Functional Data>>Subject>>Intra-subject>>Right click on the headmodel>>View EEG leadfield vectors>>Scout (on the right panel)>>Select the scout you desire/created>>Click on the save button (floppy disk) on the right of the window
% Provide the path + filename (.mat)
% Functional Data>>Subject>>Intra-subject>>Right click on
% the headmodel>>View EEG leadfield vectors>>Scout (on the
% right panel)>>Select the scout you desire/created>>Click
% on the save button (floppy disk) on the right of the
% window Provide the path + filename (.mat)
% scaleUnits - Logical (0|1) whether you want to convert the leadfield
% from Brainstorm V/A-m to microV/nA-m, should be easier to
% work with. Default: 1
% useMm - Logical (0|1) whether you want to the dipole and
% electrode position converted from meters to millimeters.
% Millimeters could be a better option for two reasons.
% Firstly, are used by the other leadfields included in SEREEGA.
% Secondly, plot_headmodel will display the electrode lables
% only when mm are used. Default: 1
% electrode position converted from meters to millimeters.
% Millimeters could be a better option for two reasons.
% Firstly, are used by the other leadfields included in
% SEREEGA. Secondly, plot_headmodel will display the
% electrode lables only when mm are used. Default: 1
% useMNI - Logical (0|1) whether you want to convert from the
% Subject-Coordinate-System (SCS) used in Brainstorm to the
% MNI coordinate system. Note that the plotting functions
@@ -69,7 +76,7 @@
%
%
% Usage example:
% >> lf = lf_generate_frombrainstorm() %To use the default headmodel provided
% >> lf = lf_generate_frombrainstorm() %To use the defaults
% >> lf = lf_convert_frombrainstorm('chanloc', 'my_chanloc.mat', ...
% 't1', 'my_t1_image.mat', ...
% 'headmodel', 'my_headmodel.mat',
@@ -79,26 +86,28 @@
% 'useMNI', 0)

% Function cs_convert and default headmodel provided are part of Brainstorm
% Tadel F, Baillet S, Mosher JC, Pantazis D, Leahy RM (2011)
% Brainstorm: A User-Friendly Application for MEG/EEG Analysis
% Computational Intelligence and Neuroscience, vol. 2011, Article ID 879716, 13 pages, 2011. doi:10.1155/2011/879716
% Tadel F, Baillet S, Mosher JC, Pantazis D, Leahy RM (2011) Brainstorm: A
% User-Friendly Application for MEG/EEG Analysis Computational Intelligence
% and Neuroscience, vol. 2011, Article ID 879716, 13 pages, 2011.
% doi:10.1155/2011/879716
%
% Function readlocs is part of EEGLAB
% Delorme A & Makeig S (2004) EEGLAB: an open-source toolbox for analysis of single-trial EEG dynamics, Journal of Neuroscience Methods 134:9-21. PDF.
% Function readlocs is part of EEGLAB Delorme A & Makeig S (2004) EEGLAB:
% an open-source toolbox for analysis of single-trial EEG dynamics, Journal
% of Neuroscience Methods 134:9-21.
%
% Headmodel created using OpenMEEG
% Gramfort A, Papadopoulo T, Olivi E, Clerc M
% OpenMEEG: opensource software for quasistatic bioelectromagnetics
% BioMedical Engineering OnLine 45:9, 2010
%
% Kybic J, Clerc M, Abboud T, Faugeras O, Keriven R, Papadopoulo T
% A common formalism for the integral formulations of the forward EEG problem
% IEEE Transactions on Medical Imaging, 24:12-28, 2005 | pdf
% 2022-12-03 Daniele Scanzi
% Kybic J, Clerc M, Abboud T, Faugeras O, Keriven R, Papadopoulo T (2005) A
% common formalism for the integral formulations of the forward EEG problem
% IEEE Transactions on Medical Imaging, 24:12-28,
%
% Atlas included: Mindboggle
% Klein A, Ghosh SS, Bao FS, Giard J, Hame Y, Stavsky E, Lee N, Rossa B, Reuter M, Neto EC, Keshavan A. (2017) Mindboggling morphometry of human brains.
% PLoS Computational Biology 13(3): e1005350. doi:10.1371/journal.pcbi.1005350
% Atlas included: Mindboggle Klein A, Ghosh SS, Bao FS, Giard J, Hame Y,
% Stavsky E, Lee N, Rossa B, Reuter M, Neto EC, Keshavan A. (2017)
% Mindboggling morphometry of human brains. PLoS Computational Biology
% 13(3): e1005350. doi:10.1371/journal.pcbi.1005350
%
% Version:
% - First version: 2022/12/03
@@ -112,10 +121,11 @@
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details (https://www.gnu.org/licenses).
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details
% (https://www.gnu.org/licenses).

function lf = lf_generate_frombrainstorm(varargin)

@@ -176,7 +186,7 @@
if ~isempty(bsAtlas)

if ~exist(bsAtlas,'file')
erorr(['SEREEGA:lf_generate_frombrainstorm:fileNotFound ' ...
error(['SEREEGA:lf_generate_frombrainstorm:fileNotFound ' ...
'Could not find the atlas file: %s' ...
'\nMake sure you provided the correct path and filename.\n'], bsAtlas)
else
@@ -431,21 +441,20 @@
end
end

% Old - not necessary anymore

% If there are any empty rows, it is likely that the headmodel is a
% volume headmodel and the atlas does not cover all the posible
% dipoles. Let the user know this.
% if any(cellfun(@isempty,a))
% warning(['SEREEGA:lf_generate_frombrainstorm:' ...
% 'Not all dipoles have an associated atlas label. This could happen when the atlas is made up of scouts that' ...
% 'do not cover all the areas covered by the dipoles. Dipoles not associated with a label will be labelled by default ' ...
% 'as "Brain_CorticalSurface"'])
%
% emptyIdx = find(cellfun(@isempty,a));
% % Brain will be added during the cration of the leadfield
% a(emptyIdx) = {'Unknown'};
% end
if any(cellfun(@isempty,a))
warning([ ...
'Not all dipoles have an associated atlas label.\n' ...
'This could happen when the atlas is made up of scouts that do not cover all the areas covered by the dipoles.\n' ...
'Dipoles not associated with a label will be labelled by default as "Brain_Unknown"'], '');

emptyIdx = find(cellfun(@isempty,a));
% Brain will be added during the cration of the leadfield
a(emptyIdx) = {'Unknown'};
end
end


0 comments on commit bc572c7

Please sign in to comment.