|
8 | 8 | import copy |
9 | 9 |
|
10 | 10 | __all__ = ['extract_array_2d', 'add_array_2d', 'subpixel_indices', |
11 | | - 'mask_to_mirrored_num'] |
| 11 | + 'mask_to_mirrored_num', 'get_slices'] |
12 | 12 |
|
13 | 13 |
|
14 | | -def _get_slices(large_array_shape, small_array_shape, position): |
| 14 | +def get_slices(large_array_shape, small_array_shape, position): |
15 | 15 | """ |
16 | 16 | Get slices for the overlapping part of a small and a large array. |
17 | 17 |
|
@@ -43,10 +43,10 @@ def _get_slices(large_array_shape, small_array_shape, position): |
43 | 43 | Slice in x direction for the small array. |
44 | 44 | """ |
45 | 45 | # 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.) |
50 | 50 |
|
51 | 51 | # Set up slices in x direction |
52 | 52 | 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): |
90 | 90 | """ |
91 | 91 | # Check if larger array is really larger |
92 | 92 | 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) |
94 | 94 | return array_large[s_y, s_x] |
95 | 95 | else: |
96 | 96 | raise Exception("Can't extract array. Shape too large.") |
@@ -128,7 +128,7 @@ def add_array_2d(array_large, array_small, position): |
128 | 128 | """ |
129 | 129 | # Check if larger array is really larger |
130 | 130 | 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, |
132 | 132 | array_small.shape, position) |
133 | 133 | array_large[s_y, s_x] += array_small[b_y, b_x] |
134 | 134 | return array_large |
|
0 commit comments