Skip to content

Commit 7bebafb

Browse files
committed
Fix for astropy#40 and astropy#29
1 parent a970a61 commit 7bebafb

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎imageutils/array_utils.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import copy
99

1010
__all__ = ['extract_array_2d', 'add_array_2d', 'subpixel_indices',
11-
'mask_to_mirrored_num']
11+
'mask_to_mirrored_num', 'get_slices']
1212

1313

14-
def _get_slices(large_array_shape, small_array_shape, position):
14+
def get_slices(large_array_shape, small_array_shape, position):
1515
"""
1616
Get slices for the overlapping part of a small and a large array.
1717
@@ -43,10 +43,10 @@ def _get_slices(large_array_shape, small_array_shape, position):
4343
Slice in x direction for the small array.
4444
"""
4545
# Get edge coordinates
46-
y_min = int(position[1] + 0.5) - small_array_shape[0] // 2
47-
x_min = int(position[0] + 0.5) - small_array_shape[1] // 2
48-
y_max = int(position[1] + 0.5) + small_array_shape[0] // 2 + 1
49-
x_max = int(position[0] + 0.5) + small_array_shape[1] // 2 + 1
46+
y_min = int(position[1] + 0.5 - small_array_shape[0] / 2.)
47+
x_min = int(position[0] + 0.5 - small_array_shape[1] / 2.)
48+
y_max = int(position[1] + 0.5 + small_array_shape[0] / 2.)
49+
x_max = int(position[0] + 0.5 + small_array_shape[1] / 2.)
5050

5151
# Set up slices in x direction
5252
s_x = slice(max(0, x_min), min(large_array_shape[1], x_max))
@@ -90,7 +90,7 @@ def extract_array_2d(array_large, shape, position):
9090
"""
9191
# Check if larger array is really larger
9292
if array_large.shape >= shape:
93-
s_y, s_x, _, _ = _get_slices(array_large.shape, shape, position)
93+
s_y, s_x, _, _ = get_slices(array_large.shape, shape, position)
9494
return array_large[s_y, s_x]
9595
else:
9696
raise Exception("Can't extract array. Shape too large.")
@@ -128,7 +128,7 @@ def add_array_2d(array_large, array_small, position):
128128
"""
129129
# Check if larger array is really larger
130130
if array_large.shape >= array_small.shape:
131-
s_y, s_x, b_y, b_x = _get_slices(array_large.shape,
131+
s_y, s_x, b_y, b_x = get_slices(array_large.shape,
132132
array_small.shape, position)
133133
array_large[s_y, s_x] += array_small[b_y, b_x]
134134
return array_large

0 commit comments

Comments
 (0)