예제 #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 _load_om_source_mat(self, file_name):
     """
     Load a previously stored source matrix into an OpenMEEG Matrix object.
     """
     source_matrix = om.Matrix()
     source_matrix.load(file_name)
     return source_matrix
예제 #3
0
def _get_dipoles(src, mri_trans, head_trans):
    src_rr = np.r_[src[0]['rr'][src[0]['inuse'].astype(bool)],
                   src[1]['rr'][src[1]['inuse'].astype(bool)]]
    if src[0]['coord_frame'] == FIFF.FIFFV_COORD_MRI:
        src_rr = apply_trans(mri_trans, src_rr)
        # src_nn = apply_trans(mri_trans, src_nn, move=False)
    elif src[0]['coord_frame'] == FIFF.FIFFV_COORD_HEAD:
        src_rr = apply_trans(head_trans, src_rr)
        # src_nn = apply_trans(head_trans, src_nn, move=False)

    pos = src_rr
    ori = np.kron(np.ones(len(pos))[:, None], np.eye(3))
    pos = np.kron(pos.T, np.ones(3)[None, :]).T
    return om.Matrix(np.asfortranarray(np.c_[pos, ori]))
예제 #4
0
    def create_om_sources(self): #TODO: Prob. should make file names specifiable
        """
        Take a TVB Connectivity or Cortex object and return an OpenMEEG object
        that specifies sources, a Matrix object for region level sources or a
        Mesh object for a cortical surface source.
        """
        if isinstance(self.sources, connectivity_module.Connectivity):
            sources_file = self._tvb_connectivity_to_txt("sources.txt")
            om_sources = om.Matrix()
        elif isinstance(self.sources, Cortex):
            sources_file = self._tvb_surface_to_tri("sources.tri")
            om_sources = om.Mesh()
        else:
            LOG.error("sources must be either a Connectivity or Cortex.")

        om_sources.load(sources_file)
        return om_sources
예제 #5
0
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)

###############################################################################
# Compute forward problem (Build Gain Matrices)

gauss_order = 3
use_adaptive_integration = True
dipole_in_cortex = True
예제 #6
0
#!/usr/bin/env python
import random
import numpy as np
import openmeeg as om

W = np.asfortranarray([[0.0, 0.0, 3.0], [0.0, 2.0, 0.0], [1.0, 0.0, 0.0]])
print("W of", W.__class__)
print("W =", W, "\n")

X = om.Matrix(W)
print("X of", X.__class__)
print("X =", X, "\n")

Z = X.array()
print("Z of", Z.__class__)
print("Z =", Z, "\n")

a = np.asfortranarray([[1, 2, 3], [4, 5, 6]])
print("a=", a)

b = om.Matrix(a)
assert b.nlin() == 2
assert b.ncol() == 3

for i in range(b.nlin()):
    for j in range(b.ncol()):
        assert b.value(i, j) == a[i, j]

c = om.Matrix(b)
assert c.nlin() == 2
assert c.ncol() == 3
예제 #7
0
    "-p",
    "--path",
    dest="data_path",
    help="path to data folder",
    metavar="FILE",
    default=data_path,
)
options, args = parser.parse_args()
data_path = options.data_path

#
subject = "Head1"
file_name_skeleton = op.join(data_path, subject, subject)

# dipole
dipoles = om.Matrix()
dipoles.load(file_name_skeleton + ".dip")
D = dipoles.array()
print("D is a", D.__class__)
print(D)
# Examples of basic linear algebra
print("Determinant of D is equal to: ", np.linalg.det(D))

# TODO: sensors.read() using numpy arrays
# TODO: sensors == [ double ]
sensors = om.Sensors()
sensors.load(file_name_skeleton + ".squids")
# TODO: D = asarray(sensors).copy...
# TODO: sensors_1 = om.Matrix(D)

# TODO: mesh.read() using numpy arrays
예제 #8
0
def _get_dipoles_files(src, mri_trans, head_trans):
    dipoles_fname = 'dipoles.txt'
    write_dipoles(dipoles_fname, src, mri_trans, head_trans)
    dipoles = om.Matrix(dipoles_fname)
    return dipoles
예제 #9
0
geom_file = path + 'data\\model\\head_model.geom'
cond_file = path + 'data\\model\\head_model.cond'
dipoles_file = path + 'data/model/cortex_dipoles.txt'
squids_file = path + 'data/model/meg_channels_locations.squids'
eeg_electrodes_file = path + 'data/model/eeg_channels_locations.txt'
eit_electrodes_file = path + 'data/model/eit_locations.txt'
ecog_electrodes_file = path + 'data/model/ecog_electrodes_locations.txt'
internal_electrodes_file = path + 'data/model/internal_electrodes_locations.txt'

print(geom_file)

geom = om.Geometry(geom_file, cond_file)

print(geom)

dipoles = om.Matrix(dipoles_file)

eeg_electrodes = om.Sensors(eeg_electrodes_file)

###############################################################################
# create a dir for leadfields and tmp
if not op.exists("tmp"):
    import os
    os.mkdir('tmp')
if not op.exists("leadfields"):
    import os
    os.mkdir('leadfields')

# Compute Leadfields
gauss_order = 3
use_adaptive_integration = True
예제 #10
0
print("W1 =", W1)

# np.array -> om.Vector
W2 = np.array([1.0, 2.0, 3.0])
print("W2 of", W2.__class__)
print("W2 =", W2, "\n")

V2 = om.Vector(W2, om.DEEP_COPY)
print("V2 of", V2.__class__)
V2.info()

V3 = om.Vector(V2)
print("V3 of", V3.__class__)
V3.info()

M = om.Matrix(2, 3)
M.setlin(0, V2)
M.set(3)
M.info()
print("M of", M.__class__)

print("V3 of", V3.__class__)
V3 = om.Vector(M)
print("V3 of", V3.__class__)
V3.info()

#
error = 0
for i in range(3):
    if W1[i] != V1.value(i):
        print("vectors differ at:", i)