Exemple #1
0
def LFcomputing(condFile, geomFile, dipoleFile, electrodesFile, savedir):
    """
    condFile = 'om_demo.cond'
    geomFile = 'om_demo.geom'
    dipoleFile = 'cortex.dip'
    squidsFile = 'meg_squids.txt'
    electrodesFile = 'eeg_electrodes.txt' 
    """
    # Load data
    geom = om.Geometry()
    geom.read(geomFile, condFile)
    dipoles = om.Matrix()
    dipoles.load(dipoleFile)
    #squids = om.Sensors()
    #squids.load(squidsFile)
    electrodes = om.Sensors()
    electrodes.load(electrodesFile)

    # Compute forward problem
    gaussOrder = 3
    use_adaptive_integration = True

    hm = om.HeadMat(geom, gaussOrder)
    hminv = hm.inverse()
    dsm = om.DipSourceMat(geom, dipoles, gaussOrder, use_adaptive_integration)
    #ds2mm = om.DipSource2MEGMat (dipoles, squids)
    #h2mm = om.Head2MEGMat (geom, squids)
    h2em = om.Head2EEGMat(geom, electrodes)
    #gain_meg = om.GainMEG (hminv, dsm, h2mm, ds2mm)
    gain_eeg = om.GainEEG(hminv, dsm, h2em)
    gain_eeg.save(savedir)
    return gain_eeg
 def head2eeg(self):
     """
     Call OpenMEEG's Head2EEGMat method to calculate the head to EEG sensor
     matrix.
     """
     LOG.info("Computing Head2EEGMat...")
     h2s_mat = om.Head2EEGMat(self.om_head, self.om_sensors)
     LOG.info("head2eeg: %d x %d" % (h2s_mat.nlin(), h2s_mat.ncol()))
     return h2s_mat
def make_forward_solution(info,
                          trans_fname,
                          src,
                          bem_model,
                          meg=True,
                          eeg=True,
                          mindist=0.0,
                          ignore_ref=False,
                          n_jobs=1,
                          verbose=None):
    assert not meg  # XXX for now

    coord_frame = 'head'
    trans = mne.read_trans(trans_fname)
    head_trans, meg_trans, mri_trans = _prepare_trans(info, trans, coord_frame)

    dipoles = _get_dipoles(src, mri_trans, head_trans)
    eeg_electrodes, ch_names = _get_sensors(info, head_trans)

    geom = _get_geom_files(bem_model, mri_trans, head_trans)
    assert geom.is_nested()
    assert geom.selfCheck()

    # OpenMEEG
    gauss_order = 3
    use_adaptive_integration = True
    # dipole_in_cortex = True

    hm = om.HeadMat(geom, gauss_order)
    hm.invert()
    hminv = hm
    dsm = om.DipSourceMat(geom, dipoles, gauss_order, use_adaptive_integration,
                          "Brain")

    # For EEG
    eeg_picks = mne.pick_types(info, meg=False, eeg=True)
    # meg_picks = mne.pick_types(info, meg=True, eeg=False)
    # seeg_picks = mne.pick_types(info, meg=False, seeg=True)

    if eeg and len(eeg_picks) > 0:
        h2em = om.Head2EEGMat(geom, eeg_electrodes)
        eeg_leadfield = om.GainEEG(hminv, dsm, h2em)
        eegfwd = _make_forward(eeg_leadfield, ch_names, info, src, trans_fname)

    # if meg and len(meg_picks) > 0:
    #     h2em = om.Head2EEGMat(geom, eeg_electrodes)
    #     eeg_leadfield = om.GainEEG(hminv, dsm, h2em)
    #     megfwd = _make_forward(eeg_leadfield, ch_names, info, src, trans_fname)

    # # merge forwards
    # fwd = _merge_meg_eeg_fwds(_to_forward_dict(megfwd, megnames),
    #                           _to_forward_dict(eegfwd, eegnames),
    #                           verbose=False)

    return eegfwd
Exemple #4
0
# Compute forward problem (Build Gain Matrices)

gauss_order = 3
use_adaptive_integration = True
dipole_in_cortex = True

hm = om.HeadMat(geom, gauss_order)
#hm.invert() # invert hm inplace (no copy)
#hminv = hm
hminv = hm.inverse()  # invert hm with a copy
ssm = om.SurfSourceMat(geom, mesh)
ss2mm = om.SurfSource2MEGMat(mesh, sensors)
dsm = om.DipSourceMat(geom, dipoles, gauss_order, use_adaptive_integration, "")
ds2mm = om.DipSource2MEGMat(dipoles, sensors)
h2mm = om.Head2MEGMat(geom, sensors)
h2em = om.Head2EEGMat(geom, patches)
gain_meg_surf = om.GainMEG(hminv, ssm, h2mm, ss2mm)
gain_eeg_surf = om.GainEEG(hminv, ssm, h2em)
gain_meg_dip = om.GainMEG(hminv, dsm, h2mm, ds2mm)
gain_adjoint_meg_dip = om.GainMEGadjoint(geom, dipoles, hm, h2mm, ds2mm)
gain_eeg_dip = om.GainEEG(hminv, dsm, h2em)
gain_adjoint_eeg_dip = om.GainEEGadjoint(geom, dipoles, hm, h2em)
gain_adjoint_eeg_meg_dip = om.GainEEGMEGadjoint(geom, dipoles, hm, h2em, h2mm,
                                                ds2mm)

print "hm                  : %d x %d" % (hm.nlin(), hm.ncol())
print "hminv               : %d x %d" % (hminv.nlin(), hminv.ncol())
print "ssm                 : %d x %d" % (ssm.nlin(), ssm.ncol())
print "ss2mm               : %d x %d" % (ss2mm.nlin(), ss2mm.ncol())
print "dsm                 : %d x %d" % (ssm.nlin(), ssm.ncol())
print "ds2mm               : %d x %d" % (ss2mm.nlin(), ss2mm.ncol())
Exemple #5
0
    hm.save("tmp/hmi.mat")
    hminv = hm
    # hminv = hm.inverse() # to also test the adjoint method: comment the 3
    # previous lines, and uncomment this line, and the two others containing
    # 'adjoint'

if op.exists("tmp/dsm.mat"):
    dsm = om.Matrix("tmp/dsm.mat")
    print("DSM loaded from ", "tmp/dsm.mat")
else:
    dsm = om.DipSourceMat(geom, dipoles, gauss_order, use_adaptive_integration,
                          "Brain")
    dsm.save("tmp/dsm.mat")

# For EEG
h2em = om.Head2EEGMat(geom, eeg_electrodes)
'''
# For ECoG
h2ecogm = om.Head2ECoGMat(geom, ecog_electrodes, "Cortex")

# For MEG
ds2mm = om.DipSource2MEGMat(dipoles, meg_sensors)
h2mm = om.Head2MEGMat(geom, meg_sensors)

# For EIT
eitsm = om.EITSourceMat(geom, eit_electrodes, gauss_order)
'''
'''
# For Internal Potential
iphm = om.Surf2VolMat(geom, int_electrodes)
ipsm = om.DipSource2InternalPotMat(geom, dipoles, int_electrodes)