Skip to content

Commit b11d926

Browse files
committed
Fix for astropy#31
1 parent 7f9024d commit b11d926

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎imageutils/array_utils.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def extract_array_2d(array_large, shape, position):
7676
7777
Examples
7878
--------
79-
We consider a large array of zeros with the shape 11x10 and a small
80-
array of ones with a shape of 3x4:
79+
We consider a large array with the shape 11x10, from which we extract
80+
a small array of shape 3x5:
8181
8282
>>> import numpy as np
8383
>>> from imageutils.array_utils import extract_array_2d
8484
>>> large_array = np.arange(110).reshape((11, 10))
8585
>>> large_array[4:9, 4:9] = np.ones((5, 5))
86-
>>> extract_array_2d(large_array, (3, 4), (7, 7))
86+
>>> extract_array_2d(large_array, (3, 5), (7, 7))
8787
array([[ 1, 1, 1, 1, 69],
8888
[ 1, 1, 1, 1, 79],
8989
[ 1, 1, 1, 1, 89]])

‎imageutils/tests/test_array_utils.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_extract_array_2d():
3333
assert np.all(extracted_array == small_test_array)
3434

3535

36-
def test_add_array_2d():
36+
def test_add_array_2d_odd_shape():
3737
"""
3838
Test add_array_2D utility function.
3939
@@ -48,6 +48,21 @@ def test_add_array_2d():
4848
assert np.all(added_array == large_test_array_ref)
4949

5050

51+
def test_add_array_2d_even_shape():
52+
"""
53+
Test add_array_2D utility function.
54+
55+
Test by adding an array of ones out of an array of zeros.
56+
"""
57+
large_test_array = np.zeros((11, 11))
58+
small_test_array = np.ones((4, 4))
59+
large_test_array_ref = large_test_array.copy()
60+
large_test_array_ref[0:2, 0:2] += small_test_array[2:4, 2:4]
61+
62+
added_array = add_array_2d(large_test_array, small_test_array, (0, 0))
63+
assert np.all(added_array == large_test_array_ref)
64+
65+
5166
@pytest.mark.parametrize(('position', 'subpixel_index'),
5267
zip(test_positions, test_position_indices))
5368
def test_subpixel_indices(position, subpixel_index):

0 commit comments

Comments
 (0)