overlap_slices#
- astropy.nddata.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
ofint
orint
The shape of the large array (for 1D arrays, this can be an
int
).- small_array_shape
int
ortuple
thereof The shape of the small array (for 1D arrays, this can be an
int
). See themode
keyword for additional details.- positionnumber or
tuple
thereof 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, non-overlapping arrays will raise aNoOverlapError
.
- large_array_shape
- Returns:
- slices_large
tuple
ofslice
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
ofslice
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.
- slices_large