Open mdovgialo opened 3 months ago
Interesting problem:
Electrode Fp2_L2 - deep in the brain, correction field:
Fp2_L1 - shallow in the brain
Fp2 - 1 mm in the scalp tissue:
The solution is spherically symmetrical almost perfectly!
If you play with colors and contrast you can BARELY see a border:
This could explain why 10-20 scalp electrode kCSD and kESI solutions are basically identical!
Need to check the potential...
trying different electrode depths
4 spheres model, 0.005 max element size
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
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.
Using scalp electrodes at 88mm close to the internal layer of the mesh, creates "better" correction:
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.
Should come back to this after solving image-to-mesh problem and trying out on some realistic meshes.
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:
kCSD:
kESI - kCSD:
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:
Maybe 3 spheres with these electrodes is just too symmetrical? Maybe worth trying on a realistic model??
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
MFEM solution, 4 spheres model, with grounding plate on the bottom of air volume, all volumes have 0.33 conductivity:
MFEM solution 4 spheres model, realistic conductivities:
After some refactor of signal generator, implementing very basic point dipole, some testing of forward modelling using MFEM in 4 spheres model:
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_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
Slice along Z axis at X, Y = (0, 0)
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
Higher contrast:
point_dipole_mfem_4sph
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
Higher contrast
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
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
(blue and orange are merged)
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)
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??
Point source solutions
As we can see, potential shrinks when conductance increases
Current MFEM solution is opposite!
Similar with dipoles:
kCSD point dipole:
Analytical point dipole:
kESI point dipole:
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:
4 shpere edge:
Intermediate part has good corcondance with free space dipole:
kESI forward sim with a point source breaks down at sigma > 0.7?
kESI vs kCSD, monopole
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
[x] 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...
[x] 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.[x] 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...
[x] 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!
[x] 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