This is an automated email from the git hooks/post-receive script. yoh pushed a commit to tag 0.4 in repository python-mne.
commit 13c2aa894fd04beb6af531d819eb6d7445000bd7 Author: Alexandre Gramfort <[email protected]> Date: Mon Apr 30 14:12:40 2012 +0200 FIX : fix writing of inv op obtained with make_inverse_operator --- mne/cov.py | 2 +- mne/fiff/cov.py | 4 +-- mne/forward.py | 11 +++++---- mne/minimum_norm/inverse.py | 45 ++++++++++++++++++++++++++++------ mne/minimum_norm/tests/test_inverse.py | 5 ++-- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/mne/cov.py b/mne/cov.py index 389599e..79ae554 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -418,7 +418,7 @@ def prepare_noise_cov(noise_cov, info, ch_names): assert(len(C_meg_idx) + len(C_eeg_idx) == n_chan) - noise_cov = Covariance(None) + noise_cov = copy.deepcopy(noise_cov) noise_cov.update(data=C, eig=eig, eigvec=eigvec, dim=len(ch_names), diag=False, names=ch_names) diff --git a/mne/fiff/cov.py b/mne/fiff/cov.py index f92d0ac..984fcde 100644 --- a/mne/fiff/cov.py +++ b/mne/fiff/cov.py @@ -49,13 +49,13 @@ def read_cov(fid, node, cov_kind): tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIM) if tag is None: raise ValueError('Covariance matrix dimension not found') + dim = int(tag.data) - dim = tag.data tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_NFREE) if tag is None: nfree = -1 else: - nfree = tag.data + nfree = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_ROW_NAMES) if tag is None: diff --git a/mne/forward.py b/mne/forward.py index 025c3f6..0f12412 100644 --- a/mne/forward.py +++ b/mne/forward.py @@ -103,31 +103,32 @@ def _read_one(fid, node): if node is None: return None + one = dict() + tag = find_tag(fid, node, FIFF.FIFF_MNE_SOURCE_ORIENTATION) if tag is None: fid.close() raise ValueError('Source orientation tag not found') + one['source_ori'] = int(tag.data) - one = dict() - one['source_ori'] = tag.data tag = find_tag(fid, node, FIFF.FIFF_MNE_COORD_FRAME) if tag is None: fid.close() raise ValueError('Coordinate frame tag not found') + one['coord_frame'] = int(tag.data) - one['coord_frame'] = tag.data tag = find_tag(fid, node, FIFF.FIFF_MNE_SOURCE_SPACE_NPOINTS) if tag is None: fid.close() raise ValueError('Number of sources not found') + one['nsource'] = int(tag.data) - one['nsource'] = tag.data tag = find_tag(fid, node, FIFF.FIFF_NCHAN) if tag is None: fid.close() raise ValueError('Number of channels not found') + one['nchan'] = int(tag.data) - one['nchan'] = tag.data try: one['sol'] = _read_named_matrix(fid, node, FIFF.FIFF_MNE_FORWARD_SOLUTION) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 9399d06..a0a1102 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -21,6 +21,7 @@ from ..fiff.write import write_int, write_float_matrix, start_file, \ write_coord_trans from ..fiff.cov import read_cov, write_cov +from ..fiff.pick import pick_types from ..cov import prepare_noise_cov from ..forward import compute_depth_prior, compute_depth_prior_fixed from ..source_space import read_source_spaces_from_tree, \ @@ -93,7 +94,7 @@ def read_inverse_operator(fname): raise Exception('Modalities not found') inv = dict() - inv['methods'] = tag.data + inv['methods'] = int(tag.data) tag = find_tag(fid, invs, FIFF.FIFF_MNE_SOURCE_ORIENTATION) if tag is None: @@ -107,7 +108,7 @@ def read_inverse_operator(fname): fid.close() raise Exception('Number of sources not found') - inv['nsource'] = tag.data + inv['nsource'] = int(tag.data) inv['nchan'] = 0 # # Coordinate frame @@ -1006,7 +1007,10 @@ def make_inverse_operator(info, forward, noise_cov, loose=0.2, depth=0.8): gain = np.dot(W, gain) source_cov = depth_prior.copy() - depth_prior = dict(data=depth_prior) + depth_prior = dict(data=depth_prior, kind=FIFF.FIFFV_MNE_DEPTH_PRIOR_COV, + bads=None, diag=True, names=None, eig=None, + eigvec=None, dim=depth_prior.size, nfree=1, + projs=[]) # apply loose orientations if not is_fixed_ori: @@ -1016,7 +1020,11 @@ def make_inverse_operator(info, forward, noise_cov, loose=0.2, depth=0.8): % loose) orient_prior[np.mod(np.arange(n_dipoles), 3) != 2] *= loose source_cov *= orient_prior - orient_prior = dict(data=orient_prior) + orient_prior = dict(data=orient_prior, + kind=FIFF.FIFFV_MNE_ORIENT_PRIOR_COV, + bads=None, diag=True, names=None, eig=None, + eigvec=None, dim=orient_prior.size, nfree=1, + projs=[]) else: orient_prior = None @@ -1030,7 +1038,10 @@ def make_inverse_operator(info, forward, noise_cov, loose=0.2, depth=0.8): source_cov *= scaling_source_cov gain *= sqrt(scaling_source_cov) - source_cov = dict(data=source_cov) + source_cov = dict(data=source_cov, dim=source_cov.size, + kind=FIFF.FIFFV_MNE_SOURCE_COV, diag=True, + names=None, projs=[], eig=None, eigvec=None, + nfree=1, bads=None) # now np.trace(np.dot(gain, gain.T)) == n_nzero # print np.trace(np.dot(gain, gain.T)), n_nzero @@ -1038,16 +1049,34 @@ def make_inverse_operator(info, forward, noise_cov, loose=0.2, depth=0.8): print 'Computing SVD of whitened and weighted lead field matrix.' eigen_fields, sing, eigen_leads = linalg.svd(gain, full_matrices=False) - eigen_fields = dict(data=eigen_fields.T, col_names=ch_names) - eigen_leads = dict(data=eigen_leads.T, nrow=eigen_leads.shape[1]) + eigen_fields = dict(data=eigen_fields.T, col_names=ch_names, row_names=[], + nrow=eigen_fields.shape[1], ncol=eigen_fields.shape[0]) + eigen_leads = dict(data=eigen_leads.T, nrow=eigen_leads.shape[1], + ncol=eigen_leads.shape[0], row_names=[], + col_names=[]) nave = 1.0 + # Handle methods + n_meg = len(pick_types(info, meg=True, eeg=False, exclude=info['bads'])) + n_eeg = len(pick_types(info, meg=False, eeg=True, exclude=info['bads'])) + has_meg = n_meg > 0 + has_eeg = n_eeg > 0 + if has_eeg and has_meg: + methods = FIFF.FIFFV_MNE_MEG_EEG + elif has_meg: + methods = FIFF.FIFFV_MNE_MEG + else: + methods = FIFF.FIFFV_MNE_EEG + inv_op = dict(eigen_fields=eigen_fields, eigen_leads=eigen_leads, sing=sing, nave=nave, depth_prior=depth_prior, source_cov=source_cov, noise_cov=noise_cov, orient_prior=orient_prior, projs=deepcopy(info['projs']), eigen_leads_weighted=False, source_ori=forward['source_ori'], mri_head_t=deepcopy(forward['mri_head_t']), - src=deepcopy(forward['src'])) + methods=methods, nsource=forward['nsource'], + coord_frame=forward['coord_frame'], + source_nn=forward['source_nn'].copy(), + src=deepcopy(forward['src']), fmri_prior=None) return inv_op diff --git a/mne/minimum_norm/tests/test_inverse.py b/mne/minimum_norm/tests/test_inverse.py index 793f59e..79e6c56 100644 --- a/mne/minimum_norm/tests/test_inverse.py +++ b/mne/minimum_norm/tests/test_inverse.py @@ -11,7 +11,7 @@ from ...label import read_label, label_sign_flip from ...event import read_events from ...epochs import Epochs from ...source_estimate import SourceEstimate -from ... import fiff, Covariance, read_forward_solution +from ... import fiff, read_cov, read_forward_solution from ..inverse import apply_inverse, read_inverse_operator, \ apply_inverse_raw, apply_inverse_epochs, \ make_inverse_operator, write_inverse_operator @@ -43,7 +43,7 @@ inverse_operator = read_inverse_operator(fname_inv) inverse_operator_fixed = read_inverse_operator(fname_inv_fixed) inverse_operator_vol = read_inverse_operator(fname_vol_inv) label = read_label(fname_label) -noise_cov = Covariance(fname_cov) +noise_cov = read_cov(fname_cov) raw = fiff.Raw(fname_raw) snr = 3.0 lambda2 = 1.0 / snr ** 2 @@ -111,6 +111,7 @@ def test_apply_inverse_operator(): my_inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov, loose=0.2, depth=0.8) + write_inverse_operator('test-inv.fif', my_inv_op) my_stc = apply_inverse(evoked, my_inv_op, lambda2, dSPM) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
