Skip to content

Commit

Permalink
fix: indeed, asaffine() had the reversed convention
Browse files Browse the repository at this point in the history
Thanks Chris for pointing this out.

Co-authored-by: Chris Markiewicz <[email protected]>
  • Loading branch information
oesteban and effigies committed Jul 19, 2022
1 parent 533a03d commit e80bd3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
20 changes: 18 additions & 2 deletions nitransforms/manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def map(self, x, inverse=False):
transforms = list(reversed(self.transforms))

for xfm in transforms:
x = xfm(x, inverse=inverse)
x = xfm.map(x, inverse=inverse)

return x

Expand All @@ -156,6 +156,22 @@ def asaffine(self, indices=None):
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
>>> chain = TransformChain(transforms=[
... Affine.from_matvec(vec=(1, 2, 3)),
... Affine.from_matvec(mat=[[0, 1, 0], [0, 0, 1], [1, 0, 0]]),
... ])
>>> chain.asaffine()
array([[0., 1., 0., 2.],
[0., 0., 1., 3.],
[1., 0., 0., 1.],
[0., 0., 0., 1.]])
>>> np.allclose(
... chain.map((4, -2, 1)),
... chain.asaffine().map((4, -2, 1)),
... )
True
Parameters
----------
indices : :obj:`numpy.array_like`
Expand All @@ -165,7 +181,7 @@ def asaffine(self, indices=None):
affines = self.transforms if indices is None else np.take(self.transforms, indices)
retval = affines[0]
for xfm in affines[1:]:
retval @= xfm
retval = xfm @ retval
return retval

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions nitransforms/tests/test_manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ def test_collapse_affines(tmp_path, data_path, ext0, ext1, ext2):
"""Check whether affines are correctly collapsed."""
chain = TransformChain(
[
Affine.from_filename(
data_path / "regressions" / f"from-scanner_to-bold_mode-image.{ext1}",
fmt=f"{FMT[ext1]}",
),
Affine.from_filename(
data_path
/ "regressions"
/ f"from-fsnative_to-scanner_mode-image.{ext0}",
fmt=f"{FMT[ext0]}",
),
Affine.from_filename(
data_path / "regressions" / f"from-scanner_to-bold_mode-image.{ext1}",
fmt=f"{FMT[ext1]}",
),
]
)
assert np.allclose(
Expand Down

0 comments on commit e80bd3c

Please sign in to comment.