2
2
3
3
import numpy as np
4
4
5
- from ..io import LinearTransformArray as LTA
5
+ from ..io import (
6
+ VolumeGeometry as VG ,
7
+ LinearTransform as LT ,
8
+ LinearTransformArray as LTA ,
9
+ )
6
10
7
11
8
- def test_LinearTransformArray_input (tmpdir , data_path ):
12
+ def test_VolumeGeometry (tmpdir , get_data ):
13
+ vg = VG ()
14
+ assert vg ['valid' ] == 0
15
+
16
+ img = get_data ['RAS' ]
17
+ vg = VG .from_image (img )
18
+ assert vg ['valid' ] == 1
19
+ assert np .all (vg ['voxelsize' ] == img .header .get_zooms ()[:3 ])
20
+ assert np .all (vg .as_affine () == img .affine )
21
+
22
+ assert len (vg .to_string ().split ('\n ' )) == 8
23
+
24
+
25
+ def test_LinearTransform (tmpdir , get_data ):
26
+ lt = LT ()
27
+ assert lt ['m_L' ].shape == (4 , 4 )
28
+ assert np .all (lt ['m_L' ] == 0 )
29
+ for vol in ('src' , 'dst' ):
30
+ assert lt [vol ]['valid' ] == 0
31
+
32
+
33
+ def test_LinearTransformArray (tmpdir , data_path ):
9
34
lta = LTA ()
10
35
assert lta ['nxforms' ] == 0
11
36
assert len (lta ['xforms' ]) == 0
@@ -21,3 +46,11 @@ def test_LinearTransformArray_input(tmpdir, data_path):
21
46
assert np .allclose (
22
47
xform ['m_L' ], np .genfromtxt (test_lta , skip_header = 5 , skip_footer = 20 )
23
48
)
49
+
50
+ outlta = (tmpdir / 'out.lta' ).strpath
51
+ with open (outlta , 'w' ) as fp :
52
+ fp .write (lta .to_string ())
53
+
54
+ with open (outlta ) as fp :
55
+ lta2 = LTA .from_fileobj (fp )
56
+ np .allclose (lta ['xforms' ][0 ]['m_L' ], lta2 ['xforms' ][0 ]['m_L' ])
0 commit comments