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 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
def eeg_gain(self, eeg_file=None): """ Call OpenMEEG's GainEEG method to calculate the final projection matrix. Optionaly saving the matrix for later use. The OpenMEEG matrix is converted to a Numpy array before return. """ LOG.info("Computing GainEEG...") eeg_gain = om.GainEEG(self.om_inverse_head, self.om_source_matrix, self.om_head2sensor) LOG.info("eeg_gain: %d x %d" % (eeg_gain.nlin(), eeg_gain.ncol())) if eeg_file is not None: LOG.info("Saving eeg_gain as %s..." % eeg_file) eeg_gain.save( os.path.join(OM_STORAGE_DIR, eeg_file + OM_SAVE_SUFFIX)) return om.asarray(eeg_gain)
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()) print "ss2mm : %d x %d" % (ss2mm.nlin(), ss2mm.ncol()) print "dsm : %d x %d" % (ssm.nlin(), ssm.ncol()) print "ds2mm : %d x %d" % (ss2mm.nlin(), ss2mm.ncol()) print "h2mm : %d x %d" % (h2mm.nlin(), h2mm.ncol()) print "h2em : %d x %d" % (h2mm.nlin(), h2mm.ncol())
# For ECoG h2ecogm = om.Head2ECoGMat(geom, ecog_electrodes, "Cortex") # For MEG ds2mm = om.DipSource2MEGMat(dipoles, meg_sensors) h2mm = om.Head2MEGMat(geom, meg_sensors) # For EIT eitsm = om.EITSourceMat(geom, eit_electrodes, gauss_order) ''' ''' # For Internal Potential iphm = om.Surf2VolMat(geom, int_electrodes) ipsm = om.DipSource2InternalPotMat(geom, dipoles, int_electrodes) ''' eeg_leadfield = om.GainEEG(hminv, dsm, h2em) # eeg_leadfield_adjoint = om.GainEEGadjoint(geom,dipoles,hm, h2em) print("hminv : %d x %d" % (hminv.nlin(), hminv.ncol())) print("dsm : %d x %d" % (dsm.nlin(), dsm.ncol())) print("h2em : %d x %d" % (h2em.nlin(), h2em.ncol())) print("h2ecogm : %d x %d" % (h2ecogm.nlin(), h2ecogm.ncol())) print("ds2mm : %d x %d" % (ds2mm.nlin(), ds2mm.ncol())) print("h2mm : %d x %d" % (h2mm.nlin(), h2mm.ncol())) print("eeg_leadfield : %d x %d" % (eeg_leadfield.nlin(), eeg_leadfield.ncol())) print("ecog_leadfield : %d x %d" % (ecog_leadfield.nlin(), ecog_leadfield.ncol())) print("meg_leadfield : %d x %d" % (meg_leadfield.nlin(), meg_leadfield.ncol()))