1
2
3
4
5
6
7
8
9
10
11
12 """Reader for binary EEP files."""
13
14 __docformat__ = 'restructuredtext'
15
16 import numpy as N
17 from mvpa.misc.io import DataReader
18
19
21 """Read-access to binary EEP files.
22
23 EEP files are used by *eeprobe* a software for analysing even-related
24 potentials (ERP), which was developed at the Max-Planck Institute for
25 Cognitive Neuroscience in Leipzig, Germany.
26
27 http://www.ant-neuro.com/products/eeprobe
28
29 EEP files consist of a plain text header and a binary data block in a
30 single file. The header starts with a line of the form
31
32 ';%d %d %d %g %g' % (Nchannels, Nsamples, Ntrials, t0, dt)
33
34 where Nchannels, Nsamples, Ntrials are the numbers of channels, samples
35 per trial and trials respectively. t0 is the time of the first sample
36 of a trial relative to the stimulus onset and dt is the sampling interval.
37
38 The binary data block consists of single precision floats arranged in the
39 following way::
40
41 <trial1,channel1,sample1>,<trial1,channel1,sample2>,...
42 <trial1,channel2,sample1>,<trial1,channel2,sample2>,...
43 .
44 <trial2,channel1,sample1>,<trial2,channel1,sample2>,...
45 <trial2,channel2,sample1>,<trial2,channel2,sample2>,...
46 """
48 """Read EEP file and store header and data.
49
50 :Parameter:
51 source : str
52 Filename.
53 """
54
55 DataReader.__init__(self)
56
57 nsamples = None
58
59 hdr = {}
60
61 infile = open(source, "r")
62
63
64 while True:
65
66 line = infile.readline()
67
68
69 if not line or line.startswith(';EOH;'):
70 break
71
72
73 line = line.strip()
74
75
76 if not line.count(':'):
77
78 l = line.split()
79
80 self._props['nchannels'] = int(l[0][1:])
81 self._props['ntimepoints'] = int(l[1])
82 self._props['t0'] = float(l[3])
83 self._props['dt'] = float(l[4])
84 nsamples = int(l[2])
85 else:
86
87 l = line.split(':')
88 key = l[0].lstrip(';')
89 value = ':'.join(l[1:])
90 hdr[key] = value
91
92
93 if hdr.has_key('channels'):
94 self._props['channels'] = hdr['channels'].split()
95
96 self._data = \
97 N.reshape(N.fromfile(infile, dtype='f'), \
98 (nsamples,
99 self._props['nchannels'],
100 self._props['ntimepoints']))
101
102
103 infile.close()
104
105
106 nchannels = property(fget=lambda self: self._props['nchannels'],
107 doc="Number of channels")
108 ntimepoints = property(fget=lambda self: self._props['ntimepoints'],
109 doc="Number of data timepoints")
110 nsamples = property(fget=lambda self: self._data.shape[0],
111 doc="Number of trials/samples")
112 t0 = property(fget=lambda self: self._props['t0'],
113 doc="Relative start time of sampling interval")
114 dt = property(fget=lambda self: self._props['dt'],
115 doc="Time difference between two adjacent samples")
116 channels = property(fget=lambda self: self._props['channels'],
117 doc="List of channel names")
118