Skip to content

Commit c5b86e1

Browse files
Julien Marabottooesteban
authored andcommitted
ENH: update outsoucre apply
1 parent be7e9a9 commit c5b86e1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

nitransforms/resampling.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def apply(
9898
if data.ndim < transform.ndim:
9999
data = data[..., np.newaxis]
100100

101+
import pdb; pdb.set_trace()
101102
resampled = ndi.map_coordinates(
102103
data,
103104
_as_homogeneous(targets.reshape(-2, targets.shape[0])).T,

nitransforms/tests/test_base.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
import h5py
66

7-
from ..base import SpatialReference, SampledSpatialData, ImageGrid, TransformBase
7+
from ..base import SpatialReference, SampledSpatialData, ImageGrid, TransformBase, _as_homogeneous
88
from .. import linear as nitl
99
from ..resampling import apply
1010

@@ -42,11 +42,13 @@ def test_ImageGrid(get_testdata, image_orientation):
4242
# Test ras2vox and vox2ras conversions
4343
ijk = [[10, 10, 10], [40, 4, 20], [0, 0, 0], [s - 1 for s in im.shape[:3]]]
4444
xyz = [img._affine.dot(idx + [1])[:-1] for idx in ijk]
45+
# xyz = np.array([np.tensordot(img._affine, idx + [1], axes=1)[:-1] for idx in ijk])
4546

46-
assert np.allclose(img.ras(ijk[0]), xyz[0])
47+
# import pdb; pdb.set_trace()
48+
assert np.allclose(np.squeeze(img.ras(ijk[0])), xyz[0])
4749
assert np.allclose(np.round(img.index(xyz[0])), ijk[0])
48-
assert np.allclose(img.ras(ijk), xyz)
49-
assert np.allclose(np.round(img.index(xyz)), ijk)
50+
assert np.allclose(img.ras(ijk).T, xyz)
51+
assert np.allclose(np.round(img.index(xyz)).T, ijk)
5052

5153
# nd index / coords
5254
idxs = img.ndindex
@@ -92,12 +94,13 @@ def _to_hdf5(klass, x5_root):
9294
img = nb.load(fname)
9395
imgdata = np.asanyarray(img.dataobj, dtype=img.get_data_dtype())
9496

95-
# Test identity transform
9697
xfm = TransformBase()
97-
xfm.reference = fname
98-
9998
with pytest.raises(TypeError):
10099
_ = xfm.ndim
100+
101+
# Test identity transform
102+
xfm = nitl.Affine()
103+
xfm.reference = fname
101104
moved = apply(xfm, fname, order=0)
102105
assert np.all(
103106
imgdata == np.asanyarray(moved.dataobj, dtype=moved.get_data_dtype())

0 commit comments

Comments
 (0)