ó
U¶\c           @` s\  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d l	 m	 Z	 d d l
 Z d d l m Z m Z d d l m Z d d	 l m Z m Z m Z d d
 l m Z m Z m Z m Z m Z d d l m Z m Z m Z d d d d d d d d d d d d d d d d g Z d „  Z  d d d d „ Z" d d d  „ Z# d d d7 d" „ Z$ d d8 d# „ Z% d$ „  Z& d d d d% „ Z' d& „  Z( d d d' „ Z) d( „  Z* d) „  Z+ d* „  Z, d+ „  Z- d d d, „ Z. d d- „ Z/ d d d d. „ Z0 d/ „  Z1 d d0 „ Z2 d d1 „ Z3 d d2 „ Z4 d3 „  Z5 d e6 f d4 „  ƒ  YZ7 d d d d5 „ Z8 d6 „  Z9 d S(9   sY   
Multilevel 1D and 2D Discrete Wavelet Transform
and Inverse Discrete Wavelet Transform.
i    (   t   divisiont   print_functiont   absolute_importN(   t   product(   t   copyi   (   t   Wavelett   Modes(   t   dwt_max_level(   t   dwtt   idwtt   dwt_coeff_len(   t   dwt2t   idwt2t   dwtnt   idwtnt   _fix_coeffs(   t   _as_wavelett   _wavelets_per_axist   _modes_per_axist   wavedect   waverect   wavedec2t   waverec2t   wavedecnt   waverecnt   coeffs_to_arrayt   array_to_coeffst   ravel_coeffst   unravel_coeffst   dwtn_max_levelt   wavedecn_sizet   wavedecn_shapest
   fswavedecnt
   fswaverecnt   FswavedecnResultc         C` sÍ   t  j |  ƒ r |  f }  n  t  j | ƒ r6 | f } n  t  j g  t |  | ƒ D] \ } } t | | ƒ ^ qL ƒ } | d  k r… | } nD | d k  r¤ t d | ƒ ‚ n% | | k rÉ t j d j	 | ƒ ƒ n  | S(   Ni    s2   Level value of %d is too low . Minimum level is 0.sQ   Level value of {} is too high: all coefficients will experience boundary effects.(
   t   npt   isscalart   mint   zipR   t   Nonet
   ValueErrort   warningst   warnt   format(   t   sizest   dec_lenst   levelt   st   dt	   max_level(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _check_level   s    :	t	   symmetriciÿÿÿÿc   
      C` sÇ   t  j |  ƒ }  t | ƒ } y |  j | } Wn t k
 rK t d ƒ ‚ n Xt | | j | ƒ } g  } |  } x< t | ƒ D]. } t	 | | | | ƒ \ } }	 | j
 |	 ƒ qz W| j
 | ƒ | j ƒ  | S(   s¸  
    Multilevel 1D Discrete Wavelet Transform of data.

    Parameters
    ----------
    data: array_like
        Input data
    wavelet : Wavelet object or name string
        Wavelet to use
    mode : str, optional
        Signal extension mode, see `Modes` (default: 'symmetric')
    level : int, optional
        Decomposition level (must be >= 0). If level is None (default) then it
        will be calculated using the `dwt_max_level` function.
    axis: int, optional
        Axis over which to compute the DWT. If not given, the
        last axis is used.

    Returns
    -------
    [cA_n, cD_n, cD_n-1, ..., cD2, cD1] : list
        Ordered list of coefficients arrays
        where `n` denotes the level of decomposition. The first element
        (`cA_n`) of the result is approximation coefficients array and the
        following elements (`cD_n` - `cD_1`) are details coefficients arrays.

    Examples
    --------
    >>> from pywt import wavedec
    >>> coeffs = wavedec([1,2,3,4,5,6,7,8], 'db1', level=2)
    >>> cA2, cD2, cD1 = coeffs
    >>> cD1
    array([-0.70710678, -0.70710678, -0.70710678, -0.70710678])
    >>> cD2
    array([-2., -2.])
    >>> cA2
    array([  5.,  13.])

    s!   Axis greater than data dimensions(   R#   t   asarrayR   t   shapet
   IndexErrorR(   R2   t   dec_lent   rangeR   t   appendt   reverse(
   t   datat   wavelett   modeR.   t   axist
   axes_shapet   coeffs_listt   at   iR0   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   1   s    (
c         C` sc  t  |  t t f ƒ s$ t d ƒ ‚ n  t |  ƒ d k  rE t d ƒ ‚ n t |  ƒ d k r_ |  d S|  d |  d } } xè | D]à } | d	 k	 rC| d	 k	 rCyk | j | | j | d k rÚ | t d „  | j Dƒ ƒ } n) | j | | j | k rt d ƒ ‚ n  WqCt k
 r#t d ƒ ‚ qCt k
 r?t d ƒ ‚ qCXn  t	 | | | | | ƒ } q{ W| S(
   s6  
    Multilevel 1D Inverse Discrete Wavelet Transform.

    Parameters
    ----------
    coeffs : array_like
        Coefficients list [cAn, cDn, cDn-1, ..., cD2, cD1]
    wavelet : Wavelet object or name string
        Wavelet to use
    mode : str, optional
        Signal extension mode, see `Modes` (default: 'symmetric')
    axis: int, optional
        Axis over which to compute the inverse DWT. If not given, the
        last axis is used.

    Notes
    -----
    It may sometimes be desired to run `waverec` with some sets of
    coefficients omitted.  This can best be done by setting the corresponding
    arrays to zero arrays of matching shape and dtype.  Explicitly removing
    list entries or setting them to None is not supported.

    Specifically, to ignore detail coefficients at level 2, one could do::

        coeffs[-2] == np.zeros_like(coeffs[-2])

    Examples
    --------
    >>> import pywt
    >>> coeffs = pywt.wavedec([1,2,3,4,5,6,7,8], 'db1', level=2)
    >>> pywt.waverec(coeffs, 'db1')
    array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.])
    s(   Expected sequence of coefficient arrays.i   s7   Coefficient list too short (minimum 1 arrays required).i    c         s` s   |  ] } t  | ƒ Vq d  S(   N(   t   slice(   t   .0R/   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>¢   s    s   coefficient shape mismatchs(   Axis greater than coefficient dimensionssa   Wrong coefficient format, if using 'array_to_coeffs' please specify the 'output_format' parameterN(
   t
   isinstancet   listt   tupleR(   t   lenR'   R5   R6   t   AttributeErrorR	   (   t   coeffsR<   R=   R>   RA   t   dsR0   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   o   s,    # iþÿÿÿc         C` sn  t  j |  ƒ }  |  j d k  r- t d ƒ ‚ n  t | ƒ } t | ƒ d k rZ t d ƒ ‚ n  t | ƒ t t | ƒ ƒ k r‡ t d ƒ ‚ n  y$ g  | D] } |  j | ^ q‘ } Wn t k
 rÊ t d ƒ ‚ n Xt	 | | ƒ } g  | D] } | j
 ^ qá }	 t | |	 | ƒ } g  }
 |  } x< t | ƒ D]. } t | | | | ƒ \ } } |
 j | ƒ q!W|
 j | ƒ |
 j ƒ  |
 S(   sn  
    Multilevel 2D Discrete Wavelet Transform.

    Parameters
    ----------
    data : ndarray
        2D input data
    wavelet : Wavelet object or name string, or 2-tuple of wavelets
        Wavelet to use.  This can also be a tuple containing a wavelet to
        apply along each axis in `axes`.
    mode : str or 2-tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric').  This can
        also be a tuple containing a mode to apply along each axis in `axes`.
    level : int, optional
        Decomposition level (must be >= 0). If level is None (default) then it
        will be calculated using the `dwt_max_level` function.
    axes : 2-tuple of ints, optional
        Axes over which to compute the DWT. Repeated elements are not allowed.

    Returns
    -------
    [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)] : list
        Coefficients list.  For user-specified `axes`, `cH*`
        corresponds to ``axes[0]`` while `cV*` corresponds to ``axes[1]``.
        The first element returned is the approximation coefficients for the
        nth level of decomposition.  Remaining elements are tuples of detail
        coefficients in descending order of decomposition level.
        (i.e. `cH1` are the horizontal detail coefficients at the first level)

    Examples
    --------
    >>> import pywt
    >>> import numpy as np
    >>> coeffs = pywt.wavedec2(np.ones((4,4)), 'db1')
    >>> # Levels:
    >>> len(coeffs)-1
    2
    >>> pywt.waverec2(coeffs, 'db1')
    array([[ 1.,  1.,  1.,  1.],
           [ 1.,  1.,  1.,  1.],
           [ 1.,  1.,  1.,  1.],
           [ 1.,  1.,  1.,  1.]])
    i   s2   Expected input data to have at least 2 dimensions.s   Expected 2 axess+   The axes passed to wavedec2 must be unique.s!   Axis greater than data dimensions(   R#   R4   t   ndimR(   RG   RH   t   setR5   R6   R   R7   R2   R8   R   R9   R:   (   R;   R<   R=   R.   t   axest   axt
   axes_sizest   waveletst   wt   dec_lengthsR@   RA   RB   RK   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   °   s.    ,$
c   	      ` s“  t  |  t t f ƒ s$ t d ƒ ‚ n  t | ƒ t t | ƒ ƒ k rQ t d ƒ ‚ n  t |  ƒ d k  rr t d ƒ ‚ n t |  ƒ d k rŒ |  d S|  d |  d } } t j | ƒ } xÜ | D]Ô } t d „  | Dƒ ƒ } d „  | Dƒ } y t | ƒ ‰  Wn) t	 k
 rt
 d ƒ t
 d ƒ f } nN Xt ‡  f d †  | Dƒ ƒ sJt d	 ƒ ‚ n  t d
 „  t | j ˆ  ƒ Dƒ ƒ } t | | | f | | | ƒ } q· W| S(   sð  
    Multilevel 2D Inverse Discrete Wavelet Transform.

    coeffs : list or tuple
        Coefficients list [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)]
    wavelet : Wavelet object or name string, or 2-tuple of wavelets
        Wavelet to use.  This can also be a tuple containing a wavelet to
        apply along each axis in `axes`.
    mode : str or 2-tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric').  This can
        also be a tuple containing a mode to apply along each axis in `axes`.
    axes : 2-tuple of ints, optional
        Axes over which to compute the IDWT. Repeated elements are not allowed.

    Returns
    -------
    2D array of reconstructed data.

    Notes
    -----
    It may sometimes be desired to run `waverec2` with some sets of
    coefficients omitted.  This can best be done by setting the corresponding
    arrays to zero arrays of matching shape and dtype.  Explicitly removing
    list or tuple entries or setting them to None is not supported.

    Specifically, to ignore all detail coefficients at level 2, one could do::

        coeffs[-2] == tuple([np.zeros_like(v) for v in coeffs[-2]])

    Examples
    --------
    >>> import pywt
    >>> import numpy as np
    >>> coeffs = pywt.wavedec2(np.ones((4,4)), 'db1')
    >>> # Levels:
    >>> len(coeffs)-1
    2
    >>> pywt.waverec2(coeffs, 'db1')
    array([[ 1.,  1.,  1.,  1.],
           [ 1.,  1.,  1.,  1.],
           [ 1.,  1.,  1.,  1.],
           [ 1.,  1.,  1.,  1.]])
    s(   Expected sequence of coefficient arrays.s+   The axes passed to waverec2 must be unique.i   s6   Coefficient list too short (minimum 1 array required).i    c         s` s0   |  ]& } | d  k	 r$ t j | ƒ n d  Vq d  S(   N(   R'   R#   R4   (   RD   t   coeff(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>9  s   c         s` s$   |  ] } | d  k	 r | j Vq d  S(   N(   R'   R5   (   RD   RT   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>;  s    c         3` s   |  ] } | ˆ  k Vq d  S(   N(    (   RD   R/   (   t   d_shape(    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>A  s    s*   All detail shapes must be the same length.c         s` s:   |  ]0 \ } } t  d | | d  k r+ d n d ƒ Vq d S(   i   iÿÿÿÿN(   RC   R'   (   RD   t   a_lent   d_len(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>C  s   N(   RE   RF   RG   R(   RH   RM   R#   R4   t   nextt   StopIterationRC   R'   t   allR&   R5   R   (	   RJ   R<   R=   RN   RA   RK   R0   t   d_shapest   idxs(    (   RU   s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   ü   s2    ,		#c         C` sö   t  |  ƒ d k  r! t d ƒ ‚ n  t  |  ƒ } t j | ƒ rH | f } n  | d  k rc t | ƒ } n t | ƒ } t  | ƒ t  t | ƒ ƒ k rœ t d ƒ ‚ n  y! g  | D] } |  | ^ q¦ } Wn t k
 rÜ t d ƒ ‚ n Xt  | ƒ } | | | f S(   Ni   s    Expected at least 1D input data.s+   The axes passed to wavedecn must be unique.s!   Axis greater than data dimensions(	   RH   R(   R#   R$   R'   R8   RG   RM   R6   (   R5   RN   RL   RO   t   axes_shapest   ndim_transform(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _prep_axes_wavedecnJ  s     !c         C` sÚ   t  j |  ƒ }  t |  j | ƒ \ } } } t | | ƒ } g  | D] } | j ^ q@ }	 t | |	 | ƒ } g  }
 |  } xI t | ƒ D]; } t | | | | ƒ } | j	 d | ƒ } |
 j
 | ƒ q€ W|
 j
 | ƒ |
 j ƒ  |
 S(   s0	  
    Multilevel nD Discrete Wavelet Transform.

    Parameters
    ----------
    data : ndarray
        nD input data
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use.  This can also be a tuple containing a wavelet to
        apply along each axis in `axes`.
    mode : str or tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric').  This can
        also be a tuple containing a mode to apply along each axis in `axes`.
    level : int, optional
        Decomposition level (must be >= 0). If level is None (default) then it
        will be calculated using the `dwt_max_level` function.
    axes : sequence of ints, optional
        Axes over which to compute the DWT. Axes may not be repeated. The
        default is None, which means transform all axes
        (``axes = range(data.ndim)``).

    Returns
    -------
    [cAn, {details_level_n}, ... {details_level_1}] : list
        Coefficients list.  Coefficients are listed in descending order of
        decomposition level.  `cAn` are the approximation coefficients at
        level `n`.  Each `details_level_i` element is a dictionary
        containing detail coefficients at level `i` of the decomposition.  As
        a concrete example, a 3D decomposition would have the following set of
        keys in each `details_level_i` dictionary::

            {'aad', 'ada', 'daa', 'add', 'dad', 'dda', 'ddd'}

        where the order of the characters in each key map to the specified
        `axes`.

    Examples
    --------
    >>> import numpy as np
    >>> from pywt import wavedecn, waverecn
    >>> coeffs = wavedecn(np.ones((4, 4, 4)), 'db1')
    >>> # Levels:
    >>> len(coeffs)-1
    2
    >>> waverecn(coeffs, 'db1')  # doctest: +NORMALIZE_WHITESPACE
    array([[[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]],
           [[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]],
           [[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]],
           [[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]]])

    RA   (   R#   R4   R_   R5   R   R7   R2   R8   R   t   popR9   R:   (   R;   R<   R=   R.   RN   R]   R^   RQ   RR   RS   R@   RA   RB   RJ   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   ^  s    @
c         C` s›   |  d  k r d  S| s |  S| t t | ƒ ƒ } t j |  j | j ƒ } t j | d k  | d k Bƒ r€ t | ƒ t d ƒ ‚ n  |  t	 d „  | j Dƒ ƒ S(   Ni    i   s$   incompatible coefficient array sizesc         s` s   |  ] } t  | ƒ Vq d  S(   N(   RC   (   RD   R/   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>À  s    (
   R'   RX   t   iterR#   t   subtractR5   t   anyt   printR(   RG   (   t   a_coefft   d_coeff_dictt   d_coefft
   size_diffs(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _match_coeff_dims³  s    
c         C` s"  t  |  ƒ d k  r! t d ƒ ‚ n  |  d |  d } } t t t | ƒ ƒ } | sY |  d S| d k r t | ƒ r t d ƒ ‚ n  g  } | d k	 rµ t j | ƒ } | j	 | j
 ƒ n  x: | D]2 } | g  | j ƒ  D] \ } }	 |	 j
 ^ qÒ 7} q¼ Wt j | ƒ }
 t  |
 ƒ d k r |
 d } n t d ƒ ‚ t j | ƒ rG| f } n  | d k rbt | ƒ } n t | ƒ } t  | ƒ t  t | ƒ ƒ k r›t d ƒ ‚ n  t  | ƒ } xt t | ƒ D]f \ } } | d k rÙ| rÙq´n  | d k r÷t | | ƒ } n  | | d | <t | | | | ƒ } q´W| S(	   sÆ  
    Multilevel nD Inverse Discrete Wavelet Transform.

    coeffs : array_like
        Coefficients list [cAn, {details_level_n}, ... {details_level_1}]
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use.  This can also be a tuple containing a wavelet to
        apply along each axis in `axes`.
    mode : str or tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric').  This can
        also be a tuple containing a mode to apply along each axis in `axes`.
    axes : sequence of ints, optional
        Axes over which to compute the IDWT.  Axes may not be repeated.

    Returns
    -------
    nD array of reconstructed data.

    Notes
    -----
    It may sometimes be desired to run `waverecn` with some sets of
    coefficients omitted.  This can best be done by setting the corresponding
    arrays to zero arrays of matching shape and dtype.  Explicitly removing
    list or dictionary entries or setting them to None is not supported.

    Specifically, to ignore all detail coefficients at level 2, one could do::

        coeffs[-2] = {k: np.zeros_like(v) for k, v in coeffs[-2].items()}

    Examples
    --------
    >>> import numpy as np
    >>> from pywt import wavedecn, waverecn
    >>> coeffs = wavedecn(np.ones((4, 4, 4)), 'db1')
    >>> # Levels:
    >>> len(coeffs)-1
    2
    >>> waverecn(coeffs, 'db1')  # doctest: +NORMALIZE_WHITESPACE
    array([[[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]],
           [[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]],
           [[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]],
           [[ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.],
            [ 1.,  1.,  1.,  1.]]])

    i   s6   Coefficient list too short (minimum 1 array required).i    s4   At least one coefficient must contain a valid value.s:   All coefficients must have a matching number of dimensionss+   The axes passed to waverecn must be unique.RA   N(   RH   R(   RF   t   mapR   R'   Rc   R#   R4   R9   RL   t   itemst   uniqueR$   R8   RG   RM   t	   enumerateRi   R   (   RJ   R<   R=   RN   RA   RK   t   coeff_ndimsR0   t   kt   vt   unique_coeff_ndimsRL   R^   t   idx(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   Ã  sJ    90	c         C` s•   t  |  ƒ d k r |  St |  ƒ }  xl t d t  |  ƒ ƒ D]U } |  | d k rT q8 n  |  | j d k rv t d ƒ ‚ n  t d |  | ƒ |  | <q8 W|  S(   s4   Convert wavedec coefficients to the wavedecn format.i    i   s   expected a 1D coefficient arrayR0   N(   RH   R   R8   R'   RL   R(   t   dict(   RJ   t   n(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _coeffs_wavedec_to_wavedecn3  s    c         C` sê   t  |  ƒ d k r |  St |  ƒ }  xÁ t d t  |  ƒ ƒ D]ª } t |  | t t f ƒ sn t  |  | ƒ d k r} t d ƒ ‚ n  |  | \ } } } | d	 k s´ | d	 k s´ | d	 k rÃ t d ƒ ‚ n  t d | d | d | ƒ |  | <q8 W|  S(
   s5   Convert wavedec2 coefficients to the wavedecn format.i    i   i   s)   expected a 3-tuple of detail coefficientss\   Expected numpy arrays of detail coefficients. Setting coefficients to None is not supported.t   adt   dat   ddN(	   RH   R   R8   RE   RG   RF   R(   R'   Rs   (   RJ   Rt   Rw   Rv   Rx   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _coeffs_wavedec2_to_wavedecnA  s    0$#c   	      C` sÖ   t  j |  d j ƒ } t  j | ƒ } t | ƒ } |  d j } xd |  d D]X } | | c t  j | d | j ƒ | 7<x' | j ƒ  D] \ } } | | j 7} q„ WqI Wt | j ƒ  ƒ } t  j | ƒ | k } | | f S(   Ni    i   R0   (	   R#   R4   R5   RH   t   sizeRk   RG   t   tolistt   prod(	   RJ   RN   t	   arr_shapeR^   t   ncoeffsR0   Ro   Rp   t   is_tight_packing(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _determine_coeff_array_shapeR  s    (c         C` s²  t  |  t ƒ s" t |  ƒ d k r1 t d ƒ ‚ n  |  d d	 k rP t d ƒ ‚ n  t  |  d t j ƒ su t d ƒ ‚ n  |  d j } t |  ƒ d k rt  |  d t ƒ rª qt  |  d t j ƒ rÏ t	 |  ƒ }  qt  |  d t
 t f ƒ r÷ t |  ƒ }  qt d ƒ ‚ n  t |  ƒ d k r(|  | | d	 f St t |  d j ƒ  ƒ d ƒ } | d	 k r| | k  rot d ƒ ‚ n  t j | ƒ } n  t | ƒ | k r¢t d ƒ ‚ n  |  | | | f S(
   sw   Helper function to check type of coeffs and axes.

    This code is used by both coeffs_to_array and ravel_coeffs.
    i    s2   input must be a list of coefficients from wavedecns6   coeffs_to_array does not support missing coefficients.s(   first list element must be a numpy arrayi   s   invalid coefficient listsl   coeffs corresponds to a DWT performed over only a subset of the axes.  In this case, axes must be specified.sF   The length of axes doesn't match the number of dimensions transformed.N(   RE   RF   RH   R(   R'   R#   t   ndarrayRL   Rs   Ru   RG   Ry   t   keyst   arange(   RJ   RN   RL   R^   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _prepare_coeffs_axesb  s6    " c         C` s¨  t  |  | ƒ \ }  } } } |  d } | j } t |  ƒ d k r` | t t d
 ƒ g | ƒ g f St |  | ƒ \ } } | d
 k r± | s– t d ƒ ‚ n  t j	 | d | j
 ƒ}	 n t j | | d | j
 ƒ}	 t g  | D] }
 t |
 ƒ ^ qÖ ƒ } | |	 | <g  } | j | ƒ |  d } xƒ| D]{} | j i  ƒ t j g  | j ƒ  D] } | d
 k ^ qEƒ rot d ƒ ‚ n  | d | j } xì | j ƒ  D]Þ } | | } t d
 ƒ g | } x” t | ƒ D]† \ } } | | } | d k rùt | j | ƒ | | <q½| d k r.t | | | | | j | ƒ | | <q½t d j | ƒ ƒ ‚ q½Wt | ƒ } | |	 | <| | d	 | <qWg  t | ƒ D] } | | | | ^ q|} qW|	 | f S(   sâ	  
    Arrange a wavelet coefficient list from `wavedecn` into a single array.

    Parameters
    ----------

    coeffs : array-like
        dictionary of wavelet coefficients as returned by pywt.wavedecn
    padding : float or None, optional
        If None, raise an error if the coefficients cannot be tightly packed.
    axes : sequence of ints, optional
        Axes over which the DWT that created `coeffs` was performed.  The
        default value of None corresponds to all axes.

    Returns
    -------
    coeff_arr : array-like
        Wavelet transform coefficient array.
    coeff_slices : list
        List of slices corresponding to each coefficient.  As a 2D example,
        `coeff_arr[coeff_slices[1]['dd']]` would extract the first level detail
        coefficients from `coeff_arr`.

    See Also
    --------
    array_to_coeffs : the inverse of coeffs_to_array

    Notes
    -----
    Assume a 2D coefficient dictionary, c, from a two-level transform.

    Then all 2D coefficients will be stacked into a single larger 2D array
    as follows::

        +---------------+---------------+-------------------------------+
        |               |               |                               |
        |     c[0]      |  c[1]['da']   |                               |
        |               |               |                               |
        +---------------+---------------+           c[2]['da']          |
        |               |               |                               |
        | c[1]['ad']    |  c[1]['dd']   |                               |
        |               |               |                               |
        +---------------+---------------+ ------------------------------+
        |                               |                               |
        |                               |                               |
        |                               |                               |
        |          c[2]['ad']           |           c[2]['dd']          |
        |                               |                               |
        |                               |                               |
        |                               |                               |
        +-------------------------------+-------------------------------+

    Examples
    --------
    >>> import pywt
    >>> cam = pywt.data.camera()
    >>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
    >>> arr, coeff_slices = pywt.coeffs_to_array(coeffs)

    i    i   s+   array coefficients cannot be tightly packedt   dtypes6   coeffs_to_array does not support missing coefficients.R0   RA   s   unexpected letter: {}iÿÿÿÿN(   R„   R5   RH   RG   RC   R'   R€   R(   R#   t   emptyR…   t   fullR9   Rc   t   valuesR‚   Rm   R+   R8   (   RJ   t   paddingRN   RL   R^   t   a_coeffst   a_shapeR}   R   t	   coeff_arrR/   t   a_slicest   coeff_slicesRK   t
   coeff_dictR0   RU   t   keyt   slice_arrayRB   t   lett   ax_iRt   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR     sJ    >
	 %

.



/c         C` s8  t  j |  ƒ }  g  } t | ƒ d k r6 t d ƒ ‚ n | j |  | d ƒ xæ t d t | ƒ ƒ D]Ï } | d k rˆ |  | | d } n› | d k rÊ |  | | d |  | | d |  | | d	 f } nY | d
 k ri  } xD | | j ƒ  D] \ } } |  | | | <qí Wn t d j | ƒ ƒ ‚ | j | ƒ qa W| S(   s
  
    Convert a combined array of coefficients back to a list compatible with
    `waverecn`.

    Parameters
    ----------

    arr : array-like
        An array containing all wavelet coefficients.  This should have been
        generated via `coeffs_to_array`.
    coeff_slices : list of tuples
        List of slices corresponding to each coefficient as obtained from
        `array_to_coeffs`.
    output_format : {'wavedec', 'wavedec2', 'wavedecn'}
        Make the form of the coefficients compatible with this type of
        multilevel transform.

    Returns
    -------
    coeffs: array-like
        Wavelet transform coefficient array.

    See Also
    --------
    coeffs_to_array : the inverse of array_to_coeffs

    Notes
    -----
    A single large array containing all coefficients will have subsets stored,
    into a `waverecn` list, c, as indicated below::

        +---------------+---------------+-------------------------------+
        |               |               |                               |
        |     c[0]      |  c[1]['da']   |                               |
        |               |               |                               |
        +---------------+---------------+           c[2]['da']          |
        |               |               |                               |
        | c[1]['ad']    |  c[1]['dd']   |                               |
        |               |               |                               |
        +---------------+---------------+ ------------------------------+
        |                               |                               |
        |                               |                               |
        |                               |                               |
        |          c[2]['ad']           |           c[2]['dd']          |
        |                               |                               |
        |                               |                               |
        |                               |                               |
        +-------------------------------+-------------------------------+

    Examples
    --------
    >>> import pywt
    >>> from numpy.testing import assert_array_almost_equal
    >>> cam = pywt.data.camera()
    >>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
    >>> arr, coeff_slices = pywt.coeffs_to_array(coeffs)
    >>> coeffs_from_arr = pywt.array_to_coeffs(arr, coeff_slices)
    >>> cam_recon = pywt.waverecn(coeffs_from_arr, wavelet='db2')
    >>> assert_array_almost_equal(cam, cam_recon)

    i    s    empty list of coefficient slicesi   R   R0   R   Rw   Rv   Rx   R   s   Unrecognized output format: {}(   R#   R4   RH   R(   R9   R8   Rk   R+   (   t   arrRŽ   t   output_formatRJ   Rt   R0   Ro   Rp   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR     s(    >c         ` s£  t  ˆ  | ƒ \ } } } t | | ƒ } t | | ƒ } g  | D] }	 |	 j ^ q= }
 t t | ƒ t |
 ƒ | ƒ } g  } xt | ƒ D]} g  t d d t	 | ƒ ƒD] } d j
 | ƒ ^ q¢ } ‡  f d †  | Dƒ } xa t | | | ƒ D]M \ } } } t ˆ  | d | j d | ƒ} x | D] } | | | | <qWqæ Wx* | j ƒ  D] \ } } t | ƒ | | <qDW| j | ƒ | j d | ƒ ‰  qƒ W| j ˆ  ƒ | j ƒ  | S(   sk  Subband shapes for a multilevel nD discrete wavelet transform.

    Parameters
    ----------
    shape : sequence of ints
        The shape of the data to be transformed.
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use.  This can also be a tuple containing a wavelet to
        apply along each axis in `axes`.
    mode : str or tuple of str, optional
        Signal extension mode, see Modes (default: 'symmetric').  This can
        also be a tuple containing a mode to apply along each axis in `axes`.
    level : int, optional
        Decomposition level (must be >= 0). If level is None (default) then it
        will be calculated using the `dwt_max_level` function.
    axes : sequence of ints, optional
        Axes over which to compute the DWT. Axes may not be repeated. The
        default is None, which means transform all axes
        (``axes = range(data.ndim)``).

    Returns
    -------
    shapes : [cAn, {details_level_n}, ... {details_level_1}] : list
        Coefficients shape list.  Mirrors the output of `wavedecn`, except
        it contains only the shapes of the coefficient arrays rather than the
        arrays themselves.

    Examples
    --------
    >>> import pywt
    >>> pywt.wavedecn_shapes((64, 32), wavelet='db2', level=3, axes=(0, ))
    [(10, 32), {'d': (10, 32)}, {'d': (18, 32)}, {'d': (33, 32)}]
    Rv   t   repeatt    c         ` s   i  |  ] } t  ˆ  ƒ | “ q S(    (   RF   (   RD   Ro   (   R5   (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys
   <dictcomp>‰  s   	 t
   filter_lenR=   RA   (   R_   R   R   R7   R2   R%   t   maxR8   R   RH   t   joinR&   R
   Rk   RG   R9   R`   R:   (   R5   R<   R=   R.   RN   R]   R^   RQ   t   modesRR   RS   t   shapesRB   t   ct   detail_keyst
   new_shapesR>   t   wavR/   Ro   Rp   (    (   R5   s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   ]  s(    "4"
c         C` sz   d „  } | |  d ƒ } xZ |  d D]N } xE | j  ƒ  D]7 \ } } | d k r^ t d ƒ ‚ n  | | | ƒ 7} q7 Wq$ W| S(   s½  Compute the total number of wavedecn coefficients.

    Parameters
    ----------
    shapes : list of coefficient shapes
        A set of coefficient shapes as returned by `wavedecn_shapes`.
        Alternatively, the user can specify a set of coefficients as returned
        by `wavedecn`.

    Returns
    -------
    size : int
        The total number of coefficients.

    Examples
    --------
    >>> import pywt
    >>> data_shape = (64, 32)
    >>> shapes = pywt.wavedecn_shapes(data_shape, 'db2', mode='periodization')
    >>> pywt.wavedecn_size(shapes)
    2048
    >>> coeffs = pywt.wavedecn(np.ones(data_shape), 'sym4', mode='symmetric')
    >>> pywt.wavedecn_size(coeffs)
    3087
    c         S` s*   t  |  t j ƒ r |  j St j |  ƒ Sd S(   s@   Size corresponding to `x` as either a shape tuple or an ndarray.N(   RE   R#   R   Rz   R|   (   t   x(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _size±  s    i    i   s4   Setting coefficient arrays to None is not supported.N(   Rk   R'   R(   (   Rœ   R¢   R~   R0   Ro   Rp   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   —  s    	c   	      C` se   t  |  | ƒ \ } } } t | | ƒ } g  t | | ƒ D] \ } } t | | j ƒ ^ q7 } t | ƒ S(   s9  Compute the maximum level of decomposition for n-dimensional data.

    This returns the maximum number of levels of decomposition suitable for use
    with `wavedec`, `wavedec2` or `wavedecn`.

    Parameters
    ----------
    shape : sequence of ints
        Input data shape.
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use. This can also be a tuple containing a wavelet to
        apply along each axis in `axes`.
    axes : sequence of ints, optional
        Axes over which to compute the DWT. Axes may not be repeated.

    Returns
    -------
    level : int
        Maximum level.

    Notes
    -----
    The level returned is the smallest `dwt_max_level` over all axes.

    Examples
    --------
    >>> import pywt
    >>> pywt.dwtn_max_level((64, 32), 'db2')
    3
    (   R_   R   R&   R   R7   R%   (	   R5   R<   RN   R]   R^   RQ   Rt   R    t
   max_levels(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   Á  s
     1c         C` sÖ  t  |  | ƒ \ }  } } } |  d } | j } t |  ƒ d k rb | j ƒ  t | ƒ g | j g f St |  ƒ } t j | f d | j	 ƒ} t | ƒ } | j ƒ  | | <g  }	 g  }
 |	 j
 | ƒ |
 j
 |  d j ƒ |  d } | } xä | D]Ü } |	 j
 i  ƒ |
 j
 i  ƒ t j g  | j ƒ  D] } | d k ^ qƒ rFt d ƒ ‚ n  t | j ƒ  ƒ } xj | D]b } | | } t | | | j ƒ } | | j 7} | j ƒ  | | <| |	 d | <| j |
 d | <q_Wqé W| |	 |
 f S(   s  Ravel a set of multilevel wavelet coefficients into a single 1D array.

    Parameters
    ----------
    coeffs : array-like
        A list of multilevel wavelet coefficients as returned by
        `wavedec`, `wavedec2` or `wavedecn`.
    axes : sequence of ints, optional
        Axes over which the DWT that created `coeffs` was performed. The
        default value of None corresponds to all axes.

    Returns
    -------
    coeff_arr : array-like
        Wavelet transform coefficient array. All coefficients have been
        concatenated into a single array.
    coeff_slices : list
        List of slices corresponding to each coefficient. As a 2D example,
        ``coeff_arr[coeff_slices[1]['dd']]`` would extract the first level
        detail coefficients from `coeff_arr`.
    coeff_shapes : list
        List of shapes corresponding to each coefficient. For example, in 2D,
        ``coeff_shapes[1]['dd']`` would contain the original shape of the first
        level detail coefficients array.

    See Also
    --------
    unravel_coeffs : the inverse of ravel_coeffs

    Examples
    --------
    >>> import pywt
    >>> cam = pywt.data.camera()
    >>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
    >>> arr, coeff_slices, coeff_shapes = pywt.ravel_coeffs(coeffs)

    i    i   R…   s6   coeffs_to_array does not support missing coefficients.iÿÿÿÿN(   R„   Rz   RH   t   ravelRC   R5   R   R#   R†   R…   R9   Rc   Rˆ   R'   R(   t   sortedR‚   (   RJ   RN   RL   R^   RŠ   t   a_sizet   arr_sizeRŒ   t   a_sliceRŽ   t   coeff_shapesRK   t   offsetR   R0   R‚   R   t   sl(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   ì  s:    &
	"
.
c         C` sÒ  t  j |  ƒ }  g  } t | ƒ d k r6 t d ƒ ‚ nj t | ƒ d k rW t d ƒ ‚ nI t | ƒ t | ƒ k r~ t d ƒ ‚ n" | j |  | d j | d ƒ ƒ x+t d t | ƒ ƒ D]} | | } | | } | d k rú |  | d j | d ƒ } nÃ | d k rW|  | d	 j | d	 ƒ |  | d
 j | d
 ƒ |  | d j | d ƒ f } nf | d k r¨i  } xQ | | j ƒ  D]' \ }	 }
 |  |
 j | |	 ƒ | |	 <qzWn t d j | ƒ ƒ ‚ | j | ƒ q¶ W| S(   sÈ  Unravel a raveled array of multilevel wavelet coefficients.

    Parameters
    ----------
    arr : array-like
        An array containing all wavelet coefficients. This should have been
        generated by applying `ravel_coeffs` to the output of `wavedec`,
        `wavedec2` or `wavedecn`.
    coeff_slices : list of tuples
        List of slices corresponding to each coefficient as obtained from
        `ravel_coeffs`.
    coeff_shapes : list of tuples
        List of shapes corresponding to each coefficient as obtained from
        `ravel_coeffs`.
    output_format : {'wavedec', 'wavedec2', 'wavedecn'}, optional
        Make the form of the unraveled coefficients compatible with this type
        of multilevel transform. The default is 'wavedecn'.

    Returns
    -------
    coeffs: list
        List of wavelet transform coefficients. The specific format of the list
        elements is determined by `output_format`.

    See Also
    --------
    ravel_coeffs : the inverse of unravel_coeffs

    Examples
    --------
    >>> import pywt
    >>> from numpy.testing import assert_array_almost_equal
    >>> cam = pywt.data.camera()
    >>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
    >>> arr, coeff_slices, coeff_shapes = pywt.ravel_coeffs(coeffs)
    >>> coeffs_from_arr = pywt.unravel_coeffs(arr, coeff_slices, coeff_shapes)
    >>> cam_recon = pywt.waverecn(coeffs_from_arr, wavelet='db2')
    >>> assert_array_almost_equal(cam, cam_recon)

    i    s    empty list of coefficient slicess    empty list of coefficient shapess1   coeff_shapes and coeff_slices have unequal lengthi   R   R0   R   Rw   Rv   Rx   R   s   Unrecognized output format: {}(	   R#   R4   RH   R(   R9   t   reshapeR8   Rk   R+   (   R”   RŽ   R©   R•   RJ   Rt   t
   slice_dictt
   shape_dictR0   Ro   Rp   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR   ?  s4    )"

!"c         C` ss   t  | ƒ t  t | ƒ ƒ k r- t d ƒ ‚ n  y" g  | D] } |  j | ^ q7 Wn t k
 rn t d ƒ ‚ n Xd S(   s-   Axes checks common to fswavedecn, fswaverecn.s-   The axes passed to fswavedecn must be unique.s!   Axis greater than data dimensionsN(   RH   RM   R(   R5   R6   (   R;   RN   RO   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _check_fswavedecn_axesˆ  s    "c           B` sþ   e  Z d  Z d „  Z e d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z d „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   so  Object representing fully separable wavelet transform coefficients.

    Parameters
    ----------
    coeffs : ndarray
        The coefficient array.
    coeff_slices : list
        List of slices corresponding to each detail or approximation
        coefficient array.
    wavelets : list of pywt.DiscreteWavelet objects
        The wavelets used.  Will be a list with length equal to
        ``len(axes)``.
    mode_enums : list of int
        The border modes used.  Will be a list with length equal to
        ``len(axes)``.
    axes : tuple of int
        The set of axes over which the transform was performed.

    c         C` s   | |  _  | |  _ | |  _ t j d „  | Dƒ ƒ sC t d ƒ ‚ n  | |  _ t j d „  | Dƒ ƒ st t d ƒ ‚ n  | |  _ d  S(   Nc         s` s   |  ] } t  | t ƒ Vq d  S(   N(   RE   R   (   RD   RR   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>«  s    s*   wavelets must contain pywt.Wavelet objectsc         s` s   |  ] } t  | t ƒ Vq d  S(   N(   RE   t   int(   RD   t   m(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>¯  s    s   mode_enums must be integers(   t   _coeffst   _coeff_slicest   _axesR#   RZ   R(   t	   _waveletst   _mode_enums(   t   selfRJ   RŽ   RQ   t
   mode_enumsRN   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   __init__¦  s    				c         C` s   |  j  S(   s6   ndarray: All coefficients stacked into a single array.(   R²   (   R·   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRJ   ´  s    c         C` s1   | j  |  j j  k r$ t d ƒ ‚ n  | |  _ d  S(   Ns?   new coefficient array must match the existing coefficient shape(   R5   R²   R(   (   R·   R   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRJ   ¹  s    c         C` s   |  j  S(   s!   List: List of coefficient slices.(   R³   (   R·   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRŽ   À  s    c         C` s
   |  j  j S(   s   int: Number of data dimensions.(   RJ   RL   (   R·   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRL   Å  s    c         C` s   t  |  j ƒ S(   s    int: Number of axes transformed.(   RH   RN   (   R·   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR^   Ê  s    c         C` s   |  j  S(   s8   List of str: The axes the transform was performed along.(   R´   (   R·   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRN   Ï  s    c         C` s$   g  |  j  D] } t | ƒ d ^ q
 S(   sA   List of int: Levels of decomposition along each transformed axis.i   (   RŽ   RH   (   R·   R/   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   levelsÔ  s    c         C` s   |  j  S(   s@   List of pywt.DiscreteWavelet: wavelet for each transformed axis.(   Rµ   (   R·   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRQ   Ù  s    c         C` s   g  |  j  D] } | j ^ q
 S(   s@   List of pywt.DiscreteWavelet: wavelet for each transformed axis.(   Rµ   t   name(   R·   RR   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   wavelet_namesÞ  s    c         C` s1   d „  t  j Dƒ } g  |  j D] } | | ^ q S(   s>   List of str: The border mode used along each transformed axis.c         S` s"   i  |  ] } | t  t | ƒ “ q S(    (   t   getattrR   (   RD   R=   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys
   <dictcomp>æ  s   	(   R   R›   R¶   (   R·   t
   names_dictR±   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR›   ã  s    c         C` sd   t  d  ƒ g |  j } xA t t |  j | ƒ ƒ D]' \ } \ } } |  j | | | | <q/ Wt | ƒ S(   N(   RC   R'   RL   Rm   R&   RN   RŽ   RG   (   R·   Rº   R«   Rt   RO   t   lev(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _get_coef_slê  s    +c         C` s!   |  j  d |  j ƒ } |  j | S(   s(   ndarray: The approximation coefficients.i    (   i    (   RÀ   RL   R²   (   R·   R«   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   approxð  s    c         C` sO   |  j  d |  j ƒ } |  j | j | j k r> t d ƒ ‚ n  | |  j | <d  S(   Ni    s7   x does not match the shape of the requested coefficient(   i    (   RÀ   RL   R²   R5   R(   (   R·   RA   R«   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRÁ   ö  s
    c         C` s0  t  | ƒ } t | ƒ t |  j ƒ k r6 t d ƒ ‚ n  t j g  | D] } t | t j ƒ ^ qC ƒ s¯ t j	 t j
 | ƒ d d k ƒ s¯ t j	 g  | D] } | d k  ^ q” ƒ r¾ t d ƒ ‚ n  t  g  | D] } t | ƒ ^ qÈ ƒ } t j	 g  t | |  j ƒ D] \ } } | | k ^ qü ƒ r,t d ƒ ‚ n  d  S(   Ns0   levels must match the number of transformed axesi   i    s.   Index must be a tuple of non-negative integerss8   Specified indices exceed the number of transform levels.(   RG   RH   RN   R(   R#   RZ   RE   t   numberst   NumberRc   R4   R°   R&   Rº   (   R·   Rº   R¿   t   maxlev(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   _validate_indexþ  s    /"(%:c         C` s'   |  j  | ƒ |  j | ƒ } |  j | S(   sÉ   Retrieve a coefficient subband.

        Parameters
        ----------
        levels : tuple of int
            The number of degrees of decomposition along each transformed
            axis.
        (   RÅ   RÀ   R²   (   R·   Rº   R«   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   __getitem__  s    	c         C` s   |  j  | ƒ |  j | ƒ } |  j | j } |  j | j | j k rT t d ƒ ‚ n  | j | k r| t j d j | ƒ ƒ n  | |  j | <d S(   sd  Assign values to a coefficient subband.

        Parameters
        ----------
        levels : tuple of int
            The number of degrees of decomposition along each transformed
            axis.
        x : ndarray
            The data corresponding to assign. It must match the expected
            shape and dtype of the specified subband.
        s7   x does not match the shape of the requested coefficients9   dtype mismatch:  converting the provided array todtype {}N(	   RÅ   RÀ   R²   R…   R5   R(   R)   R*   R+   (   R·   Rº   R¡   R«   t   current_dtype(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   __setitem__  s    c         C` sC   t  t d „  |  j Dƒ Œ  ƒ } | j d t |  j ƒ ƒ t | ƒ S(   s£   Return a list of all detail coefficient keys.

        Returns
        -------
        keys : list of str
            List of all detail coefficient keys.
        c         s` s   |  ] } t  | d  ƒ Vq d S(   i   N(   R8   (   RD   t   l(    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pys	   <genexpr>>  s    i    (   i    (   RF   R   Rº   t   removeRH   RN   R¥   (   R·   R‚   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyRž   6  s    (   t   __name__t
   __module__t   __doc__R¹   t   propertyRJ   t   setterRŽ   RL   R^   RN   Rº   RQ   R¼   R›   RÀ   RÁ   RÅ   RÆ   RÈ   Rž   (    (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR"   ’  s&   					c      
   C` sÐ  t  j |  ƒ }  | d k r6 t t  j |  j ƒ ƒ } n  t |  | ƒ | d k s^ t  j | ƒ rt | g t | ƒ } n  t | ƒ t | ƒ k r› t	 d ƒ ‚ n  t
 | | ƒ } t | | ƒ } t d ƒ g t | ƒ } |  } xß t t | | | | ƒ ƒ D]Â \ }	 \ }
 } } } t | | d | d | d |
 ƒ} g  | D] } | j |
 ^ q4} t  j d g | ƒ } g  t t | ƒ ƒ D]! } t | | | | d ƒ ^ qv| |	 <t  j | d |
 ƒ} qô Wt | | | | | ƒ S(   s  Fully Separable Wavelet Decomposition.

    This is a variant of the multilevel discrete wavelet transform where all
    levels of decomposition are performed along a single axis prior to moving
    onto the next axis.  Unlike in ``wavedecn``, the number of levels of
    decomposition are not required to be the same along each axis which can be
    a benefit for anisotropic data.

    Parameters
    ----------
    data: array_like
        Input data
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use.  This can also be a tuple containing a wavelet to
        apply along each axis in ``axes``.
    mode : str or tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric').  This can
        also be a tuple containing a mode to apply along each axis in ``axes``.
    levels : int or sequence of ints, optional
        Decomposition levels along each axis (must be >= 0). If an integer is
        provided, the same number of levels are used for all axes. If
        ``levels`` is None (default), `dwt_max_level` will be used to compute
        the maximum number of levels possible for each axis.
    axes : sequence of ints, optional
        Axes over which to compute the transform. Axes may not be repeated. The
        default is to transform along all axes.

    Returns
    -------
    fswavedecn_result : FswavedecnResult object
        Contains the wavelet coefficients, slice objects to allow obtaining
        the coefficients per detail or approximation level, and more.
        See `FswavedecnResult` for details.

    Examples
    --------
    >>> from pywt import fswavedecn
    >>> fs_result = fswavedecn(np.ones((32, 32)), 'sym2', levels=(1, 3))
    >>> print(fs_result.detail_keys())
    [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3)]
    >>> approx_coeffs = fs_result.approx
    >>> detail_1_2 = fs_result[(1, 2)]


    Notes
    -----
    This transformation has been variously referred to as the (fully) separable
    wavelet transform (e.g. refs [1]_, [3]_), the tensor-product wavelet
    ([2]_) or the hyperbolic wavelet transform ([4]_).  It is well suited to
    data with anisotropic smoothness.

    In [2]_ it was demonstrated that fully separable transform performs at
    least as well as the DWT for image compression.  Computation time is a
    factor 2 larger than that for the DWT.

    See Also
    --------
    fswaverecn : inverse of fswavedecn

    References
    ----------
    .. [1] PH Westerink. Subband Coding of Images. Ph.D. dissertation, Dept.
       Elect. Eng., Inf. Theory Group, Delft Univ. Technol., Delft, The
       Netherlands, 1989.  (see Section 2.3)
       http://resolver.tudelft.nl/uuid:a4d195c3-1f89-4d66-913d-db9af0969509

    .. [2] CP Rosiene and TQ Nguyen. Tensor-product wavelet vs. Mallat
       decomposition: A comparative analysis, in Proc. IEEE Int. Symp.
       Circuits and Systems, Orlando, FL, Jun. 1999, pp. 431-434.

    .. [3] V Velisavljevic, B Beferull-Lozano, M Vetterli and PL Dragotti.
       Directionlets: Anisotropic Multidirectional Representation With
       Separable Filtering. IEEE Transactions on Image Processing, Vol. 15,
       No. 7, July 2006.

    .. [4] RA DeVore, SV Konyagin and VN Temlyakov. "Hyperbolic wavelet
       approximation," Constr. Approx. 14 (1998), 1-26.
    s-   levels must match the length of the axes listR=   R.   R>   i    i   N(   R#   R4   R'   RG   Rƒ   RL   R¯   R$   RH   R(   R   R   RC   Rm   R&   R   R5   t   cumsumR8   t   concatenateR"   (   R;   R<   R=   Rº   RN   R›   RQ   RŽ   t
   coeffs_arrt   ax_countRO   R¿   R    RJ   R   t   c_shapest	   c_offsetsR0   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR    C  s(    O.! >c         C` s  |  j  } |  j } |  j } |  j } |  j } t | | ƒ t | ƒ t | ƒ k ra t d ƒ ‚ n  | } t d ƒ g | j
 } x– t t | | | ƒ ƒ D]| \ } \ }	 }
 } g  } x3 | | D]' } | | |	 <| j | t | ƒ ƒ q¼ Wt d ƒ | |	 <t | |
 d | d |	 ƒ} q– W| S(   s±  Fully Separable Inverse Wavelet Reconstruction.

    Parameters
    ----------
    fswavedecn_result : FswavedecnResult object
        FswavedecnResult object from ``fswavedecn``.

    Returns
    -------
    reconstructed : ndarray
        Array of reconstructed data.

    Notes
    -----
    This transformation has been variously referred to as the (fully) separable
    wavelet transform (e.g. refs [1]_, [3]_), the tensor-product wavelet
    ([2]_) or the hyperbolic wavelet transform ([4]_).  It is well suited to
    data with anisotropic smoothness.

    In [2]_ it was demonstrated that the fully separable transform performs at
    least as well as the DWT for image compression. Computation time is a
    factor 2 larger than that for the DWT.

    See Also
    --------
    fswavedecn : inverse of fswaverecn

    References
    ----------
    .. [1] PH Westerink. Subband Coding of Images. Ph.D. dissertation, Dept.
       Elect. Eng., Inf. Theory Group, Delft Univ. Technol., Delft, The
       Netherlands, 1989.  (see Section 2.3)
       http://resolver.tudelft.nl/uuid:a4d195c3-1f89-4d66-913d-db9af0969509

    .. [2] CP Rosiene and TQ Nguyen. Tensor-product wavelet vs. Mallat
       decomposition: A comparative analysis, in Proc. IEEE Int. Symp.
       Circuits and Systems, Orlando, FL, Jun. 1999, pp. 431-434.

    .. [3] V Velisavljevic, B Beferull-Lozano, M Vetterli and PL Dragotti.
       Directionlets: Anisotropic Multidirectional Representation With
       Separable Filtering. IEEE Transactions on Image Processing, Vol. 15,
       No. 7, July 2006.

    .. [4] RA DeVore, SV Konyagin and VN Temlyakov. "Hyperbolic wavelet
       approximation," Constr. Approx. 14 (1998), 1-26.
    s   dimension mismatchR=   R>   N(   RJ   RŽ   RN   R›   RQ   R¯   RH   R(   RC   R'   RL   Rm   R&   R9   RG   R   (   t   fswavedecn_resultRÒ   RŽ   RN   R›   RQ   R”   t   cslRÓ   RO   R    R=   RJ   R«   (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyR!   ³  s$    /					.
(   iþÿÿÿiÿÿÿÿ(   iþÿÿÿiÿÿÿÿ(:   RÍ   t
   __future__R    R   R   RÂ   R)   t	   itertoolsR   R   t   numpyR#   t   _extensions._pywtR   R   t   _extensions._dwtR   t   _dwtR   R	   R
   t	   _multidimR   R   R   R   R   t   _utilsR   R   R   t   __all__R2   R'   R   R   R   R   R_   R   Ri   R   Ru   Ry   R€   R„   R   R   R   R   R   R   R   R¯   t   objectR"   R    R!   (    (    (    s/   lib/python2.7/site-packages/pywt/_multilevel.pyt   <module>	   sN   (		>ALN	U	p				.uX:	*+SI	
±p