[med-svn] [python-mne] 196/376: MISC : s/from_/from/g + some pep8
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:22:36 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 879debc2bc9c635da801f2acfb9a2d5385a315d5
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Thu Apr 14 17:41:04 2011 -0400
MISC : s/from_/from/g + some pep8
---
mne/fiff/meas_info.py | 80 +++++++++++++++++++++++++--------------------------
mne/fiff/tag.py | 2 +-
mne/fiff/write.py | 2 +-
mne/forward.py | 32 +++++++++++----------
mne/inverse.py | 4 +--
mne/transforms.py | 62 ++++++++++++++++++++-------------------
6 files changed, 93 insertions(+), 89 deletions(-)
diff --git a/mne/fiff/meas_info.py b/mne/fiff/meas_info.py
index 61c4b29..52898a6 100755
--- a/mne/fiff/meas_info.py
+++ b/mne/fiff/meas_info.py
@@ -41,16 +41,16 @@ def read_meas_info(fid, tree):
# Find the desired blocks
meas = dir_tree_find(tree, FIFF.FIFFB_MEAS)
if len(meas) == 0:
- raise ValueError, 'Could not find measurement data'
+ raise ValueError('Could not find measurement data')
if len(meas) > 1:
- raise ValueError, 'Cannot read more that 1 measurement data'
+ raise ValueError('Cannot read more that 1 measurement data')
meas = meas[0]
meas_info = dir_tree_find(meas, FIFF.FIFFB_MEAS_INFO)
if len(meas_info) == 0:
- raise ValueError, 'Could not find measurement info'
+ raise ValueError('Could not find measurement info')
if len(meas_info) > 1:
- raise ValueError, 'Cannot read more that 1 measurement info'
+ raise ValueError('Cannot read more that 1 measurement info')
meas_info = meas_info[0]
# Read measurement info
@@ -88,72 +88,72 @@ def read_meas_info(fid, tree):
elif kind == FIFF.FIFF_COORD_TRANS:
tag = read_tag(fid, pos)
cand = tag.data
- if cand['from_'] == FIFF.FIFFV_COORD_DEVICE and \
- cand['to'] == FIFF.FIFFV_COORD_HEAD: # XXX : from
+ if cand['from'] == FIFF.FIFFV_COORD_DEVICE and \
+ cand['to'] == FIFF.FIFFV_COORD_HEAD:
dev_head_t = cand
- elif cand['from_'] == FIFF.FIFFV_MNE_COORD_CTF_HEAD and \
+ elif cand['from'] == FIFF.FIFFV_MNE_COORD_CTF_HEAD and \
cand['to'] == FIFF.FIFFV_COORD_HEAD:
ctf_head_t = cand
# Check that we have everything we need
if nchan is None:
- raise ValueError, 'Number of channels in not defined'
+ raise ValueError('Number of channels in not defined')
if sfreq is None:
- raise ValueError, 'Sampling frequency is not defined'
+ raise ValueError('Sampling frequency is not defined')
if len(chs) == 0:
- raise ValueError, 'Channel information not defined'
+ raise ValueError('Channel information not defined')
if len(chs) != nchan:
- raise ValueError, 'Incorrect number of channel definitions found'
+ raise ValueError('Incorrect number of channel definitions found')
if dev_head_t is None or ctf_head_t is None:
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
- if kind == FIFF.FIFF_COORD_TRANS:
+ 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;
- if cand.from_ == FIFF.FIFFV_COORD_DEVICE and \
- cand.to == FIFF.FIFFV_COORD_HEAD: # XXX: from
- dev_head_t = cand;
- elif cand.from_ == FIFF.FIFFV_MNE_COORD_CTF_HEAD and \
- cand.to == FIFF.FIFFV_COORD_HEAD:
- ctf_head_t = cand;
+ cand = tag.data
+ if cand['from'] == FIFF.FIFFV_COORD_DEVICE and \
+ cand['to'] == FIFF.FIFFV_COORD_HEAD:
+ dev_head_t = cand
+ elif cand['from'] == FIFF.FIFFV_MNE_COORD_CTF_HEAD and \
+ cand['to'] == FIFF.FIFFV_COORD_HEAD:
+ ctf_head_t = cand
# Locate the Polhemus data
- isotrak = dir_tree_find(meas_info,FIFF.FIFFB_ISOTRAK)
+ isotrak = dir_tree_find(meas_info, FIFF.FIFFB_ISOTRAK)
if len(isotrak):
isotrak = isotrak[0]
else:
if len(isotrak) == 0:
- raise ValueError, 'Isotrak not found'
+ raise ValueError('Isotrak not found')
if len(isotrak) > 1:
- raise ValueError, 'Multiple Isotrak found'
+ raise ValueError('Multiple Isotrak found')
dig = []
if len(isotrak) == 1:
for k in range(isotrak.nent):
- kind = isotrak.directory[k].kind;
- pos = isotrak.directory[k].pos;
+ kind = isotrak.directory[k].kind
+ pos = isotrak.directory[k].pos
if kind == FIFF.FIFF_DIG_POINT:
- tag = read_tag(fid,pos);
+ tag = read_tag(fid, pos)
dig.append(tag.data)
dig[-1]['coord_frame'] = FIFF.FIFFV_COORD_HEAD
# Locate the acquisition information
- acqpars = dir_tree_find(meas_info, FIFF.FIFFB_DACQ_PARS);
+ acqpars = dir_tree_find(meas_info, FIFF.FIFFB_DACQ_PARS)
acq_pars = None
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
+ pos = acqpars.directory[k].pos
if kind == FIFF.FIFF_DACQ_PARS:
tag = read_tag(fid, pos)
acq_pars = tag.data
@@ -174,9 +174,9 @@ def read_meas_info(fid, tree):
# Put the data together
#
if tree.id is not None:
- info = dict(file_id=tree.id)
+ info = dict(file_id=tree.id)
else:
- info = dict(file_id=None)
+ info = dict(file_id=None)
# Make the most appropriate selection for the measurement id
if meas_info.parent_id is None:
@@ -191,12 +191,12 @@ def read_meas_info(fid, tree):
else:
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']]
+ info['meas_date'] = [info['meas_id']['secs'], info['meas_id']['usecs']]
else:
- info['meas_date'] = meas_date
+ info['meas_date'] = meas_date
info['nchan'] = nchan
info['sfreq'] = sfreq
@@ -205,7 +205,7 @@ def read_meas_info(fid, tree):
# Add the channel information and make a list of channel names
# for convenience
- info['chs'] = chs;
+ info['chs'] = chs
info['ch_names'] = [ch.ch_name for ch in chs]
#
@@ -214,11 +214,12 @@ def read_meas_info(fid, tree):
info['dev_head_t'] = dev_head_t
info['ctf_head_t'] = ctf_head_t
if dev_head_t is not None and ctf_head_t is not None:
- info['dev_ctf_t'] = info['dev_head_t']
- info['dev_ctf_t'].to = info['ctf_head_t'].from_ # XXX : see if better name
- info['dev_ctf_t'].trans = np.dot(np.inv(ctf_head_t.trans), info.dev_ctf_t.trans)
+ info['dev_ctf_t'] = info['dev_head_t']
+ info['dev_ctf_t']['to'] = info['ctf_head_t']['from']
+ info['dev_ctf_t']['trans'] = np.dot(np.inv(ctf_head_t['trans']),
+ info['dev_ctf_t']['trans'])
else:
- info['dev_ctf_t'] = []
+ info['dev_ctf_t'] = []
# All kinds of auxliary stuff
info['dig'] = dig
@@ -299,4 +300,3 @@ def write_meas_info(fid, info):
end_block(fid, FIFF.FIFFB_MNE_BAD_CHANNELS)
end_block(fid, FIFF.FIFFB_MEAS_INFO)
-
diff --git a/mne/fiff/tag.py b/mne/fiff/tag.py
index de91909..d3652ae 100755
--- a/mne/fiff/tag.py
+++ b/mne/fiff/tag.py
@@ -235,7 +235,7 @@ def read_tag(fid, pos=None):
tag.data['coord_frame'] = 0
elif tag.type == FIFF.FIFFT_COORD_TRANS_STRUCT:
tag.data = Bunch()
- tag.data['from_'] = int(np.fromfile(fid, dtype=">i4", count=1))
+ 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)
move = np.fromfile(fid, dtype=">f4", count=3)
diff --git a/mne/fiff/write.py b/mne/fiff/write.py
index d96b6ff..51e0f61 100755
--- a/mne/fiff/write.py
+++ b/mne/fiff/write.py
@@ -184,7 +184,7 @@ def write_coord_trans(fid, trans):
fid.write(np.array(FIFFT_COORD_TRANS_STRUCT, dtype='>i4').tostring())
fid.write(np.array(data_size, dtype='>i4').tostring())
fid.write(np.array(FIFFV_NEXT_SEQ, dtype='>i4').tostring())
- fid.write(np.array(trans['from_'], dtype='>i4').tostring())
+ fid.write(np.array(trans['from'], dtype='>i4').tostring())
fid.write(np.array(trans['to'], dtype='>i4').tostring())
# The transform...
diff --git a/mne/forward.py b/mne/forward.py
index d5ba2ce..28b08a2 100755
--- a/mne/forward.py
+++ b/mne/forward.py
@@ -22,19 +22,21 @@ def _block_diag(A, n):
You have to try it on a matrix to see what it's doing.
- % If A is not sparse, then returns a sparse block diagonal "bd",
- % diagonalized from the
- % elements in "A".
- % "A" is ma x na, comprising bdn=(na/"n") blocks of submatrices.
- % Each submatrix is ma x "n", and these submatrices are
- % placed down the diagonal of the matrix.
- %
- % If A is already sparse, then the operation is reversed, yielding
- # a block
- % row matrix, where each set of n columns corresponds to a block element
- % from the block diagonal.
- %
- % Routine uses NO for-loops for speed considerations.
+ If A is not sparse, then returns a sparse block diagonal "bd",
+ diagonalized from the
+ elements in "A".
+ "A" is ma x na, comprising bdn=(na/"n") blocks of submatrices.
+ Each submatrix is ma x "n", and these submatrices are
+ placed down the diagonal of the matrix.
+
+ If A is already sparse, then the operation is reversed, yielding
+ a block
+ row matrix, where each set of n columns corresponds to a block element
+ from the block diagonal.
+
+ Routine uses NO for-loops for speed considerations.
+
+ XXX : format doc
"""
from scipy import sparse
@@ -294,10 +296,10 @@ def read_forward_solution(fname, force_fixed=False, surf_ori=False,
raise ValueError, 'MRI/head coordinate transformation not found'
else:
mri_head_t = tag.data;
- if (mri_head_t['from_'] != FIFF.FIFFV_COORD_MRI or
+ if (mri_head_t['from'] != FIFF.FIFFV_COORD_MRI or
mri_head_t['to'] != FIFF.FIFFV_COORD_HEAD):
mri_head_t = invert_transform(mri_head_t)
- if (mri_head_t['from_'] != FIFF.FIFFV_COORD_MRI
+ 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 not ' \
diff --git a/mne/inverse.py b/mne/inverse.py
index e563b61..e7a596d 100755
--- a/mne/inverse.py
+++ b/mne/inverse.py
@@ -199,10 +199,10 @@ def read_inverse_operator(fname):
raise ValueError('MRI/head coordinate transformation not found')
else:
mri_head_t = tag.data
- if mri_head_t['from_'] != FIFF.FIFFV_COORD_MRI or \
+ if mri_head_t['from'] != FIFF.FIFFV_COORD_MRI or \
mri_head_t['to'] != FIFF.FIFFV_COORD_HEAD:
mri_head_t = invert_transform(mri_head_t)
- if mri_head_t['from_'] != FIFF.FIFFV_COORD_MRI or \
+ 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 '
diff --git a/mne/transforms.py b/mne/transforms.py
index 80912aa..5de385d 100755
--- a/mne/transforms.py
+++ b/mne/transforms.py
@@ -2,44 +2,46 @@ import copy
import numpy as np
from scipy import linalg
-from .fiff import FIFF
-
+# from .fiff import FIFF
def invert_transform(trans):
"""Invert a transformation between coordinate systems
"""
itrans = copy.copy(trans)
- aux = itrans['from_']
- itrans['from_'] = itrans['to']
+ aux = itrans['from']
+ itrans['from'] = itrans['to']
itrans['to'] = aux
itrans['trans'] = linalg.inv(itrans['trans'])
return itrans
def transform_source_space_to(src, dest, trans):
- """
- %
- % [res] = mne_transform_source_space_to(src,dest,trans)
- %
- % Transform source space data to the desired coordinate system
- %
- % fname - The name of the file
- % include - Include these channels (optional)
- % exclude - Exclude these channels (optional)
- %
+ """Transform source space data to the desired coordinate system
+
+ Parameters
+ ----------
+ src : dict
+ Source space
+ dest : dict
+ destination coordinate system
+ trans : dict
+ Transformation
- XXX
+ Returns
+ -------
+ res : dict
+ Transformed source space
"""
if src['coord_frame'] == dest:
res = src
return res
- if trans['to'] == src['coord_frame'] and trans['from_'] == dest:
+ if trans['to'] == src['coord_frame'] and trans['from'] == dest:
trans = invert_transform(trans)
- elif trans['from_'] != src['coord_frame'] or trans['to'] != dest:
- raise ValueError, 'Cannot transform the source space using this ' \
- 'coordinate transformation'
+ elif trans['from'] != src['coord_frame'] or trans['to'] != dest:
+ raise ValueError('Cannot transform the source space using this '
+ 'coordinate transformation')
t = trans['trans'][:3,:]
res = src
@@ -62,26 +64,26 @@ def transform_source_space_to(src, dest, trans):
# % loc which remains to reflect the original data read from the fif file
# %
# %
-#
+#
# XXX
# """
-#
+#
# res = copy.copy(chs)
-#
+#
# count = 0
# t = trans['trans']
# for ch in res:
# if (ch['kind'] == FIFF.FIFFV_MEG_CH
# or ch['kind'] == FIFF.FIFFV_REF_MEG_CH):
-# if (ch['coord_frame'] == trans['from_']
+# if (ch['coord_frame'] == trans['from']
# and ch['coil_trans'] is not None):
# ch['coil_trans'] = np.dot(t, ch['coil_trans'])
# ch['coord_frame'] = trans['to']
# count += 1
-#
+#
# if count > 0:
# print '\t%d MEG channel locations transformed' % count
-#
+#
# return res, count
@@ -96,11 +98,11 @@ def transform_source_space_to(src, dest, trans):
# % NOTE: Only the eeg_loc field is modified by this routine, not
# % loc which remains to reflect the original data read from the fif file
# %
-#
+#
# XXX
# """
# res = copy.copy(chs)
-#
+#
# count = 0
# #
# # Output unaugmented vectors from the transformation
@@ -108,7 +110,7 @@ def transform_source_space_to(src, dest, trans):
# t = trans['trans'][:3,:]
# for ch in res:
# if ch['kind'] == FIFF.FIFFV_EEG_CH:
-# if (ch['coord_frame'] == trans['from_']
+# if (ch['coord_frame'] == trans['from']
# and ch['eeg_loc'] is not None):
# #
# # Transform the augmented EEG location vectors
@@ -118,8 +120,8 @@ def transform_source_space_to(src, dest, trans):
# np.r_[ch['eeg_loc'][:,p], 1])
# count += 1
# ch['coord_frame'] = trans['to']
-#
+#
# if count > 0:
# print '\t%d EEG electrode locations transformed\n' % count
-#
+#
# return res, count
--
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