Skip to content

Commit 26970f2

Browse files
committed
enh+doc: increase linear coverage
1 parent 2ab68b3 commit 26970f2

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

nitransforms/linear.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,
108108
109109
Examples
110110
--------
111+
>>> a = Affine()
112+
>>> a.matrix
113+
array([[[1., 0., 0., 0.],
114+
[0., 1., 0., 0.],
115+
[0., 0., 1., 0.],
116+
[0., 0., 0., 1.]]])
117+
111118
>>> xfm = Affine([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
112119
>>> ref = nb.load(testfile)
113120
>>> xfm.reference = ref
@@ -172,7 +179,34 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,
172179
return moved_image
173180

174181
def map_point(self, coords, index=0, forward=True):
175-
"""Apply y = f(x), where x is the argument `coords`."""
182+
"""
183+
Apply y = f(x), where x is the argument `coords`.
184+
185+
Parameters
186+
----------
187+
coords : array_like
188+
RAS coordinates to map
189+
index : int, optional
190+
Transformation index
191+
forward: bool, optional
192+
Direction of mapping. Default is set to ``True``. If ``False``,
193+
the inverse transformation is applied.
194+
195+
Returns
196+
-------
197+
out: ndarray
198+
Transformed coordinates
199+
200+
Examples
201+
--------
202+
>>> xfm = Affine([[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]])
203+
>>> xfm.map_point((0,0,0))
204+
array([1, 2, 3])
205+
206+
>>> xfm.map_point((0,0,0), forward=False)
207+
array([-1., -2., -3.])
208+
209+
"""
176210
coords = np.array(coords)
177211
if coords.shape[0] == self._matrix[index].shape[0] - 1:
178212
coords = np.append(coords, [1])

nitransforms/tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def test_LinearTransformArray(tmpdir, data_path):
5353

5454
with open(outlta) as fp:
5555
lta2 = LTA.from_fileobj(fp)
56-
np.allclose(lta['xforms'][0]['m_L'], lta2['xforms'][0]['m_L'])
56+
assert np.allclose(lta['xforms'][0]['m_L'], lta2['xforms'][0]['m_L'])

nitransforms/tests/test_transform.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@
3131
}
3232

3333

34+
def test_map_voxel(tmpdir, get_data):
35+
xfm = nbl.Affine([[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]])
36+
with pytest.raises(ValueError):
37+
# reference / moving are not set
38+
xfm.map_voxel((0, 0, 0))
39+
40+
img = get_data['RAS']
41+
xfm.reference = img
42+
assert xfm.map_voxel((0, 0, 0)) == (2.75, 5.5, 8.25)
43+
del xfm
44+
45+
# use moving space as reference
46+
xfm = nbl.Affine([[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]])
47+
mov = get_data['LPS']
48+
assert xfm.map_voxel((0, 0, 0), moving=mov) == (-2.75, -5.5, 8.25)
49+
50+
# use RAS space as reference
51+
xfm.reference = img
52+
assert xfm.map_voxel((0, 0, 0), moving=mov) == (0.75, 5.0, 8.25)
53+
54+
3455
@pytest.mark.xfail(reason="Not fully implemented")
3556
@pytest.mark.parametrize('image_orientation', [
3657
'RAS', 'LAS', 'LPS', # 'oblique',

0 commit comments

Comments
 (0)