Skip to content

Commit d0a0576

Browse files
committed
enh: LTA + components tests
1 parent 8e23723 commit d0a0576

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

nitransforms/tests/test_io.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
import numpy as np
44

5-
from ..io import LinearTransformArray as LTA
5+
from ..io import (
6+
VolumeGeometry as VG,
7+
LinearTransform as LT,
8+
LinearTransformArray as LTA,
9+
)
610

711

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):
934
lta = LTA()
1035
assert lta['nxforms'] == 0
1136
assert len(lta['xforms']) == 0
@@ -21,3 +46,11 @@ def test_LinearTransformArray_input(tmpdir, data_path):
2146
assert np.allclose(
2247
xform['m_L'], np.genfromtxt(test_lta, skip_header=5, skip_footer=20)
2348
)
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

Comments
 (0)