Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sty: pep8 complaints #14

Merged
merged 4 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .pep8speaks.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
scanner:
diff_only: True # If False, the entire file touched by the Pull Request is scanned for errors. If True, only the diff is scanned.
linter: pycodestyle # Other option is flake8
linter: flake8 # Other option is flake8

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

no_blank_comment: False # If True, no comment is made on PR without any errors.
descending_issues_order: False # If True, PEP 8 issues in message will be displayed in descending order of line numbers in the file
Expand Down
6 changes: 4 additions & 2 deletions nitransforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def _to_hdf5(self, group):

def __eq__(self, other):
try:
return np.allclose(
self.affine, other.affine, rtol=EQUALITY_TOL) and self.shape == other.shape
return (
np.allclose(self.affine, other.affine, rtol=EQUALITY_TOL)
and self.shape == other.shape
)
except AttributeError:
pass
return False
Expand Down
8 changes: 6 additions & 2 deletions nitransforms/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ def get_data():
newaff[0, 0] *= -1.0
newaff[1, 1] *= -1.0
newaff[:2, 3] = imgaff.dot(np.hstack((np.array(img.shape[:3]) - 1, 1.0)))[:2]
_data['LPS'] = nb.Nifti1Image(np.flip(np.flip(img.get_fdata(), 0), 1), newaff, img.header)
A = nb.volumeutils.shape_zoom_affine(img.shape, img.header.get_zooms(), x_flip=False)
_data['LPS'] = nb.Nifti1Image(
np.flip(np.flip(img.get_fdata(), 0), 1), newaff, img.header
)
A = nb.volumeutils.shape_zoom_affine(
img.shape, img.header.get_zooms(), x_flip=False
)
R = nb.affines.from_matvec(nb.eulerangles.euler2mat(x=0.09, y=0.001, z=0.001))
newaff = R.dot(A)
oblique_img = nb.Nifti1Image(img.get_fdata(), newaff, img.header)
Expand Down
19 changes: 15 additions & 4 deletions nitransforms/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def __init__(self, matrix=None, reference=None):

self._matrix = np.array(matrix)
assert self._matrix.ndim == 3, 'affine matrix should be 3D'
assert self._matrix.shape[-2] == self._matrix.shape[-1], 'affine matrix is not square'
assert (
self._matrix.shape[-2] == self._matrix.shape[-1]
), 'affine matrix is not square'

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

matrix = reference.affine.dot(self._matrix[nindex].dot(np.linalg.inv(moving.affine)))
matrix = reference.affine.dot(
self._matrix[nindex].dot(np.linalg.inv(moving.affine))
)
return tuple(matrix.dot(index)[:-1])

def _to_hdf5(self, x5_root):
Expand Down Expand Up @@ -235,7 +239,10 @@ def to_filename(self, filename, fmt='X5', moving=None):
T = self.matrix.copy()
pre = LPS
post = LPS
if obliquity(self.reference.affine).min() * 180 / pi > OBLIQUITY_THRESHOLD_DEG:
if (
obliquity(self.reference.affine).min() * 180 / pi
> OBLIQUITY_THRESHOLD_DEG
):
print('Reference affine axes are oblique.')
M = self.reference.affine
A = shape_zoom_affine(self.reference.shape,
Expand All @@ -245,7 +252,11 @@ def to_filename(self, filename, fmt='X5', moving=None):
if not moving:
moving = self.reference

if moving and obliquity(moving.affine).min() * 180 / pi > OBLIQUITY_THRESHOLD_DEG:
if (
moving
and obliquity(moving.affine).min() * 180 / pi
> OBLIQUITY_THRESHOLD_DEG
):
print('Moving affine axes are oblique.')
M2 = moving.affine
A2 = shape_zoom_affine(moving.shape,
Expand Down
6 changes: 4 additions & 2 deletions nitransforms/nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _interp_transform(self, coords):
self._coeffs[ijk] if not np.any(offbounds)
else [0.0] * self.ndim)

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

def map_voxel(self, index, moving=None):
Expand All @@ -237,7 +237,9 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,
>>> coeffs = np.zeros((6, 6, 6, 3))
>>> coeffs[2, 2, 2, ...] = [10.0, -20.0, 0]
>>> aff = ref.affine
>>> aff[:3, :3] = aff[:3, :3].dot(np.eye(3) * np.array(ref.header.get_zooms()[:3]) / 6.0)
>>> aff[:3, :3] = aff[:3, :3].dot(np.eye(3) * np.array(
... ref.header.get_zooms()[:3]) / 6.0
... )
>>> coeffsimg = nb.Nifti1Image(coeffs, ref.affine, ref.header)
>>> xfm = BSplineFieldTransform(ref, coeffsimg) # doctest: +SKIP
>>> new = xfm.resample(ref) # doctest: +SKIP
Expand Down
4 changes: 3 additions & 1 deletion nitransforms/patched.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from nibabel.affines import voxel_sizes


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


def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
''' Get affine implied by given shape and zooms
We get the translations from the center of the image (implied by
Expand Down Expand Up @@ -85,4 +87,4 @@ def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
aff = np.eye(4)
aff[:3, :3] = np.diag(zooms)
aff[:3, -1] = -origin * zooms
return aff
return aff
1 change: 1 addition & 0 deletions nitransforms/tests/test_affines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nibabel.eulerangles import euler2mat
from ..patched import obliquity


def test_obliquity():
"""Check the calculation of inclination of an affine axes."""
from math import pi
Expand Down
8 changes: 7 additions & 1 deletion nitransforms/tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ def test_linear_save(data_path, get_data, image_orientation, sw_tool):
'RAS', 'LAS', 'LPS', # 'oblique',
])
@pytest.mark.parametrize('sw_tool', ['itk', 'fsl', 'afni'])
def test_apply_linear_transform(tmpdir, data_path, get_data, image_orientation, sw_tool):
def test_apply_linear_transform(
tmpdir,
data_path,
get_data,
image_orientation,
sw_tool
):
"""Check implementation of exporting affines to formats."""
tmpdir.chdir()

Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ tests =
all =
%(test)s

[flake8]
max-line-length = 100
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