Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions nibabies/utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
if path.suffix == '.h5':
# Load as a TransformChain
xfm = nt.manip.load(path)
if len(xfm.transforms) == 4:
# MG: This behavior should be ported to nitransforms
xfm = nt.manip.TransformChain(reverse_pairs(xfm.transforms))

Check warning on line 26 in nibabies/utils/transforms.py

View check run for this annotation

Codecov / codecov/patch

nibabies/utils/transforms.py#L26

Added line #L26 was not covered by tests
else:
xfm = nt.linear.load(path)
if inv:
Expand All @@ -32,3 +35,19 @@
if chain is None:
chain = nt.Affine() # Identity
return chain


def reverse_pairs(arr: list) -> list:
"""
Reverse the order of pairs in a list.

>>> reverse_pairs([1, 2, 3, 4])
[3, 4, 1, 2]

>>> reverse_pairs([1, 2, 3, 4, 5, 6])
[5, 6, 3, 4, 1, 2]
"""
rev = []
for i in range(len(arr), 0, -2):
rev.extend(arr[i - 2 : i])
return rev
Loading