Duneuro FEM doesn't finish

Dear brainstorm-team,

I am currently trying to use the duneuro FEM-modeling and I used different methods in order to compute the mesh. For the 3 layer model (iso2mesh), i can compute a leadfield, however for the 5 layers (brain2mesh and fieldtrip), the computation of the lead field somehow doesn't seem to converge. I am currently running a computation for the fieldtrip-mesh (without the shift of the nodes) for EEG data (around 60 electrodes) with the default settings from brainstorm. I don't know how long it is supposed to take, but it has been running for over 20h now and I still don't have a result. Is there anything I should consider? :slight_smile:

Best
Yvonne

@tmedani @juangpc ?

1 Like

Hi @yvonnebuschermoehle,
Depending on the number of cells defined in your model, the FEM computation can be, unfortunately, quite time-consuming. Or perhaps there is an error in the mesh or in the dipole definition that hangs the application for some reason. It is difficult to say.

Please take into account that this feature is still under development. I will try to add a feature to better update the user of whatever is going on with the computation, so that at least you know what is going on.

Take care,

Hi @yvonnebuschermoehle,

I agree with Juan, it can take a long time and it could be also an error somewhere.
For the time, it depends on the resolution of your mesh, the number of electrodes, and the size of the source space (for some FEM source model).

From our testings, for SimNibs mesh with ~80 electrodes, it can take up to 2/3 hours, depending on the performance of your computer.

Could you share the content of the tmp folder data, and also the mesh from brainstorm (right-click export to Matlab, and save as mat format), then we can check it.

Best,

Dear @juangpc, dear @tmedani,

Thank you for your kind replies! A little update on the computation: I let it run over the weekend (more than 4 days in total), and it didn't work, so I assume there is a problem, since I think my mesh is not too big (136611V). Here you find the tmp folder data and the mesh (i hope this is the correct folder data - if not, please let me know!). I also added a screenshot of the matlab output I received when I stopped the computation, in case that is in any way helpful.

https://uni-muenster.sciebo.de/f/1935227606

I will also now start to get simnibs running and keep you posted on the results :slight_smile:

All the best from Münster and thanks again,
Yvonne

1 Like

So I have now computed the Simnibs mesh and I succeeded in computing the head model for EEG, that's great (it only took approximately 1h I'd say!) :slight_smile: However, with MEG data it now aborts with the information "Unknown exception thrown" - do you have an idea what the reason could be that MEG doesn't work?
I thought it might be the larger amount of channels, so I tried to reduce the number of MEG-channels to only 2 (just to see if it works), but I am not quiet sure if I manipulated the corresponding files correctly (I exported them to matlab and deleted some columns, it looked good when I imported it back), since I then got the error "coordinate is outside of the grid, or grid is not convex".
Any help is highly appreciated! :slight_smile:
P.S. I know that this is all still under construction and that this is a lot of work, so please feel free to stop me, if I am trying to run or asking too much about things, that are not supposed to be properly running yet :slight_smile:

1 Like

Hi @yvonnebuschermoehle ,
Please keep this post and do not remove it, it will be useful later for other users.

The first error is related to the high cash memory that Duneuro requires for the computation. There is a flag that should be deactivated, we will add it asap.

The second error is related to two possible errors:
-1- the source space or the localization of your dipoles are outside of the GM or the Brain.
-2- there are possible holes in the mesh, this is mainly in the skull and need to be fixed.

We are working to solve both of these problems.

What you can test right now, is to select the option "Force inside the xx" on the DUNEuro panel

Let us know the results.

Best,
Takfarinas

Hey Takfa,

Thanks for the advice! Two questions regarding your answer:

If that's the case - how would that happen and is there anything I could do to prevent it?

If this is the case - wouldn't it also be a problem for my EEG head model or is that only an MEG problem?

I followed you advied and tried to force the dipoles inside the gray matter, here is the output I got:

Do you have an idea what this results from? :slight_smile:

Hey Yvonne,

Visually, the fast way is to display the cortex and the mesh, and then check if the cortex is totally inside the GM volume, similar process with the WM
Here is an example of a bad dipole location:


in red is the cortex surface (dipole locations) and in gray the surface of the GM.

The requirement for the FEM (also for the other method) is to have the neural source within the GM. FEM is more complex since there are different source models.
If you don't there is a high chance that the solution is not correct.

Practically, to prevent this problem, you need to use the option "force inside ... ", with this, all the dipole outside the GM are moved slightly to their nearest centroids of the GM element and ensured to be within the GM

The other solution, is highlighted by the second option "Shrink source space" by xx mm, in this case, the cortex surface is "deflated?" or shrined by xx mm inward following the normal direction for each vertex.
You can use both these options together and then save the FEM source space if you want to check it.

indeed, you are right, we are checking this issue with Christian/Carsten.
Right now, we think that a random initialization of the process is applied and then it can work in some cases ... if you are lucky :slightly_smiling_face:

We are going to fix this asap.
The other solution is to mesh the air bubbles inside the skull that are the reason for this error.

This is weird, which version of Brainstorm do you have (date of your last update)?

What is the size of the cortex and the FEM mesh that you are using?

Maybe I need to reproduce this error with your data.

Let me know, otherwise, I need to check it with your dataset :slight_smile:

Best,
Takfarinas

Cher Takfa,

Here you see my mesh with the cortex (it's not the exact same one as in the last error I posted, but it leads to the same error):

  1. GM (gray) and cortex (red) - basically no red spots except the spinal cord, which I assume is due to the fact that I cut the neck of the mesh. Do you think that might be problematic? If yes, is there an easy way to also cut the cortex also?

  2. WM (white) and cortex (red) - no white spots visible

So to me it looks quite good! However, if I use this mesh and say "force source space inside layer gray", it says that all dipoles are outside the gray matter. If I additionally "shrink the source space" by 1mm, I (as expected) get kicked out at the "unknown exception thrown"-error you explained as the cache problem, so this step seems to be neccessary (which doesn't make sense to me, because as the pictures show, the dipoles should be in the GM).
I am updating brainstorm every morning before starting working with it, so it's always up to date :wink:
Unfortunately I forgot to check the exact size of the mesh before I left the office today (I don't think it's too big, I used the SimNibs default parameters), but I'll provide it first thing tomorrow morning together with the data for you to reproduce the error, if you don't have other ideas what I could try :slight_smile:

1 Like

here the completion: my mesh has 1019154V and the cortex 132694V. You find them as .mat files here: https://uni-muenster.sciebo.de/s/4P55ynaeKG0iaZL

1 Like

Hi Yvonne,

It seems that both files that you shared contain the same data which is the fem_cortex.

Could you please check again.

Thanks

Indeed, I am sorry! I fixed it, you can use the same link! :slightly_smiling_face:

Hi Yvonne,

Thanks to the data, I'm able to check some parts of it.

I think there are some points that we need to documents better for FEM modeling.
If I'm right, you are using the fem_cortex as the default cortex?

One of the major issues of the FEM is the definition of the position of the dipoles, and the common approach is to use the cortex surface where each node is one dipole.
For all methods, the dipoles should be in the inner layer (sphere model, BEM...), which is, in most cases, the brain layer.
For the FEM is more complex, in the case where the WM and the GM are separated, all the dipoles should be within the GM layer and outside of the WM.

The fem_cortex is just the cortex's outer layer, and we do not recommend you to use it as the default cortex; we should add more explanation for this part.

I recommend you, for now, to use the cortex generated by spm/cat, which is also available after the simnibs computation. This cortex has ~15000 nodes, and most of them (>70%) are within the GM.
The rest of the dipole could be forced to be inside by the previous option "force inside GM"

I will check the second part of the error asap.

A+

Merci @tmedani, for the explanations!
I also added the two SPM-surface files to the folder in the link (higher and lower resolutions). I end up with the same error though. The problem seems to be the "forcing into gray matter" function, because it only occurs when I activate this option. Also I have the impression that the "numbers of dipoles outside of GM" that you get as output is always extraordinarily high (eg around 14500 outside GM from 15000). Estimating the numbers from the visualization, I would expect those numbers to be reverse.

Best,
Yvonne

1 Like

Hi Yvonne,
I'm checking your data and I can't reproduce your error, all is working correctly.
Here is the view of the cortex 15000 and the GM, where it seems most of the cortex is inside the GM,

When I run the compute the head model with duneuro and option 'force within gm', it works without errors
image

there are 105 dipoles outside GM and 455 inside WM (>95% of your dipoles are ~good)

Are you sure that you highlighted the correct FEM head model and the correct cortex that is using?
you have to check is they are displayed with green color

Also, you need to check if you are using the last version of Brainstorm, without any other copies in your MatLab path.

Could you check again.

Best,
Takfarinas

1 Like

Dear @tmedani,

Thanks for checking! Did you try to compute the MEG head model here? Because what you find ("105 dipoles outside of GM, 455 inside the WM"), I only find when computing the EEG head model. However, when choosing MEG, it results in the above mentioned problem, that the dipoles can not be forced inside the GM and basically all of them are located outside the GM.
I triple checked, that I chose the correct cortex and FEM-Model and I my brainstorm version is also up to date, so that should not be the problem.

Best,
Yvonne

Hi @yvonnebuschermoehle

I guess that for the MEG you are keeping only the "white" in the panel as in this picture?

image

Then you ask to force inside the GM, but the "gray" is not included in the list of layers.

In order to avoid this error you need to select a least the "gray", but I recommend to three first layers (gm, wm and csf)
[or just select all the of them, it will be good if you can check if any difference in the results later].

Let me know if this is working.

Best,
Takfarinas

1 Like

Good Morning @tmedani,

This indeed was the problem - I thought I'd keep it simple for now by not changing the defaults, but it makes sense that I have to include the gray layer here. Great! :slight_smile: Now the computation stops as before with the "unknown exception thrown" error as discussed, so I'll wait until you have fixed the memory issue.

Thank you for you support!

Best from Germany,
Yvonne

1 Like

Great,

we will update it soon.

In meantime, you can try to fix it locally on your computer:
open the bst_duneuro.m function on you Matlab,

and at line 391, add these two lines

...
fprintf(fid, 'type = %s\n', cfg.MegType);
cfg.MegCacheEnable = 0; % <=== this one 
fprintf(fid, 'cache.enable = %s\n',bool2str(cfg.MegCacheEnable) ); % <=== this one and this one 
% [coils]
fprintf(fid, '[coils]\n');
 ....

Then save it,
with this, there is a high chance that you can compute your MEG forward problem.

Let us know how it's going.

Best,
Takfarinas