Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with dipole scan + EEG precomputed leadfield #2188

Closed
mcpiastra opened this issue Feb 10, 2023 · 4 comments · Fixed by #2339
Closed

error with dipole scan + EEG precomputed leadfield #2188

mcpiastra opened this issue Feb 10, 2023 · 4 comments · Fixed by #2339
Assignees

Comments

@mcpiastra
Copy link
Contributor

mcpiastra commented Feb 10, 2023

hi, I have been trying to compute a dipole scan with an EEG pre-computed leadfield and timelocked data.
This is the code I used for the dipole scan:

input_fem = [];
input_fem.time = 1;
input_fem.label = avg_787.label;
input_fem.elec = elec_787;
input_fem.avg = avg_787.avg;

cfg_dipfit = [];
cfg_dipfit.numdipoles   = 1;                              
cfg_dipfit.headmodel    = [];
cfg_dipfit.sourcemodel  = lf_787;
cfg_dipfit.gridsearch   = 'yes';                           
cfg_dipfit.nonlinear    = 'no';
cfg_dipfit.elec         = elec_787;                           
cfg_dipfit.latency      = 0.01;                               
cfg_dipfit.channel      = 'EEG';
cfg_dipfit.reducerank   = 'no';

dipfit              = ft_dipolefitting(cfg_dipfit,input_fem);

where avg,elec,lf_787 are the timelocked data, elec file and leadfield for dataset 787, resp.

The error:

Unrecognized field name "cond".

Error in eeg_infinite_dipole (line 50)
cond     = vol.cond;

Error in ft_compute_leadfield (line 488)
      lf = eeg_infinite_dipole(dippos, sens.elecpos, headmodel);

Error in ft_dipolefitting (line 578)
      lf = ft_compute_leadfield(dip.pos, sens, headmodel,
      leadfieldopt{:});

Error in show_results_787 (line 83)
dipfit              = ft_dipolefitting(cfg_dipfit,input_fem);

is given by the fact that after identifying the dipole with minimum error (ft_dipolefitting line 497), the leadfield is computed again in ft_dipolefitting line 578, where the headmodel is assigned to be "infinite", instead of retrieving the leadfield that is already computed.

@mcpiastra
Copy link
Contributor Author

after discussing it with @schoffelen, I will make some changes in my local fork and see if I can fix it locally.
The idea would be to copy the corresponding leadfield along with the dipole that gives the minimum error, so that this leadfield can be reused in line 578 for the "compute the model potential distribution and the residual variance".

@mcpiastra
Copy link
Contributor Author

I do not know how to change the label btw

@schoffelen
Copy link
Contributor

Indeed, just to add some info:
The context is to perform ft_dipolefitting on FEM-precomputed leadfields. The only sensible approach is then to use cfg.gridsearch = 'yes', and cfg.nonlinear = 'no'

Yet, irrespective of whether cfg.nonlinear was yes or no, the final solution will be computed by a call to ft_compute_leadfield, given the optimal dipole parameters. This is impractical in the context of a FEM headmodel, since it will require a lengthy re-computation. Hence MC's workaround to add an empty headmodel to ft_dipolefitting. This - in the context of EEG - leads to a low-level error, since an infinite volume conductor for EEG expects a conductivitiy to be specified.

The idea thus is to add to the (intermediate) dip structure the (possibly already precomputed) leadfield corresponding to the optimal solution during the gridsearch, which allows a bypass of the re-computation of the leadfield in the final part of the code. Clearly, the leadfield corresponding to the optimal grid point(s) will need to be removed if cfg.nonlinear = 'yes'.

@mcpiastra
Copy link
Contributor Author

I created a pull request #2339
The corresponding leadfield mentioned above was already saved at line 420 in the variable lf, now the code will check if the variable lf exists or not, and recompute the leadfield only if lf does not exist.

@schoffelen schoffelen linked a pull request Jun 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants