[med-svn] [python-mne] 337/376: FIX : less code duplication in write of meas info between raw and evoked (WIP)
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:23:18 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 36133fc3692f66547aca8217b453beba2ee0a0cd
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Thu Aug 11 14:46:31 2011 -0400
FIX : less code duplication in write of meas info between raw and evoked (WIP)
---
mne/fiff/meas_info.py | 4 +-
mne/fiff/raw.py | 129 ++++++++++++++------------------------------------
mne/fiff/write.py | 2 +-
3 files changed, 39 insertions(+), 96 deletions(-)
diff --git a/mne/fiff/meas_info.py b/mne/fiff/meas_info.py
index e1a0aeb..9f5b097 100644
--- a/mne/fiff/meas_info.py
+++ b/mne/fiff/meas_info.py
@@ -232,7 +232,7 @@ def read_meas_info(fid, tree):
return info, meas
-def write_meas_info(fid, info):
+def write_meas_info(fid, info, data_type=None):
"""Write measurement info in fif file."""
# Measurement info
@@ -262,6 +262,8 @@ def write_meas_info(fid, info):
write_float(fid, FIFF.FIFF_HIGHPASS, info['highpass'])
write_float(fid, FIFF.FIFF_LOWPASS, info['lowpass'])
write_int(fid, FIFF.FIFF_NCHAN, info['nchan'])
+ if data_type is not None:
+ write_int(fid, FIFF.FIFF_DATA_PACK, data_type)
if info['meas_date'] is not None:
write_int(fid, FIFF.FIFF_MEAS_DATE, info['meas_date'])
diff --git a/mne/fiff/raw.py b/mne/fiff/raw.py
index f90d8e6..410ab5a 100644
--- a/mne/fiff/raw.py
+++ b/mne/fiff/raw.py
@@ -9,7 +9,7 @@ import numpy as np
from .constants import FIFF
from .open import fiff_open
-from .evoked import read_meas_info
+from .meas_info import read_meas_info, write_meas_info
from .tree import dir_tree_find
from .tag import read_tag
@@ -498,13 +498,13 @@ def start_writing_raw(name, info, sel=None):
#
# We will always write floats
#
- if sel is None:
- chs = info['chs']
- nchan = len(chs)
- else:
- chs = [info['chs'][k] for k in sel]
- nchan = len(sel)
- data_type = 4
+ # if sel is None:
+ # chs = info['chs']
+ # nchan = len(chs)
+ # else:
+ # chs = [info['chs'][k] for k in sel]
+ # nchan = len(sel)
+ # data_type = 4
#
# Create the file and save the essentials
#
@@ -516,65 +516,13 @@ def start_writing_raw(name, info, sel=None):
#
# Measurement info
#
- start_block(fid, FIFF.FIFFB_MEAS_INFO)
- #
- # Blocks from the original
- #
- blocks = [FIFF.FIFFB_SUBJECT, FIFF.FIFFB_HPI_MEAS, FIFF.FIFFB_HPI_RESULT,
- FIFF.FIFFB_ISOTRAK, FIFF.FIFFB_PROCESSING_HISTORY]
- have_hpi_result = False
- have_isotrak = False
- if len(blocks) > 0 and 'filename' in info and info['filename'] is not None:
- fid2, tree, _ = fiff_open(info['filename'])
- for b in blocks:
- nodes = dir_tree_find(tree, b)
- 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:
- have_isotrak = True
- fid2.close()
-
- #
- # megacq parameters
- #
- if info['acq_pars'] is not None or info['acq_stim'] is not None:
- start_block(fid, FIFF.FIFFB_DACQ_PARS)
- if info['acq_pars'] is not None:
- write_string(fid, FIFF.FIFF_DACQ_PARS, info['acq_pars'])
-
- if info['acq_stim'] is not None:
- write_string(fid, FIFF.FIFF_DACQ_STIM, info['acq_stim'])
-
- end_block(fid, FIFF.FIFFB_DACQ_PARS)
- #
- # Coordinate transformations if the HPI result block was not there
- #
- if not have_hpi_result:
- if info['dev_head_t'] is not None:
- write_coord_trans(fid, info['dev_head_t'])
-
- if info['ctf_head_t'] is not None:
- write_coord_trans(fid, info['ctf_head_t'])
- #
- # Polhemus data
- #
- if info['dig'] is not None and not have_isotrak:
- start_block(fid, FIFF.FIFFB_ISOTRAK)
- for dig_point in info['dig']:
- write_dig_point(fid, dig_point)
- end_block(fid, FIFF.FIFFB_ISOTRAK)
- #
- # Projectors
- #
- write_proj(fid, info['projs'])
- #
- # CTF compensation info
- #
- comps = info['comps']
if sel is not None:
- ch_names = [c['ch_name'] for c in chs] # name of good channels
- comps = copy.deepcopy(comps)
+ info = copy.deepcopy(info)
+ info['chs'] = [info['chs'][k] for k in sel]
+ info['nchan'] = len(sel)
+
+ ch_names = [c['ch_name'] for c in info['chs']] # name of good channels
+ comps = copy.deepcopy(info['comps'])
for c in comps:
row_idx = [k for k, n in enumerate(c['data']['row_names'])
if n in ch_names]
@@ -584,38 +532,31 @@ def start_writing_raw(name, info, sel=None):
c['data']['nrow'] = len(row_names)
c['data']['row_names'] = row_names
c['data']['data'] = c['data']['data'][row_idx]
- write_ctf_comp(fid, comps)
- #
- # Bad channels
- #
- if len(info['bads']) > 0:
- start_block(fid, FIFF.FIFFB_MNE_BAD_CHANNELS)
- write_name_list(fid, FIFF.FIFF_MNE_CH_NAME_LIST, info['bads'])
- end_block(fid, FIFF.FIFFB_MNE_BAD_CHANNELS)
- #
- # General
- #
- write_float(fid, FIFF.FIFF_SFREQ, info['sfreq'])
- write_float(fid, FIFF.FIFF_HIGHPASS, info['highpass'])
- write_float(fid, FIFF.FIFF_LOWPASS, info['lowpass'])
- write_int(fid, FIFF.FIFF_NCHAN, nchan)
- write_int(fid, FIFF.FIFF_DATA_PACK, data_type)
- if info['meas_date'] is not None:
- write_int(fid, FIFF.FIFF_MEAS_DATE, info['meas_date'])
- #
- # Channel info
- #
+ info['comps'] = comps
+
cals = []
- for k in range(nchan):
+ for k in range(info['nchan']):
#
# Scan numbers may have been messed up
#
- 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])
-
- end_block(fid, FIFF.FIFFB_MEAS_INFO)
+ info['chs'][k]['scanno'] = k + 1 # scanno starts at 1 in FIF format
+ info['chs'][k]['range'] = 1.0
+ cals.append(info['chs'][k]['cal'])
+
+ write_meas_info(fid, info, data_type=4)
+
+ # #
+ # # megacq parameters
+ # #
+ # if info['acq_pars'] is not None or info['acq_stim'] is not None:
+ # start_block(fid, FIFF.FIFFB_DACQ_PARS)
+ # if info['acq_pars'] is not None:
+ # write_string(fid, FIFF.FIFF_DACQ_PARS, info['acq_pars'])
+ #
+ # if info['acq_stim'] is not None:
+ # write_string(fid, FIFF.FIFF_DACQ_STIM, info['acq_stim'])
+ #
+ # end_block(fid, FIFF.FIFFB_DACQ_PARS)
#
# Start the raw data
#
diff --git a/mne/fiff/write.py b/mne/fiff/write.py
index d255944..6349ed5 100644
--- a/mne/fiff/write.py
+++ b/mne/fiff/write.py
@@ -194,7 +194,7 @@ def write_coord_trans(fid, trans):
fid.write(np.array(move, dtype='>f4').tostring())
# ...and its inverse
- trans_inv = linalg.inv(trans.trans)
+ trans_inv = linalg.inv(trans['trans'])
rot = trans_inv[:3, :3]
move = trans_inv[:3, 3]
fid.write(np.array(rot, dtype='>f4').tostring())
--
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