Skip to content

Commit 7905f83

Browse files
committed
enh: fix lta conversion, add data
1 parent 4f1b738 commit 7905f83

File tree

6 files changed

+35
-66
lines changed

6 files changed

+35
-66
lines changed

nitransforms/io/lta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def from_string(klass, string):
9292

9393
class LinearTransform(StringBasedStruct):
9494
template_dtype = np.dtype([
95-
('mean', 'f4', (3, 1)), # x0, y0, z0
95+
('mean', 'f4', (3, 1)), # x0, y0, z0
9696
('sigma', 'f4'),
9797
('m_L', 'f4', (4, 4)),
9898
('m_dL', 'f4', (4, 4)),

nitransforms/linear.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def load(filename, fmt='X5', reference=None):
257257
if lta['nxforms'] > 1:
258258
raise NotImplementedError("Multiple transforms are not yet supported.")
259259
if lta['type'] != 1:
260+
warnings.warn("Converting LTA to RAS2RAS")
260261
lta.set_type(1)
261262
matrix = lta['xforms'][0]['m_L']
262263
elif fmt.lower() in ('x5', 'bids'):
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
type = 0 # LINEAR_VOX_TO_VOX
2+
nxforms = 1
3+
mean = 0.0000 0.0000 0.0000
4+
sigma = 1.0000
5+
1 4 4
6+
9.999989867210388e-01 -9.999993490055203e-04 9.999998146668077e-04 1.454572677612305e+00
7+
1.404936425387859e-03 6.216088533401489e-01 -7.833265066146851e-01 3.912971496582031e+01
8+
1.617172238184139e-04 7.833272218704224e-01 6.216096878051758e-01 -1.376794815063477e+01
9+
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00
10+
src volume info
11+
valid = 1 # volume info valid
12+
filename = unknown
13+
volume = 57 67 56
14+
voxelsize = 2.750000000000000e+00 2.750000000000000e+00 2.750000000000000e+00
15+
xras = 1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00
16+
yras = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e+00
17+
zras = 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00
18+
cras = 3.750000000000000e-01 1.125000000000000e+00 -1.400000000000000e+01
19+
dst volume info
20+
valid = 1 # volume info valid
21+
filename = unknown
22+
volume = 57 67 56
23+
voxelsize = 2.750000000000000e+00 2.750000000000000e+00 2.750000000000000e+00
24+
xras = 1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00
25+
yras = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e+00
26+
zras = 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00
27+
cras = 3.750000000000000e-01 1.125000000000000e+00 -1.400000000000000e+01
28+
fscale 0.100000

nitransforms/tests/data/r2r.lta

Lines changed: 0 additions & 30 deletions
This file was deleted.

nitransforms/tests/data/v2v.lta

Lines changed: 0 additions & 30 deletions
This file was deleted.

nitransforms/tests/test_io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_LinearTransformArray(tmpdir, data_path):
3636
assert lta['nxforms'] == 0
3737
assert len(lta['xforms']) == 0
3838

39-
test_lta = str(data_path / 'r2r.lta')
39+
test_lta = str(data_path / 'affine-RAS.fs.lta')
4040
with open(test_lta) as fp:
4141
lta = LTA.from_fileobj(fp)
4242

@@ -45,7 +45,7 @@ def test_LinearTransformArray(tmpdir, data_path):
4545
xform = lta['xforms'][0]
4646

4747
assert np.allclose(
48-
xform['m_L'], np.genfromtxt(test_lta, skip_header=8, skip_footer=18)
48+
xform['m_L'], np.genfromtxt(test_lta, skip_header=5, skip_footer=20)
4949
)
5050

5151
outlta = (tmpdir / 'out.lta').strpath
@@ -58,8 +58,8 @@ def test_LinearTransformArray(tmpdir, data_path):
5858

5959

6060
def test_LT_conversions(data_path):
61-
r = str(data_path / 'r2r.lta')
62-
v = str(data_path / 'v2v.lta')
61+
r = str(data_path / 'affine-RAS.fs.lta')
62+
v = str(data_path / 'affine-RAS.fs.v2v.lta')
6363
with open(r) as fa, open(v) as fb:
6464
r2r = LTA.from_fileobj(fa)
6565
v2v = LTA.from_fileobj(fb)
@@ -72,7 +72,7 @@ def test_LT_conversions(data_path):
7272
# convert vox2vox LTA to ras2ras
7373
v2v.set_type('LINEAR_RAS_TO_RAS')
7474
assert v2v['type'] == 1
75-
assert np.allclose(r2r_m, v2v_m)
75+
assert np.allclose(r2r_m, v2v_m, atol=1e-05)
7676

7777

7878
def test_ITKLinearTransformArray(tmpdir, data_path):

0 commit comments

Comments
 (0)