[med-svn] [python-mne] 32/52: ENH : adding mne.read_proj and adding __repr__ to projection vectors
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:23:47 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.2
in repository python-mne.
commit aef0cd79b0543c6d121de236098bd7865feff39e
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Tue Oct 11 11:10:38 2011 -0400
ENH : adding mne.read_proj and adding __repr__ to projection vectors
---
mne/__init__.py | 1 +
mne/fiff/proj.py | 43 +++++++++++++++++++++++++++----------------
mne/proj.py | 24 ++++++++++++++++++++++++
3 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/mne/__init__.py b/mne/__init__.py
index 92379c9..31702d8 100644
--- a/mne/__init__.py
+++ b/mne/__init__.py
@@ -13,6 +13,7 @@ from .epochs import Epochs
from .label import label_time_courses, read_label
from .misc import parse_config, read_reject_parameters
from .transforms import transform_coordinates
+from .proj import read_proj
import fiff
import artifacts
import stats
diff --git a/mne/fiff/proj.py b/mne/fiff/proj.py
index 9cb31ca..3fda207 100644
--- a/mne/fiff/proj.py
+++ b/mne/fiff/proj.py
@@ -13,8 +13,20 @@ from .tag import find_tag
from .pick import pick_types
+class Projection(dict):
+ """Projection vector
+
+ A basic class to proj a meaningful print for projection vectors.
+ """
+ def __repr__(self):
+ s = "%s" % self['desc']
+ s += ", active : %s " % self['active']
+ s += ", nb of channels : %s " % self['data']['ncol']
+ return "Projection (%s)" % s
+
+
def read_proj(fid, node):
- """Read a projection operator from a FIF file.
+ """Read spatial projections from a FIF file.
Parameters
----------
@@ -26,16 +38,15 @@ def read_proj(fid, node):
Returns
-------
- projdata: dict
- The projection operator
+ projs: dict
+ The list of projections
"""
-
- projdata = []
+ projs = list()
# Locate the projection data
nodes = dir_tree_find(node, FIFF.FIFFB_PROJ)
if len(nodes) == 0:
- return projdata
+ return projs
tag = find_tag(fid, nodes[0], FIFF.FIFF_NCHAN)
if tag is not None:
@@ -104,25 +115,25 @@ def read_proj(fid, node):
'size of data matrix')
# Use exactly the same fields in data as in a named matrix
- one = dict(kind=kind, active=active, desc=desc,
+ one = Projection(kind=kind, active=active, desc=desc,
data=dict(nrow=nvec, ncol=nchan, row_names=None,
col_names=names, data=data))
- projdata.append(one)
+ projs.append(one)
- 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 len(projs) > 0:
+ print '\tRead a total of %d projection items:' % len(projs)
+ for k in range(len(projs)):
+ if projs[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' % (projs[k]['desc'],
+ projs[k]['data']['nrow'],
+ projs[k]['data']['ncol'],
misc)
- return projdata
+ return projs
###############################################################################
# Write
diff --git a/mne/proj.py b/mne/proj.py
new file mode 100644
index 0000000..2bd4172
--- /dev/null
+++ b/mne/proj.py
@@ -0,0 +1,24 @@
+# Authors: Alexandre Gramfort <gramfort at nmr.mgh.harvard.edu>
+#
+# License: BSD (3-clause)
+
+from .fiff import fiff_open
+from .fiff.proj import read_proj as fiff_read_proj
+
+
+def read_proj(fname):
+ """Read projections from a FIF file.
+
+ Parameters
+ ----------
+ fname: string
+ The name of file containing the projections vectors.
+
+ Returns
+ -------
+ projs: list
+ The list of projection vectors.
+ """
+ fid, tree, _ = fiff_open(fname)
+ projs = fiff_read_proj(fid, tree)
+ return projs
--
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