[med-svn] [python-mne] 301/376: FIX: getting rid of Bunch object which was error prone with deepcopy
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:23:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.1
in repository python-mne.
commit d7aaed6cfece546ce34505b0742fce149ee7d90d
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Mon Jun 13 15:42:12 2011 -0400
FIX: getting rid of Bunch object which was error prone with deepcopy
---
mne/cov.py | 2 +-
mne/epochs.py | 4 +--
mne/event.py | 2 +-
mne/fiff/bunch.py | 14 --------
mne/fiff/compensator.py | 4 +--
mne/fiff/constants.py | 8 ++++-
mne/fiff/ctf.py | 28 ++++++++--------
mne/fiff/evoked.py | 15 +++++----
mne/fiff/matrix.py | 10 +++---
mne/fiff/meas_info.py | 48 +++++++++++++-------------
mne/fiff/pick.py | 12 +++----
mne/fiff/proj.py | 17 +++++-----
mne/fiff/raw.py | 6 ++--
mne/fiff/tag.py | 39 +++++++++++----------
mne/fiff/tree.py | 39 +++++++++++----------
mne/minimum_norm/inverse.py | 82 +++++++++++++++++----------------------------
mne/source_estimate.py | 2 +-
mne/transforms.py | 6 ++--
18 files changed, 154 insertions(+), 184 deletions(-)
diff --git a/mne/cov.py b/mne/cov.py
index 3843075..25a2687 100644
--- a/mne/cov.py
+++ b/mne/cov.py
@@ -332,7 +332,7 @@ def read_cov(fid, node, cov_kind):
eigvec=eigvec)
return cov
- raise ValueError('Did not find the desired covariance matrix')
+ print 'Did not find the desired covariance matrix'
return None
diff --git a/mne/epochs.py b/mne/epochs.py
index 1f16abe..924deca 100644
--- a/mne/epochs.py
+++ b/mne/epochs.py
@@ -101,7 +101,7 @@ class Epochs(object):
self.flat = flat
# Handle measurement info
- self.info = copy.copy(raw.info)
+ self.info = copy.deepcopy(raw.info)
if picks is not None:
self.info['chs'] = [self.info['chs'][k] for k in picks]
self.info['ch_names'] = [self.info['ch_names'][k] for k in picks]
@@ -311,7 +311,7 @@ class Epochs(object):
The averaged epochs
"""
evoked = Evoked(None)
- evoked.info = copy.copy(self.info)
+ evoked.info = copy.deepcopy(self.info)
n_channels = len(self.ch_names)
n_times = len(self.times)
n_events = len(self.events)
diff --git a/mne/event.py b/mne/event.py
index e790110..358c139 100644
--- a/mne/event.py
+++ b/mne/event.py
@@ -41,7 +41,7 @@ def read_events(filename):
events = events[0]
- for d in events.directory:
+ for d in events['directory']:
kind = d.kind
pos = d.pos
if kind == FIFF.FIFF_MNE_EVENT_LIST:
diff --git a/mne/fiff/bunch.py b/mne/fiff/bunch.py
deleted file mode 100644
index 3e4545e..0000000
--- a/mne/fiff/bunch.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# Authors: Alexandre Gramfort <gramfort at nmr.mgh.harvard.edu>
-# Matti Hamalainen <msh at nmr.mgh.harvard.edu>
-#
-# License: BSD (3-clause)
-
-
-class Bunch(dict):
- """ Container object for datasets: dictionnary-like object that
- exposes its keys as attributes.
- """
-
- def __init__(self, **kwargs):
- dict.__init__(self, kwargs)
- self.__dict__ = self
diff --git a/mne/fiff/compensator.py b/mne/fiff/compensator.py
index 9f87264..4f4e8a1 100644
--- a/mne/fiff/compensator.py
+++ b/mne/fiff/compensator.py
@@ -9,7 +9,7 @@ def get_current_comp(info):
comp = 0
first_comp = -1
for k, chan in enumerate(info['chs']):
- if chan.kind == FIFF.FIFFV_MEG_CH:
+ if chan['kind'] == FIFF.FIFFV_MEG_CH:
comp = int(chan['coil_type']) >> 16
if first_comp < 0:
first_comp = comp
@@ -171,7 +171,7 @@ def get_current_comp(info):
#
# lower_half = int('FFFF', 16) # hex2dec('FFFF')
# for k in range(len(chs)):
-# if chs[k].kind == FIFF.FIFFV_MEG_CH:
+# if chs[k]['kind'] == FIFF.FIFFV_MEG_CH:
# coil_type = float(chs[k]['coil_type']) & lower_half
# new_chs[k]['coil_type'] = int(coil_type | (value << 16))
#
diff --git a/mne/fiff/constants.py b/mne/fiff/constants.py
index c1242b2..d9a6d70 100644
--- a/mne/fiff/constants.py
+++ b/mne/fiff/constants.py
@@ -3,8 +3,14 @@
#
# License: BSD (3-clause)
-from bunch import Bunch
+class Bunch(dict):
+ """ Container object for datasets: dictionnary-like object that
+ exposes its keys as attributes.
+ """
+ def __init__(self, **kwargs):
+ dict.__init__(self, kwargs)
+ self.__dict__ = self
FIFF = Bunch()
diff --git a/mne/fiff/ctf.py b/mne/fiff/ctf.py
index d59f9a1..6b36816 100644
--- a/mne/fiff/ctf.py
+++ b/mne/fiff/ctf.py
@@ -24,11 +24,11 @@ def _read_named_matrix(fid, node, matkind):
"""
# Descend one level if necessary
- if node.block != FIFF.FIFFB_MNE_NAMED_MATRIX:
- for k in range(node.nchild):
- if node.children(k).block == FIFF.FIFFB_MNE_NAMED_MATRIX:
- if has_tag(node.children(k), matkind):
- node = node.children(k)
+ if node['block'] != FIFF.FIFFB_MNE_NAMED_MATRIX:
+ for k in range(node['nchild']):
+ if node['children'][k]['block'] == FIFF.FIFFB_MNE_NAMED_MATRIX:
+ if has_tag(node['children'][k], matkind):
+ node = node['children'][k]
break
else:
raise ValueError('Desired named matrix (kind = %d) not'
@@ -116,9 +116,9 @@ def read_ctf_comp(fid, node, chs):
#
# # Read the data we need
# mat = _read_named_matrix(fid, node, FIFF.FIFF_MNE_CTF_COMP_DATA)
- # for p in range(node.nent):
- # kind = node.dir[p].kind
- # pos = node.dir[p].pos
+ # for p in range(node['nent']):
+ # kind = node['dir'][p].kind
+ # pos = node['dir'][p].pos
# if kind == FIFF.FIFF_MNE_CTF_COMP_KIND:
# tag = read_tag(fid, pos)
# break
@@ -138,9 +138,9 @@ def read_ctf_comp(fid, node, chs):
# else:
# one.kind = one.ctfkind
#
- # for p in range(node.nent):
- # kind = node.dir[p].kind
- # pos = node.dir[p].pos
+ # for p in range(node['nent']):
+ # kind = node['dir'][p].kind
+ # pos = node['dir'][p].pos
# if kind == FIFF.FIFF_MNE_CTF_COMP_CALIBRATED:
# tag = read_tag(fid, pos)
# calibrated = tag.data
@@ -159,7 +159,7 @@ def read_ctf_comp(fid, node, chs):
# #
# ch_names = []
# for p in range(len(chs)):
- # ch_names.append(chs[p].ch_name)
+ # ch_names.append(chs[p]['ch_name'])
#
# col_cals = np.zeros(mat.data.shape[1])
# for col in range(mat.data.shape[1]):
@@ -171,7 +171,7 @@ def read_ctf_comp(fid, node, chs):
# raise ValueError, 'Ambiguous channel %s' % \
# mat.col_names[col]
#
- # col_cals[col] = 1.0 / (chs[p].range * chs[p].cal)
+ # col_cals[col] = 1.0 / (chs[p]['range'] * chs[p]['cal'])
#
# # Then the rows
# row_cals = np.zeros(mat.data.shape[0])
@@ -184,7 +184,7 @@ def read_ctf_comp(fid, node, chs):
# raise ValueError, 'Ambiguous channel %s' % \
# mat.row_names[row]
#
- # row_cals[row] = chs[p].range * chs[p].cal
+ # row_cals[row] = chs[p]['range'] * chs[p]['cal']
#
# mat.data = np.dot(np.diag(row_cals), np.dot(mat.data,
# np.diag(col_cals)))
diff --git a/mne/fiff/evoked.py b/mne/fiff/evoked.py
index bde77b0..18fa6ed 100644
--- a/mne/fiff/evoked.py
+++ b/mne/fiff/evoked.py
@@ -3,6 +3,7 @@
#
# License: BSD (3-clause)
+from copy import deepcopy
import numpy as np
from .constants import FIFF
@@ -109,9 +110,9 @@ class Evoked(object):
sfreq = -1
chs = []
comment = None
- for k in range(my_evoked.nent):
- kind = my_evoked.directory[k].kind
- pos = my_evoked.directory[k].pos
+ for k in range(my_evoked['nent']):
+ kind = my_evoked['directory'][k].kind
+ pos = my_evoked['directory'][k].pos
if kind == FIFF.FIFF_COMMENT:
tag = read_tag(fid, pos)
comment = tag.data
@@ -164,9 +165,9 @@ class Evoked(object):
# Read the data in the aspect block
nave = 1
epoch = []
- for k in range(my_aspect.nent):
- kind = my_aspect.directory[k].kind
- pos = my_aspect.directory[k].pos
+ for k in range(my_aspect['nent']):
+ kind = my_aspect['directory'][k].kind
+ pos = my_aspect['directory'][k].pos
if kind == FIFF.FIFF_COMMENT:
tag = read_tag(fid, pos)
comment = tag.data
@@ -204,7 +205,7 @@ class Evoked(object):
% (all_data.shape[1], nsamp))
# Calibrate
- cals = np.array([info['chs'][k].cal for k in range(info['nchan'])])
+ cals = np.array([info['chs'][k]['cal'] for k in range(info['nchan'])])
all_data = cals[:, None] * all_data
times = np.arange(first, last + 1, dtype=np.float) / info['sfreq']
diff --git a/mne/fiff/matrix.py b/mne/fiff/matrix.py
index ebf4823..6ce044b 100644
--- a/mne/fiff/matrix.py
+++ b/mne/fiff/matrix.py
@@ -24,11 +24,11 @@ def _read_named_matrix(fid, node, matkind):
"""
# Descend one level if necessary
- if node.block != FIFF.FIFFB_MNE_NAMED_MATRIX:
- for k in range(node.nchild):
- if node.children[k].block == FIFF.FIFFB_MNE_NAMED_MATRIX:
- if has_tag(node.children[k], matkind):
- node = node.children[k]
+ if node['block'] != FIFF.FIFFB_MNE_NAMED_MATRIX:
+ for k in range(node['nchild']):
+ if node['children'][k]['block'] == FIFF.FIFFB_MNE_NAMED_MATRIX:
+ if has_tag(node['children'][k], matkind):
+ node = node['children'][k]
break
else:
raise ValueError('Desired named matrix (kind = %d) not available'
diff --git a/mne/fiff/meas_info.py b/mne/fiff/meas_info.py
index ff5e002..a9afd67 100644
--- a/mne/fiff/meas_info.py
+++ b/mne/fiff/meas_info.py
@@ -63,9 +63,9 @@ def read_meas_info(fid, tree):
sfreq = None
chs = []
p = 0
- for k in range(meas_info.nent):
- kind = meas_info.directory[k].kind
- pos = meas_info.directory[k].pos
+ for k in range(meas_info['nent']):
+ kind = meas_info['directory'][k].kind
+ pos = meas_info['directory'][k].pos
if kind == FIFF.FIFF_NCHAN:
tag = read_tag(fid, pos)
nchan = int(tag.data)
@@ -112,9 +112,9 @@ def read_meas_info(fid, tree):
hpi_result = dir_tree_find(meas_info, FIFF.FIFFB_HPI_RESULT)
if len(hpi_result) == 1:
hpi_result = hpi_result[0]
- for k in range(hpi_result.nent):
- kind = hpi_result.directory[k].kind
- pos = hpi_result.directory[k].pos
+ for k in range(hpi_result['nent']):
+ kind = hpi_result['directory'][k].kind
+ pos = hpi_result['directory'][k].pos
if kind == FIFF.FIFF_COORD_TRANS:
tag = read_tag(fid, pos)
cand = tag.data
@@ -137,9 +137,9 @@ def read_meas_info(fid, tree):
dig = []
if len(isotrak) == 1:
- for k in range(isotrak.nent):
- kind = isotrak.directory[k].kind
- pos = isotrak.directory[k].pos
+ for k in range(isotrak['nent']):
+ kind = isotrak['directory'][k].kind
+ pos = isotrak['directory'][k].pos
if kind == FIFF.FIFF_DIG_POINT:
tag = read_tag(fid, pos)
dig.append(tag.data)
@@ -151,9 +151,9 @@ def read_meas_info(fid, tree):
acq_stim = None
if len(acqpars) == 1:
acqpars = acqpars[0]
- for k in range(acqpars.nent):
- kind = acqpars.directory[k].kind
- pos = acqpars.directory[k].pos
+ for k in range(acqpars['nent']):
+ kind = acqpars['directory'][k].kind
+ pos = acqpars['directory'][k].pos
if kind == FIFF.FIFF_DACQ_PARS:
tag = read_tag(fid, pos)
acq_pars = tag.data
@@ -173,25 +173,25 @@ def read_meas_info(fid, tree):
#
# Put the data together
#
- if tree.id is not None:
- info = dict(file_id=tree.id)
+ if tree['id'] is not None:
+ info = dict(file_id=tree['id'])
else:
info = dict(file_id=None)
# Make the most appropriate selection for the measurement id
- if meas_info.parent_id is None:
- if meas_info.id is None:
- if meas.id is None:
- if meas.parent_id is None:
- info['meas_id'] = info.file_id
+ if meas_info['parent_id'] is None:
+ if meas_info['id'] is None:
+ if meas['id'] is None:
+ if meas['parent_id'] is None:
+ info['meas_id'] = info['file_id']
else:
- info['meas_id'] = meas.parent_id
+ info['meas_id'] = meas['parent_id']
else:
- info['meas_id'] = meas.id
+ info['meas_id'] = meas['id']
else:
- info['meas_id'] = meas_info.id
+ info['meas_id'] = meas_info['id']
else:
- info['meas_id'] = meas_info.parent_id
+ info['meas_id'] = meas_info['parent_id']
if meas_date is None:
info['meas_date'] = [info['meas_id']['secs'], info['meas_id']['usecs']]
@@ -206,7 +206,7 @@ def read_meas_info(fid, tree):
# Add the channel information and make a list of channel names
# for convenience
info['chs'] = chs
- info['ch_names'] = [ch.ch_name for ch in chs]
+ info['ch_names'] = [ch['ch_name'] for ch in chs]
#
# Add the coordinate transformations
diff --git a/mne/fiff/pick.py b/mne/fiff/pick.py
index 262bc6f..d615655 100644
--- a/mne/fiff/pick.py
+++ b/mne/fiff/pick.py
@@ -3,7 +3,7 @@
#
# License: BSD (3-clause)
-from copy import copy
+from copy import deepcopy
import numpy as np
from .constants import FIFF
@@ -25,7 +25,7 @@ def channel_type(info, idx):
Type of channel
"""
- kind = info['chs'][idx].kind
+ kind = info['chs'][idx]['kind']
if (kind == FIFF.FIFFV_MEG_CH or kind == FIFF.FIFFV_REF_MEG_CH):
if info['chs'][idx]['unit'] == FIFF.FIFF_UNIT_T_M:
return 'grad'
@@ -110,7 +110,7 @@ def pick_types(info, meg=True, eeg=False, stim=False, eog=False, ecg=False,
pick = np.zeros(nchan, dtype=np.bool)
for k in range(nchan):
- kind = info['chs'][k].kind
+ kind = info['chs'][k]['kind']
if (kind == FIFF.FIFFV_MEG_CH or kind == FIFF.FIFFV_REF_MEG_CH):
if meg == True:
pick[k] = True
@@ -158,7 +158,7 @@ def pick_info(info, sel=[]):
Info structure restricted to a selection of channels
"""
- res = copy(info)
+ res = deepcopy(info)
if len(sel) == 0:
raise ValueError('Warning : No channels match the selection.')
@@ -198,7 +198,7 @@ def pick_channels_evoked(orig, include=[], exclude=[]):
if len(sel) == 0:
raise ValueError('Warning : No channels match the selection.')
- res = copy(orig)
+ res = deepcopy(orig)
#
# Modify the measurement info
#
@@ -238,7 +238,7 @@ def pick_channels_forward(orig, include=[], exclude=[]):
sel = pick_channels(orig['sol']['row_names'], include=include,
exclude=exclude)
- fwd = copy(orig)
+ fwd = deepcopy(orig)
# Do we have something?
nuse = len(sel)
diff --git a/mne/fiff/proj.py b/mne/fiff/proj.py
index 7f8b41b..def4df3 100644
--- a/mne/fiff/proj.py
+++ b/mne/fiff/proj.py
@@ -10,7 +10,6 @@ from scipy import linalg
from .tree import dir_tree_find
from .constants import FIFF
from .tag import find_tag
-from .bunch import Bunch
def read_proj(fid, node):
@@ -104,8 +103,8 @@ def read_proj(fid, node):
'size of data matrix')
# Use exactly the same fields in data as in a named matrix
- one = Bunch(kind=kind, active=active, desc=desc,
- data=Bunch(nrow=nvec, ncol=nchan, row_names=None,
+ one = dict(kind=kind, active=active, desc=desc,
+ data=dict(nrow=nvec, ncol=nchan, row_names=None,
col_names=names, data=data))
projdata.append(one)
@@ -113,13 +112,13 @@ def read_proj(fid, node):
if len(projdata) > 0:
print '\tRead a total of %d projection items:' % len(projdata)
for k in range(len(projdata)):
- if projdata[k].active:
+ if projdata[k]['active']:
misc = 'active'
else:
misc = ' idle'
- print '\t\t%s (%d x %d) %s' % (projdata[k].desc,
- projdata[k].data.nrow,
- projdata[k].data.ncol,
+ print '\t\t%s (%d x %d) %s' % (projdata[k]['desc'],
+ projdata[k]['data']['nrow'],
+ projdata[k]['data']['ncol'],
misc)
return projdata
@@ -203,7 +202,7 @@ def make_projector(projs, ch_names, bads=[]):
nactive = 0
nvec = 0
for p in projs:
- if p.active:
+ if p['active']:
nactive += 1
nvec += p['data']['nrow']
@@ -215,7 +214,7 @@ def make_projector(projs, ch_names, bads=[]):
nvec = 0
nonzero = 0
for k, p in enumerate(projs):
- if p.active:
+ if p['active']:
if len(p['data']['col_names']) != \
len(np.unique(p['data']['col_names'])):
raise ValueError('Channel name list in projection item %d'
diff --git a/mne/fiff/raw.py b/mne/fiff/raw.py
index bf1c588..55e8234 100644
--- a/mne/fiff/raw.py
+++ b/mne/fiff/raw.py
@@ -515,7 +515,7 @@ def start_writing_raw(name, info, sel=None):
fid2, tree, _ = fiff_open(info['filename'])
for b in blocks:
nodes = dir_tree_find(tree, b)
- copy_tree(fid2, tree.id, nodes, fid)
+ copy_tree(fid2, tree['id'], nodes, fid)
if b == FIFF.FIFFB_HPI_RESULT and len(nodes) > 0:
have_hpi_result = True
if b == FIFF.FIFFB_ISOTRAK and len(nodes) > 0:
@@ -584,8 +584,8 @@ def start_writing_raw(name, info, sel=None):
#
# Scan numbers may have been messed up
#
- chs[k].scanno = k + 1 # scanno starts at 1 in FIF format
- chs[k].range = 1.0
+ chs[k]['scanno'] = k + 1 # scanno starts at 1 in FIF format
+ chs[k]['range'] = 1.0
cals.append(chs[k]['cal'])
write_ch_info(fid, chs[k])
diff --git a/mne/fiff/tag.py b/mne/fiff/tag.py
index a2c156b..66dcd6a 100644
--- a/mne/fiff/tag.py
+++ b/mne/fiff/tag.py
@@ -6,7 +6,6 @@
import struct
import numpy as np
-from .bunch import Bunch
from .constants import FIFF
@@ -124,7 +123,7 @@ def read_tag(fid, pos=None):
fid.seek(pos, 0)
if ndim != 2:
- raise ValueError('Only two-dimensional matrices are '
+ raise Exception('Only two-dimensional matrices are '
'supported at this time')
matrix_type = data_type & tag.type
@@ -150,7 +149,7 @@ def read_tag(fid, pos=None):
# Note: we need the non-conjugate transpose here
tag.data = (data[::2] + 1j * data[1::2]).reshape(dims)
else:
- raise ValueError('Cannot handle matrix of type %d yet' %
+ raise Exception('Cannot handle matrix of type %d yet' %
matrix_type)
elif matrix_coding == matrix_coding_CCS or \
@@ -163,7 +162,7 @@ def read_tag(fid, pos=None):
fid.seek(-(ndim + 2) * 4, 1)
dims = np.fromfile(fid, dtype='>i', count=ndim + 1)
if ndim != 2:
- raise ValueError('Only two-dimensional matrices are '
+ raise Exception('Only two-dimensional matrices are '
'supported at this time')
# Back to where the data start
@@ -187,7 +186,7 @@ def read_tag(fid, pos=None):
tag.data = sparse.csr_matrix((sparse_data, sparse_indices,
sparse_ptrs), shape=shape)
else:
- raise ValueError('Cannot handle other than dense or sparse '
+ raise Exception('Cannot handle other than dense or sparse '
'matrices yet')
else:
# All other data types
@@ -237,7 +236,7 @@ def read_tag(fid, pos=None):
tag.data['r'] = np.fromfile(fid, dtype=">i4", count=3)
tag.data['coord_frame'] = 0
elif tag.type == FIFF.FIFFT_COORD_TRANS_STRUCT:
- tag.data = Bunch()
+ tag.data = dict()
tag.data['from'] = int(np.fromfile(fid, dtype=">i4", count=1))
tag.data['to'] = int(np.fromfile(fid, dtype=">i4", count=1))
rot = np.fromfile(fid, dtype=">f4", count=9).reshape(3, 3)
@@ -250,7 +249,7 @@ def read_tag(fid, pos=None):
#
fid.seek(12 * 4, 1)
elif tag.type == FIFF.FIFFT_CH_INFO_STRUCT:
- d = Bunch()
+ d = dict()
d['scanno'] = int(np.fromfile(fid, dtype=">i4", count=1))
d['logno'] = int(np.fromfile(fid, dtype=">i4", count=1))
d['kind'] = int(np.fromfile(fid, dtype=">i4", count=1))
@@ -268,19 +267,19 @@ def read_tag(fid, pos=None):
#
# Convert loc into a more useful format
#
- loc = tag.data.loc
- kind = tag.data.kind
+ loc = tag.data['loc']
+ kind = tag.data['kind']
if kind == FIFF.FIFFV_MEG_CH or kind == FIFF.FIFFV_REF_MEG_CH:
- tag.data.coil_trans = np.r_[np.c_[loc[3:5], loc[6:8],
+ tag.data['coil_trans'] = np.r_[np.c_[loc[3:5], loc[6:8],
loc[9:11], loc[0:2]],
np.array([0, 0, 0, 1]).reshape(1, 4)]
- tag.data.coord_frame = FIFF.FIFFV_COORD_DEVICE
- elif tag.data.kind == FIFF.FIFFV_EEG_CH:
+ tag.data['coord_frame'] = FIFF.FIFFV_COORD_DEVICE
+ elif tag.data['kind'] == FIFF.FIFFV_EEG_CH:
if np.linalg.norm(loc[3:5]) > 0:
- tag.data.eeg_loc = np.c_[loc[0:2], loc[3:5]]
+ tag.data['eeg_loc'] = np.c_[loc[0:2], loc[3:5]]
else:
- tag.data.eeg_loc = loc[1:3]
- tag.data.coord_frame = FIFF.FIFFV_COORD_HEAD
+ tag.data['eeg_loc'] = loc[1:3]
+ tag.data['coord_frame'] = FIFF.FIFFV_COORD_HEAD
#
# Unit and exponent
#
@@ -309,7 +308,7 @@ def read_tag(fid, pos=None):
s = fid.read(4 * 4)
tag.data.append(Tag(*struct.unpack(">iIii", s)))
else:
- raise ValueError('Unimplemented tag data type %s' % tag.type)
+ raise Exception('Unimplemented tag data type %s' % tag.type)
if tag.next != FIFF.FIFFV_NEXT_SEQ:
# f.seek(tag.next,0)
@@ -321,9 +320,9 @@ def read_tag(fid, pos=None):
def find_tag(fid, node, findkind):
"""Find Tag in an open FIF file descriptor
"""
- for p in range(node.nent):
- if node.directory[p].kind == findkind:
- return read_tag(fid, node.directory[p].pos)
+ for p in range(node['nent']):
+ if node['directory'][p].kind == findkind:
+ return read_tag(fid, node['directory'][p].pos)
tag = None
return tag
@@ -331,7 +330,7 @@ def find_tag(fid, node, findkind):
def has_tag(node, kind):
"""Does the node contains a Tag of a given kind?
"""
- for d in node.directory:
+ for d in node['directory']:
if d.kind == kind:
return True
return False
diff --git a/mne/fiff/tree.py b/mne/fiff/tree.py
index 84d4919..edad57d 100644
--- a/mne/fiff/tree.py
+++ b/mne/fiff/tree.py
@@ -3,7 +3,6 @@
#
# License: BSD (3-clause)
-from .bunch import Bunch
from .tag import read_tag
@@ -21,11 +20,11 @@ def dir_tree_find(tree, kind):
nodes += dir_tree_find(t, kind)
else:
# Am I desirable myself?
- if tree.block == kind:
+ if tree['block'] == kind:
nodes.append(tree)
# Search the subtrees
- for child in tree.children:
+ for child in tree['children']:
nodes += dir_tree_find(child, kind)
return nodes
@@ -50,7 +49,7 @@ def make_dir_tree(fid, directory, start=0, indent=0, verbose=False):
this = start
- tree = Bunch()
+ tree = dict()
tree['block'] = block
tree['id'] = None
tree['parent_id'] = None
@@ -64,40 +63,40 @@ def make_dir_tree(fid, directory, start=0, indent=0, verbose=False):
if this != start:
child, this = make_dir_tree(fid, directory, this,
indent + 1, verbose)
- tree.nchild += 1
- tree.children.append(child)
+ tree['nchild'] += 1
+ tree['children'].append(child)
elif directory[this].kind == FIFF_BLOCK_END:
tag = read_tag(fid, directory[start].pos)
if tag.data == block:
break
else:
- tree.nent += 1
- if tree.nent == 1:
- tree.directory = list()
- tree.directory.append(directory[this])
+ tree['nent'] += 1
+ if tree['nent'] == 1:
+ tree['directory'] = list()
+ tree['directory'].append(directory[this])
# Add the id information if available
if block == 0:
if directory[this].kind == FIFF_FILE_ID:
tag = read_tag(fid, directory[this].pos)
- tree.id = tag.data
+ tree['id'] = tag.data
else:
if directory[this].kind == FIFF_BLOCK_ID:
tag = read_tag(fid, directory[this].pos)
- tree.id = tag.data
+ tree['id'] = tag.data
elif directory[this].kind == FIFF_PARENT_BLOCK_ID:
tag = read_tag(fid, directory[this].pos)
- tree.parent_id = tag.data
+ tree['parent_id'] = tag.data
this += 1
# Eliminate the empty directory
- if tree.nent == 0:
- tree.directory = None
+ if tree['nent'] == 0:
+ tree['directory'] = None
if verbose:
print '\t' * (indent + 1) + 'block = %d nent = %d nchild = %d' % (
- tree.block, tree.nent, tree.nchild)
+ tree['block'], tree['nent'], tree['nchild'])
print '\t' * indent, 'end } %d' % block
last = this
@@ -123,7 +122,7 @@ def copy_tree(fidin, in_id, nodes, fidout):
nodes = [nodes]
for node in nodes:
- start_block(fidout, node.block)
+ start_block(fidout, node['block'])
if node['id'] is not None:
if in_id is not None:
write_id(fidout, FIFF.FIFF_PARENT_FILE_ID, in_id)
@@ -131,8 +130,8 @@ def copy_tree(fidin, in_id, nodes, fidout):
write_id(fidout, FIFF.FIFF_BLOCK_ID)
write_id(fidout, FIFF.FIFF_PARENT_BLOCK_ID, node['id'])
- if node.directory is not None:
- for d in node.directory:
+ if node['directory'] is not None:
+ for d in node['directory']:
# Do not copy these tags
if d.kind == FIFF.FIFF_BLOCK_ID or \
d.kind == FIFF.FIFF_PARENT_BLOCK_ID or \
@@ -151,4 +150,4 @@ def copy_tree(fidin, in_id, nodes, fidout):
for child in node['children']:
copy_tree(fidin, in_id, child, fidout)
- end_block(fidout, node.block)
+ end_block(fidout, node['block'])
diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py
index 375f23e..926aa04 100644
--- a/mne/minimum_norm/inverse.py
+++ b/mne/minimum_norm/inverse.py
@@ -47,7 +47,7 @@ def read_inverse_operator(fname):
invs = dir_tree_find(tree, FIFF.FIFFB_MNE_INVERSE_SOLUTION)
if invs is None:
fid.close()
- raise ValueError('No inverse solutions in %s' % fname)
+ raise Exception('No inverse solutions in %s' % fname)
invs = invs[0]
#
@@ -56,7 +56,7 @@ def read_inverse_operator(fname):
parent_mri = dir_tree_find(tree, FIFF.FIFFB_MNE_PARENT_MRI_FILE)
if len(parent_mri) == 0:
fid.close()
- raise ValueError('No parent MRI information in %s' % fname)
+ raise Exception('No parent MRI information in %s' % fname)
parent_mri = parent_mri[0]
print '\tReading inverse operator info...',
@@ -66,7 +66,7 @@ def read_inverse_operator(fname):
tag = find_tag(fid, invs, FIFF.FIFF_MNE_INCLUDED_METHODS)
if tag is None:
fid.close()
- raise ValueError('Modalities not found')
+ raise Exception('Modalities not found')
inv = dict()
inv['methods'] = tag.data
@@ -74,14 +74,14 @@ def read_inverse_operator(fname):
tag = find_tag(fid, invs, FIFF.FIFF_MNE_SOURCE_ORIENTATION)
if tag is None:
fid.close()
- raise ValueError('Source orientation constraints not found')
+ raise Exception('Source orientation constraints not found')
inv['source_ori'] = int(tag.data)
tag = find_tag(fid, invs, FIFF.FIFF_MNE_SOURCE_SPACE_NPOINTS)
if tag is None:
fid.close()
- raise ValueError('Number of sources not found')
+ raise Exception('Number of sources not found')
inv['nsource'] = tag.data
inv['nchan'] = 0
@@ -91,7 +91,7 @@ def read_inverse_operator(fname):
tag = find_tag(fid, invs, FIFF.FIFF_MNE_COORD_FRAME)
if tag is None:
fid.close()
- raise ValueError('Coordinate frame tag not found')
+ raise Exception('Coordinate frame tag not found')
inv['coord_frame'] = tag.data
#
@@ -100,7 +100,7 @@ def read_inverse_operator(fname):
tag = find_tag(fid, invs, FIFF.FIFF_MNE_INVERSE_SOURCE_ORIENTATIONS)
if tag is None:
fid.close()
- raise ValueError('Source orientation information not found')
+ raise Exception('Source orientation information not found')
inv['source_nn'] = tag.data
print '[done]'
@@ -111,7 +111,7 @@ def read_inverse_operator(fname):
tag = find_tag(fid, invs, FIFF.FIFF_MNE_INVERSE_SING)
if tag is None:
fid.close()
- raise ValueError('Singular values not found')
+ raise Exception('Singular values not found')
inv['sing'] = tag.data
inv['nchan'] = len(inv['sing'])
@@ -124,60 +124,40 @@ def read_inverse_operator(fname):
FIFF.FIFF_MNE_INVERSE_LEADS)
except:
inv['eigen_leads_weighted'] = True
- try:
- inv['eigen_leads'] = _read_named_matrix(fid, invs,
- FIFF.FIFF_MNE_INVERSE_LEADS_WEIGHTED)
- except Exception as inst:
- raise ValueError('%s' % inst)
+ inv['eigen_leads'] = _read_named_matrix(fid, invs,
+ FIFF.FIFF_MNE_INVERSE_LEADS_WEIGHTED)
#
# Having the eigenleads as columns is better for the inverse calculations
#
inv['eigen_leads'] = _transpose_named_matrix(inv['eigen_leads'])
- try:
- inv['eigen_fields'] = _read_named_matrix(fid, invs,
- FIFF.FIFF_MNE_INVERSE_FIELDS)
- except Exception as inst:
- raise ValueError('%s' % inst)
+ inv['eigen_fields'] = _read_named_matrix(fid, invs,
+ FIFF.FIFF_MNE_INVERSE_FIELDS)
print '[done]'
#
# Read the covariance matrices
#
- try:
- inv['noise_cov'] = read_cov(fid, invs, FIFF.FIFFV_MNE_NOISE_COV)
- print '\tNoise covariance matrix read.'
- except Exception as inst:
- fid.close()
- raise ValueError('%s' % inst)
+ inv['noise_cov'] = read_cov(fid, invs, FIFF.FIFFV_MNE_NOISE_COV)
+ print '\tNoise covariance matrix read.'
- try:
- inv['source_cov'] = read_cov(fid, invs, FIFF.FIFFV_MNE_SOURCE_COV)
- print '\tSource covariance matrix read.'
- except Exception as inst:
- fid.close()
- raise ValueError('%s' % inst)
+ inv['source_cov'] = read_cov(fid, invs, FIFF.FIFFV_MNE_SOURCE_COV)
+ print '\tSource covariance matrix read.'
#
# Read the various priors
#
- try:
- inv['orient_prior'] = read_cov(fid, invs,
- FIFF.FIFFV_MNE_ORIENT_PRIOR_COV)
+ inv['orient_prior'] = read_cov(fid, invs,
+ FIFF.FIFFV_MNE_ORIENT_PRIOR_COV)
+ if inv['orient_prior'] is not None:
print '\tOrientation priors read.'
- except Exception as inst:
- inv['orient_prior'] = []
- try:
- inv['depth_prior'] = read_cov(fid, invs,
- FIFF.FIFFV_MNE_DEPTH_PRIOR_COV)
+ inv['depth_prior'] = read_cov(fid, invs,
+ FIFF.FIFFV_MNE_DEPTH_PRIOR_COV)
+ if inv['depth_prior'] is not None:
print '\tDepth priors read.'
- except:
- inv['depth_prior'] = []
- try:
- inv['fmri_prior'] = read_cov(fid, invs, FIFF.FIFFV_MNE_FMRI_PRIOR_COV)
+ inv['fmri_prior'] = read_cov(fid, invs, FIFF.FIFFV_MNE_FMRI_PRIOR_COV)
+ if inv['fmri_prior'] is not None:
print '\tfMRI priors read.'
- except:
- inv['fmri_prior'] = []
#
# Read the source spaces
@@ -186,7 +166,7 @@ def read_inverse_operator(fname):
inv['src'] = read_source_spaces_from_tree(fid, tree, add_geom=False)
except Exception as inst:
fid.close()
- raise ValueError('Could not read the source spaces (%s)' % inst)
+ raise Exception('Could not read the source spaces (%s)' % inst)
for s in inv['src']:
s['id'] = find_source_space_hemi(s)
@@ -197,7 +177,7 @@ def read_inverse_operator(fname):
tag = find_tag(fid, parent_mri, FIFF.FIFF_COORD_TRANS)
if tag is None:
fid.close()
- raise ValueError('MRI/head coordinate transformation not found')
+ raise Exception('MRI/head coordinate transformation not found')
else:
mri_head_t = tag.data
if mri_head_t['from'] != FIFF.FIFFV_COORD_MRI or \
@@ -206,7 +186,7 @@ def read_inverse_operator(fname):
if mri_head_t['from'] != FIFF.FIFFV_COORD_MRI or \
mri_head_t['to'] != FIFF.FIFFV_COORD_HEAD:
fid.close()
- raise ValueError('MRI/head coordinate transformation '
+ raise Exception('MRI/head coordinate transformation '
'not found')
inv['mri_head_t'] = mri_head_t
@@ -217,7 +197,7 @@ def read_inverse_operator(fname):
if inv['coord_frame'] != FIFF.FIFFV_COORD_MRI and \
inv['coord_frame'] != FIFF.FIFFV_COORD_HEAD:
fid.close()
- raise ValueError('Only inverse solutions computed in MRI or '
+ raise Exception('Only inverse solutions computed in MRI or '
'head coordinates are acceptable')
#
@@ -244,7 +224,7 @@ def read_inverse_operator(fname):
inv['coord_frame'], mri_head_t)
except Exception as inst:
fid.close()
- raise ValueError('Could not transform source space (%s)' % inst)
+ raise Exception('Could not transform source space (%s)' % inst)
nuse += inv['src'][k]['nuse']
@@ -276,9 +256,9 @@ def combine_xyz(vec, square=False):
Output vector [sqrt(x1^2+y1^2+z1^2), ..., sqrt(x_n^2+y_n^2+z_n^2)]
"""
if vec.ndim != 2:
- raise ValueError('Input must be 2D')
+ raise Exception('Input must be 2D')
if (vec.shape[0] % 3) != 0:
- raise ValueError('Input must have 3N rows')
+ raise Exception('Input must have 3N rows')
n, p = vec.shape
if np.iscomplexobj(vec):
diff --git a/mne/source_estimate.py b/mne/source_estimate.py
index b96f353..36060fe 100644
--- a/mne/source_estimate.py
+++ b/mne/source_estimate.py
@@ -376,7 +376,7 @@ def morph_data(subject_from, subject_to, stc_from, grade=5, smooth=None,
dots = np.dot(rr[k:k + dr], rhs.T)
nearest[1, k:k + dr] = np.argmax(dots, axis=1)
- stc_to = copy.copy(stc_from)
+ stc_to = copy.deepcopy(stc_from)
stc_to.lh_vertno = nearest[0]
stc_to.rh_vertno = nearest[1]
stc_to.data = np.r_[dmap[0][nearest[0], :], dmap[1][nearest[1], :]]
diff --git a/mne/transforms.py b/mne/transforms.py
index 6e6a895..2b07e49 100644
--- a/mne/transforms.py
+++ b/mne/transforms.py
@@ -8,7 +8,7 @@ from scipy import linalg
def invert_transform(trans):
"""Invert a transformation between coordinate systems
"""
- itrans = copy.copy(trans)
+ itrans = copy.deepcopy(trans)
aux = itrans['from']
itrans['from'] = itrans['to']
itrans['to'] = aux
@@ -69,7 +69,7 @@ def transform_source_space_to(src, dest, trans):
# XXX
# """
#
-# res = copy.copy(chs)
+# res = copy.deepcopy(chs)
#
# count = 0
# t = trans['trans']
@@ -102,7 +102,7 @@ def transform_source_space_to(src, dest, trans):
#
# XXX
# """
-# res = copy.copy(chs)
+# res = copy.deepcopy(chs)
#
# count = 0
# #
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git
More information about the debian-med-commit
mailing list