prtools.sample#

sample(x, oversample, offset=0, axes=(-2, -1), indexing='ij')[source]#

Extract samples from an oversampled array.

The sampled axes are tiled into contiguous blocks of oversample samples, with one sample being taken from each block. No averaging or filtering is performed.

Parameters:
  • x (array_like) – Array to sample

  • oversample (int or tuple of ints) – Decimation factor. Providing two values defines asymmetric oversampling with ordering interpreted according to indexing.

  • offset (int or tuple of ints, optional) – Position of the sample with each block, measured from oversample//2. The sub-sampled position reachable by offset is quantized to 1/oversample. Default is 0. If two values are provided, their ordering is interpreted according to indexing.

  • axes ((2,) sequence of ints, optional) – Axes over which to sample. If not provided, the last two axes are used.

  • indexing ({'ij', 'xy'}, optional) – Matrix (‘ij’, default) or cartesian (‘xy’) indexing of x grid.

Returns:

x – Each sampled axis has length x.shape[axis]//oversample. If axis length is not a multiple of oversample, samples taken beyond the last whole block are ignored.

Return type:

ndarray

Examples

>>> psf = prtools.calcpsf(amp, opd, wave, sampling, (32, 32),
...                       oversample=8)
>>> k = prtools.pixel_kernel(psf.shape, oversample=8)
>>> native = prtools.sample(prtools.fftconv(psf, k), 8)
>>> native.shape
(32, 32)