import openmeeg as om
## Load data
geom = om.Geometry()
geom.read(‘head_model.geom’, ‘head_model.cond’)
dipoles = om.Matrix()
dipoles.load(‘cortex_dipoles.txt’)
meg_sensors = om.Sensors()
meg_sensors.load(‘meg_channels.squids’)
eeg_electrodes = om.Matrix()
eeg_electrodes.load(‘eeg_channels.txt’)
int_electrodes = om.Matrix()
int_electrodes.load(‘internal_electrodes.txt’)
## Assemble matrices
gauss_order = 3
use_adaptive_integration = True
hm = om.HeadMat(geom, gauss_order)
hminv = hm.inverse()
dsm = om.DipSourceMat(geom, dipoles, gauss_order, use_adaptive_integration)
# For EEG
h2em = om.Head2EEGMat(geom, eeg_electrodes)
# For MEG
ds2mm = om.DipSource2MEGMat(dipoles, meg_sensors)
h2mm = om.Head2MEGMat(geom, meg_sensors)
# For EIT (using the same electrodes as EEG)
eitsm = om.EITSourceMat(geom, eeg_electrodes, gauss_order)
# For Internal Potential
iphm = om.Surf2VolMat(geom, int_electrodes)
ipsm = om.DipSource2InternalPotMat(geom, dipoles, int_electrodes)
## Compute leadfiels
eeg_leadfield = om.GainEEG(hminv, dsm, h2em)
meg_leadfield = om.GainMEG(hminv, dsm, h2mm, ds2mm)
eit_leadfield = om.GainEEG(hminv, eitsm, h2em)
ip_leadfield = om.GainInternalPot(hminv, dsm, iphm, ipsm)
Algorithm 1: Demo script for computing the 4 types of lead fields with OpenMEEG in python.