Package stsci :: Package convolve :: Module Convolve
[hide private]
[frames] | no frames]

Module Convolve

source code

Functions [hide private]
 
_condition_inputs(data, kernel) source code
 
correlate(data, kernel, mode=FULL) source code
 
cross_correlate(data, kernel, mode=FULL) source code
 
convolve(data, kernel, mode=FULL)
Returns the discrete, linear convolution of 1-D sequences a and v; mode can be 0 (VALID), 1 (SAME), or 2 (FULL) to specify size of the resulting sequence.
source code
 
_gaussian(sigma, mew, npoints, sigmas) source code
 
_correlate2d_fft(data0, kernel0, output=None, mode='nearest', cval=0.0)
_correlate2d_fft does 2d correlation of 'data' with 'kernel', storing the result in 'output' using the FFT to perform the correlation.
source code
 
_correlate2d_naive(data, kernel, output=None, mode='nearest', cval=0.0) source code
 
_fix_data_kernel(data, kernel)
The _correlate.Correlate2d C-code can only handle kernels which fit inside the data array.
source code
 
correlate2d(data, kernel, output=None, mode='nearest', cval=0.0, fft=0)
correlate2d does 2d correlation of 'data' with 'kernel', storing the result in 'output'.
source code
 
convolve2d(data, kernel, output=None, mode='nearest', cval=0.0, fft=0)
convolve2d does 2d convolution of 'data' with 'kernel', storing the result in 'output'.
source code
 
_boxcar(data, output, boxshape, mode, cval) source code
 
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.
source code
 
_fbroadcast(f, N, shape, args, params=())
_fbroadcast(f, N, args, shape, params=()) calls 'f' for each of the 'N'-dimensional inner subnumarray of 'args'.
source code
Variables [hide private]
  VALID = 0
  SAME = 1
  FULL = 2
  PASS = 3
  convolution_modes = {'full': 2, 'pass': 3, 'same': 1, 'valid': 0}
  pix_modes = {'constant': 3, 'nearest': 0, 'reflect': 1, 'wrap'...
  __package__ = 'stsci.convolve'

Imports: num, _correlate, dft, iraf_frame


Function Details [hide private]

convolve(data, kernel, mode=FULL)

source code 

Returns the discrete, linear convolution of 1-D sequences a and v; mode can be 0 (VALID), 1 (SAME), or 2 (FULL) to specify size of the resulting sequence.

>>> convolve(num.arange(8), [1, 2], mode=VALID)
array([ 1,  4,  7, 10, 13, 16, 19])
>>> convolve(num.arange(8), [1, 2], mode=SAME)
array([ 0,  1,  4,  7, 10, 13, 16, 19])
>>> convolve(num.arange(8), [1, 2], mode=FULL)
array([ 0,  1,  4,  7, 10, 13, 16, 19, 14])
>>> convolve(num.arange(8), [1, 2, 3], mode=VALID)
array([ 4, 10, 16, 22, 28, 34])
>>> convolve(num.arange(8), [1, 2, 3], mode=SAME)
array([ 1,  4, 10, 16, 22, 28, 34, 32])
>>> convolve(num.arange(8), [1, 2, 3], mode=FULL)
array([ 0,  1,  4, 10, 16, 22, 28, 34, 32, 21])
>>> convolve(num.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
array([35, 56, 77])
>>> convolve(num.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
array([ 4, 10, 20, 35, 56, 77, 90, 94])
>>> convolve(num.arange(8), [1, 2, 3, 4, 5, 6], mode=FULL)
array([ 0,  1,  4, 10, 20, 35, 56, 77, 90, 94, 88, 71, 42])
>>> convolve([1.,2.], num.arange(10.))
array([  0.,   1.,   4.,   7.,  10.,  13.,  16.,  19.,  22.,  25.,  18.])

_correlate2d_fft(data0, kernel0, output=None, mode='nearest', cval=0.0)

source code 
_correlate2d_fft does 2d correlation of 'data' with 'kernel', storing
the result in 'output' using the FFT to perform the correlation.

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'

_fix_data_kernel(data, kernel)

source code 

The _correlate.Correlate2d C-code can only handle kernels which fit inside the data array. Since convolution and correlation are commutative, _fix_data_kernel reverses kernel and data if necessary and panics if there's no good order.

correlate2d(data, kernel, output=None, mode='nearest', cval=0.0, fft=0)

source code 
correlate2d does 2d correlation of 'data' with 'kernel', storing
the result in 'output'.

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'

If fft is True,  the correlation is performed using the FFT, else the
correlation is performed using the naive approach.

>>> a = num.arange(20*20)
>>> a = a.reshape((20,20))
>>> b = num.ones((5,5), dtype=num.float64)
>>> rn = correlate2d(a, b, fft=0)
>>> rf = correlate2d(a, b, fft=1)
>>> num.alltrue(num.ravel(rn-rf<1e-10))
True

convolve2d(data, kernel, output=None, mode='nearest', cval=0.0, fft=0)

source code 
convolve2d does 2d convolution of 'data' with 'kernel', storing
the result in 'output'.

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'

>>> a = num.arange(20*20)
>>> a = a.reshape((20,20))
>>> b = num.ones((5,5), dtype=num.float64)
>>> rn = convolve2d(a, b, fft=0)
>>> rf = convolve2d(a, b, fft=1)
>>> num.alltrue(num.ravel(rn-rf<1e-10))
True

boxcar(data, boxshape, output=None, mode='nearest', cval=0.0)

source code 
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(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="nearest").astype(num.longlong)
 array([  6,   3,   0,   0,   0, 333, 666], dtype=int64)
 >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="wrap").astype(num.longlong)
 array([336,   3,   0,   0,   0, 333, 336], dtype=int64)
 >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="reflect").astype(num.longlong)
 array([  6,   3,   0,   0,   0, 333, 666], dtype=int64)
 >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="constant").astype(num.longlong)
 array([  3,   3,   0,   0,   0, 333, 333], dtype=int64)
 >>> a = num.zeros((10,10),dtype=num.int64)
 >>> a[0,0] = 100
 >>> a[5,5] = 1000
 >>> a[9,9] = 10000
 >>> boxcar(a, (3,3)).astype(num.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(num.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(num.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(num.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 = num.zeros((10,10))
 >>> a[3:6,3:6] = 111
 >>> boxcar(a, (3,3)).astype(num.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)
 

_fbroadcast(f, N, shape, args, params=())

source code 

_fbroadcast(f, N, args, shape, params=()) calls 'f' for each of the 'N'-dimensional inner subnumarray of 'args'. Each subarray has .shape == 'shape'[-N:]. There are a total of product(shape[:-N],axis=0) calls to 'f'.


Variables Details [hide private]

pix_modes

Value:
{'constant': 3, 'nearest': 0, 'reflect': 1, 'wrap': 2}