Headmodel with EEG questions

Hello Brainstorm experts

I am attempting source reconstruction with EEG data. I am in the stage to compute the head model right now. I would like to confirm my concerns during the past steps.

My steps from the very beginning:
1: Import BISD dataset
2: Convert DWI to DTI
3: Compute mesh with SimNIBS
4: Align EEG electrode
5: Compute head model

The first issue I observed is that the different space between T1 and FEM mesh. It was noticed when I was trying to align my EEG electrode in Step 4 as shown in the screenshot below. If I understand correctly once I import from the BIDS dataset, there is automated preprocessing for the T1 image and generate head mask and other tissue. Since SimNIBS will do a better job with CAT12 and SPM segmentation, I directly generate the mesh with that. The result of SimNIBS is a 5 layers mesh in the space that is not consistent with the previously generated head mask, so what I did is to extract all the 5 layers first and activate the head mask from the 5 layers for my EEG alignment. I wonder is a correct way of doing it or it is wrong?

The second concern is about the group analysis, I wanted to extract the time series estimated from a specific brain region after the inverse solution. I check the tutorial online, Volume atlases. It seems the atlas can be transformed to the subject space, does that mean I can do this for each subject and then analyze the time series for my group analysis instead of creating a group grid? If I create a group grid, does my FEM mesh(different space issue in Question 1) will be automated coregistered with the template correctly?

The last issue I am considering is the channel number of the head model. Since the head model can be generated independent from EEG recordings, I couldn't tell whether the EEG recording aftering clearning will still keep the same channels. For example, I make the head model based on 256 channels, but cleaned EEG recording may have just 230 channels, would it still work with the head model when estimating the source?

Thank you very much for your answer, if anything is not clear don't hesitate to request. Thanks.

Hi @kenzo0619

Regarding your first issue, where the mesh and head surface are not aligned, we have already faced this issue and we have solved it.

Which version of Brainstorm are you using?

Could you display the mesh and the MRI simultaneously?
You can refer to this section that explains how to do it:
https://neuroimage.usc.edu/brainstorm/Tutorials/tutoFEMadvanced#Visualisation_of_the_FEM_mesh_and_tensors

Have you moved the head surface when you tried to align the electrodes?

Hi @tmedani

Thank you for your reply.

Which version of Brainstorm are you using?

The computer running mesh was using Brainstorm 15-mar-2021 version. Do you think the issue was fixed before that build?

Could you display the mesh and the MRI simultaneously?

I have attached the screenshot with FEM, T1, and the head mask together.

Have you moved the head surface when you tried to align the electrodes?

I do not think I move the head mask during the alignment because this misalignment was observed without any modification with the EEG position.

In addition, there one thing that performed differently in my mesh generation, the external library Simnibs version used was 2.1 due to the low kernel version in my Linux server(Centos 6) that does not support the required library for the newest version of Simnibs. Do you think this would be a potential issue? I am now trying to run just one subject again on my Mac with all things newest to see whether the misalignment still exists.

Previously I tried to create a group grid and then performed the headmodel computation with the FEM mesh I got and I received an error message at the end of computing the leadfield matrix. I have 256 channel + 1 Cz(manually added). Do you think this is caused by the additional electrode I added or because of the misalignment of the mesh with the grid template?

solver.electrode_256.time_rhs_assembly = 0.000281118
solver.electrode_256.linear_system_solver.iterations = 39
solver.electrode_256.linear_system_solver.reduction = 6.72448e-11
solver.electrode_256.linear_system_solver.conv_rate = 0.548493
solver.electrode_256.linear_system_solver.time_solution = 24.4656
solver.electrode_256.linear_system_solver.time = 24.4668
solver.electrode_256.linear_system_solver.time = 24.5075
solver.electrode_256.time_solution = 24.5075
solver.electrode_256.time = 24.5078
Dune reported error: Dune::Exception [findEntityImpl:/Users/juan/projects/bst-duneuro/src/duneuro/duneuro/common/edgehopping.hh:84]: coordinate is outside of the grid, or grid is not convex
"/Users/ken/.brainstorm/plugins/duneuro/bst_duneuro/bin/bst_duneuro_meeg_mac64.app" "/Users/ken/.brainstorm/tmp/duneuro_minifile.mini": Signal 127
status =
   255

Thank you for your time.

Yes, we have fixed this issue on this version.
I can't find what wrong with your data from here.
Could you share the MRI?
I will try to reproduce it, you can deface it using Brainstorm: run > process > import>anatomy > deface MRI> and keep the default value, with Brainsuite.

It could be, but I can't guess, the problem is in the coordinate system and the transformation matrix.

This error appear when you have the cortex nodes (source space) not aligned with the FEM mesh, and I think it's your case,
if you display the FEM mesh and the cortex, you can check it.

A second possible issue is when you have holes in the FEM mesh, in this case, you need to re-mesh the head from the extracted surfaces using iso2mesh option (included in also within brainstorm)
[right click on FEM mesh=> extract surfaces,
then select all the extracted surfaces (hold the shift key)
=> right-click ==> generate FEM mesh => select Iso2mesh, and reduce the maxvol to 0.01 or less.

This will generate a new FEM mesh free from possible mesh holes, then recompute the forward model DUNEuro.

@tmedani is more competent to address the issues related with the coordinate system used in SimNIBS. I'll try to address your more generic questions about the Brainstorm workflow.

It seems the atlas can be transformed to the subject space, does that mean I can do this for each subject and then analyze the time series for my group analysis instead of creating a group grid?

What do you mean with "the atlas can be transformed to the subject space"? What properties are you interested in? How are you planning to do your source analysis?
If you are only interested in specific ROIs that you know how to define for each of your subject, indeed you don't need to have the full source maps available in the template space.

If I create a group grid, does my FEM mesh(different space issue in Question 1) will be automated coregistered with the template correctly?

The FEM mesh stays only at the subject-level.
The correspondence between the subject and the template brain (default anatomy) are only established for the source space (= the points where you estimate the sources = the group grid, which is independent from the tetrahedral meshing of the head tissues).

For example, I make the head model based on 256 channels, but cleaned EEG recording may have just 230 channels, would it still work with the head model when estimating the source?

The forward model ("head model" file in Brainstorm = linear model that gives the value of each electrode independently based on the values of the sources) is estimated for all the electrodes.
When estimating the sources, only the good channels are selected to compute the inverse model. You should get a dialog box asking you to confirm the list of channels to exclude from the source modeling.

1 Like

Hi @tmedani

Thank you for your answer.

Could you share the MRI?

I have rerun it on a Mac desktop with everything newest(Brainstorm, Simnibs). The result now looks good as the FEM mesh is perfectly aligned with T1. I presume the misalignment issue was related to the output from Simnibs version 2.1 Probably it is too old and I also needed to add an additional argument to the command in Brainstorm function process_fem_meshin order to run CAT12 within the external Simnibs process.

This error appear when you have the cortex nodes (source space) not aligned with the FEM mesh, and I think it's your case,
if you display the FEM mesh and the cortex, you can check it.

A second possible issue is when you have holes in the FEM mesh, in this case, you need to re-mesh the head from the extracted surfaces using iso2mesh option (included in also within brainstorm)
[right click on FEM mesh=> extract surfaces,
then select all the extracted surfaces (hold the shift key)
=> right-click ==> generate FEM mesh => select Iso2mesh, and reduce the maxvol to 0.01 or less.

This will generate a new FEM mesh free from possible mesh holes, then recompute the forward model DUNEuro.

The computer is still running, I will try to computer head model later with the correctly aligned FEM mesh. I'd let you know if the problem still exists. Your suggestion is much appriciated.

What do you mean with "the atlas can be transformed to the subject space"? What properties are you interested in? How are you planning to do your source analysis?
If you are only interested in specific ROIs that you know how to define for each of your subject, indeed you don't need to have the full source maps available in the template space.

The steps I am planning are:
1.import BISD
2.generate FEM mesh
3.compute tensor for FEM
4.align EEG positions and compute head model
5.running beamformer to reconstruct the source for specific frequency bands
6.extract time series for volumes based on atlas
7.I would use the extracted time series to perform some other statistical analysis e.g granger causality or other approaches.

In general, I am planning to reconstruct the source space and then extract time series from specific volumes (e.g after source reconstruction, I use AAL atlas to extract time series from the motor cortex).

Since subjects in their subject space after the inverse solution is different from template space(correct me if I am wrong), I was thinking about how I can extract the volume per subject, the solution to me seems to create the group grid so that I can compute the head model in line with the template. Later on, I saw the tutorial in section Volume_atlases, it says Volumes in MNI space can be imported and transformed to the subject space.. Does that mean I can just import atlas(MNI space) then it would be warp to my subject space? In this way, I do not need to create a group grid for my head model computation, right?

Thank you very much for your time and attention.

after source reconstruction, I use AAL atlas to extract time series from the motor cortex

If you are using the entire precentral gyrus from AAL, you need to be aware that this region is very large and may include a lot of different sources. Averaging such large regions can be detrimental to the analysis. (I'm not saying you should not use it this way, just that it could be good to test this approach against smaller/more focal motor ROIs, at least on a few pilot subjects).

Since subjects in their subject space after the inverse solution is different from template space(correct me if I am wrong), I was thinking about how I can extract the volume per subject, the solution to me seems to create the group grid so that I can compute the head model in line with the template.

This is one approach, suggested in the tutorials. Indeed, if you're using a grid of sources that is matching point-to-point with across all the subjects and the template, then you can define your ROI (=volume scout) at the group level, project it to the individual space of each subject, and then run the analysis in subject space. You could even directly average/compare the entire source maps across subjects. Note that with a group grid, you still need to recompute the forward model for each subject separately.
https://neuroimage.usc.edu/brainstorm/Tutorials/CoregisterSubjects#Volume_source_models

Later on, I saw the tutorial in section Volume_atlases, it says Volumes in MNI space can be imported and transformed to the subject space. . Does that mean I can just import atlas(MNI space) then it would be warp to my subject space? In this way, I do not need to create a group grid for my head model computation, right?

This is correct too. Once you have a non-linear MNI transformation computed for the T1 MRI of your subject (using SPM12 or CAT: https://neuroimage.usc.edu/brainstorm/CoordinateSystems#Non-linear_normalization), you can import any MNI-based parcellation into this subject:
https://neuroimage.usc.edu/brainstorm/Tutorials/DefaultAnatomy#MNI_parcellations

The two solutions should give very similar results, as they rely on the same mechanism: the MNI normalization available for the subject. In the first case the source grid is transformed from MNI space to subject space, in the second case an entire volume parcellation is transformed from MNI space to subject space using the same transformation.
However, I think the first option (the group grid) provides more capabilities for additional analyses (comparing directly the entire source maps) with almost no extra work.

But maybe there is some extra complexity that I don't picture precisely at the moment?
The best solution for you to gain confidence in your results is maybe be to compare the two approaches for a few pilot subjects and observe that the differences are marginal. If they are not, there is an issue somewhere.

PS:
I've just added a missing link between the volume parcellations and the source analysis.
Now they can be imported directly as volume scouts.

Documentation: https://neuroimage.usc.edu/brainstorm/Tutorials/TutVolSource#Volume_atlases
Commit: https://github.com/brainstorm-tools/brainstorm3/commit/2ca2cd7bcd24fa4c9588e460b84991c8d57e183b

1 Like

Hi @tmedani

I have attempted to extract the surface and remesh it with ISO2MESH, however, I got error Tetgen command failed. which triggered in surf2mesh.m (line 110-119 as below)

The cmd output is

cmdout =

'Opening C:\Users\Ken\.brainstorm\tmp\post_vmesh.poly.
 Delaunizing vertices...
 Delaunay seconds:  4.321
 Creating surface mesh ...
 Surface mesh seconds:  0.824
 Constrained Delaunay...
 Constrained Delaunay seconds:  4.203
 Removing exterior tetrahedra ...
 Spreading region attributes.
 Exterior tets removal seconds:  0.714
 Refining mesh...
 Error:  Out of memory.
 '

So, it says out of memory, do you have any idea how to overcome it? thanks

Hi @kenzo0619,

Which value are you using for the "maxVol"?

Could you try with a lowest value?

Hi @tmedani

I have tried from 0.01, 0.001, 0.0001, the error is the same. The running platform is windows 10 with newest brainstorm version. However, the same data on Mac is not reported but I received another error after the process as shown in the screenshoot.

Screen Shot 2021-05-19 at 9.36.47 AM

The first error is related to the tetgen binaries on windows,
this needs more investigation on the version, we will check it with Iso2Mesh.
The second error on mac is at the Brainstorm level, tetgen is working, however, the model finds 6 tissues instead of 5, there is one extra tissue!
Could you share the data then I can check it?

Hi @tmedani

Could you share the data then I can check it?

I have sent you a link via private messege, check it please. I defaced the subject. This is the subject I was trying to do FEM mesh and headmodel with template 256 channel position. I have attempted all the methods for mesh but get error messages in head model computation.

For the second error, this was observed with SimNIBS mesh, I have noticed it in process_fem_mesh.m. @Francois May I know which layer index shall I drop ?

@kenzo0619 just checked your data,
could you please share the surfaces that you use by surf2mesh instead of the defaced MRI?
it's much easier and fast for to reproduce it.

Also, for the FEM computation, it's recommended to deface MRI with the Brainsuite option, which keep the skull safe.
from the process box => run => import => import anatomy => deface MRI ==> keep the default values for Brainsuite option.

Hi @kenzo0619,

could you change on your computers (both windows and mac) this line

       [node,elem] = surf2mesh(newnode, newelem, min(newnode), max(newnode),...
            OPTIONS.KeepRatio, factor_bst .* OPTIONS.MaxVol, regions, [], [], 'tetgen1.5');

to

[node,elem] = surf2mesh(newnode, newelem, min(newnode), max(newnode),...
OPTIONS.KeepRatio, factor_bst .* OPTIONS.MaxVol, regions, [], []);

just remove the ''tetgen1.5'' arguments?

you can find it in the function process_fem_mesh at line 423

and run it again, then let us know what you get

HI @tmedani

Thank you for your quick response, on WIN10 the error is: FEMmesh

I will update Mac result tomorrow.

1 Like

Ok, thanks for checking it,
now the results are here and need to be adapted for Brainstorm.
I "believe" that the label zero should be 1, you can correct it locally for your data and we will improve the code soon.
so, you need to add this code at line 434
elem(elem(:,5)==0,5) = 1;
this will correct your error.

@Francois we may need to come back to the previous version of "process_fem_mesh"?
and use "try-catch" with the different OS and version of tetgen?
and we should report this to iso2mesh as well.

Hi @tmedani

For windows, I have tried what you suggested(change index 0 to 1 in the 5th dimension of elem array). After I get the new mesh(isomesh), i tried to compute headmodel with 256 channel template position. The previous error in channel computing is not appeared but the same error is observed in the dipole localization as you can see:

solver.electrode_1.time_rhs_assembly = 0 
solver.electrode_1.linear_system_solver.iterations = 58 
solver.electrode_1.linear_system_solver.reduction = 3.1791e-011 
solver.electrode_1.linear_system_solver.conv_rate = 0.659182 
solver.electrode_1.linear_system_solver.time_solution = 36.161 
solver.electrode_1.linear_system_solver.time = 36.161 
solver.electrode_1.linear_system_solver.time = 36.2079 
solver.electrode_1.time_solution = 36.2079 
solver.electrode_1.time = 36.2079 
……
……
……
solver.electrode_256.time_rhs_assembly = 0 
solver.electrode_256.linear_system_solver.iterations = 49 
solver.electrode_256.linear_system_solver.reduction = 8.8898e-011 
solver.electrode_256.linear_system_solver.conv_rate = 0.623556 
solver.electrode_256.linear_system_solver.time_solution = 29.3474 
solver.electrode_256.linear_system_solver.time = 29.363 
solver.electrode_256.linear_system_solver.time = 29.3943 
solver.electrode_256.time_solution = 29.3943 
solver.electrode_256.time = 29.3943 
dipole_0.density = sparse 
dipole_0.time = 0 
dipole_1.density = sparse 
dipole_1.time = 0 
……
……
……
dipole_104.density = sparse 
dipole_104.time = 0 

Dune reported error: Dune::Exception [findEntityImpl:/home/juan/bst-duneuro/src/duneuro/duneuro/common/edgehopping.hh:84]: coordinate is outside of the grid, or grid is not convex 

status =
-1

It seems that you have discussed the issue last year with duneuro team from here but the solution was not found. Do you have any idea on this?

For mac, after remove the argument tetgen1.5, the error is shown below, I thought I could do the same as you suggested, so I reordered 4 5 6 to 3 4 5. The plot color does not seem to be correct, what do you think?
Screen Shot 2021-05-21 at 10.35.38 AM

Both Win10 and Mac ended with the dipole error specifically dipole 104 in headmodel computation. I tried using a different electrode template(e.g EGI 128 or 10-10 system 77), the error remains the same.

Hi @kenzo0619

I may recommend to fixe this issue locally, you need to check the labels one by one by displaying them one by one,
you can use this line

figure; plotmesh(node(:,1:3), elem(elem(:,5)==ID),:);

you need to vary the ID with 1, 2, 4, 5, and 6.
then you need to identify each tissue from the displayed figure, then you need to re-arrange the labels manually (wm=1, gm=2, csf=3, skull=4 and scalp =5).

We are working on a better version,