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

kESI experiments on 4 spheres models #20

Open
5 tasks done
mdovgialo opened this issue Jun 11, 2024 · 14 comments
Open
5 tasks done

kESI experiments on 4 spheres models #20

mdovgialo opened this issue Jun 11, 2024 · 14 comments
Assignees

Comments

@mdovgialo
Copy link

mdovgialo commented Jun 11, 2024

Todo:

From #17 we now have forward solver for point sources - electrodes and arbitrary meshes. But it seems to work correctly only for 4 spheres meshes in vaccuum

  • scalp electrodes are weird!!!
    need to try with higher resolution meshes, deeper scalp electrodes, scalp electrodes have wrong correction...
    might need to do local mesh refinement, or add real electrodes in the mesh. That will not change long range interactions... Most likely spherical symmetricity of the 4 spheres scalp electrodes is just homogeneous enough to be kCSD solveable...

  • Check how exactly leadfield correction is used, should it really be the difference between analytic and FEM solution? Or was it all just a FEM solver trick to soften singularities.
    looking at the solve_sphere_on_plate.py and it's imports it seems the correction potential saved by the FeNiCs solver is u - u_inf, which is exactly what I'm doing in MFEM.

  • Check for analytical 4 spheres solution? Calculate leadfields using analytical model? Useful link https://github.com/Neuroinflab/fourspheremodel
    kESI project has a working version for point dipoles only, can't compare with electrodes, and can only sample the potential "above" the dipole position...

  • compare dipole solution analytical/numerical
    in numerical I cannot really create a point dipole, only a dipole with some existing size, unless maybe I try implementing my own point Dipole based on DeltaCoefficient??? 2 super close delta coeffs!

  • experiment with multilayered depth 10-05 electrodes on four spheres
    had to optimise solution storing, and need to fix scalp electrodes

https://github.com/Neuroinflab/kESI/tree/dev/20_experiments_with_4_spheres

@mdovgialo mdovgialo self-assigned this Jun 11, 2024
@mdovgialo mdovgialo changed the title kESI leadfield debugging kESI leadfield debugging/trying analytical model Jun 14, 2024
@mdovgialo mdovgialo changed the title kESI leadfield debugging/trying analytical model kESI experiments on 4 spheres models Jun 18, 2024
@mdovgialo
Copy link
Author

mdovgialo commented Jun 20, 2024

Interesting problem:

Electrode Fp2_L2 - deep in the brain, correction field:

Image

Fp2_L1 - shallow in the brain

Image

Fp2 - 1 mm in the scalp tissue:

Image

The solution is spherically symmetrical almost perfectly!

If you play with colors and contrast you can BARELY see a border:

Image

This could explain why 10-20 scalp electrode kCSD and kESI solutions are basically identical!

Need to check the potential...

@mdovgialo
Copy link
Author

trying different electrode depths

Image

4 spheres model, 0.005 max element size

Image

Correction (v_kesi - v_kcsd)

Seems like electrode position in respect of mesh vertices matters a lot for the correction. I guess this is the singularity problem

Image

But also, I think there is not enough accuracy in the mesh around electrodes. Feel like the best way to solve it is to use MFEM dynamic refinement, or add real, physical electrodes as mesh elements.

@mdovgialo
Copy link
Author

mdovgialo commented Jun 21, 2024

Using scalp electrodes at 88mm close to the internal layer of the mesh, creates "better" correction:

image

But the kESI Eigensources and solution is still almost exactly the same as kCSD, except of some small differences. My guess it's because we increased the accuracy of local sampling around electrode, but the long reaching "visibility" stays the same.

@mdovgialo
Copy link
Author

Should come back to this after solving image-to-mesh problem and trying out on some realistic meshes.

@mdovgialo
Copy link
Author

mdovgialo commented Jun 27, 2024

Trying to solve 3 layered 10-05 system, kCSD and kESI eigensources still look pretty much identical.

10-05_layers_eigenvectors.webm

Solutions (ground truth is overlaid) of 4 spheres with a dipole, red circles are electrodes:

kESI:

image

kCSD:

image

kESI - kCSD:

Image

The difference exists, it doesn't seem to be a numerical noise, but CSD solution is on a scale between [-4000; 4000] units, and the difference is between [-0.005; 0.005] units, so it's basically a few parts per million, and is mostly around the ground truth and borders. So the kESI might influence the solution a bit, in this spherical case.

potential:

image

Maybe 3 spheres with these electrodes is just too symmetrical? Maybe worth trying on a realistic model??

@mdovgialo
Copy link
Author

mdovgialo commented Jul 16, 2024

Potential from point CSD in the center and top of the 4 spheres,

Horizontal - Z axis in meters.

Fully analytical solution in infinite 0.33 conductivity space
anal_potential_homogenious

MFEM solution, 4 spheres model, with grounding plate on the bottom of air volume, all volumes have 0.33 conductivity:
mfem_potential_homogenious

MFEM solution 4 spheres model, realistic conductivities:
mfem_potential_4spheres

@mdovgialo
Copy link
Author

mdovgialo commented Sep 11, 2024

After some refactor of signal generator, implementing very basic point dipole, some testing of forward modelling using MFEM in 4 spheres model:

Dipoles

Sphere radii in meters: brain, csf, skull, scalp: 0.079, 0.082, 0.086, 0.09
Sphere conductances: 0.33, 1.65, 0.0165, 0.33, 1e-10 (last one - air is only used in mfem, analytical model doesn't have it)

Slice along Z axis at X, Y = (0, 0)

image

image

point_dip_mfem_4sph

source_type	x	y	z	ori_x	ori_y	ori_z	sepera	size	frequency	phase			moment
dipole		0	0	0	0		1	NAN	NAN	76		5.60024664008999	100

gauss_dip_mfem_4sph

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			amplitude
dipole		0	0	0	0	0	1	1		3	67		6.23679640668398	100

gausss_dip_kcsd.nii.gz

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			amplitude
dipole		0	0	0	0	0	1	1		3	67		6.07443711518915	100

Monopoles

Slice along Z axis at X, Y = (0, 0)

image

image

gauss_mon_kcsd

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			amplitude
monopole	0	0	0						1	70		4.12748723235593	100

gauss_mon_mfem_4sph

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			amplitude
monopole	0	0	0						1	70		3.23643567590633	100

point_mon_mfem_4sph

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			amplitude
monopole	0	0	0						1	80		0.796161017437315	100

Point Dipole MFEM vs Analytical 4 sphere model

Horizontal

image

image

Higher contrast:

image

image

Vertical

Slice

point_dipole_mfem_4sph

image

image

image

Something is weird with how layers react??

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			moment
pointdipole	0	0	30	0	0	1	None		None	76		1.39303222062097	100

point_dipole_anal_4sph

source_type	x	y	z	ori_x	ori_y	ori_z	seperation	size	frequency	phase			moment
pointdipole	0	0	30	0	0	1	None		None	76		2.27378002952686	100

3D view

image

image

Higher contrast

image

image

@mdovgialo
Copy link
Author

mdovgialo commented Sep 13, 2024

Small experiments with dipoles

4 spheres dipoles, real spheres

Sphere radii in meters: brain, csf, skull, scalp: 0.079, 0.082, 0.086, 0.09
Sphere conductances: 0.33, 1.65, 0.0165, 0.33, 1e-10 (last one - air is only used in mfem, analytical model doesn't have it)

Slice along Z axis at X, Y = (0, 0)

point dipol 4 spheres analytic vs point dipole free space vs point dipole mfem 4 spheres

Image

Image

4 spheres dipoles, shperes set to homogeneous

Sphere radii in meters: brain, csf, skull, scalp: 0.079, 0.082, 0.086, 0.09
Sphere conductances: 0.33, 0.33, 0.33, 0.33 , 0.33

Image

Image

Image
(blue and orange are merged)

Point source, 4 spheres homogeneus + optional last element as air

Sphere radii in meters: brain, csf, skull, scalp: 0.079, 0.082, 0.086, 0.09
Sphere conductances: 0.33, 0.33, 0.33, 0.33, 1e-10 (last one - air is only used in mfem, analytical model doesn't have it)
alternatively Sphere conductances: 3, 3, 3, 3, 1e-10 (last one - air is only used in mfem, analytical model doesn't have it)

Image
Image
Image
Image

kCSD - free space solution (had to rescale it x10 for some reason... something with normalisation??? It's correct for point sources when calculating electrodes...)

Something doesn't work... sigma 3.0 kCSD fits sigma 0.33 MFEM, sigma 0.3 kCSD fits 3.0 MFEM??

@mdovgialo
Copy link
Author

MFEM problem with conductances parameter

  • analytical 4 shperes - all spheres have identical conductance param
  • kCSD - as usual
  • mfem - all mesh materials have identical concuctance

Point source solutions

monopole_kcsd

As we can see, potential shrinks when conductance increases

Current MFEM solution is opposite!

monopole_kesi

Similar with dipoles:

kCSD point dipole:

dipole_kcsd

Analytical point dipole:

dipole_analytic

kESI point dipole:

dipole_kesi

Conductance relationship is reversed!

4 Sphere solution vs kCSD solution also have some differences, on the edge of the spheres and just above the defined depth

Overall:

image

4 shpere edge:

image

Intermediate part has good corcondance with free space dipole:

image

@mdovgialo
Copy link
Author

kESI forward sim with a point source breaks down at sigma > 0.7?

kESI vs kCSD, monopole

monopole_kesi_0 33

monopole_kesi_0 55

monopole_kesi_0 66

monopole_kesi_0 77

@mdovgialo
Copy link
Author

mdovgialo commented Oct 11, 2024

After some fixing:

4 shpere model, with realistic conductivities, MFEM 4 spheres in air with ground electrode in the base of the spheres:

mfem shpere mesh with 5 mm elements

image

image

image

@mdovgialo
Copy link
Author

After some fixing:

4 shpere model, with realistic conductivities, MFEM 4 spheres in air with ground electrode in the base of the spheres:

mfem shpere mesh with 5 mm elements

image

image

image

@danek8317

@mdovgialo
Copy link
Author

I think I've managed to fix the big mesh saving issue, and make it faster too!

Here's results for 2mm maximum element size mesh:

image

image

image

@mdovgialo
Copy link
Author

mdovgialo commented Oct 11, 2024

TODO:
Use this model https://github.com/Neuroinflab/fourspheremodel/blob/master/CalcPotential4Sphere.py - it should be able to sample beneath the dipole.
Test different conductivity values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant