Skip to content

Commit b7d2fea

Browse files
authored
Merge pull request #14 from mgxd/sty/pep8
sty: pep8 complaints
2 parents 221a43a + f60ae45 commit b7d2fea

9 files changed

+44
-17
lines changed

.pep8speaks.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
scanner:
22
diff_only: True # If False, the entire file touched by the Pull Request is scanned for errors. If True, only the diff is scanned.
3-
linter: pycodestyle # Other option is flake8
3+
linter: flake8 # Other option is flake8
44

5-
pycodestyle: # Same as scanner.linter value. Other option is flake8
6-
max-line-length: 88 # Follow black's line length
7-
ignore: # Errors and warnings to ignore
8-
- E402 # module level import not at top of file
95

106
no_blank_comment: False # If True, no comment is made on PR without any errors.
117
descending_issues_order: False # If True, PEP 8 issues in message will be displayed in descending order of line numbers in the file

nitransforms/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def _to_hdf5(self, group):
8787

8888
def __eq__(self, other):
8989
try:
90-
return np.allclose(
91-
self.affine, other.affine, rtol=EQUALITY_TOL) and self.shape == other.shape
90+
return (
91+
np.allclose(self.affine, other.affine, rtol=EQUALITY_TOL)
92+
and self.shape == other.shape
93+
)
9294
except AttributeError:
9395
pass
9496
return False

nitransforms/conftest.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ def get_data():
5858
newaff[0, 0] *= -1.0
5959
newaff[1, 1] *= -1.0
6060
newaff[:2, 3] = imgaff.dot(np.hstack((np.array(img.shape[:3]) - 1, 1.0)))[:2]
61-
_data['LPS'] = nb.Nifti1Image(np.flip(np.flip(img.get_fdata(), 0), 1), newaff, img.header)
62-
A = nb.volumeutils.shape_zoom_affine(img.shape, img.header.get_zooms(), x_flip=False)
61+
_data['LPS'] = nb.Nifti1Image(
62+
np.flip(np.flip(img.get_fdata(), 0), 1), newaff, img.header
63+
)
64+
A = nb.volumeutils.shape_zoom_affine(
65+
img.shape, img.header.get_zooms(), x_flip=False
66+
)
6367
R = nb.affines.from_matvec(nb.eulerangles.euler2mat(x=0.09, y=0.001, z=0.001))
6468
newaff = R.dot(A)
6569
oblique_img = nb.Nifti1Image(img.get_fdata(), newaff, img.header)

nitransforms/linear.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def __init__(self, matrix=None, reference=None):
5858

5959
self._matrix = np.array(matrix)
6060
assert self._matrix.ndim == 3, 'affine matrix should be 3D'
61-
assert self._matrix.shape[-2] == self._matrix.shape[-1], 'affine matrix is not square'
61+
assert (
62+
self._matrix.shape[-2] == self._matrix.shape[-1]
63+
), 'affine matrix is not square'
6264

6365
if reference:
6466
if isinstance(reference, str):
@@ -196,7 +198,9 @@ def map_voxel(self, index, nindex=0, moving=None):
196198
if index.shape[0] == self._matrix[nindex].shape[0] - 1:
197199
index = np.append(index, [1])
198200

199-
matrix = reference.affine.dot(self._matrix[nindex].dot(np.linalg.inv(moving.affine)))
201+
matrix = reference.affine.dot(
202+
self._matrix[nindex].dot(np.linalg.inv(moving.affine))
203+
)
200204
return tuple(matrix.dot(index)[:-1])
201205

202206
def _to_hdf5(self, x5_root):
@@ -235,7 +239,10 @@ def to_filename(self, filename, fmt='X5', moving=None):
235239
T = self.matrix.copy()
236240
pre = LPS
237241
post = LPS
238-
if obliquity(self.reference.affine).min() * 180 / pi > OBLIQUITY_THRESHOLD_DEG:
242+
if (
243+
obliquity(self.reference.affine).min() * 180 / pi
244+
> OBLIQUITY_THRESHOLD_DEG
245+
):
239246
print('Reference affine axes are oblique.')
240247
M = self.reference.affine
241248
A = shape_zoom_affine(self.reference.shape,
@@ -245,7 +252,11 @@ def to_filename(self, filename, fmt='X5', moving=None):
245252
if not moving:
246253
moving = self.reference
247254

248-
if moving and obliquity(moving.affine).min() * 180 / pi > OBLIQUITY_THRESHOLD_DEG:
255+
if (
256+
moving
257+
and obliquity(moving.affine).min() * 180 / pi
258+
> OBLIQUITY_THRESHOLD_DEG
259+
):
249260
print('Moving affine axes are oblique.')
250261
M2 = moving.affine
251262
A2 = shape_zoom_affine(moving.shape,

nitransforms/nonlinear.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _interp_transform(self, coords):
219219
self._coeffs[ijk] if not np.any(offbounds)
220220
else [0.0] * self.ndim)
221221

222-
coords[:3] += weights.dot(np.array(coeffs, dtype=float))
222+
# coords[:3] += weights.dot(np.array(coeffs, dtype=float))
223223
return self.reference.inverse.dot(np.hstack((coords, 1)))[:3]
224224

225225
def map_voxel(self, index, moving=None):
@@ -237,7 +237,9 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,
237237
>>> coeffs = np.zeros((6, 6, 6, 3))
238238
>>> coeffs[2, 2, 2, ...] = [10.0, -20.0, 0]
239239
>>> aff = ref.affine
240-
>>> aff[:3, :3] = aff[:3, :3].dot(np.eye(3) * np.array(ref.header.get_zooms()[:3]) / 6.0)
240+
>>> aff[:3, :3] = aff[:3, :3].dot(np.eye(3) * np.array(
241+
... ref.header.get_zooms()[:3]) / 6.0
242+
... )
241243
>>> coeffsimg = nb.Nifti1Image(coeffs, ref.affine, ref.header)
242244
>>> xfm = BSplineFieldTransform(ref, coeffsimg) # doctest: +SKIP
243245
>>> new = xfm.resample(ref) # doctest: +SKIP

nitransforms/patched.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
from nibabel.affines import voxel_sizes
33

4+
45
def obliquity(affine):
56
r"""
67
Estimate the *obliquity* an affine's axes represent.
@@ -24,6 +25,7 @@ def obliquity(affine):
2425
best_cosines = np.abs((affine[:-1, :-1] / vs).max(axis=1))
2526
return np.arccos(best_cosines)
2627

28+
2729
def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
2830
''' Get affine implied by given shape and zooms
2931
We get the translations from the center of the image (implied by
@@ -85,4 +87,4 @@ def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
8587
aff = np.eye(4)
8688
aff[:3, :3] = np.diag(zooms)
8789
aff[:3, -1] = -origin * zooms
88-
return aff
90+
return aff

nitransforms/tests/test_affines.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from nibabel.eulerangles import euler2mat
44
from ..patched import obliquity
55

6+
67
def test_obliquity():
78
"""Check the calculation of inclination of an affine axes."""
89
from math import pi

nitransforms/tests/test_transform.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ def test_linear_save(data_path, get_data, image_orientation, sw_tool):
107107
'RAS', 'LAS', 'LPS', # 'oblique',
108108
])
109109
@pytest.mark.parametrize('sw_tool', ['itk', 'fsl', 'afni'])
110-
def test_apply_linear_transform(tmpdir, data_path, get_data, image_orientation, sw_tool):
110+
def test_apply_linear_transform(
111+
tmpdir,
112+
data_path,
113+
get_data,
114+
image_orientation,
115+
sw_tool
116+
):
111117
"""Check implementation of exporting affines to formats."""
112118
tmpdir.chdir()
113119

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ tests =
2424
all =
2525
%(test)s
2626

27+
[flake8]
28+
max-line-length = 100
29+
ignore = D100,D101,D102,D103,D104,D105,D200,D201,D202,D204,D205,D208,D209,D210,D300,D301,D400,D401,D403,E24,E121,E123,E126,E226,E266,E402,E704,E731,F821,I100,I101,I201,N802,N803,N804,N806,W503,W504,W605

0 commit comments

Comments
 (0)