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_shapepython:tuple of python:int or python:int

The shape of the large array (for 1D arrays, this can be an int).

small_array_shapepython:int or python:tuple thereof

The shape of the small array (for 1D arrays, this can be an int). See the mode keyword for additional details.

positionnumber or python: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 of 1 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, but slices_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 an PartialOverlapError is raised. In all modes, non-overlapping arrays will raise a NoOverlapError.

Returns:
slices_largepython:tuple of slice

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_smallpython:tuple of slice

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.