Skip to content

Instantly share code, notes, and snippets.

@larsoner
Created October 1, 2019 15:35
Show Gist options
  • Save larsoner/ebbfa132ffd881bd839a578e1ed2e8e6 to your computer and use it in GitHub Desktop.
Save larsoner/ebbfa132ffd881bd839a578e1ed2e8e6 to your computer and use it in GitHub Desktop.
import mne
from mne.utils import object_diff
from mne.forward.forward import is_fixed_orient, convert_forward_solution
from mne.datasets import sample
data_path = sample.data_path()
fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-oct-6-fwd.fif'
fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
fwd = mne.read_forward_solution(fname_fwd)
inv = mne.minimum_norm.read_inverse_operator(fname_inv)
def _convert_forward_match_inv(fwd, inv):
is_fixed_inv = inv['eigen_leads']['data'].shape[0] == inv['nsource']
is_loose = not (inv['orient_prior'] == 1.).all()
if is_fixed_inv:
if not is_fixed_orient(fwd):
fwd = convert_forward_solution(fwd, force_fixed=True)
elif is_loose:
if not fwd['surf_ori']:
fwd = convert_forward_solution(fwd, surf_ori=True)
else: # free orientation
if fwd['surf_ori']:
fwd = convert_forward_solution(fwd, surf_ori=False)
differences = object_diff(fwd['src'], inv['src'])
if differences:
raise RuntimeError('fwd["src"] and inv["src"] did not match: %s'
% (differences,))
return fwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment