overlap_slices¶

astropy.nddata.utils.
overlap_slices
(large_array_shape, small_array_shape, position, mode='partial')[source]¶ Get slices for the overlapping part of a small and a large array.
Given a certain position of the center of the small array, with respect to the large array, tuples of slices are returned which can be used to extract, add or subtract the small array at the given position. This function takes care of the correct behavior at the boundaries, where the small array is cut of appropriately. Integer positions are at the pixel centers.
Parameters:  large_array_shape : tuple of int or int
The shape of the large array (for 1D arrays, this can be an
int
). small_array_shape : tuple of int or int
The shape of the small array (for 1D arrays, this can be an
int
). See themode
keyword for additional details. position : tuple of numbers or number
The position of the small array’s center with respect to the large array. The pixel coordinates should be in the same order as the array shape. Integer positions are at the pixel centers. For any axis where
small_array_shape
is even, the position is rounded up, e.g. extracting two elements with a center of1
will define the extracted region as[0, 1]
. mode : {‘partial’, ‘trim’, ‘strict’}, optional
In
'partial'
mode, a partial overlap of the small and the large array is sufficient. The'trim'
mode is similar to the'partial'
mode, butslices_small
will be adjusted to return only the overlapping elements. In the'strict'
mode, the small array has to be fully contained in the large array, otherwise anPartialOverlapError
is raised. In all modes, nonoverlapping arrays will raise aNoOverlapError
.
Returns:  slices_large : tuple of slices
A tuple of slice objects for each axis of the large array, such that
large_array[slices_large]
extracts the region of the large array that overlaps with the small array. slices_small : tuple of slices
A tuple of slice objects for each axis of the small array, such that
small_array[slices_small]
extracts the region that is inside the large array.