[med-svn] [python-mne] 203/376: ENH : rm some XXX for speed
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:22:37 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 49c4df618be02f7e0722e9c8e26790a2afac62e2
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Sun Apr 17 19:59:26 2011 -0400
ENH : rm some XXX for speed
---
examples/read_bem_surfaces.py | 2 +-
mne/bem_surfaces.py | 20 ++++++--------------
mne/fiff/raw.py | 3 +--
3 files changed, 8 insertions(+), 17 deletions(-)
diff --git a/examples/read_bem_surfaces.py b/examples/read_bem_surfaces.py
index d70d3c1..fc8cb47 100755
--- a/examples/read_bem_surfaces.py
+++ b/examples/read_bem_surfaces.py
@@ -15,7 +15,7 @@ from mne.datasets import sample
data_path = sample.data_path('.')
fname = data_path + '/subjects/sample/bem/sample-5120-5120-5120-bem-sol.fif'
-surfaces = mne.read_bem_surfaces(fname)
+surfaces = mne.read_bem_surfaces(fname, add_geom=True)
print "Number of surfaces : %d" % len(surfaces)
diff --git a/mne/bem_surfaces.py b/mne/bem_surfaces.py
index 90fbb0f..2c62811 100755
--- a/mne/bem_surfaces.py
+++ b/mne/bem_surfaces.py
@@ -4,7 +4,6 @@
# License: BSD (3-clause)
import numpy as np
-from scipy import linalg
from .fiff.constants import FIFF
from .fiff.open import fiff_open
@@ -173,8 +172,7 @@ def _read_bem_surface(fid, this, def_coord_frame):
def _complete_surface_info(this):
- """ XXX : should be factorize with complete_source_space_info
- """
+ """Complete surface info"""
#
# Main triangulation
#
@@ -189,27 +187,21 @@ def _complete_surface_info(this):
#
# Triangle normals and areas
#
- for p in range(this['ntri']):
- size = linalg.norm(this['tri_nn'][p, :])
- this['tri_area'][p] = size / 2.0
- if size > 0.0:
- this['tri_nn'][p, :] = this['tri_nn'][p, :] / size
+ size = np.sqrt(np.sum(this['tri_nn'] ** 2, axis=1))
+ this['tri_area'] = size / 2.0
+ this['tri_nn'] /= size[:, None]
#
# Accumulate the vertex normals
#
print 'vertex normals...',
this['nn'] = np.zeros((this['np'], 3))
for p in range(this['ntri']):
- this['nn'][this['tris'][p, :], :] = this['nn'][this['tris'][p, :], :] \
- + np.kron(np.ones((3, 1)), this['tri_nn'][p, :])
+ this['nn'][this['tris'][p, :], :] += this['tri_nn'][p, :]
#
# Compute the lengths of the vertex normals and scale
#
print 'normalize...',
- for p in range(this['np']):
- size = linalg.norm(this['nn'][p, :])
- if size > 0:
- this['nn'][p, :] = this['nn'][p, :] / size
+ this['nn'] /= np.sqrt(np.sum(this['nn'] ** 2, axis=1))[:, None]
print '[done]'
return this
diff --git a/mne/fiff/raw.py b/mne/fiff/raw.py
index 702da96..5d9d15a 100755
--- a/mne/fiff/raw.py
+++ b/mne/fiff/raw.py
@@ -611,8 +611,7 @@ def write_raw_buffer(fid, buf, cals):
if buf.shape[0] != len(cals):
raise ValueError('buffer and calibration sizes do not match')
- write_float(fid, FIFF.FIFF_DATA_BUFFER, # XXX can do better
- np.dot(np.diag(1.0 / np.ravel(cals)), buf))
+ write_float(fid, FIFF.FIFF_DATA_BUFFER, buf / np.ravel(cals)[:, None])
def finish_writing_raw(fid):
--
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