Ñò
ÆoXJc        	   @   sc  d  d k  Z d  d k Z d  d k i Z d  d k Z d Z d Z d Z	 d Z
 h d d 6d d 6d d 6d d	 6Z d
 „  Z e	 d „ Z e Z h d d 6d d 6d d 6d d 6Z e	 d „ Z d „  Z d d d d „ Z d d d d „ Z d „  Z d d d d d „ Z d d d d d „ Z d „  Z d d d d „ Z d d „ Z d „  Z e d j o e ƒ  GHn d S(   iÿÿÿÿNi    i   i   i   t   validt   samet   fullt   passc         C   sÕ   t  i |  ƒ t  i | ƒ }  } t  i |  ƒ d j o d |  _ n t  i | ƒ d j o d | _ n t  i |  ƒ d j p t  i | ƒ d j o t d ƒ ‚ n t |  ƒ t | ƒ j  o | |  }  } n |  | f S(   Ni    i   s   arrays must be 1D(   i   (   i   (   t   npt   asarrayt   rankt   shapet
   ValueErrort   len(   t   datat   kernel(    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   _condition_inputs   s    ,c   
      C   sâ  t  |  | ƒ \ }  } t | ƒ } t | d ƒ } | d d j } d g | } | t i ƒ  j o t | } n t | i i |  i i ƒ } | t j oS t	 i
 | |  | f ƒ } | i | ƒ }	 t i | | |	 ƒ |	 | | | | | !S| t j oG t	 i
 | |  | f ƒ } | i | ƒ }	 t i | | |	 ƒ |	 | | !S| t j oS t	 i
 | |  | f ƒ } | i | ƒ }	 t i | | |	 ƒ |	 | d | d | !S| t j o' |  i | ƒ }	 t i | |  |	 ƒ |	 St d ƒ ‚ d S(   sY  correlate(data, kernel, mode=FULL)

    >>> correlate(np.arange(8), [1, 2], mode=VALID)
    array([ 2,  5,  8, 11, 14, 17, 20])
    >>> correlate(np.arange(8), [1, 2], mode=SAME)
    array([ 0,  2,  5,  8, 11, 14, 17, 20])
    >>> correlate(np.arange(8), [1, 2], mode=FULL)
    array([ 0,  2,  5,  8, 11, 14, 17, 20,  7])
    >>> correlate(np.arange(8), [1, 2, 3], mode=VALID)
    array([ 8, 14, 20, 26, 32, 38])
    >>> correlate(np.arange(8), [1, 2, 3], mode=SAME)
    array([ 3,  8, 14, 20, 26, 32, 38, 20])
    >>> correlate(np.arange(8), [1, 2, 3], mode=FULL)
    array([ 0,  3,  8, 14, 20, 26, 32, 38, 20,  7])
    >>> correlate(np.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
    array([ 70,  91, 112])
    >>> correlate(np.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
    array([ 17,  32,  50,  70,  91, 112,  85,  60])
    >>> correlate(np.arange(8), [1, 2, 3, 4, 5, 6], mode=FULL)
    array([  0,   6,  17,  32,  50,  70,  91, 112,  85,  60,  38,  20,   7])
    >>> correlate(np.arange(8), 1+1j)
    Traceback (most recent call last):
    ...
    TypeError: array cannot be safely cast to required type

    i   i    i   s   Invalid convolution mode.N(   R   R	   t   intt   convolution_modest   keyst   maxt   dtypet   namet   VALIDR   t   concatenatet   astypet
   _correlatet   Correlate1dt   SAMEt   FULLt   PASSR   (
   R
   R   t   modet   lenkt   halfkt   event   kdatat   result_typet   wdatat   result(    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt	   correlate   s8    t   nearestt   reflectt   wrapt   constantc         C   sm   t  |  | ƒ \ }  } t |  ƒ t | ƒ j o t |  | d d d … | ƒ St | |  d d d … | ƒ Sd S(   sÄ  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.

    >>> convolve(np.arange(8), [1, 2], mode=VALID)
    array([ 1,  4,  7, 10, 13, 16, 19])
    >>> convolve(np.arange(8), [1, 2], mode=SAME)
    array([ 0,  1,  4,  7, 10, 13, 16, 19])
    >>> convolve(np.arange(8), [1, 2], mode=FULL)
    array([ 0,  1,  4,  7, 10, 13, 16, 19, 14])
    >>> convolve(np.arange(8), [1, 2, 3], mode=VALID)
    array([ 4, 10, 16, 22, 28, 34])
    >>> convolve(np.arange(8), [1, 2, 3], mode=SAME)
    array([ 1,  4, 10, 16, 22, 28, 34, 32])
    >>> convolve(np.arange(8), [1, 2, 3], mode=FULL)
    array([ 0,  1,  4, 10, 16, 22, 28, 34, 32, 21])
    >>> convolve(np.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
    array([35, 56, 77])
    >>> convolve(np.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
    array([ 4, 10, 20, 35, 56, 77, 90, 94])
    >>> convolve(np.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.], np.arange(10.))
    array([  0.,   1.,   4.,   7.,  10.,  13.,  16.,  19.,  22.,  25.,  18.])
    Niÿÿÿÿ(   R   R	   R#   (   R
   R   R   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   convolvec   s    c         C   s›   t  i | | |  | | |  d | |  | d t  i ƒ} | | } | |  :} | | } | d d 9} t  i | ƒ } | d |  t  i d t  i ƒ | f S(   Ni   t   typeiÿÿÿÿi   (   R   t   aranget   float64t   expt   sqrtt   pi(   t   sigmat   mewt   npointst   sigmast   oxt   x(    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt	   _gaussian…   s    


g        c         C   sÆ  |  i  } | i  } t i | ƒ t i | ƒ } | d d } | d d }	 t i | d t i ƒ}
 | d d d … d d d … f |
 d | d … d | d … f <t i |  | d | d | ƒ} t | t i ƒ p t |
 t i ƒ } t	 i
 | ƒ } ~ t	 i
 |
 ƒ } ~
 t i | | | ƒ ~ | o t	 i | d	 | ƒ} n t	 i | d	 | ƒ} | | d d | d | d d … | d d | d | d d … f } | d j	 o | i | ƒ n | Sd S(
   sß  _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'
    i    i   i   R   NiÿÿÿÿR   t   cvalt   s(   R   R   t   arrayt   zerosR+   t
   iraf_framet   framet
   isinstancet   complexfloatingt   dftt   fft2t   multiplyt   irfft2t   Nonet	   _copyFrom(   t   data0t   kernel0t   outputR   R6   R   t   kshapet	   oversizedt   dyt   dxR   R
   t   complex_resultt   Fdatat   Fkernelt	   convolvedR"   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   _correlate2d_fft   s.    
		@Lc         C   s   t  i | |  | t | | ƒ S(   N(   R   t   Correlate2dt	   pix_modes(   R
   R   RF   R   R6   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   _correlate2d_naive¾   s    c         C   sC  t  t i |  | g ƒ \ }  } t i |  ƒ d j o d |  _ n+ t i |  ƒ d j o d |  i |  _ n t i | ƒ d j o d | _ n+ t i | ƒ d j o d | i | _ n | i d |  i d j o, | i d |  i d j o |  | } }  n; | i d |  i d j o | i d |  i d j o n |  | f S(   sû   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.
    i    i   (   i   i   (   i   (   i   i   (   i   (   t   mapR   R   R   R   (   R
   R   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   _fix_data_kernelÁ   s     c         C   sS   t  |  | ƒ \ }  } | o t |  | | | | ƒ St |  | | | | ƒ } | Sd S(   s  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 = np.arange(20*20)
    >>> a = a.reshape((20,20))
    >>> b = np.ones((5,5), dtype=np.float64)
    >>> rn = correlate2d(a, b, fft=0)
    >>> rf = correlate2d(a, b, fft=1)
    >>> np.alltrue(np.ravel(rn-rf<1e-10))
    True
    N(   RT   RO   RR   (   R
   R   RF   R   R6   t   fftt   a(    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   correlate2dØ   s
    c         C   so   t  |  | ƒ \ }  } | d d d … d d d … f } | o t |  | | | | ƒ St |  | | | | ƒ Sd S(   s—  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 = np.arange(20*20)
    >>> a = a.reshape((20,20))
    >>> b = np.ones((5,5), dtype=np.float64)
    >>> rn = convolve2d(a, b, fft=0)
    >>> rf = convolve2d(a, b, fft=1)
    >>> np.alltrue(np.ravel(rn-rf<1e-10))
    True
    Niÿÿÿÿ(   RT   RO   RR   (   R
   R   RF   R   R6   RU   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt
   convolve2dõ   s
    "c         C   sœ   t  | ƒ d j o> t i |  t i d f d | d | t i d f | | ƒ nH t  | ƒ d j o( t i |  | d | d | | | ƒ n t d ƒ ‚ d  S(   Ni   .i    i   s"   boxshape must be a 1D or 2D shape.(   R	   R   t   Boxcar2dR   t   newaxisR   (   R
   RF   t   boxshapeR   R6   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   _boxcar  s     (c         C   sw   t  | } | d j o |  i t i ƒ } n | } t t t | ƒ |  i |  | f | | | f ƒ | d j o | Sd S(   s‡  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)
    N(	   RQ   RB   R   R   R+   t   _fbroadcastR\   R	   R   (   R
   R[   RF   R   R6   t   woutput(    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   boxcar  s    U
c         C   s†   t  | ƒ | j o t |  t | ƒ | ƒ nU xQ t | d ƒ D]? } t |  | | d g  } | D] } | | | q` ~ | ƒ q? Wd S(   së   _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'.
    i    i   N(   R	   t   applyt   tuplet   rangeR]   (   t   ft   NR   t   argst   paramst   it   _[1]R4   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyR]   v  s
     c          C   s%   d d  k  }  d d  k } |  i | ƒ S(   Niÿÿÿÿ(   t   doctestt   Convolvet   testmod(   Ri   Rj   (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   test‚  s    t   __main__(    (   t   numpyR   R   t	   numpy.fftRU   R>   R:   R   R   R   R   R   R   R#   t   cross_correlateRQ   R(   R5   RB   RO   RR   RT   RW   RX   R\   R_   R]   Rl   t   __name__(    (    (    sM   C:\graphics\Tools\Python26\Lib\site-packages\scipy\stsci\convolve\Convolve.pyt   <module>   sB   
	<
"	.			_	