Beispiel #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 _get_sensors(info, head_trans):
    eeg_picks = mne.pick_types(info, meg=False, eeg=True, ref_meg=False)
    eeg_loc = np.array([info['chs'][k]['loc'][:3] for k in eeg_picks])
    eeg_loc = np.asfortranarray(apply_trans(head_trans, eeg_loc))
    ch_names = [info['chs'][k]['ch_name'] for k in eeg_picks]
    orientations = np.ones((len(ch_names), 3), order='F')
    weights = np.ones(len(ch_names))
    radii = np.ones(len(ch_names))

    return om.Sensors(ch_names, eeg_loc, orientations, weights, radii),\
        ch_names
    def create_om_sensors(self, file_name=None):
        """
        Take a TVB Sensors object and return an OpenMEEG Sensors object.
        """
        if isinstance(self.sensors, sensors_module.SensorsEEG):
            file_name = file_name or "eeg_sensors.txt"
            sensors_file = self._tvb_eeg_sensors_to_txt(file_name)
        elif isinstance(self.sensors, sensors_module.SensorsMEG):
            file_name = file_name or "meg_sensors.squid"
            sensors_file = self._tvb_meg_sensors_to_squid(file_name)
        else:
            LOG.error("sensors should be either SensorsEEG or SensorsMEG")

        LOG.info("Wrote sensors to temporary file: %s" % str(file_name))

        om_sensors = om.Sensors()
        om_sensors.load(sensors_file)
        return om_sensors
Beispiel #4
0
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

hm = om.HeadMat(geom, gauss_order)
#hm.invert() # invert hm inplace (no copy)
#hminv = hm
Beispiel #5
0
#
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
# TODO: mesh == [ double ] , [ int ]
# mesh = om.Mesh()
# mesh.load( file_name_skeleton + ".tri")
# TODO: V = [...]
# TODO: I = [...]
# TODO: mesh_1 = om.Mesh(V, I)

# TODO: geom.read() using raw python
# TODO: conductivity == { string => double}
# TODO: geometry     == { [ mesh ] , { string => [ int ] } }
def _get_sensors_files(info, head_trans):
    electrodes_fname = 'electrodes.txt'
    ch_names = write_eeg_locations(electrodes_fname, info, head_trans)
    eeg_electrodes = om.Sensors(electrodes_fname)
    return eeg_electrodes, ch_names
Beispiel #7
0
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
dipole_in_cortex = True
Beispiel #8
0
#!/usr/bin/env python

import numpy as np

import openmeeg as om

# nes Sensors construtor
labels = ["toto"]
positions = np.array([[0, 1, 2], [0, 1, 2]], order='F')
orientations = np.array([[-1, -1, -2], [-1, -1, -2]], order='F')
weights = np.array([0.5, 0.5])
radii = np.array([1, 1])

s1 = om.Sensors(labels, positions, orientations, weights, radii)
print("s1 =", s1)
s1.info()