Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e80bd3c

Browse files
oestebaneffigies
andcommittedJul 19, 2022
fix: indeed, asaffine() had the reversed convention
Thanks Chris for pointing this out. Co-authored-by: Chris Markiewicz <[email protected]>
1 parent 533a03d commit e80bd3c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed
 

‎nitransforms/manip.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def map(self, x, inverse=False):
136136
transforms = list(reversed(self.transforms))
137137

138138
for xfm in transforms:
139-
x = xfm(x, inverse=inverse)
139+
x = xfm.map(x, inverse=inverse)
140140

141141
return x
142142

@@ -156,6 +156,22 @@ def asaffine(self, indices=None):
156156
[0., 0., 1., 0.],
157157
[0., 0., 0., 1.]])
158158
159+
>>> chain = TransformChain(transforms=[
160+
... Affine.from_matvec(vec=(1, 2, 3)),
161+
... Affine.from_matvec(mat=[[0, 1, 0], [0, 0, 1], [1, 0, 0]]),
162+
... ])
163+
>>> chain.asaffine()
164+
array([[0., 1., 0., 2.],
165+
[0., 0., 1., 3.],
166+
[1., 0., 0., 1.],
167+
[0., 0., 0., 1.]])
168+
169+
>>> np.allclose(
170+
... chain.map((4, -2, 1)),
171+
... chain.asaffine().map((4, -2, 1)),
172+
... )
173+
True
174+
159175
Parameters
160176
----------
161177
indices : :obj:`numpy.array_like`
@@ -165,7 +181,7 @@ def asaffine(self, indices=None):
165181
affines = self.transforms if indices is None else np.take(self.transforms, indices)
166182
retval = affines[0]
167183
for xfm in affines[1:]:
168-
retval @= xfm
184+
retval = xfm @ retval
169185
return retval
170186

171187
@classmethod

‎nitransforms/tests/test_manip.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ def test_collapse_affines(tmp_path, data_path, ext0, ext1, ext2):
6868
"""Check whether affines are correctly collapsed."""
6969
chain = TransformChain(
7070
[
71-
Affine.from_filename(
72-
data_path / "regressions" / f"from-scanner_to-bold_mode-image.{ext1}",
73-
fmt=f"{FMT[ext1]}",
74-
),
7571
Affine.from_filename(
7672
data_path
7773
/ "regressions"
7874
/ f"from-fsnative_to-scanner_mode-image.{ext0}",
7975
fmt=f"{FMT[ext0]}",
8076
),
77+
Affine.from_filename(
78+
data_path / "regressions" / f"from-scanner_to-bold_mode-image.{ext1}",
79+
fmt=f"{FMT[ext1]}",
80+
),
8181
]
8282
)
8383
assert np.allclose(

0 commit comments

Comments
 (0)