Skip to content

Commit 73245ac

Browse files
committed
ENH: Require explicit source_ornt None to use reorient_pedir as inverse, update docs
1 parent 4c1b42c commit 73245ac

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

sdcflows/utils/tools.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,21 @@ def brain_masker(in_file, out_file=None, padding=5):
156156
return str(out_brain), str(out_probseg), str(out_mask)
157157

158158

159-
def reorient_pedir(pe_dir, source_ornt=None, target_ornt=None):
159+
def reorient_pedir(pe_dir, source_ornt, target_ornt=None):
160160
"""Return updated PhaseEncodingDirection to account for an image data array rotation
161161
162-
This function can accept one or two orientations.
162+
Orientations form a natural group with identity, product and inverse.
163+
This function thus has the following properties (here ``e`` is the identity,
164+
``*`` the product and ``-`` the inverse; ``a`` and ``b`` are arbitrary orientations):
165+
166+
reorient(pe_dir, e, e) == pe_dir
167+
reorient(pe_dir, a, e) == reorient(pe_dir, a)
168+
reorient(pe_dir, e, b) == reorient(pe_dir, -b)
169+
reorient(pe_dir, a, b) == reorient(pe_dir, a * -b, e)
170+
171+
Therefore, this function accepts one or two orientations, and precomputed transforms
172+
from a to b can be passed as the "source" orientation.
173+
163174
Passing only a source orientation will rotate into RAS:
164175
165176
>>> from nibabel.orientations import axcodes2ornt
@@ -170,9 +181,9 @@ def reorient_pedir(pe_dir, source_ornt=None, target_ornt=None):
170181
171182
Passing only a target_ornt will rotate from RAS:
172183
173-
>>> reorient_pedir("j", target_ornt=axcodes2ornt("RAS"))
184+
>>> reorient_pedir("j", source_ornt=None, target_ornt=axcodes2ornt("RAS"))
174185
'j'
175-
>>> reorient_pedir("i", target_ornt=axcodes2ornt("PSL"))
186+
>>> reorient_pedir("i", source_ornt=None, target_ornt=axcodes2ornt("PSL"))
176187
'k-'
177188
178189
Passing both will rotate from source to target.
@@ -187,7 +198,7 @@ def reorient_pedir(pe_dir, source_ornt=None, target_ornt=None):
187198
>>> xfm = ornt_transform(axcodes2ornt("LPS"), axcodes2ornt("AIR"))
188199
>>> reorient_pedir("j", xfm)
189200
'i-'
190-
>>> reorient_pedir("j", target_ornt=xfm)
201+
>>> reorient_pedir("j", source_ornt=None, target_ornt=xfm)
191202
'k-'
192203
"""
193204
from nibabel.orientations import ornt_transform

0 commit comments

Comments
 (0)