1
2
3
4
5
6
7
8
9 """Tiny snippets to interface with FSL easily."""
10
11 __docformat__ = 'restructuredtext'
12
13 from mvpa.misc.io import ColumnData
14 from mvpa.misc.support import Event
15
16 if __debug__:
17 from mvpa.base import debug
18
19
21 """IO helper to read FSL's EV3 files.
22
23 This is a three-column textfile format that is used to specify stimulation
24 protocols for fMRI data analysis in FSL's FEAT module.
25
26 Data is always read as `float`.
27 """
29 """Read and write FSL EV3 files.
30
31 :Parameter:
32 source: filename of an EV3 file
33 """
34
35 ColumnData.__init__(self, source,
36 header=['onsets', 'durations', 'intensities'],
37 sep=None, dtype=float)
38
39
41 """Returns the number of EVs in the file.
42 """
43 return self.getNRows()
44
45
47 """Returns a tuple of (onset time, simulus duration, intensity) for a
48 certain EV.
49 """
50 return (self['onsets'][evid],
51 self['durations'][evid],
52 self['intensities'][evid])
53
54
56 """Write data to a FSL EV3 file.
57 """
58 ColumnData.tofile(self, filename,
59 header=False,
60 header_order=['onsets', 'durations', 'intensities'],
61 sep=' ')
62
63
65 """Convert into a list of `Event` instances.
66 """
67 return \
68 [Event(onset=self['onsets'][i],
69 duration=self['durations'][i],
70 features=[self['intensities'][i]])
71 for i in xrange(self.nevs)]
72
73
74 onsets = property(fget=lambda self: self['onsets'])
75 durations = property(fget=lambda self: self['durations'])
76 intensities = property(fget=lambda self: self['intensities'])
77 nevs = property(fget=getNEVs)
78
79
80
82 """Read and write McFlirt's motion estimation parameters from and to text
83 files.
84 """
85 header_def = ['rot1', 'rot2', 'rot3', 'x', 'y', 'z']
86
97
98
106
107
109 """Produce a simple plot of the estimated translation and rotation
110 parameters using.
111
112 You still need to can pylab.show() or pylab.savefig() if you want to
113 see/get anything.
114 """
115
116
117 import pylab as P
118
119
120 P.subplot(211)
121 P.plot(self.x)
122 P.plot(self.y)
123 P.plot(self.z)
124 P.ylabel('Translations in mm')
125 P.legend(('x', 'y', 'z'), loc=0)
126
127
128 P.subplot(212)
129 P.plot(self.rot1)
130 P.plot(self.rot2)
131 P.plot(self.rot3)
132 P.ylabel('Rotations in rad')
133 P.legend(('rot1', 'rot2', 'rot3'), loc=0)
134
135
137 """Returns the data as an array with six columns (same order as in file).
138 """
139 import numpy as N
140
141
142 return N.array([self[i] for i in McFlirtParams.header_def],
143 dtype='float').T
144