@@ -136,20 +136,19 @@ def test_viewer_nonRAS():
136
136
assert_array_equal (axi , data1 [:, 13 , :].T )
137
137
138
138
139
-
140
139
@needs_mpl
141
140
def test_viewer_nonRAS_on_mouse ():
142
141
"""
143
142
test on_mouse selection on non RAS matrices
144
-
143
+
145
144
"""
146
- # This affine simulates an acquisition on a quadruped subject that is in a prone position.
147
- # This corresponds to an acquisition with:
145
+ # This affine simulates an acquisition on a quadruped subject that is in a prone position.
146
+ # This corresponds to an acquisition with:
148
147
# - LR inverted on scanner x (i)
149
148
# - IS on scanner y (j)
150
149
# - PA on scanner z (k)
151
- # This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.
152
-
150
+ # This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.
151
+
153
152
(I , J , K ) = (10 , 20 , 40 )
154
153
data1 = np .random .rand (I , J , K )
155
154
(i_target , j_target , k_target ) = (2 , 14 , 12 )
@@ -159,68 +158,65 @@ def test_viewer_nonRAS_on_mouse():
159
158
j2 = j_target + 3
160
159
k1 = k_target - 4
161
160
k2 = k_target + 4
162
- data1 [i1 : i2 + 1 , j1 : j2 + 1 , k1 : k2 + 1 ] = 0
161
+ data1 [i1 : i2 + 1 , j1 : j2 + 1 , k1 : k2 + 1 ] = 0
163
162
data1 [i_target , j_target , k_target ] = 1
164
163
valp1 = 1.5
165
164
valm1 = 0.5
166
- data1 [i_target - 1 , j_target , k_target ] = valp1 # x flipped
167
- data1 [i_target + 1 , j_target , k_target ] = valm1 # x flipped
165
+ data1 [i_target - 1 , j_target , k_target ] = valp1 # x flipped
166
+ data1 [i_target + 1 , j_target , k_target ] = valm1 # x flipped
168
167
data1 [i_target , j_target - 1 , k_target ] = valm1
169
168
data1 [i_target , j_target + 1 , k_target ] = valp1
170
169
data1 [i_target , j_target , k_target - 1 ] = valm1
171
170
data1 [i_target , j_target , k_target + 1 ] = valp1
172
-
173
- aff1 = np .array ([[- 1 , 0 , 0 , 5 ],
174
- [0 , 0 , 1 , - 10 ],
175
- [0 , 1 , 0 , - 30 ],
176
- [0 , 0 , 0 , 1 ]])
177
-
171
+
172
+ aff1 = np .array ([[- 1 , 0 , 0 , 5 ], [0 , 0 , 1 , - 10 ], [0 , 1 , 0 , - 30 ], [0 , 0 , 0 , 1 ]])
173
+
178
174
o1 = OrthoSlicer3D (data1 , aff1 )
179
-
180
- class Event :
181
- def __init__ (self ):
182
- self .name = " simulated mouse event"
175
+
176
+ class Event :
177
+ def __init__ (self ):
178
+ self .name = ' simulated mouse event'
183
179
self .button = 1
184
-
180
+
185
181
event = Event ()
186
182
event .xdata = k_target
187
183
event .ydata = j_target
188
184
event .inaxes = o1 ._ims [0 ].axes
189
185
o1 ._on_mouse (event )
190
-
186
+
191
187
event .inaxes = o1 ._ims [1 ].axes
192
- event .xdata = (I - 1 ) - i_target # x flipped
188
+ event .xdata = (I - 1 ) - i_target # x flipped
193
189
event .ydata = j_target
194
190
o1 ._on_mouse (event )
195
-
191
+
196
192
event .inaxes = o1 ._ims [2 ].axes
197
- event .xdata = (I - 1 ) - i_target # x flipped
193
+ event .xdata = (I - 1 ) - i_target # x flipped
198
194
event .ydata = k_target
199
195
o1 ._on_mouse (event )
200
-
196
+
201
197
sag = o1 ._ims [0 ].get_array ()
202
198
cor = o1 ._ims [1 ].get_array ()
203
199
axi = o1 ._ims [2 ].get_array ()
204
-
205
- assert_array_equal (sag , data1 [i_target , :, :]) #
206
- assert_array_equal (cor , data1 [::- 1 , :, k_target ].T ) # x flipped
207
- assert_array_equal (axi , data1 [::- 1 , j_target , :].T ) # x flipped
200
+
201
+ assert_array_equal (sag , data1 [i_target , :, :]) #
202
+ assert_array_equal (cor , data1 [::- 1 , :, k_target ].T ) # x flipped
203
+ assert_array_equal (axi , data1 [::- 1 , j_target , :].T ) # x flipped
208
204
return None
209
205
210
206
211
207
@needs_mpl
212
208
def test_viewer_nonRAS_on_scroll ():
213
209
"""
214
210
test scrolling on non RAS matrices
215
-
211
+
216
212
"""
217
- # This affine simulates an acquisition on a quadruped subject that is in a prone position.
218
- # This corresponds to an acquisition with:
213
+ # This affine simulates an acquisition on a quadruped subject that is in a prone position.
214
+ # This corresponds to an acquisition with:
219
215
# - LR inverted on scanner x (i)
220
216
# - IS on scanner y (j)
221
217
# - PA on scanner z (k)
222
218
# This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.
223
-
219
+
224
220
(I , J , K ) = (10 , 20 , 40 )
225
221
data1 = np .random .rand (I , J , K )
226
222
(i_target , j_target , k_target ) = (2 , 14 , 12 )
@@ -230,40 +226,35 @@ def test_viewer_nonRAS_on_scroll():
230
226
j2 = j_target + 3
231
227
k1 = k_target - 4
232
228
k2 = k_target + 4
233
- data1 [i1 : i2 + 1 , j1 : j2 + 1 , k1 : k2 + 1 ] = 0
229
+ data1 [i1 : i2 + 1 , j1 : j2 + 1 , k1 : k2 + 1 ] = 0
234
230
data1 [i_target , j_target , k_target ] = 1
235
231
valp1 = 1.5
236
232
valm1 = 0.5
237
- data1 [i_target - 1 , j_target , k_target ] = valp1 # x flipped
238
- data1 [i_target + 1 , j_target , k_target ] = valm1 # x flipped
233
+ data1 [i_target - 1 , j_target , k_target ] = valp1 # x flipped
234
+ data1 [i_target + 1 , j_target , k_target ] = valm1 # x flipped
239
235
data1 [i_target , j_target - 1 , k_target ] = valm1
240
236
data1 [i_target , j_target + 1 , k_target ] = valp1
241
237
data1 [i_target , j_target , k_target - 1 ] = valm1
242
238
data1 [i_target , j_target , k_target + 1 ] = valp1
243
-
244
- aff1 = np .array ([[- 1 , 0 , 0 , 5 ],
245
- [0 , 0 , 1 , - 10 ],
246
- [0 , 1 , 0 , - 30 ],
247
- [0 , 0 , 0 , 1 ]])
248
-
239
+
240
+ aff1 = np .array ([[- 1 , 0 , 0 , 5 ], [0 , 0 , 1 , - 10 ], [0 , 1 , 0 , - 30 ], [0 , 0 , 0 , 1 ]])
241
+
249
242
o1 = OrthoSlicer3D (data1 , aff1 )
250
-
251
- class Event :
252
- def __init__ (self ):
253
- self .name = " simulated mouse event"
243
+
244
+ class Event :
245
+ def __init__ (self ):
246
+ self .name = ' simulated mouse event'
254
247
self .button = None
255
248
self .key = None
256
-
257
- i_last = data1 .shape [0 ] - 1
258
-
249
+
259
250
[x_t , y_t , z_t ] = list (aff1 .dot (np .array ([i_target , j_target , k_target , 1 ]))[:3 ])
260
251
# print(x_t, y_t, z_t)
261
252
# scanner positions are x_t=3, y_t=2, z_t=16
262
-
253
+
263
254
event = Event ()
264
-
255
+
265
256
# Sagittal plane - one scroll up
266
- # x coordinate is flipped so index decrease by 1
257
+ # x coordinate is flipped so index decrease by 1
267
258
o1 .set_position (x_t , y_t , z_t )
268
259
event .inaxes = o1 ._ims [0 ].axes
269
260
event .button = 'up'
@@ -272,10 +263,10 @@ def __init__(self):
272
263
cor = o1 ._ims [1 ].get_array ()
273
264
axi = o1 ._ims [2 ].get_array ()
274
265
assert_array_equal (sag , data1 [i_target - 1 , :, :])
275
- assert_array_equal (cor , data1 [::- 1 , :, k_target ].T ) # ::-1 because the array is flipped in x
276
- assert_array_equal (axi , data1 [::- 1 , j_target , :].T ) # ::-1 because the array is flipped in x
277
-
278
- # Sagittal plane - one scrolled down
266
+ assert_array_equal (cor , data1 [::- 1 , :, k_target ].T ) # ::-1 because the array is flipped in x
267
+ assert_array_equal (axi , data1 [::- 1 , j_target , :].T ) # ::-1 because the array is flipped in x
268
+
269
+ # Sagittal plane - one scrolled down
279
270
o1 .set_position (x_t , y_t , z_t )
280
271
event .button = 'down'
281
272
o1 ._on_scroll (event )
@@ -285,9 +276,9 @@ def __init__(self):
285
276
assert_array_equal (sag , data1 [i_target + 1 , :, :])
286
277
assert_array_equal (cor , data1 [::- 1 , :, k_target ].T )
287
278
assert_array_equal (axi , data1 [::- 1 , j_target , :].T )
288
-
279
+
289
280
# Coronal plane - one scroll up
290
- # y coordinate is increase by 1
281
+ # y coordinate is increase by 1
291
282
o1 .set_position (x_t , y_t , z_t )
292
283
event .inaxes = o1 ._ims [1 ].axes
293
284
event .button = 'up'
@@ -296,10 +287,12 @@ def __init__(self):
296
287
cor = o1 ._ims [1 ].get_array ()
297
288
axi = o1 ._ims [2 ].get_array ()
298
289
assert_array_equal (sag , data1 [i_target , :, :])
299
- assert_array_equal (cor , data1 [::- 1 , :, k_target + 1 ].T ) # ::-1 because the array is flipped in x
300
- assert_array_equal (axi , data1 [::- 1 , j_target , :].T ) # ::-1 because the array is flipped in x
301
-
302
- # Coronal plane - one scrolled down
290
+ assert_array_equal (
291
+ cor , data1 [::- 1 , :, k_target + 1 ].T
292
+ ) # ::-1 because the array is flipped in x
293
+ assert_array_equal (axi , data1 [::- 1 , j_target , :].T ) # ::-1 because the array is flipped in x
294
+
295
+ # Coronal plane - one scrolled down
303
296
o1 .set_position (x_t , y_t , z_t )
304
297
event .button = 'down'
305
298
o1 ._on_scroll (event )
@@ -309,9 +302,9 @@ def __init__(self):
309
302
assert_array_equal (sag , data1 [i_target , :, :])
310
303
assert_array_equal (cor , data1 [::- 1 , :, k_target - 1 ].T )
311
304
assert_array_equal (axi , data1 [::- 1 , j_target , :].T )
312
-
305
+
313
306
# Axial plane - one scroll up
314
- # y is increase by 1
307
+ # y is increase by 1
315
308
o1 .set_position (x_t , y_t , z_t )
316
309
event .inaxes = o1 ._ims [2 ].axes
317
310
event .button = 'up'
@@ -320,10 +313,12 @@ def __init__(self):
320
313
cor = o1 ._ims [1 ].get_array ()
321
314
axi = o1 ._ims [2 ].get_array ()
322
315
assert_array_equal (sag , data1 [i_target , :, :])
323
- assert_array_equal (cor , data1 [::- 1 , :, k_target ].T ) # ::-1 because the array is flipped in x
324
- assert_array_equal (axi , data1 [::- 1 , j_target + 1 , :].T ) # ::-1 because the array is flipped in x
325
-
326
- # Axial plane - one scrolled down
316
+ assert_array_equal (cor , data1 [::- 1 , :, k_target ].T ) # ::-1 because the array is flipped in x
317
+ assert_array_equal (
318
+ axi , data1 [::- 1 , j_target + 1 , :].T
319
+ ) # ::-1 because the array is flipped in x
320
+
321
+ # Axial plane - one scrolled down
327
322
o1 .set_position (x_t , y_t , z_t )
328
323
event .button = 'down'
329
324
o1 ._on_scroll (event )
@@ -333,4 +328,4 @@ def __init__(self):
333
328
assert_array_equal (sag , data1 [i_target , :, :])
334
329
assert_array_equal (cor , data1 [::- 1 , :, k_target ].T )
335
330
assert_array_equal (axi , data1 [::- 1 , j_target - 1 , :].T )
336
- return None
331
+ return None
0 commit comments