Skip to content

Commit f8ad078

Browse files
author
Ben Cipollini
committed
Code reorganization, comment editing.
1 parent 47fc8f0 commit f8ad078

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

nibabel/funcs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ def concat_images(images, check_affines=True, axis=None):
9494
Parameters
9595
----------
9696
images : sequence
97-
sequence of ``SpatialImage`` or filenames\s
97+
sequence of ``SpatialImage`` or filenames of the same dimensionality\s
9898
check_affines : {True, False}, optional
9999
If True, then check that all the affines for `images` are nearly
100100
the same, raising a ``ValueError`` otherwise. Default is True
101101
axis : None or int, optional
102-
If None, concatenates on the 4th dimension.
103-
If not None, concatenates on the specified dimension [-2 to 3).
102+
If None, concatenates on a new dimension. This rrequires all images
103+
to be the same shape).
104+
If not None, concatenates on the specified dimension. This requires
105+
all images to be the same shape, except on the specified dimension.
106+
For 4D images, axis must be between -2 and 3.
104107
Returns
105108
-------
106109
concat_img : ``SpatialImage``
@@ -110,7 +113,7 @@ def concat_images(images, check_affines=True, axis=None):
110113

111114
n_imgs = len(images)
112115
if n_imgs == 0:
113-
raise ValueError('Cannot concatenate an empty list of images.')
116+
raise ValueError("Cannot concatenate an empty list of images.")
114117

115118
for i, img in enumerate(images):
116119
if not hasattr(img, 'get_data'):

nibabel/tests/test_funcs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ def test_concat():
110110
try:
111111
all_imgs = concat_images([img0, img1],
112112
**concat_imgs_kwargs)
113-
assert_array_equal(all_imgs.get_data(), all_data)
114-
assert_array_equal(all_imgs.affine, affine)
115-
assert_false(expect_error, "Expected a concatenation error, but got none.")
116113
except ValueError as ve:
117114
assert_true(expect_error, ve.message)
115+
else:
116+
assert_false(expect_error, "Expected a concatenation error, but got none.")
117+
assert_array_equal(all_imgs.get_data(), all_data)
118+
assert_array_equal(all_imgs.affine, affine)
118119

119120
# check that not-matching affines raise error
120121
assert_raises(ValueError, concat_images, [img0, img2], **concat_imgs_kwargs)
@@ -123,12 +124,12 @@ def test_concat():
123124
# except if check_affines is False
124125
try:
125126
all_imgs = concat_images([img0, img1], **concat_imgs_kwargs)
126-
assert_array_equal(all_imgs.get_data(), all_data)
127-
assert_array_equal(all_imgs.affine, affine)
128-
assert_false(expect_error, "Expected a concatenation error, but got none.")
129127
except ValueError as ve:
130128
assert_true(expect_error, ve.message)
131-
129+
else:
130+
assert_false(expect_error, "Expected a concatenation error, but got none.")
131+
assert_array_equal(all_imgs.get_data(), all_data)
132+
assert_array_equal(all_imgs.affine, affine)
132133

133134

134135
def test_closest_canonical():

0 commit comments

Comments
 (0)