scipy.stsci.convolve.boxcar

scipy.stsci.convolve.boxcar(data, boxshape, output=None, mode='nearest', cval=0.0)

boxcar computes a 1D or 2D boxcar filter on every 1D or 2D subarray of data.

‘boxshape’ is a tuple of integers specifying the dimensions of the filter: e.g. (3,3)

if ‘output’ is specified, it should be the same shape as ‘data’ and None will be returned.

supported ‘mode’s include:
‘nearest’ elements beyond boundary come from nearest edge pixel. ‘wrap’ elements beyond boundary come from the opposite array edge. ‘reflect’ elements beyond boundary come from reflection on same array edge. ‘constant’ elements beyond boundary are set to ‘cval’
>>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="nearest").astype(np.longlong)
array([  6,   3,   0,   0,   0, 333, 666], dtype=int64)
>>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="wrap").astype(np.longlong)
array([336,   3,   0,   0,   0, 333, 336], dtype=int64)
>>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="reflect").astype(np.longlong)
array([  6,   3,   0,   0,   0, 333, 666], dtype=int64)
>>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="constant").astype(np.longlong)
array([  3,   3,   0,   0,   0, 333, 333], dtype=int64)
>>> a = np.zeros((10,10))
>>> a[0,0] = 100
>>> a[5,5] = 1000
>>> a[9,9] = 10000
>>> boxcar(a, (3,3)).astype(np.longlong)
array([[  44,   22,    0,    0,    0,    0,    0,    0,    0,    0],
       [  22,   11,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0, 1111, 2222],
       [   0,    0,    0,    0,    0,    0,    0,    0, 2222, 4444]], dtype=int64)
>>> boxcar(a, (3,3), mode="wrap").astype(np.longlong)
array([[1122,   11,    0,    0,    0,    0,    0,    0, 1111, 1122],
       [  11,   11,    0,    0,    0,    0,    0,    0,    0,   11],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [1111,    0,    0,    0,    0,    0,    0,    0, 1111, 1111],
       [1122,   11,    0,    0,    0,    0,    0,    0, 1111, 1122]], dtype=int64)
>>> boxcar(a, (3,3), mode="reflect").astype(np.longlong)
array([[  44,   22,    0,    0,    0,    0,    0,    0,    0,    0],
       [  22,   11,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0, 1111, 2222],
       [   0,    0,    0,    0,    0,    0,    0,    0, 2222, 4444]], dtype=int64)
>>> boxcar(a, (3,3), mode="constant").astype(np.longlong)
array([[  11,   11,    0,    0,    0,    0,    0,    0,    0,    0],
       [  11,   11,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,  111,  111,  111,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0],
       [   0,    0,    0,    0,    0,    0,    0,    0, 1111, 1111],
       [   0,    0,    0,    0,    0,    0,    0,    0, 1111, 1111]], dtype=int64)
>>> a = np.zeros((10,10))
>>> a[3:6,3:6] = 111
>>> boxcar(a, (3,3)).astype(np.longlong)
array([[  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0,   0,  12,  24,  37,  24,  12,   0,   0,   0],
       [  0,   0,  24,  49,  74,  49,  24,   0,   0,   0],
       [  0,   0,  37,  74, 111,  74,  37,   0,   0,   0],
       [  0,   0,  24,  49,  74,  49,  24,   0,   0,   0],
       [  0,   0,  12,  24,  37,  24,  12,   0,   0,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=int64)