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 a31f9453fb22354d8c2246ca0d8007442e0224d5 Author: Alexandre Gramfort <[email protected]> Date: Fri Dec 31 17:31:18 2010 -0500 more more on doc + pep8 --- fiff/bem_surfaces.py | 33 +++++---- fiff/channels.py | 14 +++- fiff/cov.py | 21 +++--- fiff/ctf.py | 43 +++++++----- fiff/inverse.py | 19 ++--- fiff/source_space.py | 140 ++++++++++++++++++++----------------- fiff/stc.py | 57 ++++++++------- fiff/tag.py | 151 +++++++++++++++++++++++++++------------- fiff/tests/test_bem_surfaces.py | 1 + 9 files changed, 285 insertions(+), 194 deletions(-) diff --git a/fiff/bem_surfaces.py b/fiff/bem_surfaces.py index f5ee64d..1ec7546 100644 --- a/fiff/bem_surfaces.py +++ b/fiff/bem_surfaces.py @@ -24,15 +24,20 @@ FIFF_BEM_SIGMA = 3113 # Conductivity of a compartment def read_bem_surfaces(fname, add_geom=False): - """ - # - # [surf] = mne_read_bem_surfaces(fname, add_geom) - # - # Reads source spaces from a fif file - # - # fname - The name of the file or an open file id - # add_geom - Add geometry information to the surfaces - # + """Read the BEM surfaces from a FIF file + + Parameters + ---------- + fname: string + The name of the file containing the surfaces + + add_geom: bool, optional (default False) + If True add geometry information to the surfaces + + Returns + ------- + surf: list + A list of dictionaries that each contain a surface """ # # Default coordinate frame @@ -72,10 +77,10 @@ def read_bem_surfaces(fname, add_geom=False): surf = [] for bsurf in bemsurf: print '\tReading a surface...' - this = read_bem_surface(fid, bsurf, coord_frame) + this = _read_bem_surface(fid, bsurf, coord_frame) print '[done]' if add_geom: - complete_surface_info(this) + _complete_surface_info(this) surf.append(this) print '\t%d BEM surfaces read' % len(surf) @@ -85,8 +90,8 @@ def read_bem_surfaces(fname, add_geom=False): return surf -def read_bem_surface(fid, this, def_coord_frame): - """ +def _read_bem_surface(fid, this, def_coord_frame): + """Read one bem surface """ res = dict() # @@ -163,7 +168,7 @@ def read_bem_surface(fid, this, def_coord_frame): return res -def complete_surface_info(this): +def _complete_surface_info(this): """ XXX : should be factorize with complete_source_space_info """ # diff --git a/fiff/channels.py b/fiff/channels.py index 01ec9ba..31aaa03 100644 --- a/fiff/channels.py +++ b/fiff/channels.py @@ -6,9 +6,19 @@ from .constants import FIFF def _read_bad_channels(fid, node): """Read bad channels - It returns the list of channel's names. - """ + Parameters + ---------- + fid: file + The file descriptor + + node: dict + The node of the FIF tree that contains info on the bad channels + Returns + ------- + bads: list + A list of bad channel's names + """ nodes = dir_tree_find(node, FIFF.FIFFB_MNE_BAD_CHANNELS) bads = []; diff --git a/fiff/cov.py b/fiff/cov.py index 2d4529d..36ae8d1 100644 --- a/fiff/cov.py +++ b/fiff/cov.py @@ -126,19 +126,16 @@ from .proj import write_proj def write_cov(fid, cov): - - """ - % - % - % mne_write_cov(fid,cov) - % - % Write a covariance matrix to an open file - % - % fid - an open file id - % cov - the covariance matrix to write - % - """ + """Write a noise covariance matrix + + Parameters + ---------- + fid: file + The file descriptor + cov: dict + The noise covariance matrix to write + """ start_block(fid, FIFF.FIFFB_MNE_COV) # Dimensions etc. diff --git a/fiff/ctf.py b/fiff/ctf.py index 6fa9a96..354d650 100644 --- a/fiff/ctf.py +++ b/fiff/ctf.py @@ -82,14 +82,24 @@ def _read_named_matrix(fid, node, matkind): def read_ctf_comp(fid, node, chs): - """ - % - % [ compdata ] = fiff_read_ctf_comp(fid,node,chs) - % - % Read the CTF software compensation data from the given node - % - """ + """Read the CTF software compensation data from the given node + Parameters + ---------- + fid: file + The file descriptor + + node: dict + The node in the FIF tree + + chs: list + The list of channels # XXX unclear + + Returns + ------- + compdata: list + The compensation data + """ compdata = [] comps = dir_tree_find(node, FIFF.FIFFB_MNE_CTF_COMP_DATA) @@ -191,17 +201,16 @@ from .write import start_block, end_block, write_int, write_named_matrix def write_ctf_comp(fid, comps): - """ - % - % fiff_write_ctf_comp(fid,comps) - % - % Writes the CTF compensation data into a fif file - % - % fid An open fif file descriptor - % comps The compensation data to write - % - """ + """Write the CTF compensation data into a fif file + Parameters + ---------- + fid: file + The open FIF file descriptor + + comps: list + The compensation data to write + """ if len(comps) <= 0: return diff --git a/fiff/inverse.py b/fiff/inverse.py index 7ed16e6..ed4ab45 100644 --- a/fiff/inverse.py +++ b/fiff/inverse.py @@ -10,14 +10,17 @@ from .forward import _invert_transform, _transform_source_space_to def read_inverse_operator(fname): - """ - % - % [inv] = mne_read_inverse_operator(fname) - % - % Reads the inverse operator decomposition from a fif file - % - % fname - The name of the file - % + """Read the inverse operator decomposition from a FIF file + + Parameters + ---------- + fname: string + The name of the FIF file. + + Returns + ------- + inv: dict + The inverse operator """ # # Open the file, create directory diff --git a/fiff/source_space.py b/fiff/source_space.py index 0dd866b..9381250 100644 --- a/fiff/source_space.py +++ b/fiff/source_space.py @@ -8,17 +8,24 @@ from .open import fiff_open def patch_info(nearest): - """ - % - % [pinfo] = mne_patch_info(nearest) - % - % Generate the patch information from the 'nearest' vector in a source space - % - """ + """Patch information in a source space + + Generate the patch information from the 'nearest' vector in + a source space + Parameters + ---------- + nearest: array + XXX ? + + Returns + ------- + pinfo: list + XXX ? + """ if nearest is None: - pinfo = None - return pinfo + pinfo = None + return pinfo indn = np.argsort(nearest) nearest_sorted = nearest[indn] @@ -29,28 +36,33 @@ def patch_info(nearest): pinfo = list() for k in range(len(uniq)): - pinfo.append(indn[firsti[k]:lasti[k]]) + pinfo.append(indn[firsti[k]:lasti[k]]) return pinfo def read_source_spaces(source, add_geom=False, tree=None): - """ - % - % [src] = mne_read_source_spaces(source,add_geom,tree) - % - % Reads source spaces from a fif file - % - % source - The name of the file or an open file id - % add_geom - Add geometry information to the source spaces - % tree - Required if source is an open file id, search for the - % source spaces here - % - """ + """Read the source spaces from a FIF file + + Parameters + ---------- + source: string or file + The name of the file or an open file descriptor + + add_geom: bool, optional (default False) + Add geometry information to the surfaces + + tree: dict + The FIF tree structure if source is a file id. + Returns + ------- + src: list + The list of source spaces + """ # Open the file, create directory if isinstance(source, str): - fid, tree, _ = fiff_open(source); + fid, tree, _ = fiff_open(source) open_here = True else: fid = source @@ -65,13 +77,13 @@ def read_source_spaces(source, add_geom=False, tree=None): src = list() for s in spaces: - print '\tReading a source space...' - this = _read_one_source_space(fid, s, open_here) - print '[done]' - if add_geom: - complete_source_space_info(this) + print '\tReading a source space...' + this = _read_one_source_space(fid, s, open_here) + print '[done]' + if add_geom: + complete_source_space_info(this) - src.append(this) + src.append(this) print '\t%d source spaces read\n' % len(spaces) @@ -82,10 +94,7 @@ def read_source_spaces(source, add_geom=False, tree=None): def _read_one_source_space(fid, this, open_here): - """ - % - % Read all the interesting stuff - % + """Read one source space """ FIFF_BEM_SURF_NTRI = 3104 FIFF_BEM_SURF_TRIANGLES = 3106 @@ -98,7 +107,7 @@ def _read_one_source_space(fid, this, open_here): else: res['id'] = int(tag.data) - tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_NPOINTS); + tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_NPOINTS) if tag is None: if open_here: fid.close() @@ -145,9 +154,9 @@ def _read_one_source_space(fid, this, open_here): res['nn'] = tag.data if res['nn'].shape[0] != res['np']: - if open_here: - fid.close() - raise ValueError, 'Vertex normal information is incorrect' + if open_here: + fid.close() + raise ValueError, 'Vertex normal information is incorrect' if res['ntri'] > 0: tag = find_tag(fid, this, FIFF_BEM_SURF_TRIANGLES) @@ -172,7 +181,7 @@ def _read_one_source_space(fid, this, open_here): # Which vertices are active tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_NUSE) if tag is None: - res['nuse'] = 0; + res['nuse'] = 0 res['inuse'] = np.zeros(res['nuse'], dtype=np.int) res['vertno'] = None else: @@ -183,11 +192,12 @@ def _read_one_source_space(fid, this, open_here): fid.close() raise ValueError, 'Source selection information missing' - res['inuse'] = tag.data.astype(np.int).T + res['inuse'] = tag.data.astype(np.int).T if len(res['inuse']) != res['np']: if open_here: fid.close() - raise ValueError, 'Incorrect number of entries in source space selection' + raise ValueError, 'Incorrect number of entries in source space ' \ + 'selection' res['vertno'] = np.where(res['inuse'])[0] @@ -206,11 +216,11 @@ def _read_one_source_space(fid, this, open_here): tag2 = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_NEAREST_DIST) if tag1 is None or tag2 is None: - res['nearest'] = None - res['nearest_dist'] = None + res['nearest'] = None + res['nearest_dist'] = None else: - res['nearest'] = tag1.data - res['nearest_dist'] = tag2.data.T + res['nearest'] = tag1.data + res['nearest_dist'] = tag2.data.T res['pinfo'] = patch_info(res['nearest']) if res['pinfo'] is not None: @@ -220,14 +230,14 @@ def _read_one_source_space(fid, this, open_here): def complete_source_space_info(this): - """ + """Add more info on surface """ # Main triangulation print '\tCompleting triangulation info...' this['tri_area'] = np.zeros(this['ntri']) - r1 = this['rr'][this['tris'][:,0],:] - r2 = this['rr'][this['tris'][:,1],:] - r3 = this['rr'][this['tris'][:,2],:] + r1 = this['rr'][this['tris'][:, 0], :] + r2 = this['rr'][this['tris'][:, 1], :] + r3 = this['rr'][this['tris'][:, 2], :] this['tri_cent'] = (r1 + r2 + r3) / 3.0 this['tri_nn'] = np.cross((r2-r1), (r3-r1)) @@ -241,30 +251,32 @@ def complete_source_space_info(this): # Selected triangles print '\tCompleting selection triangulation info...' if this['nuse_tri'] > 0: - r1 = this['rr'][this['use_tris'][:,0],:] - r2 = this['rr'][this['use_tris'][:,1],:] - r3 = this['rr'][this['use_tris'][:,2],:] + r1 = this['rr'][this['use_tris'][:, 0],:] + r2 = this['rr'][this['use_tris'][:, 1],:] + r3 = this['rr'][this['use_tris'][:, 2],:] this['use_tri_cent'] = (r1 + r2 + r3) / 3.0 - this['use_tri_nn'] = np.cross((r2-r1), (r3-r1)); + this['use_tri_nn'] = np.cross((r2-r1), (r3-r1)) for p in range(this['nuse_tri']): # XXX can do better - this['use_tri_area'][p] = sqrt(np.sum(this['use_tri_nn'][p,:] * this['use_tri_nn'][p,:])) / 2.0 + this['use_tri_area'][p] = sqrt(np.sum(this['use_tri_nn'][p,:] + * this['use_tri_nn'][p,:])) / 2.0 print '[done]' def find_source_space_hemi(src): - """ - % - % function mne_find_source_space_hemi(src) - % - % Return the hemisphere id for a source space - % - % src - The source space to investigate - % hemi - Deduced hemisphere id - % - """ + """Return the hemisphere id for a source space - xave = src['rr'][:,0].sum(); + Parameters + ---------- + src: dict + The source space to investigate + + Returns + ------- + hemi: int + Deduced hemisphere id + """ + xave = src['rr'][:, 0].sum() if xave < 0: hemi = int(FIFF.FIFFV_MNE_SURF_LEFT_HEMI) diff --git a/fiff/stc.py b/fiff/stc.py index c21cc15..cb662ae 100644 --- a/fiff/stc.py +++ b/fiff/stc.py @@ -2,20 +2,24 @@ import numpy as np def read_stc(filename): + """Read an STC file + + STC files contain activations or source reconstructions + + Parameters + ---------- + filename: string + The name of the STC file + + Returns + ------- + data: dict + The STC structure. It has the following keys: + tmin The first time point of the data in seconds + tstep Time between frames in seconds + vertices vertex indices (0 based) + data The data matrix (nvert * ntime) """ - % - % [stc] = mne_read_stc_file(filename) - % - % Reads an stc file. The returned structure has the following fields - % - % tmin The first time point of the data in seconds - % tstep Time between frames in seconds - % vertices vertex indices (0 based) - % data The data matrix (nvert * ntime) - % - % - """ - fid = open(filename, 'rb') stc = dict() @@ -54,20 +58,19 @@ def read_stc(filename): def write_stc(filename, stc): - """ - % - % mne_write_stc_file(filename,stc) - % - % writes an stc file - % - % filename output file - % stc a stucture containing the stc data with fields: - % - % tmin The time of the first frame in seconds - % tstep Time between frames in seconds - % vertices Vertex indices (0 based) - % data The data matrix nvert * ntime - % + """Write an STC file + + Parameters + ---------- + filename: string + The name of the STC file + + stc: dict + The STC structure. It has the following keys: + tmin The first time point of the data in seconds + tstep Time between frames in seconds + vertices vertex indices (0 based) + data The data matrix (nvert * ntime) """ fid = open(filename, 'wb') diff --git a/fiff/tag.py b/fiff/tag.py index d932272..d1bf294 100644 --- a/fiff/tag.py +++ b/fiff/tag.py @@ -6,7 +6,27 @@ from .constants import FIFF class Tag(object): - """docstring for Tag""" + """Tag in FIF tree structure + + Parameters + ---------- + kind: int + Kind of Tag + + type_: int + Type of Tag + + size: int + Size in bytes + + int: next + Position of next Tag + + pos: int + Position of Tag is the original file. + + """ + def __init__(self, kind, type_, size, next, pos=None): self.kind = int(kind) self.type = int(type_) @@ -26,6 +46,8 @@ class Tag(object): def read_tag_info(fid): + """Read Tag info (or header) + """ s = fid.read(4*4) tag = Tag(*struct.unpack(">iiii", s)) if tag.next == 0: @@ -36,6 +58,21 @@ def read_tag_info(fid): def read_tag(fid, pos=None): + """Read a Tag from a file at a given position + + Parameters + ---------- + fid: file + The open FIF file descriptor + + pos: int + The position of the Tag in the file. + + Returns + ------- + tag: Tag + The Tag read + """ if pos is not None: fid.seek(pos, 0) @@ -45,11 +82,11 @@ def read_tag(fid, pos=None): # # The magic hexadecimal values # - is_matrix = 4294901760 # ffff0000 + is_matrix = 4294901760 # ffff0000 matrix_coding_dense = 16384 # 4000 - matrix_coding_CCS = 16400 # 4010 - matrix_coding_RCS = 16416 # 4020 - data_type = 65535 # ffff + matrix_coding_CCS = 16400 # 4010 + matrix_coding_RCS = 16416 # 4020 + data_type = 65535 # ffff # if tag.size > 0: matrix_coding = is_matrix & tag.type @@ -67,21 +104,26 @@ def read_tag(fid, pos=None): # # Back to where the data start # - fid.seek(pos, 0); + fid.seek(pos, 0) if ndim != 2: - raise ValueError, 'Only two-dimensional matrices are supported at this time' + raise ValueError, 'Only two-dimensional matrices are ' \ + 'supported at this time' matrix_type = data_type & tag.type if matrix_type == FIFF.FIFFT_INT: - tag.data = np.fromfile(fid, dtype='>i', count=dims.prod()).reshape(dims) + tag.data = np.fromfile(fid, dtype='>i', + count=dims.prod()).reshape(dims) elif matrix_type == FIFF.FIFFT_JULIAN: - tag.data = np.fromfile(fid, dtype='>i', count=dims.prod()).reshape(dims) + tag.data = np.fromfile(fid, dtype='>i', + count=dims.prod()).reshape(dims) elif matrix_type == FIFF.FIFFT_FLOAT: - tag.data = np.fromfile(fid, dtype='>f4', count=dims.prod()).reshape(dims) + tag.data = np.fromfile(fid, dtype='>f4', + count=dims.prod()).reshape(dims) elif matrix_type == FIFF.FIFFT_DOUBLE: - tag.data = np.fromfile(fid, dtype='>f8', count=dims.prod()).reshape(dims) + tag.data = np.fromfile(fid, dtype='>f8', + count=dims.prod()).reshape(dims) elif matrix_type == FIFF.FIFFT_COMPLEX_FLOAT: data = np.fromfile(fid, dtype='>f4', count=2*dims.prod()) # Note: we need the non-conjugate transpose here @@ -91,9 +133,11 @@ 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' % matrix_type + raise ValueError, 'Cannot handle matrix of type %d yet' % ( + matrix_type) - elif matrix_coding == matrix_coding_CCS or matrix_coding == matrix_coding_RCS: + elif matrix_coding == matrix_coding_CCS or \ + matrix_coding == matrix_coding_RCS: from scipy import sparse # Find dimensions and return to the beginning of tag data pos = fid.tell() @@ -102,7 +146,8 @@ 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 supported at this time' + raise ValueError, 'Only two-dimensional matrices are ' \ + 'supported at this time' # Back to where the data start fid.seek(pos, 0) @@ -114,17 +159,18 @@ def read_tag(fid, pos=None): # CCS sparse.csc_matrix() sparse_indices = np.fromfile(fid, dtype='>i4', count=nnz) - sparse_ptrs = np.fromfile(fid, dtype='>i4', count=ncol+1) + sparse_ptrs = np.fromfile(fid, dtype='>i4', count=ncol+1) tag.data = sparse.csc_matrix((sparse_data, sparse_indices, sparse_ptrs), shape=dims) else: # RCS sparse_indices = np.fromfile(fid, dtype='>i4', count=nnz) - sparse_ptrs = np.fromfile(fid, dtype='>i4', count=nrow+1) + sparse_ptrs = np.fromfile(fid, dtype='>i4', count=nrow+1) tag.data = sparse.csr_matrix((sparse_data, sparse_indices, sparse_ptrs), shape=dims) else: - raise ValueError, 'Cannot handle other than dense or sparse matrices yet' + raise ValueError, 'Cannot handle other than dense or sparse ' \ + 'matrices yet' else: # All other data types @@ -133,25 +179,25 @@ def read_tag(fid, pos=None): tag.data = np.fromfile(fid, dtype=">B1", count=tag.size) elif tag.type == FIFF.FIFFT_SHORT: tag.data = np.fromfile(fid, dtype=">h2", count=tag.size/2) - elif tag.type == FIFF.FIFFT_INT: + elif tag.type == FIFF.FIFFT_INT: tag.data = np.fromfile(fid, dtype=">i4", count=tag.size/4) - elif tag.type == FIFF.FIFFT_USHORT: + elif tag.type == FIFF.FIFFT_USHORT: tag.data = np.fromfile(fid, dtype=">H2", count=tag.size/2) - elif tag.type == FIFF.FIFFT_UINT: + elif tag.type == FIFF.FIFFT_UINT: tag.data = np.fromfile(fid, dtype=">I4", count=tag.size/4) - elif tag.type == FIFF.FIFFT_FLOAT: + elif tag.type == FIFF.FIFFT_FLOAT: tag.data = np.fromfile(fid, dtype=">f4", count=tag.size/4) - elif tag.type == FIFF.FIFFT_DOUBLE: + elif tag.type == FIFF.FIFFT_DOUBLE: tag.data = np.fromfile(fid, dtype=">f8", count=tag.size/8) - elif tag.type == FIFF.FIFFT_STRING: + elif tag.type == FIFF.FIFFT_STRING: tag.data = np.fromfile(fid, dtype=">c", count=tag.size) tag.data = ''.join(tag.data) - elif tag.type == FIFF.FIFFT_DAU_PACK16: + elif tag.type == FIFF.FIFFT_DAU_PACK16: tag.data = np.fromfile(fid, dtype=">h2", count=tag.size/2) - elif tag.type == FIFF.FIFFT_COMPLEX_FLOAT: + elif tag.type == FIFF.FIFFT_COMPLEX_FLOAT: tag.data = np.fromfile(fid, dtype=">f4", count=tag.size/4) tag.data = tag.data[::2] + 1j * tag.data[1::2] - elif tag.type == FIFF.FIFFT_COMPLEX_DOUBLE: + elif tag.type == FIFF.FIFFT_COMPLEX_DOUBLE: tag.data = np.fromfile(fid, dtype=">f8", count=tag.size/8) tag.data = tag.data[::2] + 1j * tag.data[1::2] # @@ -176,13 +222,13 @@ def read_tag(fid, pos=None): tag.data['to'] = 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) - tag.data['trans'] = np.r_[ np.c_[rot, move], + tag.data['trans'] = np.r_[np.c_[rot, move], np.array([[0], [0], [0], [1]]).T] # # Skip over the inverse transformation # It is easier to just use inverse of trans in Matlab # - fid.seek(12*4,1) + fid.seek(12*4, 1) elif tag.type == FIFF.FIFFT_CH_INFO_STRUCT: tag.data = Bunch() tag.data['scanno'] = np.fromfile(fid, dtype=">i4", count=1) @@ -204,15 +250,15 @@ def read_tag(fid, pos=None): 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], - loc[9:11], loc[0:2] ], - np.array([0, 0, 0, 1 ]).reshape(1, 4) ] + 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: 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.eeg_loc = loc[1:3] tag.data.coord_frame = FIFF.FIFFV_COORD_HEAD # # Unit and exponent @@ -222,22 +268,23 @@ def read_tag(fid, pos=None): # # Handle the channel name # - ch_name = np.fromfile(fid, dtype=">c", count=16) + ch_name = np.fromfile(fid, dtype=">c", count=16) # # Omit nulls # - tag.data['ch_name'] = ''.join(ch_name[:np.where(ch_name == '')[0][0]]) + tag.data['ch_name'] = ''.join( + ch_name[:np.where(ch_name == '')[0][0]]) elif tag.type == FIFF.FIFFT_OLD_PACK: - offset = np.fromfile(fid, dtype=">f4", count=1) - scale = np.fromfile(fid, dtype=">f4", count=1) - tag.data = np.fromfile(fid, dtype=">h2", count=(tag.size-8)/2) - tag.data = scale*tag.data + offset + offset = np.fromfile(fid, dtype=">f4", count=1) + scale = np.fromfile(fid, dtype=">f4", count=1) + tag.data = np.fromfile(fid, dtype=">h2", count=(tag.size-8)/2) + tag.data = scale*tag.data + offset elif tag.type == FIFF.FIFFT_DIR_ENTRY_STRUCT: - tag.data = list() - for _ in range(tag.size/16-1): - s = fid.read(4*4) - tag.data.append(Tag(*struct.unpack(">iIii", s))) + tag.data = list() + for _ in range(tag.size/16-1): + s = fid.read(4*4) + tag.data.append(Tag(*struct.unpack(">iIii", s))) else: raise ValueError, 'Unimplemented tag data type %s' % tag.type @@ -249,15 +296,19 @@ 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) + if node.directory[p].kind == findkind: + return read_tag(fid, node.directory[p].pos) tag = None return tag -def has_tag(this, findkind): - for p in range(this.nent): - if this.directory[p].kind == findkind: - return True - return False +def has_tag(node, kind): + """Does the node contains a Tag of a given kind? + """ + for d in node.directory: + if d.kind == kind: + return True + return False diff --git a/fiff/tests/test_bem_surfaces.py b/fiff/tests/test_bem_surfaces.py index 3f4bdfb..a8588a4 100644 --- a/fiff/tests/test_bem_surfaces.py +++ b/fiff/tests/test_bem_surfaces.py @@ -13,5 +13,6 @@ fname = op.join(MNE_SAMPLE_DATASET_PATH, 'subjects', 'sample', 'bem', def test_io_bem_surfaces(): """Testing reading of bem surfaces """ + surf = fiff.read_bem_surfaces(fname, add_geom=False) surf = fiff.read_bem_surfaces(fname, add_geom=True) print "Number of surfaces : %d" % len(surf) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
