Skip to content

Commit 14faf88

Browse files
authored
Merge pull request #1124 from effigies/sty/normalize
STY: Normalize to blue and isort
2 parents 0a6e73e + 69785cd commit 14faf88

File tree

212 files changed

+9681
-8437
lines changed

Some content is hidden

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

212 files changed

+9681
-8437
lines changed

.git-blame-ignore-revs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Thu Dec 29 22:53:17 2022 -0500 - [email protected] - STY: Reduce array().astype() and similar constructs
2+
bf298113da99079c9c7b5e1690e41879828cd472
3+
# Thu Dec 29 22:32:46 2022 -0500 - [email protected] - STY: pyupgrade --py37-plus
4+
4481a4c2640bd4be6e9c468e550d01aae448ab99
5+
# Fri Dec 30 11:01:19 2022 -0500 - [email protected] - STY: Run vanilla blue
6+
6b0ddd23b1da1df7ca9ae275673f82bfa20a754c
7+
# Thu Dec 29 21:46:13 2022 -0500 - [email protected] - STY: Manual, blue-compatible touchups
8+
263fca9bf6d4ca314a5a322b4824d6f53d0589df
9+
# Thu Dec 29 21:32:00 2022 -0500 - [email protected] - STY: isort
10+
0ab2856cac4d4baae7ab3e2f6d58421db55d807f
11+
# Thu Dec 29 21:30:29 2022 -0500 - [email protected] - STY: blue
12+
1a8dd302ff85b1136c81d492509b80e7748339f0

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ distclean: clean
7878
$(WWW_DIR):
7979
if [ ! -d $(WWW_DIR) ]; then mkdir -p $(WWW_DIR); fi
8080

81+
.git-blame-ignore-revs:
82+
git log --grep "\[git-blame-ignore-rev\]" --pretty=format:"# %ad - %ae - %s%n%H" \
83+
> .git-blame-ignore-revs
8184

8285
#
8386
# Tests
@@ -288,4 +291,4 @@ rm-orig:
288291
# Remove .orig temporary diff files generated by git
289292
find . -name "*.orig" -print | grep -v "fsaverage" | xargs rm
290293

291-
.PHONY: orig-src pylint all build
294+
.PHONY: orig-src pylint all build .git-blame-ignore-revs

nibabel/__init__.py

+50-34
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
import os
1111

12-
from .pkg_info import __version__
1312
from .info import long_description as __doc__
13+
from .pkg_info import __version__
14+
1415
__doc__ += """
1516
Quickstart
1617
==========
@@ -38,32 +39,39 @@
3839

3940
# module imports
4041
from . import analyze as ana
41-
from . import spm99analyze as spm99
42-
from . import spm2analyze as spm2
42+
from . import ecat, mriutils
4343
from . import nifti1 as ni1
44-
from . import ecat
44+
from . import spm2analyze as spm2
45+
from . import spm99analyze as spm99
46+
from . import streamlines, viewers
47+
48+
# isort: split
49+
4550
# object imports
46-
from .fileholders import FileHolder, FileHolderError
47-
from .loadsave import load, save
48-
from .arrayproxy import is_proxy
4951
from .analyze import AnalyzeHeader, AnalyzeImage
50-
from .spm99analyze import Spm99AnalyzeHeader, Spm99AnalyzeImage
51-
from .spm2analyze import Spm2AnalyzeHeader, Spm2AnalyzeImage
52-
from .nifti1 import Nifti1Header, Nifti1Image, Nifti1Pair
53-
from .nifti2 import Nifti2Header, Nifti2Image, Nifti2Pair
54-
from .minc1 import Minc1Image
55-
from .minc2 import Minc2Image
52+
from .arrayproxy import is_proxy
5653
from .cifti2 import Cifti2Header, Cifti2Image
57-
from .gifti import GiftiImage
54+
from .fileholders import FileHolder, FileHolderError
5855
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)
56+
from .funcs import as_closest_canonical, concat_images, four_to_three, squeeze_image
57+
from .gifti import GiftiImage
6358
from .imageclasses import all_image_classes
64-
from . import mriutils
65-
from . import streamlines
66-
from . import viewers
59+
from .loadsave import load, save
60+
from .minc1 import Minc1Image
61+
from .minc2 import Minc2Image
62+
from .nifti1 import Nifti1Header, Nifti1Image, Nifti1Pair
63+
from .nifti2 import Nifti2Header, Nifti2Image, Nifti2Pair
64+
from .orientations import (
65+
OrientationError,
66+
aff2axcodes,
67+
apply_orientation,
68+
flip_axis,
69+
io_orientation,
70+
)
71+
from .spm2analyze import Spm2AnalyzeHeader, Spm2AnalyzeImage
72+
from .spm99analyze import Spm99AnalyzeHeader, Spm99AnalyzeImage
73+
74+
# isort: split
6775

6876
from .pkg_info import get_pkg_info as _get_pkg_info
6977

@@ -72,9 +80,15 @@ def get_info():
7280
return _get_pkg_info(os.path.dirname(__file__))
7381

7482

75-
def test(label=None, verbose=1, extra_argv=None,
76-
doctests=False, coverage=False, raise_warnings=None,
77-
timer=False):
83+
def test(
84+
label=None,
85+
verbose=1,
86+
extra_argv=None,
87+
doctests=False,
88+
coverage=False,
89+
raise_warnings=None,
90+
timer=False,
91+
):
7892
"""
7993
Run tests for nibabel using pytest
8094
@@ -107,29 +121,30 @@ def test(label=None, verbose=1, extra_argv=None,
107121
Returns the result of running the tests as a ``pytest.ExitCode`` enum
108122
"""
109123
import pytest
124+
110125
args = []
111126

112127
if label is not None:
113-
raise NotImplementedError("Labels cannot be set at present")
128+
raise NotImplementedError('Labels cannot be set at present')
114129

115130
verbose = int(verbose)
116131
if verbose > 0:
117-
args.append("-" + "v" * verbose)
132+
args.append('-' + 'v' * verbose)
118133
elif verbose < 0:
119-
args.append("-" + "q" * -verbose)
134+
args.append('-' + 'q' * -verbose)
120135

121136
if extra_argv:
122137
args.extend(extra_argv)
123138
if doctests:
124-
args.append("--doctest-modules")
139+
args.append('--doctest-modules')
125140
if coverage:
126-
args.extend(["--cov", "nibabel"])
141+
args.extend(['--cov', 'nibabel'])
127142
if raise_warnings is not None:
128-
raise NotImplementedError("Warning filters are not implemented")
143+
raise NotImplementedError('Warning filters are not implemented')
129144
if timer:
130-
raise NotImplementedError("Timing is not implemented")
145+
raise NotImplementedError('Timing is not implemented')
131146

132-
args.extend(["--pyargs", "nibabel"])
147+
args.extend(['--pyargs', 'nibabel'])
133148

134149
return pytest.main(args=args)
135150

@@ -157,9 +172,10 @@ def bench(label=None, verbose=1, extra_argv=None):
157172
Returns the result of running the tests as a ``pytest.ExitCode`` enum
158173
"""
159174
from pkg_resources import resource_filename
160-
config = resource_filename("nibabel", "benchmarks/pytest.benchmark.ini")
175+
176+
config = resource_filename('nibabel', 'benchmarks/pytest.benchmark.ini')
161177
args = []
162178
if extra_argv is not None:
163179
args.extend(extra_argv)
164-
args.extend(["-c", config])
180+
args.extend(['-c', config])
165181
return test(label, verbose, extra_argv=args)

nibabel/affines.py

+14-14
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
"""
5-
import numpy as np
6-
75
from functools import reduce
86

7+
import numpy as np
8+
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)