1
1
"""Read/write AFNI's transforms."""
2
+
2
3
from math import pi
3
4
import numpy as np
4
5
from nibabel .affines import (
@@ -132,15 +133,16 @@ def to_ras(self, moving=None, reference=None):
132
133
"""Return a nitransforms' internal RAS matrix."""
133
134
134
135
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
+ ):
136
139
pre_rotation = _cardinal_rotation (ref_aff , True )
137
140
if moving is not None and _is_oblique (mov_aff := _ensure_image (moving ).affine ):
138
141
post_rotation = _cardinal_rotation (mov_aff , False )
139
142
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
+ )
144
146
145
147
def to_string (self ):
146
148
"""Convert to a string directly writeable to file."""
@@ -161,7 +163,9 @@ def from_ras(cls, ras, moving=None, reference=None):
161
163
162
164
pre_rotation = post_rotation = np .eye (4 )
163
165
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
+ ):
165
169
pre_rotation = _cardinal_rotation (ref_aff , False )
166
170
if moving is not None and _is_oblique (mov_aff := _ensure_image (moving ).affine ):
167
171
post_rotation = _cardinal_rotation (mov_aff , True )
@@ -198,7 +202,7 @@ def from_image(cls, imgobj):
198
202
hdr = imgobj .header .copy ()
199
203
shape = hdr .get_data_shape ()
200
204
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 ):
202
206
raise TransformFileError (
203
207
'Displacements field "%s" does not come from AFNI.'
204
208
% imgobj .file_map ["image" ].filename
0 commit comments