rebin

pydl.rebin(x, d, sample=False)[source]

Resize x to new dimensions given by d. The new dimensions must be integer multiples or factors of the original dimensions.

Although there are some elegant solutions out there for rebinning, this function is intended to replace the IDL REBIN() function, which has a number of special properties:

  • It refuses to perform extrapolation when rebinning to a larger size in a particular dimension.
  • It can simultaneously rebin to a larger size in one dimension while rebinning to a smaller size in another dimension.
Parameters:
x : ndarray

The array to resample.

d : tuple()

The new shape of the array.

sample : bool, optional

If True, nearest-neighbor techniques will be used instead of interpolation.

Returns:
:class:`~numpy.ndarray`

The resampled array.

Raises:
:exc:`ValueError`

If the new dimensions are incompatible with the algorithm.

References

http://www.harrisgeospatial.com/docs/rebin.html

Examples

>>> from numpy import arange, float
>>> from pydl import rebin
>>> rebin(arange(10, dtype=float), (5,)) # doctest: +NORMALIZE_WHITESPACE
array([ 0.5,  2.5,  4.5,  6.5,  8.5])
>>> rebin(arange(5, dtype=float), (10,)) # doctest: +NORMALIZE_WHITESPACE
array([ 0. ,  0.5,  1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4. ])