Skip to content

Commit

Permalink
enh: remove unnecessary new arguments
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Markiewicz <[email protected]>
  • Loading branch information
oesteban and effigies committed Nov 16, 2023
1 parent 6b0f3a8 commit 4ace2be
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions nitransforms/io/afni.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,23 @@ def from_string(cls, string):
sa["parameters"] = parameters
return tf

def to_ras(self, moving=None, reference=None, pre_rotation=None, post_rotation=None):
def to_ras(self, moving=None, reference=None):
"""Return a nitransforms internal RAS+ matrix."""
# swapaxes is necessary, as axis 0 encodes series of transforms
retval = LPS @ np.swapaxes(self.structarr["parameters"].T, 0, 1) @ LPS

if pre_rotation is None and reference is not None:
ref_aff = _ensure_image(reference).affine
pre_rotation = _cardinal_rotation(ref_aff, True) if _is_oblique(ref_aff) else None

if pre_rotation is not None:
retval = retval @ pre_rotation

if post_rotation is None and reference is not None:
mov_aff = _ensure_image(moving).affine
post_rotation = _cardinal_rotation(mov_aff, True) if _is_oblique(mov_aff) else None

if post_rotation is not None:
retval = post_rotation @ retval
pre_rotation = post_rotation = np.eye(4)
if reference is not None and _is_oblique(ref_aff := _ensure_image(reference).affine):
pre_rotation = _cardinal_rotation(ref_aff, True)
if moving is not None and _is_oblique(mov_aff := _ensure_image(moving).affine):
post_rotation = _cardinal_rotation(mov_aff, True)

return retval
return (
post_rotation
@ LPS
@ np.swapaxes(self.structarr["parameters"].T, 0, 1)
@ LPS
@ pre_rotation
)


class AFNILinearTransformArray(BaseLinearTransformList):
Expand All @@ -139,7 +136,6 @@ def to_ras(self, moving=None, reference=None):
"""Return a nitransforms' internal RAS matrix."""

pre_rotation = post_rotation = np.eye(4)

if reference is not None and _is_oblique(ref_aff := _ensure_image(reference).affine):
pre_rotation = _cardinal_rotation(ref_aff, True)
if moving is not None and _is_oblique(mov_aff := _ensure_image(moving).affine):
Expand Down

0 comments on commit 4ace2be

Please sign in to comment.