
    i,                     z    d Z ddlmZ ddlZddlmZ ddlmZm	Z	 ddl
mZmZmZ g dZdd	Zdd
ZddZd ZddZy)zP
2D and nD Discrete Wavelet Transforms and Inverse Discrete Wavelet Transforms.
    )productN   )_have_c99_complex)dwt_axis	idwt_axis)	AxisError_modes_per_axis_wavelets_per_axis)dwt2idwt2dwtnidwtnc                 "   t        |      }t        j                  |       } t        |      dk7  rt	        d      | j
                  t        t        j                  |            k  rt	        d      t        | |||      }|d   |d   |d   |d   ffS )a  
    2D Discrete Wavelet Transform.

    Parameters
    ----------
    data : array_like
        2D array with 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 strings, optional
        Signal extension mode, see :ref:`Modes <ref-modes>`. This can
        also be a tuple of modes specifying the mode to use on each axis in
        ``axes``.
    axes : 2-tuple of ints, optional
        Axes over which to compute the DWT. Repeated elements mean the DWT will
        be performed multiple times along these axes.

    Returns
    -------
    (cA, (cH, cV, cD)) : tuple
        Approximation, horizontal detail, vertical detail and diagonal
        detail coefficients respectively.  Horizontal refers to array axis 0
        (or ``axes[0]`` for user-specified ``axes``).

    Examples
    --------
    >>> import numpy as np
    >>> import pywt
    >>> data = np.ones((4,4), dtype=np.float64)
    >>> coeffs = pywt.dwt2(data, 'haar')
    >>> cA, (cH, cV, cD) = coeffs
    >>> cA
    array([[ 2.,  2.],
           [ 2.,  2.]])
    >>> cV
    array([[ 0.,  0.],
           [ 0.,  0.]])

       Expected 2 axesz8Input array has fewer dimensions than the specified axesaadaaddd)tuplenpasarraylen
ValueErrorndimuniquer   )datawaveletmodeaxescoefss        J/var/www/html/BatchJob/venv/lib/python3.12/site-packages/pywt/_multidim.pyr   r      s    R ;D::dD
4yA~*++yy3ryy''   ! 	! wd+E;teDk5;???    c                     | \  }\  }}}t        |      }t        |      dk7  rt        d      ||||d} t        | |||      S )a  
    2-D Inverse Discrete Wavelet Transform.

    Reconstructs data from coefficient arrays.

    Parameters
    ----------
    coeffs : tuple
        (cA, (cH, cV, cD)) A tuple with approximation coefficients and three
        details coefficients 2D arrays like from ``dwt2``.  If any of these
        components are set to ``None``, it will be treated as zeros.
    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 strings, optional
        Signal extension mode, see :ref:`Modes <ref-modes>`. This can
        also be a tuple of modes specifying the mode to use on each axis in
        ``axes``.
    axes : 2-tuple of ints, optional
        Axes over which to compute the IDWT. Repeated elements mean the IDWT
        will be performed multiple times along these axes.

    Examples
    --------
    >>> import numpy as np
    >>> import pywt
    >>> data = np.array([[1,2], [3,4]], dtype=np.float64)
    >>> coeffs = pywt.dwt2(data, 'haar')
    >>> pywt.idwt2(coeffs, 'haar')
    array([[ 1.,  2.],
           [ 3.,  4.]])

    r   r   )r   r   r   r   )r   r   r   r   )coeffsr   r   r    LLHLLHHHs           r"   r   r   K   sT    F BR;D
4yA~*++b"5F$--r#   c                    t        j                  |       } t        sbt        j                  |       rMt	        | j
                  |||      }t	        | j                  |||      }|D ci c]  }|||   d||   z  z    c}S | j                  t        j                  d      k(  rt        d      | j                  dk  rt        d      |t        | j                        }|D cg c]  }|dk  r|| j                  z   n| }}t        ||      }t        ||      }	d| fg}
t        ||	|      D ]B  \  }}}g }|
D ]3  \  }}t        ||||      \  }}|j!                  |dz   |f|d	z   |fg       5 |}
D t#        |
      S c c}w c c}w )
aO  
    Single-level n-dimensional Discrete Wavelet Transform.

    Parameters
    ----------
    data : array_like
        n-dimensional array with 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 string, optional
        Signal extension mode used in the decomposition,
        see :ref:`Modes <ref-modes>`. This can also be a tuple of modes
        specifying the mode to use on each axis in ``axes``.
    axes : sequence of ints, optional
        Axes over which to compute the DWT. Repeated elements mean the DWT will
        be performed multiple times along these axes. A value of ``None`` (the
        default) selects all axes.

        Axes may be repeated, but information about the original size may be
        lost if it is not divisible by ``2 ** nrepeats``. The reconstruction
        will be larger, with additional values derived according to the
        ``mode`` parameter. ``pywt.wavedecn`` should be used for multilevel
        decomposition.

    Returns
    -------
    coeffs : dict
        Results are arranged in a dictionary, where key specifies
        the transform type on each dimension and value is a n-dimensional
        coefficients array.

        For example, for a 2D case the result will look something like this::

            {'aa': <coeffs>  # A(LL) - approx. on 1st dim, approx. on 2nd dim
             'ad': <coeffs>  # V(LH) - approx. on 1st dim, det. on 2nd dim
             'da': <coeffs>  # H(HL) - det. on 1st dim, approx. on 2nd dim
             'dd': <coeffs>  # D(HH) - det. on 1st dim, det. on 2nd dim
            }

        For user-specified ``axes``, the order of the characters in the
        dictionary keys map to the specified ``axes``.

                  ?objectz"Input must be a numeric array-liker   zInput data must be at least 1Dr    ad)r   r   r   iscomplexobjr   realimagdtype	TypeErrorr   r   ranger	   r
   zipr   extenddict)r   r   r   r    r1   r2   kr.   modeswaveletsr%   axiswav
new_coeffssubbandxcAcDs                     r"   r   r   w   s   Z ::dD!6DIIwd3DIIwd3378a47R$q'\))88zzRXXh''<==yy1}9::|TYY378aQUA		M)8D8D$'E!'40H4j\FtXu5 c4
  	5JGQadD1FB#r2 '#r24 5	5  <- 9 9s   %E9 E>c                 &   | j                         D cg c]
  \  }}|	| }}}|rt        d| d      | j                         D cg c]  \  }}t        |      t        d      k  s|  }}}|rt        d| d      | D cg c]  }t        |       }}t        t	        j
                  |            dkD  rt        d      | j                         D ci c]  \  }}|t	        j                  |       c}}S c c}}w c c}}w c c}w c c}}w )Nz4The following detail coefficients were set to None:
zr
For multilevel transforms, rather than setting
	coeffs[key] = None
use
	coeffs[key] = np.zeros_like(coeffs[key])
r   zLThe following invalid keys were found in the detail coefficient dictionary: .r   z4All detail coefficient names must have equal length.)itemsr   setr   r   r   r   )r%   r9   vmissing_keysinvalid_keyskey_lengthss         r"   _fix_coeffsrK      s   "(,,.>$!QAIA>L>Cn ;;< 	< #),,. -$!QA#d)+  -L -''3nA78 	8 $**a3q6*K*
299[!"Q&BD 	D *08AArzz!}88- ?- +
 9s   
C<C<
#DD Dc                 h   | j                         D ci c]  \  }}|	|| } }}| j                         D ci c]  \  }}|	|| } }}t        |       } t        st        d | j	                         D              rz| j                         D ci c]  \  }}||j
                   }}}| j                         D ci c]  \  }}||j                   }}}t        ||||      dt        ||||      z  z   S t        d | D              	 fd| j                         D        }t        |      t        fd|D              rt        d      |t              }}	nt              }	|D 
cg c]  }
|
d	k  r|
|	z   n|
 }}
t        ||      }t        ||      }t!        t#        t%        t'        |||                        D ]-  \  }\  }}}|d	k  s||	k\  rt)        d
      i }t+        d|      D cg c]  }dj-                  |       }}|D ]  }| j/                  |dz   d      }| j/                  |dz   d      }|||j0                  |j0                  k7  r|j0                  j2                  dk(  s|j0                  j2                  dk(  rt4        j6                  }nt4        j8                  }t5        j:                  ||      }t5        j:                  ||      }t=        |||||      ||<    |} 0 | d   S c c}}w c c}}w c c}}w c c}}w # t        $ r t        d      w xY wc c}
w c c}w )aV  
    Single-level n-dimensional Inverse Discrete Wavelet Transform.

    Parameters
    ----------
    coeffs: dict
        Dictionary as in output of ``dwtn``. Missing or ``None`` items
        will be treated as zeros.
    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 list of string, optional
        Signal extension mode used in the decomposition,
        see :ref:`Modes <ref-modes>`. This can also be a tuple of modes
        specifying the mode to use on each axis in ``axes``.
    axes : sequence of ints, optional
        Axes over which to compute the IDWT. Repeated elements mean the IDWT
        will be performed multiple times along these axes. A value of ``None``
        (the default) selects all axes.

        For the most accurate reconstruction, the axes should be provided in
        the same order as they were provided to ``dwtn``.

    Returns
    -------
    data: ndarray
        Original signal reconstructed from input data.

    Nc              3   F   K   | ]  }t        j                  |        y wN)r   r0   ).0rG   s     r"   	<genexpr>zidwtn.<locals>.<genexpr>  s     <q"<s   !r+   c              3   2   K   | ]  }t        |        y wrN   )r   )rO   keys     r"   rP   zidwtn.<locals>.<genexpr>  s     4cS4s   c              3   \   K   | ]#  \  }}|t        |      k(  r|j                   % y wrN   )r   shape)rO   r9   rG   ndim_transforms      r"   rP   zidwtn.<locals>.<genexpr>  s2      GDAq=SV~-E  Gs   ),z8`coeffs` must contain at least one non-null wavelet bandc              3   (   K   | ]	  }|k7    y wrN    )rO   scoeff_shapes     r"   rP   zidwtn.<locals>.<genexpr>  s     
21
2s   z,`coeffs` must all be of equal size (or None)r   z!Axis greater than data dimensionsr   )repeatr-   r.   r/   c)r3   )rE   rK   r   anyvaluesr1   r2   r   maxnextStopIterationr   r5   r   r	   r
   reversedlist	enumerater6   r   r   joingetr3   kindr   
complex128float64r   r   )r%   r   r   r    r9   rG   real_coeffsimag_coeffscoeff_shapesr   r.   r:   r;   
key_lengthr<   r=   r>   coefnew_keysrR   LHr3   rY   rU   s                          @@r"   r   r      s   @  &||~?tq!ad?F?  &||~?tq!ad?F?  F<FMMO<<-3\\^<TQq!&&y<<-3\\^<TQq!&&y<<k7D$7U;t<<= 	> 4V44N!GFLLN G<( 
2\
22GHH|^$;.23AAH1$3D3D$'E!'40H)13tXu567*9 %
%T3!8tt|?@@
.5d:.NOdBGGDMOO 	?C

39d+A

39d+A}77agg%ww||s*aggllc.A " "



1E2A

1E2A'1c4>JsO	? +. ":y @ @ =<  !   ! 	!! 4 Ps9   
K:K:
L L L L$L /L*5L/L')	symmetric))rq   N)__doc__	itertoolsr   numpyr   _c99_configr   _extensions._dwtr   r   _utilsr   r	   r
   __all__r   r   r   rK   r   rW   r#   r"   <module>r{      sB   
   * 1 B B
,2@j).XGT94\r#   