예제 #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
예제 #2
0
    def inverse_head(self, gauss_order=3, inv_head_mat_file=None):
        """
        Call OpenMEEG's HeadMat method to calculate a head matrix. The inverse 
        method of the head matrix is subsequently called to invert the matrix.
        Optionaly saving the inverted matrix for later use.

        Runtime ~8 hours, mostly in martix inverse as I just use a stock ATLAS 
        install which doesn't appear to be multithreaded (custom building ATLAS
        should sort this)... Under Windows it should use MKL, not sure for Mac

        For reg13+potato surfaces, saved file size: hminv ~ 5GB, ssm ~ 3GB.
        """

        LOG.info("Computing HeadMat...")
        head_matrix = om.HeadMat(self.om_head, gauss_order)
        LOG.info("head_matrix: %d x %d" %
                 (head_matrix.nlin(), head_matrix.ncol()))

        LOG.info("Inverting HeadMat...")
        hminv = head_matrix.inverse()
        LOG.info("inverse head_matrix: %d x %d" % (hminv.nlin(), hminv.ncol()))

        if inv_head_mat_file is not None:
            LOG.info("Saving inverse_head matrix as %s..." % inv_head_mat_file)
            hminv.save(
                os.path.join(OM_STORAGE_DIR,
                             inv_head_mat_file + OM_SAVE_SUFFIX))  #~5GB
        return hminv
예제 #3
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
예제 #4
0
dipoles.load(dipole_file)

sensors = om.Sensors()
sensors.load(squidsFile)

patches = om.Sensors()
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)
예제 #5
0
dipoles.load(dipole_file)

sensors = om.Sensors()
sensors.load(squidsFile)

patches = om.Sensors()
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)
예제 #6
0
    import os
    os.mkdir('tmp')
if not op.exists("leadfields"):
    import os
    os.mkdir('leadfields')

# Compute Leadfields
gauss_order = 3
use_adaptive_integration = True
dipole_in_cortex = True

if op.exists("tmp/hmi.mat"):
    hminv = om.SymMatrix("tmp/hmi.mat")
    print("HM inverse loaded from ", "tmp/hmi.mat")
else:
    hm = om.HeadMat(geom, gauss_order)
    hm.invert()
    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")