Ejemplo n.º 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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
 def dipole_source(self, gauss_order = 3, use_adaptive_integration = True,
                   dip_source_file=None):
     """ 
     Call OpenMEEG's DipSourceMat method to calculate a dipole source matrix.
     Optionaly saving the matrix for later use.
     """
     LOG.info("Computing DipSourceMat...")
     dsm   = om.DipSourceMat(self.om_head, self.om_sources, gauss_order, 
                             use_adaptive_integration)
     LOG.info("dipole_source_mat: %d x %d" % (dsm.nlin(), dsm.ncol()))
     if dip_source_file is not None:
         LOG.info("Saving dipole_source matrix as %s..." % dip_source_file)
         dsm.save(os.path.join(OM_STORAGE_DIR,
                               dip_source_file + OM_SAVE_SUFFIX))
     return dsm
Ejemplo n.º 4
0
patches.load(patches_file)

###############################################################################
# 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())