Skip to content

Commit de81e23

Browse files
committed
sty: format changed files
1 parent 06a1c01 commit de81e23

7 files changed

+78
-40
lines changed

nitransforms/base.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
"""Common interface for transforms."""
10+
1011
from pathlib import Path
1112
import numpy as np
1213
import h5py
@@ -146,13 +147,13 @@ def from_arrays(cls, coordinates, triangles):
146147
darrays = [
147148
nb.gifti.GiftiDataArray(
148149
coordinates.astype(np.float32),
149-
intent=nb.nifti1.intent_codes['NIFTI_INTENT_POINTSET'],
150-
datatype=nb.nifti1.data_type_codes['NIFTI_TYPE_FLOAT32'],
150+
intent=nb.nifti1.intent_codes["NIFTI_INTENT_POINTSET"],
151+
datatype=nb.nifti1.data_type_codes["NIFTI_TYPE_FLOAT32"],
151152
),
152153
nb.gifti.GiftiDataArray(
153154
triangles.astype(np.int32),
154-
intent=nb.nifti1.intent_codes['NIFTI_INTENT_TRIANGLE'],
155-
datatype=nb.nifti1.data_type_codes['NIFTI_TYPE_INT32'],
155+
intent=nb.nifti1.intent_codes["NIFTI_INTENT_TRIANGLE"],
156+
datatype=nb.nifti1.data_type_codes["NIFTI_TYPE_INT32"],
156157
),
157158
]
158159
gii = nb.gifti.GiftiImage(darrays=darrays)
@@ -282,7 +283,7 @@ def __add__(self, b):
282283
def __len__(self):
283284
"""
284285
Enable ``len()``.
285-
286+
286287
By default, all transforms are of length one.
287288
This must be overriden by transforms arrays and chains.
288289
@@ -345,9 +346,7 @@ def apply(self, *args, **kwargs):
345346
346347
Deprecated. Please use ``nitransforms.resampling.apply`` instead.
347348
"""
348-
message = (
349-
"The `apply` method is deprecated. Please use `nitransforms.resampling.apply` instead."
350-
)
349+
message = "The `apply` method is deprecated. Please use `nitransforms.resampling.apply` instead."
351350
warnings.warn(message, DeprecationWarning, stacklevel=2)
352351
from .resampling import apply
353352

nitransforms/resampling.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ def apply(
188188
)
189189

190190
if isinstance(_ref, ImageGrid): # If reference is grid, reshape
191-
hdr = _ref.header.copy() if _ref.header is not None else spatialimage.header.__class__()
191+
hdr = (
192+
_ref.header.copy()
193+
if _ref.header is not None
194+
else spatialimage.header.__class__()
195+
)
192196
hdr.set_data_dtype(output_dtype or spatialimage.header.get_data_dtype())
193197

194198
moved = spatialimage.__class__(

nitransforms/tests/test_base.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests of the base module."""
2+
23
import numpy as np
34
import nibabel as nb
45
from nibabel.arrayproxy import get_obj_dtype
@@ -114,7 +115,9 @@ def _to_hdf5(klass, x5_root):
114115
xfm.reference = fname
115116
moved = apply(xfm, fname, order=0)
116117

117-
assert np.all(imgdata == np.asanyarray(moved.dataobj, dtype=get_obj_dtype(moved.dataobj)))
118+
assert np.all(
119+
imgdata == np.asanyarray(moved.dataobj, dtype=get_obj_dtype(moved.dataobj))
120+
)
118121

119122
# Test ndim returned by affine
120123
assert nitl.Affine().ndim == 3
@@ -168,7 +171,10 @@ def test_concatenation(testdata_path):
168171

169172
def test_SurfaceMesh(testdata_path):
170173
surf_path = testdata_path / "sub-200148_hemi-R_pial.surf.gii"
171-
shape_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_thickness.shape.gii"
174+
shape_path = (
175+
testdata_path
176+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_thickness.shape.gii"
177+
)
172178
img_path = testdata_path / "bold.nii.gz"
173179

174180
mesh = SurfaceMesh(nb.load(surf_path))

nitransforms/tests/test_linear.py

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Tests of linear transforms."""
4-
import os
4+
55
import pytest
66
import numpy as np
77
import h5py
88

9-
import nibabel as nb
109
from nibabel.eulerangles import euler2mat
1110
from nibabel.affines import from_matvec
1211
from nitransforms import linear as nitl
1312
from nitransforms import io
1413
from .utils import assert_affines_by_filename
1514

1615

17-
@pytest.mark.parametrize("matrix", [[0.0], np.ones((3, 3, 3)), np.ones((3, 4)), ])
16+
@pytest.mark.parametrize(
17+
"matrix",
18+
[
19+
[0.0],
20+
np.ones((3, 3, 3)),
21+
np.ones((3, 4)),
22+
],
23+
)
1824
def test_linear_typeerrors1(matrix):
1925
"""Exercise errors in Affine creation."""
2026
with pytest.raises(TypeError):
@@ -136,7 +142,9 @@ def test_loadsave(tmp_path, data_path, testdata_path, autofmt, fmt):
136142

137143
assert np.allclose(
138144
xfm.matrix,
139-
nitl.load(fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file).matrix,
145+
nitl.load(
146+
fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file
147+
).matrix,
140148
)
141149
else:
142150
assert xfm == nitl.load(fname, fmt=supplied_fmt, reference=ref_file)
@@ -146,7 +154,9 @@ def test_loadsave(tmp_path, data_path, testdata_path, autofmt, fmt):
146154
if fmt == "fsl":
147155
assert np.allclose(
148156
xfm.matrix,
149-
nitl.load(fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file).matrix,
157+
nitl.load(
158+
fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file
159+
).matrix,
150160
rtol=1e-2, # FSL incurs into large errors due to rounding
151161
)
152162
else:
@@ -160,7 +170,9 @@ def test_loadsave(tmp_path, data_path, testdata_path, autofmt, fmt):
160170
if fmt == "fsl":
161171
assert np.allclose(
162172
xfm.matrix,
163-
nitl.load(fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file).matrix,
173+
nitl.load(
174+
fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file
175+
).matrix,
164176
rtol=1e-2, # FSL incurs into large errors due to rounding
165177
)
166178
else:
@@ -170,7 +182,9 @@ def test_loadsave(tmp_path, data_path, testdata_path, autofmt, fmt):
170182
if fmt == "fsl":
171183
assert np.allclose(
172184
xfm.matrix,
173-
nitl.load(fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file).matrix,
185+
nitl.load(
186+
fname, fmt=supplied_fmt, reference=ref_file, moving=ref_file
187+
).matrix,
174188
rtol=1e-2, # FSL incurs into large errors due to rounding
175189
)
176190
else:
@@ -190,12 +204,15 @@ def test_linear_save(tmpdir, data_path, get_testdata, image_orientation, sw_tool
190204
T = np.linalg.inv(T)
191205

192206
xfm = (
193-
nitl.Affine(T) if (sw_tool, image_orientation) != ("afni", "oblique") else
207+
nitl.Affine(T)
208+
if (sw_tool, image_orientation) != ("afni", "oblique")
194209
# AFNI is special when moving or reference are oblique - let io do the magic
195-
nitl.Affine(io.afni.AFNILinearTransform.from_ras(T).to_ras(
196-
reference=img,
197-
moving=img,
198-
))
210+
else nitl.Affine(
211+
io.afni.AFNILinearTransform.from_ras(T).to_ras(
212+
reference=img,
213+
moving=img,
214+
)
215+
)
199216
)
200217
xfm.reference = img
201218

nitransforms/tests/test_manip.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Tests of nonlinear transforms."""
4+
45
import pytest
56

67
import numpy as np

nitransforms/tests/test_nonlinear.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Tests of nonlinear transforms."""
4+
45
import os
5-
import shutil
6-
from subprocess import check_call
76
import pytest
87

98
import numpy as np
@@ -14,7 +13,6 @@
1413
from nitransforms.nonlinear import (
1514
BSplineFieldTransform,
1615
DenseFieldTransform,
17-
load as nlload,
1816
)
1917
from ..io.itk import ITKDisplacementsField
2018

nitransforms/tests/test_resampling.py

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Exercise the standalone ``apply()`` implementation."""
4+
45
import os
56
import pytest
67
import numpy as np
@@ -50,9 +51,19 @@
5051
}
5152

5253

53-
@pytest.mark.parametrize("image_orientation", ["RAS", "LAS", "LPS", 'oblique', ])
54+
@pytest.mark.parametrize(
55+
"image_orientation",
56+
[
57+
"RAS",
58+
"LAS",
59+
"LPS",
60+
"oblique",
61+
],
62+
)
5463
@pytest.mark.parametrize("sw_tool", ["itk", "fsl", "afni", "fs"])
55-
def test_apply_linear_transform(tmpdir, get_testdata, get_testmask, image_orientation, sw_tool):
64+
def test_apply_linear_transform(
65+
tmpdir, get_testdata, get_testmask, image_orientation, sw_tool
66+
):
5667
"""Check implementation of exporting affines to formats."""
5768
tmpdir.chdir()
5869

@@ -107,7 +118,7 @@ def test_apply_linear_transform(tmpdir, get_testdata, get_testmask, image_orient
107118
nt_moved_mask.to_filename("ntmask.nii.gz")
108119
diff = np.asanyarray(sw_moved_mask.dataobj) - np.asanyarray(nt_moved_mask.dataobj)
109120

110-
assert np.sqrt((diff ** 2).mean()) < RMSE_TOL_LINEAR
121+
assert np.sqrt((diff**2).mean()) < RMSE_TOL_LINEAR
111122
brainmask = np.asanyarray(nt_moved_mask.dataobj, dtype=bool)
112123

113124
cmd = APPLY_LINEAR_CMD[sw_tool](
@@ -123,19 +134,17 @@ def test_apply_linear_transform(tmpdir, get_testdata, get_testmask, image_orient
123134
sw_moved.set_data_dtype(img.get_data_dtype())
124135

125136
nt_moved = apply(xfm, img, order=0)
126-
diff = (
127-
np.asanyarray(sw_moved.dataobj, dtype=sw_moved.get_data_dtype())
128-
- np.asanyarray(nt_moved.dataobj, dtype=nt_moved.get_data_dtype())
129-
)
137+
diff = np.asanyarray(
138+
sw_moved.dataobj, dtype=sw_moved.get_data_dtype()
139+
) - np.asanyarray(nt_moved.dataobj, dtype=nt_moved.get_data_dtype())
130140

131141
# A certain tolerance is necessary because of resampling at borders
132142
assert np.sqrt((diff[brainmask] ** 2).mean()) < RMSE_TOL_LINEAR
133143

134144
nt_moved = apply(xfm, "img.nii.gz", order=0)
135-
diff = (
136-
np.asanyarray(sw_moved.dataobj, dtype=sw_moved.get_data_dtype())
137-
- np.asanyarray(nt_moved.dataobj, dtype=nt_moved.get_data_dtype())
138-
)
145+
diff = np.asanyarray(
146+
sw_moved.dataobj, dtype=sw_moved.get_data_dtype()
147+
) - np.asanyarray(nt_moved.dataobj, dtype=nt_moved.get_data_dtype())
139148
# A certain tolerance is necessary because of resampling at borders
140149
assert np.sqrt((diff[brainmask] ** 2).mean()) < RMSE_TOL_LINEAR
141150

@@ -281,7 +290,8 @@ def test_apply_transformchain(tmp_path, testdata_path):
281290

282291
ref_fname = tmp_path / "reference.nii.gz"
283292
nb.Nifti1Image(
284-
np.zeros(xfm.reference.shape, dtype="uint16"), xfm.reference.affine,
293+
np.zeros(xfm.reference.shape, dtype="uint16"),
294+
xfm.reference.affine,
285295
).to_filename(str(ref_fname))
286296

287297
# Then apply the transform and cross-check with software
@@ -310,7 +320,9 @@ def test_apply_transformchain(tmp_path, testdata_path):
310320

311321

312322
@pytest.mark.parametrize("serialize_4d", [True, False])
313-
def test_LinearTransformsMapping_apply(tmp_path, data_path, testdata_path, serialize_4d):
323+
def test_LinearTransformsMapping_apply(
324+
tmp_path, data_path, testdata_path, serialize_4d
325+
):
314326
"""Apply transform mappings."""
315327
hmc = nitl.load(
316328
data_path / "hmc-itk.tfm", fmt="itk", reference=testdata_path / "sbref.nii.gz"
@@ -333,7 +345,8 @@ def test_LinearTransformsMapping_apply(tmp_path, data_path, testdata_path, seria
333345
)
334346

335347
nii = apply(
336-
hmcinv, testdata_path / "fmap.nii.gz",
348+
hmcinv,
349+
testdata_path / "fmap.nii.gz",
337350
order=1,
338351
serialize_nvols=2 if serialize_4d else np.inf,
339352
)

0 commit comments

Comments
 (0)