11"""Read/write AFNI's transforms."""
2+
23from math import pi
34import numpy as np
45from nibabel .affines import (
@@ -132,15 +133,16 @@ def to_ras(self, moving=None, reference=None):
132133 """Return a nitransforms' internal RAS matrix."""
133134
134135 pre_rotation = post_rotation = np .eye (4 )
135- if reference is not None and _is_oblique (ref_aff := _ensure_image (reference ).affine ):
136+ if reference is not None and _is_oblique (
137+ ref_aff := _ensure_image (reference ).affine
138+ ):
136139 pre_rotation = _cardinal_rotation (ref_aff , True )
137140 if moving is not None and _is_oblique (mov_aff := _ensure_image (moving ).affine ):
138141 post_rotation = _cardinal_rotation (mov_aff , False )
139142
140- return np .stack ([
141- post_rotation @ (xfm .to_ras () @ pre_rotation )
142- for xfm in self .xforms
143- ])
143+ return np .stack (
144+ [post_rotation @ (xfm .to_ras () @ pre_rotation ) for xfm in self .xforms ]
145+ )
144146
145147 def to_string (self ):
146148 """Convert to a string directly writeable to file."""
@@ -161,7 +163,9 @@ def from_ras(cls, ras, moving=None, reference=None):
161163
162164 pre_rotation = post_rotation = np .eye (4 )
163165
164- if reference is not None and _is_oblique (ref_aff := _ensure_image (reference ).affine ):
166+ if reference is not None and _is_oblique (
167+ ref_aff := _ensure_image (reference ).affine
168+ ):
165169 pre_rotation = _cardinal_rotation (ref_aff , False )
166170 if moving is not None and _is_oblique (mov_aff := _ensure_image (moving ).affine ):
167171 post_rotation = _cardinal_rotation (mov_aff , True )
@@ -198,7 +202,7 @@ def from_image(cls, imgobj):
198202 hdr = imgobj .header .copy ()
199203 shape = hdr .get_data_shape ()
200204
201- if len (shape ) != 5 or shape [- 2 ] != 1 or not shape [- 1 ] in (2 , 3 ):
205+ if len (shape ) != 5 or shape [- 2 ] != 1 or shape [- 1 ] not in (2 , 3 ):
202206 raise TransformFileError (
203207 'Displacements field "%s" does not come from AFNI.'
204208 % imgobj .file_map ["image" ].filename
0 commit comments