Skip to content

Commit c3a4f54

Browse files
committed
RF: add AffineError
Change append_diag to use AffineError
1 parent 981db47 commit c3a4f54

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

nibabel/affines.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
from .externals.six.moves import reduce
99

1010

11+
class AffineError(ValueError):
12+
""" Errors in calculating or using affines """
13+
# Inherits from ValueError to keep compatibility with ValueError previously
14+
# raised in append_diag
15+
pass
16+
17+
1118
def apply_affine(aff, pts):
1219
""" Apply affine matrix `aff` to points `pts`
1320
@@ -213,7 +220,7 @@ def append_diag(aff, steps, starts=()):
213220
if len(starts) == 0:
214221
starts = np.zeros(n_steps, dtype=steps.dtype)
215222
elif len(starts) != n_steps:
216-
raise ValueError('Steps should have same length as starts')
223+
raise AffineError('Steps should have same length as starts')
217224
old_n_out, old_n_in = aff.shape[0]-1, aff.shape[1]-1
218225
# make new affine
219226
aff_plus = np.zeros((old_n_out + n_steps + 1,

nibabel/tests/test_affines.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import numpy as np
55

6-
from ..affines import (apply_affine, append_diag, to_matvec, from_matvec,
7-
dot_reduce)
6+
from ..affines import (AffineError, apply_affine, append_diag, to_matvec,
7+
from_matvec, dot_reduce)
88

99

1010
from nose.tools import assert_equal, assert_raises
@@ -123,7 +123,7 @@ def test_append_diag():
123123
[0,0,0,5,9],
124124
[0,0,0,0,1]])
125125
# Length of starts has to match length of steps
126-
assert_raises(ValueError, append_diag, aff, [5,6], [9])
126+
assert_raises(AffineError, append_diag, aff, [5,6], [9])
127127

128128

129129
def test_dot_reduce():

0 commit comments

Comments
 (0)