Skip to content

Commit a2a563e

Browse files
committed
STY: blue
Run with a custom patch to avoid realigning inline comments: pipx run --spec git+https://github.com/effigies/blue.git@fix/hanging-comments blue nibabel [git-blame-ignore-rev]
1 parent c1dac14 commit a2a563e

File tree

207 files changed

+8734
-7556
lines changed

Some content is hidden

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

207 files changed

+8734
-7556
lines changed

nibabel/__init__.py

Lines changed: 31 additions & 17 deletions
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,10 +58,14 @@
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, flip_axis, OrientationError,
62-
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+
flip_axis,
65+
OrientationError,
66+
apply_orientation,
67+
aff2axcodes,
68+
)
6369
from .imageclasses import all_image_classes
6470
from . import mriutils
6571
from . import streamlines
@@ -72,9 +78,15 @@ def get_info():
7278
return _get_pkg_info(os.path.dirname(__file__))
7379

7480

75-
def test(label=None, verbose=1, extra_argv=None,
76-
doctests=False, coverage=False, raise_warnings=None,
77-
timer=False):
81+
def test(
82+
label=None,
83+
verbose=1,
84+
extra_argv=None,
85+
doctests=False,
86+
coverage=False,
87+
raise_warnings=None,
88+
timer=False,
89+
):
7890
"""
7991
Run tests for nibabel using pytest
8092
@@ -107,29 +119,30 @@ def test(label=None, verbose=1, extra_argv=None,
107119
Returns the result of running the tests as a ``pytest.ExitCode`` enum
108120
"""
109121
import pytest
122+
110123
args = []
111124

112125
if label is not None:
113-
raise NotImplementedError("Labels cannot be set at present")
126+
raise NotImplementedError('Labels cannot be set at present')
114127

115128
verbose = int(verbose)
116129
if verbose > 0:
117-
args.append("-" + "v" * verbose)
130+
args.append('-' + 'v' * verbose)
118131
elif verbose < 0:
119-
args.append("-" + "q" * -verbose)
132+
args.append('-' + 'q' * -verbose)
120133

121134
if extra_argv:
122135
args.extend(extra_argv)
123136
if doctests:
124-
args.append("--doctest-modules")
137+
args.append('--doctest-modules')
125138
if coverage:
126-
args.extend(["--cov", "nibabel"])
139+
args.extend(['--cov', 'nibabel'])
127140
if raise_warnings is not None:
128-
raise NotImplementedError("Warning filters are not implemented")
141+
raise NotImplementedError('Warning filters are not implemented')
129142
if timer:
130-
raise NotImplementedError("Timing is not implemented")
143+
raise NotImplementedError('Timing is not implemented')
131144

132-
args.extend(["--pyargs", "nibabel"])
145+
args.extend(['--pyargs', 'nibabel'])
133146

134147
return pytest.main(args=args)
135148

@@ -157,9 +170,10 @@ def bench(label=None, verbose=1, extra_argv=None):
157170
Returns the result of running the tests as a ``pytest.ExitCode`` enum
158171
"""
159172
from pkg_resources import resource_filename
160-
config = resource_filename("nibabel", "benchmarks/pytest.benchmark.ini")
173+
174+
config = resource_filename('nibabel', 'benchmarks/pytest.benchmark.ini')
161175
args = []
162176
if extra_argv is not None:
163177
args.extend(extra_argv)
164-
args.extend(["-c", config])
178+
args.extend(['-c', config])
165179
return test(label, verbose, extra_argv=args)

nibabel/affines.py

Lines changed: 12 additions & 12 deletions
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)