Example #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 create_om_head(self):  #TODO: Prob. need to make file names specifiable
        """
        Generates 5 files::

            skull_skin.tri
            skin_air.tri
            brain_skull.tri
            head_model.geom
            head_model.cond

        Containing the specification of a head in a form that can be read by 
        OpenMEEG, then creates and returns an OpenMEEG Geometry object containing 
        this information.
        """
        surface_files = []
        surface_files.append(self._tvb_surface_to_tri("skull_skin.tri"))
        surface_files.append(self._tvb_surface_to_tri("brain_skull.tri"))
        surface_files.append(self._tvb_surface_to_tri("skin_air.tri"))

        geometry_file = self._write_head_geometry(surface_files,
                                                  "head_model.geom")
        conductances_file = self._write_conductances("head_model.cond")

        LOG.info("Creating OpenMEEG Geometry object for the head...")
        om_head = om.Geometry()
        om_head.read(geometry_file, conductances_file)
        #om_head.selfCheck() #Didn't catch bad order...
        LOG.info("OpenMEEG Geometry object for the head successfully created.")
        return om_head
Example #3
0
def _get_geom_files(bem_model, mri_trans, head_trans):
    surf_names = ['inner_skull', 'outer_skull', 'outer_skin'][::-1]
    for surf_name, surf in zip(surf_names, bem_model):
        surf = _convert_bem_surf(surf, mri_trans, head_trans)
        points, faces, normals = surf['rr'], surf['tris'], surf['nn']
        # mlab.triangular_mesh(points[:, 0], points[:, 1], points[:, 2],
        #                      faces, colormap='RdBu', opacity=0.5)
        write_tri('%s.tri' % surf_name, points, swap_faces(faces), normals)

    geom_fname = 'model.geom'
    cond_fname = 'model.cond'

    conductivity = [s['sigma'] for s in bem_model]

    write_geom(geom_fname, surf_names)
    write_cond(cond_fname, conductivity)

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

    surf_names = ['inner_skull', 'outer_skull', 'outer_skin'][::-1]
    for surf_name, surf in zip(surf_names, bem_model):
        surf = _convert_bem_surf(surf, mri_trans, head_trans)
        points, faces, normals = surf['rr'], surf['tris'], surf['nn']
        # mlab.triangular_mesh(points[:, 0], points[:, 1], points[:, 2],
        #                      faces, colormap='RdBu', opacity=0.5)
        write_tri('%s.tri' % surf_name, points, swap_faces(faces), normals)

    write_geom(geom_fname, surf_names)
    write_cond(cond_fname, conductivity)

    # OpenMEEG
    geom = om.Geometry(geom_fname, cond_fname)
    return geom
Example #4
0
                  default=data_path)
options, args = parser.parse_args()
data_path = options.data_path

###############################################################################
# Load data

subject = 'Head1'
cond_file = op.join(data_path, subject, subject + '.cond')
geom_file = op.join(data_path, subject, subject + '.geom')
source_mesh_file = op.join(data_path, subject, subject + '.tri')
dipole_file = op.join(data_path, subject, subject + '.dip')
squidsFile = op.join(data_path, subject, subject + '.squids')
patches_file = op.join(data_path, subject, subject + '.patches')

geom = om.Geometry()
geom.read(geom_file, cond_file)

mesh = om.Mesh()
mesh.load(source_mesh_file)

dipoles = om.Matrix()
dipoles.load(dipole_file)

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

patches = om.Sensors()
patches.load(patches_file)

###############################################################################
Example #5
0
    default=data_path,
)
options, args = parser.parse_args()
data_path = options.data_path

# Load data

subject = "Head1"
cond_file = op.join(data_path, subject, subject + ".cond")
geom_file = op.join(data_path, subject, subject + ".geom")
source_mesh_file = op.join(data_path, subject, subject + ".tri")
dipole_file = op.join(data_path, subject, subject + ".dip")
squidsFile = op.join(data_path, subject, subject + ".squids")
patches_file = op.join(data_path, subject, subject + ".patches")

geom = om.Geometry(geom_file, cond_file)

mesh = om.Mesh(source_mesh_file)

dipoles = om.Matrix()
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
Example #6
0
meshes["skull"] = python_mesh("skull", op.join(dirpath, "skull.1.tri"))
meshes["scalp"] = python_mesh("scalp", op.join(dirpath, "scalp.1.tri"))

# It should be possible to have multiple oriented meshes per interface. e.g.
# interface1 = [(m1,om.OrientedMesh.Normal), (m2,om.OrientedMesh.Opposite), (m3,om.OrientedMesh.Normal)]
# It should also be possible to have a name added at the beginning of the
# tuple.

interfaces = {
    "interface1": [('cortex', om.OrientedMesh.Normal)],
    "interface2": [('skull', om.OrientedMesh.Normal)],
    "interface3": [('scalp', om.OrientedMesh.Normal)]
}

domains = {
    "Scalp": ([('interface2', om.SimpleDomain.Outside),
               ('interface3', om.SimpleDomain.Inside)], 1.0),
    "Brain": ([('interface1', om.SimpleDomain.Inside)], 1.0),
    "Air": ([('interface3', om.SimpleDomain.Outside)], 0.0),
    "Skull": ([('interface2', om.SimpleDomain.Inside),
               ('interface1', om.SimpleDomain.Outside)], 0.0125)
}

g1 = om.make_geometry(meshes, interfaces, domains)
g2 = om.Geometry(op.join(dirpath, subject + ".geom"),
                 op.join(dirpath, subject + ".cond"))

assert g1.is_nested()
assert g2.is_nested()
assert g1.__class__ == g2.__class__
Example #7
0
#!/usr/bin/env python

import numpy as np

import openmeeg as om

vertices = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0],
                     [0.0, 1.0, 0.0]])
triangles = np.array([[1, 2, 3], [2, 3, 0]])

mesh = om.Mesh(vertices, triangles)

g = om.Geometry()

assert g.check(mesh)

g.import_meshes([mesh])

assert not g.check(mesh)