Fit Dipoles on a given source space location through code

Hello @Francois,

I have the coordinates of the source location for my subject's brain, and I wish to fit a dipole of a given magnitude and direction on a few of the sources and look at the forward solution.' I want to do it iteratively for around a 100 source locations, so I don't want to do it with the GUI( using dipole simulator) but rather do it by scripting where I manually enter the source location coordinates and dipole magnitude and orientation to look at the result in sensor space( topography map). Could you help with that? How can I fit dipoles at a given source location and look at the response at the sensor level?

A code that does the same would be of great help, please let me know.

Hi @SubratBastola,

You can create a script to automate that. The simplest way will be to create once the pipeline to simulate a dipole, but do not Run it. The pipeline will look similar to this one:

Then, make it a script with the button :

And add the FOR loop generate the 100 dipoles programatically.
See this example: Brainstorm: Programatically generate 10 dipoles changing: simulated signal and dipole location ยท GitHub

Note you will need to remove the fields 'meg', 'eeg', 'ecog', 'seeg', IF they are empty, i.e, ' '.


Hi @Raymundo.Cassani, could you help me with how to generate a script for a scenario like mine. I have a very limited knowledge of scripting on MATLAB.

Unfortunately, we do not have the necessary resources to help you write your simulation scripts - this is a research work in itself.
The purpose of this forum is to help with the use of the Brainstorm software.
To get training or help with Matlab programming, please refer to tutorials or forums that are dedicated to this purpose.

Hi @Francois , I got this error when trying to load the topography from my simulated recording.

In view_timeseries (line 273)
In tree_callbacks>@(h,ev)view_timeseries(filenameRelative,AllMod{iMod},[],'NewFigure') (line 1372) 
Warning: Imaginary parts of complex X, Y, and/or Z arguments ignored 
> In figure_timeseries>PlotGFP (line 3838)
In figure_timeseries>PlotAxesButterfly (line 3604)
In figure_timeseries>PlotAxes (line 3286)
In figure_timeseries>PlotFigure (line 2984)
In figure_timeseries (line 39)
In view_timeseries (line 273)
In tree_callbacks>@(h,ev)view_timeseries(filenameRelative,AllMod{iMod},[],'NewFigure') (line 1372) 
Error using
Error setting property 'FaceVertexCData' of class 'Patch':
Complex values are not supported.

Error in bst_figures (line 60)

Error in figure_timeseries>@(h,ev)bst_figures('ViewTopography',hFig,1) (line 2265)
        jItem = gui_component('MenuItem', jPopup, [], 'View topography', IconLoader.ICON_TOPOGRAPHY, [], @(h,ev)bst_figures('ViewTopography', hFig, 1));

How can I solve it?

You have complex values in your files, you need to find how that happened and fix your scripts.

For each new problem, please create a new topic on the forum.