<s> from collections import namedtuple as nt <EOL> import numpy as np <EOL> from . . optpkg import optional_package <EOL> from . . viewers import OrthoSlicer3D <EOL> from numpy . testing . decorators import skipif <EOL> from numpy . testing import assert_array_equal , assert_equal <EOL> from nose . tools import assert_raises , assert_true <EOL> matplotlib , has_mpl , _ = optional_package ( '<STR_LIT>' , min_version = '<STR_LIT>' ) <EOL> needs_mpl = skipif ( not has_mpl , '<STR_LIT>' ) <EOL> if has_mpl : <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> @ needs_mpl <EOL> def test_viewer ( ) : <EOL> plt = optional_package ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> a = np . sin ( np . linspace ( <NUM_LIT:0> , np . pi , <NUM_LIT:20> ) ) <EOL> b = np . sin ( np . linspace ( <NUM_LIT:0> , np . pi * <NUM_LIT:5> , <NUM_LIT:30> ) ) <EOL> data = ( np . outer ( a , b ) [ ... , np . newaxis ] * a ) [ : , : , : , np . newaxis ] <EOL> data = data * np . array ( [ <NUM_LIT:1.> , <NUM_LIT> ] ) <EOL> v = OrthoSlicer3D ( data ) <EOL> assert_array_equal ( v . position , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert_true ( '<STR_LIT>' in repr ( v ) ) <EOL> v . _on_scroll ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( '<STR_LIT>' , None , None ) ) <EOL> for ax in ( v . _axes [ <NUM_LIT:0> ] , v . _axes [ <NUM_LIT:3> ] ) : <EOL> v . _on_scroll ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( '<STR_LIT>' , ax , None ) ) <EOL> v . _on_scroll ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( '<STR_LIT>' , ax , '<STR_LIT>' ) ) <EOL> v . _on_mouse ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , None , <NUM_LIT:1> ) ) <EOL> for ax in v . _axes : <EOL> v . _on_mouse ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , ax , <NUM_LIT:1> ) ) <EOL> v . _on_mouse ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , None , None ) ) <EOL> v . set_volume_idx ( <NUM_LIT:1> ) <EOL> v . cmap = '<STR_LIT>' <EOL> v . clim = ( <NUM_LIT:0> , <NUM_LIT:3> ) <EOL> assert_raises ( ValueError , OrthoSlicer3D . clim . fset , v , ( <NUM_LIT:0.> , ) ) <EOL> assert_raises ( ValueError , OrthoSlicer3D . cmap . fset , v , '<STR_LIT:foo>' ) <EOL> v . set_volume_idx ( <NUM_LIT:1> ) <EOL> v . _on_keypress ( nt ( '<STR_LIT>' , '<STR_LIT:key>' ) ( '<STR_LIT:->' ) ) <EOL> assert_equal ( v . _data_idx [ <NUM_LIT:3> ] , <NUM_LIT:0> ) <EOL> v . _on_keypress ( nt ( '<STR_LIT>' , '<STR_LIT:key>' ) ( '<STR_LIT:+>' ) ) <EOL> assert_equal ( v . _data_idx [ <NUM_LIT:3> ] , <NUM_LIT:1> ) <EOL> v . _on_keypress ( nt ( '<STR_LIT>' , '<STR_LIT:key>' ) ( '<STR_LIT:->' ) ) <EOL> v . _on_keypress ( nt ( '<STR_LIT>' , '<STR_LIT:key>' ) ( '<STR_LIT:=>' ) ) <EOL> assert_equal ( v . _data_idx [ <NUM_LIT:3> ] , <NUM_LIT:1> ) <EOL> v . close ( ) <EOL> v . _draw ( ) <EOL> v = OrthoSlicer3D ( data [ : , : , : , <NUM_LIT:0> ] ) <EOL> v . _on_scroll ( nt ( '<STR_LIT>' , '<STR_LIT>' ) ( '<STR_LIT>' , v . _axes [ <NUM_LIT:0> ] , '<STR_LIT>' ) ) <EOL> v . _on_keypress ( nt ( '<STR_LIT>' , '<STR_LIT:key>' ) ( '<STR_LIT>' ) ) <EOL> v . close ( ) <EOL> assert_raises ( TypeError , OrthoSlicer3D , <EOL> data [ : , : , : , <NUM_LIT:0> ] . astype ( np . complex64 ) ) <EOL> fig , axes = plt . subplots ( <NUM_LIT:1> , <NUM_LIT:4> ) <EOL> plt . close ( fig ) <EOL> v1 = OrthoSlicer3D ( data , axes = axes ) <EOL> aff = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ] , [ - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] , <EOL> float ) <EOL> v2 = OrthoSlicer3D ( data , affine = aff , axes = axes [ : <NUM_LIT:3> ] ) <EOL> assert_raises ( ValueError , OrthoSlicer3D , data [ : , : , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> assert_raises ( ValueError , OrthoSlicer3D , data , affine = np . eye ( <NUM_LIT:3> ) ) <EOL> assert_raises ( TypeError , v2 . link_to , <NUM_LIT:1> ) <EOL> v2 . link_to ( v1 ) <EOL> v2 . link_to ( v1 ) <EOL> v1 . close ( ) <EOL> v2 . close ( ) </s>
