@@ -99,6 +99,29 @@ def _calc_norm(mc, use_differences, source, brain_pts=None):
99
99
100
100
"""
101
101
102
+ affines = [_get_affine_matrix (mc [i , :], source )
103
+ for i in range (mc .shape [0 ])]
104
+ return _calc_norm_affine (affines , use_differences , source , brain_pts )
105
+
106
+
107
+ def _calc_norm_affine (affines , use_differences , source , brain_pts = None ):
108
+ """Calculates the maximum overall displacement of the midpoints
109
+ of the faces of a cube due to translation and rotation.
110
+
111
+ Parameters
112
+ ----------
113
+ affines : list of [4 x 4] affine matrices
114
+ use_differences : boolean
115
+ brain_pts : [4 x n_points] of coordinates
116
+
117
+ Returns
118
+ -------
119
+
120
+ norm : at each time point
121
+ displacement : euclidean distance (mm) of displacement at each coordinate
122
+
123
+ """
124
+
102
125
if brain_pts is None :
103
126
respos = np .diag ([70 , 70 , 75 ])
104
127
resneg = np .diag ([- 70 , - 110 , - 45 ])
@@ -107,22 +130,19 @@ def _calc_norm(mc, use_differences, source, brain_pts=None):
107
130
else :
108
131
all_pts = brain_pts
109
132
n_pts = all_pts .size - all_pts .shape [1 ]
110
- newpos = np .zeros ((mc . shape [ 0 ] , n_pts ))
133
+ newpos = np .zeros ((len ( affines ) , n_pts ))
111
134
if brain_pts is not None :
112
- displacement = np .zeros ((mc .shape [0 ], int (n_pts / 3 )))
113
- for i in range (mc .shape [0 ]):
114
- affine = _get_affine_matrix (mc [i , :], source )
115
- newpos [i , :] = np .dot (affine ,
116
- all_pts )[0 :3 , :].ravel ()
135
+ displacement = np .zeros ((len (affines ), int (n_pts / 3 )))
136
+ for i , affine in enumerate (affines ):
137
+ newpos [i , :] = np .dot (affine , all_pts )[0 :3 , :].ravel ()
117
138
if brain_pts is not None :
118
- displacement [i , :] = \
119
- np .sqrt (np .sum (np .power (np .reshape (newpos [i , :],
120
- (3 , all_pts .shape [1 ])) -
121
- all_pts [0 :3 , :],
122
- 2 ),
123
- axis = 0 ))
139
+ displacement [i , :] = np .sqrt (np .sum (
140
+ np .power (np .reshape (newpos [i , :],
141
+ (3 , all_pts .shape [1 ])) - all_pts [0 :3 , :],
142
+ 2 ),
143
+ axis = 0 ))
124
144
# np.savez('displacement.npz', newpos=newpos, pts=all_pts)
125
- normdata = np .zeros (mc . shape [ 0 ] )
145
+ normdata = np .zeros (len ( affines ) )
126
146
if use_differences :
127
147
newpos = np .concatenate ((np .zeros ((1 , n_pts )),
128
148
np .diff (newpos , n = 1 , axis = 0 )), axis = 0 )
0 commit comments