@@ -136,20 +136,19 @@ def test_viewer_nonRAS():
136136 assert_array_equal (axi , data1 [:, 13 , :].T )
137137
138138
139-
140139@needs_mpl
141140def test_viewer_nonRAS_on_mouse ():
142141 """
143142 test on_mouse selection on non RAS matrices
144-
143+
145144 """
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:
148147 # - LR inverted on scanner x (i)
149148 # - IS on scanner y (j)
150149 # - 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+
153152 (I , J , K ) = (10 , 20 , 40 )
154153 data1 = np .random .rand (I , J , K )
155154 (i_target , j_target , k_target ) = (2 , 14 , 12 )
@@ -159,68 +158,65 @@ def test_viewer_nonRAS_on_mouse():
159158 j2 = j_target + 3
160159 k1 = k_target - 4
161160 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
163162 data1 [i_target , j_target , k_target ] = 1
164163 valp1 = 1.5
165164 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
168167 data1 [i_target , j_target - 1 , k_target ] = valm1
169168 data1 [i_target , j_target + 1 , k_target ] = valp1
170169 data1 [i_target , j_target , k_target - 1 ] = valm1
171170 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+
178174 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'
183179 self .button = 1
184-
180+
185181 event = Event ()
186182 event .xdata = k_target
187183 event .ydata = j_target
188184 event .inaxes = o1 ._ims [0 ].axes
189185 o1 ._on_mouse (event )
190-
186+
191187 event .inaxes = o1 ._ims [1 ].axes
192- event .xdata = (I - 1 ) - i_target # x flipped
188+ event .xdata = (I - 1 ) - i_target # x flipped
193189 event .ydata = j_target
194190 o1 ._on_mouse (event )
195-
191+
196192 event .inaxes = o1 ._ims [2 ].axes
197- event .xdata = (I - 1 ) - i_target # x flipped
193+ event .xdata = (I - 1 ) - i_target # x flipped
198194 event .ydata = k_target
199195 o1 ._on_mouse (event )
200-
196+
201197 sag = o1 ._ims [0 ].get_array ()
202198 cor = o1 ._ims [1 ].get_array ()
203199 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
208204 return None
209205
210206
211207@needs_mpl
212208def test_viewer_nonRAS_on_scroll ():
213209 """
214210 test scrolling on non RAS matrices
215-
211+
216212 """
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:
219215 # - LR inverted on scanner x (i)
220216 # - IS on scanner y (j)
221217 # - PA on scanner z (k)
222218 # This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.
223-
219+
224220 (I , J , K ) = (10 , 20 , 40 )
225221 data1 = np .random .rand (I , J , K )
226222 (i_target , j_target , k_target ) = (2 , 14 , 12 )
@@ -230,40 +226,35 @@ def test_viewer_nonRAS_on_scroll():
230226 j2 = j_target + 3
231227 k1 = k_target - 4
232228 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
234230 data1 [i_target , j_target , k_target ] = 1
235231 valp1 = 1.5
236232 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
239235 data1 [i_target , j_target - 1 , k_target ] = valm1
240236 data1 [i_target , j_target + 1 , k_target ] = valp1
241237 data1 [i_target , j_target , k_target - 1 ] = valm1
242238 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+
249242 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'
254247 self .button = None
255248 self .key = None
256-
257- i_last = data1 .shape [0 ] - 1
258-
249+
259250 [x_t , y_t , z_t ] = list (aff1 .dot (np .array ([i_target , j_target , k_target , 1 ]))[:3 ])
260251 # print(x_t, y_t, z_t)
261252 # scanner positions are x_t=3, y_t=2, z_t=16
262-
253+
263254 event = Event ()
264-
255+
265256 # 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
267258 o1 .set_position (x_t , y_t , z_t )
268259 event .inaxes = o1 ._ims [0 ].axes
269260 event .button = 'up'
@@ -272,10 +263,10 @@ def __init__(self):
272263 cor = o1 ._ims [1 ].get_array ()
273264 axi = o1 ._ims [2 ].get_array ()
274265 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
279270 o1 .set_position (x_t , y_t , z_t )
280271 event .button = 'down'
281272 o1 ._on_scroll (event )
@@ -285,9 +276,9 @@ def __init__(self):
285276 assert_array_equal (sag , data1 [i_target + 1 , :, :])
286277 assert_array_equal (cor , data1 [::- 1 , :, k_target ].T )
287278 assert_array_equal (axi , data1 [::- 1 , j_target , :].T )
288-
279+
289280 # Coronal plane - one scroll up
290- # y coordinate is increase by 1
281+ # y coordinate is increase by 1
291282 o1 .set_position (x_t , y_t , z_t )
292283 event .inaxes = o1 ._ims [1 ].axes
293284 event .button = 'up'
@@ -296,10 +287,12 @@ def __init__(self):
296287 cor = o1 ._ims [1 ].get_array ()
297288 axi = o1 ._ims [2 ].get_array ()
298289 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
303296 o1 .set_position (x_t , y_t , z_t )
304297 event .button = 'down'
305298 o1 ._on_scroll (event )
@@ -309,9 +302,9 @@ def __init__(self):
309302 assert_array_equal (sag , data1 [i_target , :, :])
310303 assert_array_equal (cor , data1 [::- 1 , :, k_target - 1 ].T )
311304 assert_array_equal (axi , data1 [::- 1 , j_target , :].T )
312-
305+
313306 # Axial plane - one scroll up
314- # y is increase by 1
307+ # y is increase by 1
315308 o1 .set_position (x_t , y_t , z_t )
316309 event .inaxes = o1 ._ims [2 ].axes
317310 event .button = 'up'
@@ -320,10 +313,12 @@ def __init__(self):
320313 cor = o1 ._ims [1 ].get_array ()
321314 axi = o1 ._ims [2 ].get_array ()
322315 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
327322 o1 .set_position (x_t , y_t , z_t )
328323 event .button = 'down'
329324 o1 ._on_scroll (event )
@@ -333,4 +328,4 @@ def __init__(self):
333328 assert_array_equal (sag , data1 [i_target , :, :])
334329 assert_array_equal (cor , data1 [::- 1 , :, k_target ].T )
335330 assert_array_equal (axi , data1 [::- 1 , j_target - 1 , :].T )
336- return None
331+ return None
0 commit comments