subpixel_indices

astropy.nddata.utils.subpixel_indices(position, subsampling)[source]

Convert decimal points to indices, given a subsampling factor.

This discards the integer part of the position and uses only the decimal place, and converts this to a subpixel position depending on the subsampling specified. The center of a pixel corresponds to an integer position.

Parameters:
positionndarray or numpy:array_like

Positions in pixels.

subsamplingpython:int

Subsampling factor per pixel.

Returns:
indicesndarray

The integer subpixel indices corresponding to the input positions.

Examples

If no subsampling is used, then the subpixel indices returned are always 0:

>>> from astropy.nddata.utils import subpixel_indices
>>> subpixel_indices([1.2, 3.4, 5.6], 1)  
array([0., 0., 0.])

If instead we use a subsampling of 2, we see that for the two first values (1.1 and 3.4) the subpixel position is 1, while for 5.6 it is 0. This is because the values of 1, 3, and 6 lie in the center of pixels, and 1.1 and 3.4 lie in the left part of the pixels and 5.6 lies in the right part.

>>> subpixel_indices([1.2, 3.4, 5.5], 2)  
array([1., 1., 0.])