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"""
55import numpy as np
66
77from functools import reduce
88
99
1010class 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
1718def 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
144145def 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
194195def 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
252252def 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
272272def 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
314314def obliquity (affine ):
@@ -340,7 +340,7 @@ def obliquity(affine):
340340
341341
342342def 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