Skip to content

Commit 6c64288

Browse files
authored
Merge pull request #273 from nipy/sty/format-code
STY: Run ruff at the source root
2 parents 11b08d5 + 3fe53f9 commit 6c64288

File tree

13 files changed

+194
-128
lines changed

13 files changed

+194
-128
lines changed

nitransforms/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
transform
1818
"""
19+
1920
from . import linear, manip, nonlinear, surface
2021
from .linear import Affine, LinearTransformsMapping
2122
from .nonlinear import DenseFieldTransform

nitransforms/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def cli_apply(pargs):
3232

3333
xfm = (
3434
nlinload(pargs.transform, fmt=fmt)
35-
if pargs.nonlinear else
36-
linload(pargs.transform, fmt=fmt)
35+
if pargs.nonlinear
36+
else linload(pargs.transform, fmt=fmt)
3737
)
3838

3939
# ensure a reference is set

nitransforms/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""py.test configuration."""
2+
23
import os
34
from pathlib import Path
45
import numpy as np
@@ -64,7 +65,9 @@ def _reorient(path):
6465
newaff = imgaff.copy()
6566
newaff[0, 0] *= -1.0
6667
newaff[0, 3] = imgaff.dot(np.hstack((np.array(img.shape[:3]) - 1, 1.0)))[0]
67-
_data["LAS"] = nb.Nifti1Image(np.flip(np.asanyarray(img.dataobj), 0), newaff, img.header)
68+
_data["LAS"] = nb.Nifti1Image(
69+
np.flip(np.asanyarray(img.dataobj), 0), newaff, img.header
70+
)
6871
_data["LAS"].set_data_dtype(img.get_data_dtype())
6972
newaff = imgaff.copy()
7073
newaff[0, 0] *= -1.0

nitransforms/io/afni.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Read/write AFNI's transforms."""
2+
23
from math import pi
34
import numpy as np
45
from 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

nitransforms/io/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Read/write linear transforms."""
2+
23
from pathlib import Path
34
import numpy as np
45
from nibabel import load as loadimg

nitransforms/io/fsl.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Read/write FSL's transforms."""
2+
23
import os
34
import warnings
45
import numpy as np
@@ -41,7 +42,9 @@ def from_ras(cls, ras, moving=None, reference=None):
4142
moving = reference
4243

4344
if reference is None:
44-
raise TransformIOError("Cannot build FSL linear transform without a reference")
45+
raise TransformIOError(
46+
"Cannot build FSL linear transform without a reference"
47+
)
4548

4649
reference = _ensure_image(reference)
4750
moving = _ensure_image(moving)
@@ -78,7 +81,9 @@ def from_string(cls, string):
7881
def to_ras(self, moving=None, reference=None):
7982
"""Return a nitransforms internal RAS+ matrix."""
8083
if reference is None:
81-
raise TransformIOError("Cannot build FSL linear transform without a reference")
84+
raise TransformIOError(
85+
"Cannot build FSL linear transform without a reference"
86+
)
8287

8388
if moving is None:
8489
warnings.warn(
@@ -180,10 +185,11 @@ def from_image(cls, imgobj):
180185
hdr = imgobj.header.copy()
181186
shape = hdr.get_data_shape()
182187

183-
if len(shape) != 4 or not shape[-1] in (2, 3):
188+
if len(shape) != 4 or shape[-1] not in (2, 3):
184189
raise TransformFileError(
185-
'Displacements field "%s" does not come from FSL.' %
186-
imgobj.file_map['image'].filename)
190+
'Displacements field "%s" does not come from FSL.'
191+
% imgobj.file_map["image"].filename
192+
)
187193

188194
field = np.squeeze(np.asanyarray(imgobj.dataobj))
189195
field[..., 0] *= -1.0

nitransforms/io/itk.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Read/write ITK transforms."""
2+
23
import warnings
34
import numpy as np
45
from scipy.io import loadmat as _read_mat, savemat as _save_mat
@@ -138,8 +139,7 @@ def from_matlab_dict(cls, mdict, index=0):
138139
sa = tf.structarr
139140

140141
affine = mdict.get(
141-
"AffineTransform_double_3_3",
142-
mdict.get("AffineTransform_float_3_3")
142+
"AffineTransform_double_3_3", mdict.get("AffineTransform_float_3_3")
143143
)
144144

145145
if affine is None:
@@ -337,7 +337,7 @@ def from_image(cls, imgobj):
337337
hdr = imgobj.header.copy()
338338
shape = hdr.get_data_shape()
339339

340-
if len(shape) != 5 or shape[-2] != 1 or not shape[-1] in (2, 3):
340+
if len(shape) != 5 or shape[-2] != 1 or shape[-1] not in (2, 3):
341341
raise TransformFileError(
342342
'Displacements field "%s" does not come from ITK.'
343343
% imgobj.file_map["image"].filename
@@ -412,7 +412,9 @@ def from_h5obj(cls, fileobj, check=True, only_linear=False):
412412
# ITK uses Fortran ordering, like NIfTI, but with the vector dimension first
413413
field = np.moveaxis(
414414
np.reshape(
415-
xfm[f"{typo_fallback}Parameters"], (3, *shape.astype(int)), order='F'
415+
xfm[f"{typo_fallback}Parameters"],
416+
(3, *shape.astype(int)),
417+
order="F",
416418
),
417419
0,
418420
-1,
@@ -422,9 +424,7 @@ def from_h5obj(cls, fileobj, check=True, only_linear=False):
422424
hdr.set_intent("vector")
423425
hdr.set_data_dtype("float")
424426

425-
xfm_list.append(
426-
Nifti1Image(field.astype("float"), LPS @ affine, hdr)
427-
)
427+
xfm_list.append(Nifti1Image(field.astype("float"), LPS @ affine, hdr))
428428
continue
429429

430430
raise TransformIOError(

0 commit comments

Comments
 (0)