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 :Parameters:
68 kwargs
69 Any keyword arugment provided would be replicated, through all
70 the entries. Useful to specify label or even a chunk
71 """
72 return \
73 [Event(onset=self['onsets'][i],
74 duration=self['durations'][i],
75 features=[self['intensities'][i]],
76 **kwargs)
77 for i in xrange(self.nevs)]
78
79
80 onsets = property(fget=lambda self: self['onsets'])
81 durations = property(fget=lambda self: self['durations'])
82 intensities = property(fget=lambda self: self['intensities'])
83 nevs = property(fget=getNEVs)
84
85
86
88 """Read and write McFlirt's motion estimation parameters from and to text
89 files.
90 """
91 header_def = ['rot1', 'rot2', 'rot3', 'x', 'y', 'z']
92
103
104
112
113
115 """Produce a simple plot of the estimated translation and rotation
116 parameters using.
117
118 You still need to can pylab.show() or pylab.savefig() if you want to
119 see/get anything.
120 """
121
122
123 import pylab as P
124
125
126 P.subplot(211)
127 P.plot(self.x)
128 P.plot(self.y)
129 P.plot(self.z)
130 P.ylabel('Translations in mm')
131 P.legend(('x', 'y', 'z'), loc=0)
132
133
134 P.subplot(212)
135 P.plot(self.rot1)
136 P.plot(self.rot2)
137 P.plot(self.rot3)
138 P.ylabel('Rotations in rad')
139 P.legend(('rot1', 'rot2', 'rot3'), loc=0)
140
141
143 """Returns the data as an array with six columns (same order as in file).
144 """
145 import numpy as N
146
147
148 return N.array([self[i] for i in McFlirtParams.header_def],
149 dtype='float').T
150