Skip to content

Commit e9c28a2

Browse files
committed
STY: blue
[git-blame-ignore-rev]
1 parent 21ed7f0 commit e9c28a2

File tree

214 files changed

+9167
-7946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+9167
-7946
lines changed

nibabel/__init__.py

+32-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from .pkg_info import __version__
1313
from .info import long_description as __doc__
14+
1415
__doc__ += """
1516
Quickstart
1617
==========
@@ -42,6 +43,7 @@
4243
from . import spm2analyze as spm2
4344
from . import nifti1 as ni1
4445
from . import ecat
46+
4547
# object imports
4648
from .fileholders import FileHolder, FileHolderError
4749
from .loadsave import load, save
@@ -56,11 +58,15 @@
5658
from .cifti2 import Cifti2Header, Cifti2Image
5759
from .gifti import GiftiImage
5860
from .freesurfer import MGHImage
59-
from .funcs import (squeeze_image, concat_images, four_to_three,
60-
as_closest_canonical)
61-
from .orientations import (io_orientation, orientation_affine,
62-
flip_axis, OrientationError,
63-
apply_orientation, aff2axcodes)
61+
from .funcs import squeeze_image, concat_images, four_to_three, as_closest_canonical
62+
from .orientations import (
63+
io_orientation,
64+
orientation_affine,
65+
flip_axis,
66+
OrientationError,
67+
apply_orientation,
68+
aff2axcodes,
69+
)
6470
from .imageclasses import class_map, ext_map, all_image_classes
6571
from . import mriutils
6672
from . import streamlines
@@ -73,9 +79,15 @@ def get_info():
7379
return _get_pkg_info(os.path.dirname(__file__))
7480

7581

76-
def test(label=None, verbose=1, extra_argv=None,
77-
doctests=False, coverage=False, raise_warnings=None,
78-
timer=False):
82+
def test(
83+
label=None,
84+
verbose=1,
85+
extra_argv=None,
86+
doctests=False,
87+
coverage=False,
88+
raise_warnings=None,
89+
timer=False,
90+
):
7991
"""
8092
Run tests for nibabel using pytest
8193
@@ -108,29 +120,30 @@ def test(label=None, verbose=1, extra_argv=None,
108120
Returns the result of running the tests as a ``pytest.ExitCode`` enum
109121
"""
110122
import pytest
123+
111124
args = []
112125

113126
if label is not None:
114-
raise NotImplementedError("Labels cannot be set at present")
127+
raise NotImplementedError('Labels cannot be set at present')
115128

116129
verbose = int(verbose)
117130
if verbose > 0:
118-
args.append("-" + "v" * verbose)
131+
args.append('-' + 'v' * verbose)
119132
elif verbose < 0:
120-
args.append("-" + "q" * -verbose)
133+
args.append('-' + 'q' * -verbose)
121134

122135
if extra_argv:
123136
args.extend(extra_argv)
124137
if doctests:
125-
args.append("--doctest-modules")
138+
args.append('--doctest-modules')
126139
if coverage:
127-
args.extend(["--cov", "nibabel"])
140+
args.extend(['--cov', 'nibabel'])
128141
if raise_warnings is not None:
129-
raise NotImplementedError("Warning filters are not implemented")
142+
raise NotImplementedError('Warning filters are not implemented')
130143
if timer:
131-
raise NotImplementedError("Timing is not implemented")
144+
raise NotImplementedError('Timing is not implemented')
132145

133-
args.extend(["--pyargs", "nibabel"])
146+
args.extend(['--pyargs', 'nibabel'])
134147

135148
return pytest.main(args=args)
136149

@@ -158,9 +171,10 @@ def bench(label=None, verbose=1, extra_argv=None):
158171
Returns the result of running the tests as a ``pytest.ExitCode`` enum
159172
"""
160173
from pkg_resources import resource_filename
161-
config = resource_filename("nibabel", "benchmarks/pytest.benchmark.ini")
174+
175+
config = resource_filename('nibabel', 'benchmarks/pytest.benchmark.ini')
162176
args = []
163177
if extra_argv is not None:
164178
args.extend(extra_argv)
165-
args.extend(["-c", config])
179+
args.extend(['-c', config])
166180
return test(label, verbose, extra_argv=args)

nibabel/affines.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3-
""" Utility routines for working with points and affine transforms
3+
"""Utility routines for working with points and affine transforms
44
"""
55
import numpy as np
66

77
from functools import reduce
88

99

1010
class AffineError(ValueError):
11-
""" Errors in calculating or using affines """
11+
"""Errors in calculating or using affines"""
12+
1213
# Inherits from ValueError to keep compatibility with ValueError previously
1314
# raised in append_diag
1415
pass
1516

1617

1718
def apply_affine(aff, pts, inplace=False):
18-
""" Apply affine matrix `aff` to points `pts`
19+
"""Apply affine matrix `aff` to points `pts`
1920
2021
Returns result of application of `aff` to the *right* of `pts`. The
2122
coordinate dimension of `pts` should be the last.
@@ -142,7 +143,7 @@ def to_matvec(transform):
142143

143144

144145
def from_matvec(matrix, vector=None):
145-
""" Combine a matrix and vector into an homogeneous affine
146+
"""Combine a matrix and vector into an homogeneous affine
146147
147148
Combine a rotation / scaling / shearing matrix and translation vector into
148149
a transform in homogeneous coordinates.
@@ -185,14 +186,14 @@ def from_matvec(matrix, vector=None):
185186
nin, nout = matrix.shape
186187
t = np.zeros((nin + 1, nout + 1), matrix.dtype)
187188
t[0:nin, 0:nout] = matrix
188-
t[nin, nout] = 1.
189+
t[nin, nout] = 1.0
189190
if vector is not None:
190191
t[0:nin, nout] = vector
191192
return t
192193

193194

194195
def append_diag(aff, steps, starts=()):
195-
""" Add diagonal elements `steps` and translations `starts` to affine
196+
"""Add diagonal elements `steps` and translations `starts` to affine
196197
197198
Typical use is in expanding 4x4 affines to larger dimensions. Nipy is the
198199
main consumer because it uses NxM affines, whereas we generally only use
@@ -236,8 +237,7 @@ def append_diag(aff, steps, starts=()):
236237
raise AffineError('Steps should have same length as starts')
237238
old_n_out, old_n_in = aff.shape[0] - 1, aff.shape[1] - 1
238239
# make new affine
239-
aff_plus = np.zeros((old_n_out + n_steps + 1,
240-
old_n_in + n_steps + 1), dtype=aff.dtype)
240+
aff_plus = np.zeros((old_n_out + n_steps + 1, old_n_in + n_steps + 1), dtype=aff.dtype)
241241
# Get stuff from old affine
242242
aff_plus[:old_n_out, :old_n_in] = aff[:old_n_out, :old_n_in]
243243
aff_plus[:old_n_out, -1] = aff[:old_n_out, -1]
@@ -250,7 +250,7 @@ def append_diag(aff, steps, starts=()):
250250

251251

252252
def dot_reduce(*args):
253-
r""" Apply numpy dot product function from right to left on arrays
253+
r"""Apply numpy dot product function from right to left on arrays
254254
255255
For passed arrays :math:`A, B, C, ... Z` returns :math:`A \dot B \dot C ...
256256
\dot Z` where "." is the numpy array dot product.
@@ -270,7 +270,7 @@ def dot_reduce(*args):
270270

271271

272272
def voxel_sizes(affine):
273-
r""" Return voxel size for each input axis given `affine`
273+
r"""Return voxel size for each input axis given `affine`
274274
275275
The `affine` is the mapping between array (voxel) coordinates and mm
276276
(world) coordinates.
@@ -308,7 +308,7 @@ def voxel_sizes(affine):
308308
but in general has length (N-1) where input `affine` is shape (M, N).
309309
"""
310310
top_left = affine[:-1, :-1]
311-
return np.sqrt(np.sum(top_left ** 2, axis=0))
311+
return np.sqrt(np.sum(top_left**2, axis=0))
312312

313313

314314
def obliquity(affine):
@@ -340,7 +340,7 @@ def obliquity(affine):
340340

341341

342342
def rescale_affine(affine, shape, zooms, new_shape=None):
343-
""" Return a new affine matrix with updated voxel sizes (zooms)
343+
"""Return a new affine matrix with updated voxel sizes (zooms)
344344
345345
This function preserves the rotations and shears of the original
346346
affine, as well as the RAS location of the central voxel of the

0 commit comments

Comments
 (0)