
     e8                         d dl mZmZ d dlZddlmZmZmZm	Z	m
Z
mZmZ ddlmZmZmZmZmZmZmZ ddlmZmZ g dZ	 	 ddZd Z	 	 ddZd Z	 	 ddZd ZdS )    )partialreduceN   )_prep_axes_wavedecnwavedecwavedec2wavedecnwaverecwaverec2waverecn)iswtiswt2iswtnswtswt2swt_max_levelswtn)_modes_per_axis_wavelets_per_axis)mramra2mranimraimra2imranr   periodizationc                 <   |dk    rQ|dk    rt          d          t          ||d          }t          t          f|dd|}t          t          fi |}d}	nc|dk    r;t          |||          }t          t
          fd	|i|}t          t          fi |}d
}	n"t          d                    |                     ||           }
g }t          |
          }|	r!t          j
        |
d                   }|g|z  }nd |
D             }t          |          D ]}|
|         ||<    ||          }|j        | j        k    r$|t          d | j        D                                }|                    |           |	r|||<   it          j
        ||                   ||<   |S )a  Forward 1D multiresolution analysis.

    It is a projection onto the wavelet subspaces.

    Parameters
    ----------
    data: array_like
        Input data
    wavelet : Wavelet object or name string
        Wavelet to use
    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. Currently only available when ``transform='dwt'``.
    transform : {'dwt', 'swt'}
        Whether to use the DWT or SWT for the transforms.
    mode : str, optional
        Signal extension mode, see `Modes` (default: 'symmetric'). This option
        is only used when transform='dwt'.

    Returns
    -------
    [cAn, {details_level_n}, ... {details_level_1}] : list
        For more information, see the detailed description in `wavedec`

    See Also
    --------
    imra, swt

    Notes
    -----
    This is sometimes referred to as an additive decomposition because the
    inverse transform (``imra``) is just the sum of the coefficient arrays
    [1]_. The decomposition using ``transform='dwt'`` corresponds to section
    2.2 while that using an undecimated transform (``transform='swt'``) is
    described in section 3.2 and appendix A.

    This transform does not share the variance partition property of ``swt``
    with `norm=True`. It does however, result in coefficients that are
    temporally aligned regardless of the symmetry of the wavelet used.

    The redundancy of this transform is ``(level + 1)``.

    References
    ----------
    .. [1] Donald B. Percival and Harold O. Mofjeld. Analysis of Subtidal
        Coastal Sea Level Fluctuations Using Wavelets. Journal of the American
        Statistical Association Vol. 92, No. 439 (Sep., 1997), pp. 868-880.
        https://doi.org/10.2307/2965551

    r   r   0transform swt only supports mode='periodization'T)waveletaxisnormleveltrim_approxdwt)r    moder!   r$   Funrecognized transform: {}r   c                 6    g | ]}t          j        |          S  np
zeros_like.0cs     )lib/python3.11/site-packages/pywt/_mra.py
<listcomp>zmra.<locals>.<listcomp>_   s"    444Ar}Q444    c                 ,    g | ]}t          |          S r*   slicer/   szs     r1   r2   zmra.<locals>.<listcomp>i   s    <<<2U2YY<<<r3   )
ValueErrordictr   r   r   r   r
   formatlenr,   r-   rangeshapetupleappend)datar    r$   r!   	transformr'   kwargsforwardinverseis_swt
wav_coeffs
mra_coeffsncztmpjrecs                    r1   r   r      s   n E?""BD D DgDt<<<#GUGGGG$))&))	e		gDt<<<'999&99',,V,,5<<YGGHHHJJ	ZB 5M*Q-((ebj 544442YY + +AA gcll9
""e<<<<<==>C#  	+CFF]3q6**CFFr3   c                 $    t          d |           S )aW  Inverse 1D multiresolution analysis via summation.

    Parameters
    ----------
    mra_coeffs : list of ndarray
        Multiresolution analysis coefficients as returned by `mra`.

    Returns
    -------
    rec : ndarray
        The reconstructed signal.

    See Also
    --------
    mra

    References
    ----------
    .. [1] Donald B. Percival and Harold O. Mofjeld. Analysis of Subtidal
        Coastal Sea Level Fluctuations Using Wavelets. Journal of the American
        Statistical Association Vol. 92, No. 439 (Sep., 1997), pp. 868-880.
        https://doi.org/10.2307/2965551
    c                     | |z   S Nr*   )xys     r1   <lambda>zimra.<locals>.<lambda>   s
    q1u r3   )r   )rH   s    r1   r   r   t   s    0 $$j111r3   r   r   c                    |dk    ro|dk    rt          d          |t          d | j        D                       }t          ||d          }t	          t
          f|dd|}t	          t          fi |}na|d	k    r9t          |||
          }t	          t          fd|i|}t	          t          fi |}n"t          d	                    |                     ||           }	g }
t          |	          }t          j        |	d                   }|g}t          d|          D ]'}|                    d |	|         D                        (|	d         |d<    ||          }|j        | j        k    r$|t          d | j        D                                }|
                    |           ||d<   t          d|          D ]}g }t          d          D ]}||         |         }|	|         |         ||         |<    ||          }|j        | j        k    r$|t          d | j        D                                }|                    |           |||         |<   |
                    t          |                     |
S )a  Forward 2D multiresolution analysis.

    It is a projection onto wavelet subspaces.

    Parameters
    ----------
    data: array_like
        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`.
    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.
        Currently only available when ``transform='dwt2'``.
    transform : {'dwt2', 'swt2'}
        Whether to use the DWT or SWT for the transforms.
    mode : str or 2-tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric'). This option
        is only used when transform='dwt2'.

    Returns
    -------
    coeffs : list
        For more information, see the detailed description in `wavedec2`

    Notes
    -----
    This is sometimes referred to as an additive decomposition because the
    inverse transform (``imra2``) is just the sum of the coefficient arrays
    [1]_. The decomposition using ``transform='dwt'`` corresponds to section
    2.2 while that using an undecimated transform (``transform='swt'``) is
    described in section 3.2 and appendix A.

    This transform does not share the variance partition property of ``swt2``
    with `norm=True`. It does however, result in coefficients that are
    temporally aligned regardless of the symmetry of the wavelet used.

    The redundancy of this transform is ``3 * level + 1``.

    See Also
    --------
    imra2, swt2

    References
    ----------
    .. [1] Donald B. Percival and Harold O. Mofjeld. Analysis of Subtidal
        Coastal Sea Level Fluctuations Using Wavelets. Journal of the American
        Statistical Association Vol. 92, No. 439 (Sep., 1997), pp. 868-880.
        https://doi.org/10.2307/2965551
    r   r   r   Nc              3   4   K   | ]}t          |          V  d S rP   r   r/   ss     r1   	<genexpr>zmra2.<locals>.<genexpr>   *      ==Qa((======r3   Tr    axesr"   r#   dwt2r    r'   r^   r$   r(   r   r   c                 6    g | ]}t          j        |          S r*   r+   r.   s     r1   r2   zmra2.<locals>.<listcomp>   s"    <<<BM!$$<<<r3   c                 ,    g | ]}t          |          S r*   r5   r7   s     r1   r2   zmra2.<locals>.<listcomp>       888rr888r3      c                 ,    g | ]}t          |          S r*   r5   r7   s     r1   r2   zmra2.<locals>.<listcomp>        @ @ @rr @ @ @r3   )r9   minr>   r:   r   r   r   r   r   r;   r<   r,   r-   r=   r@   r?   )rA   r    r$   r^   rB   r'   rC   rD   rE   rG   rH   rI   rJ   rK   rL   rM   dcoeffsns                     r1   r   r      s   n F?""BD D D===$*=====EgDt<<<$HeHHHH%**6**	f		gDt<<<(::%:6::(--f--5<<YGGHHHJJ	ZB
jm$$A#C1b\\ > >

<<jm<<<==== ]CF
'#,,C
yDJ%88TZ88899:cCF1b\\ * *q 	 	AAq	A"1a(CF1I'#,,CyDJ&&% @ @TZ @ @ @AABNN3CF1II%..))))r3   c                     | d         }t          dt          |                     D ]%}t          d          D ]}|| |         |         z  }&|S )aN  Inverse 2D multiresolution analysis via summation.

    Parameters
    ----------
    mra_coeffs : list
        Multiresolution analysis coefficients as returned by `mra2`.

    Returns
    -------
    rec : ndarray
        The reconstructed signal.

    See Also
    --------
    mra2

    References
    ----------
    .. [1] Donald B. Percival and Harold O. Mofjeld. Analysis of Subtidal
        Coastal Sea Level Fluctuations Using Wavelets. Journal of the American
        Statistical Association Vol. 92, No. 439 (Sep., 1997), pp. 868-880.
        https://doi.org/10.2307/2965551
    r   r   rd   )r=   r<   )rH   rM   rL   ri   s       r1   r   r      s`    0 Q-C1c*oo&& $ $q 	$ 	$A:a=##CC	$Jr3   r   c                    t          | j        |          \  }}}t          ||          }|dk    ro|dk    rt          d          |t	          d | j        D                       }t          ||d          }	t          t          f|dd|	}
t          t          fi |	}nq|d	k    rIt          ||          }t          |||
          }	t          t          fd|i|	}
t          t          fi |	}n"t          d                    |                     |
|           }g }t          |          }t          j        |d                   }|g}t!          d|          D ]9}|                    d ||                                         D                        :|d         |d<    ||          }|j        | j        k    r$|t'          d | j        D                                }|                    |           ||d<   t!          d|          D ]}i }t)          ||                                                   }|D ]v}||         |         }||         |         ||         |<    ||          }|j        | j        k    r$|t'          d | j        D                                }|||<   |||         |<   w|                    |           |S )a  Forward nD multiresolution analysis.

    It is a projection onto the wavelet subspaces.

    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`.
    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 : tuple of ints, optional
        Axes over which to compute the DWT. Repeated elements are not allowed.
    transform : {'dwtn', 'swtn'}
        Whether to use the DWT or SWT for the transforms.
    mode : str or tuple of str, optional
        Signal extension mode, see `Modes` (default: 'symmetric'). This option
        is only used when transform='dwtn'.

    Returns
    -------
    coeffs : list
        For more information, see the detailed description in `wavedecn`.

    See Also
    --------
    imran, swtn

    Notes
    -----
    This is sometimes referred to as an additive decomposition because the
    inverse transform (``imran``) is just the sum of the coefficient arrays
    [1]_. The decomposition using ``transform='dwt'`` corresponds to section
    2.2 while that using an undecimated transform (``transform='swt'``) is
    described in section 3.2 and appendix A.

    This transform does not share the variance partition property of ``swtn``
    with `norm=True`. It does however, result in coefficients that are
    temporally aligned regardless of the symmetry of the wavelet used.

    The redundancy of this transform is ``(2**n - 1) * level + 1`` where ``n``
    corresponds to the number of axes transformed.

    References
    ----------
    .. [1] Donald B. Percival and Harold O. Mofjeld. Analysis of Subtidal
        Coastal Sea Level Fluctuations Using Wavelets. Journal of the American
        Statistical Association Vol. 92, No. 439 (Sep., 1997), pp. 868-880.
        https://doi.org/10.2307/2965551
    r   r   r   Nc              3   4   K   | ]}t          |          V  d S rP   rX   rY   s     r1   r[   zmran.<locals>.<genexpr>Z  r\   r3   Tr]   r#   dwtnr`   r$   r(   r   r   c                 >    i | ]\  }}|t          j        |          S r*   r+   )r/   kvs      r1   
<dictcomp>zmran.<locals>.<dictcomp>m  s(    JJJDAqAr}Q''JJJr3   c                 ,    g | ]}t          |          S r*   r5   r7   s     r1   r2   zmran.<locals>.<listcomp>u  rc   r3   c                 ,    g | ]}t          |          S r*   r5   r7   s     r1   r2   zmran.<locals>.<listcomp>  rf   r3   )r   r>   r   r9   rg   r:   r   r   r   r   r	   r   r;   r<   r,   r-   r=   r@   itemsr?   listkeys)rA   r    r$   r^   rB   r'   axes_shapesndim_transformwaveletsrC   rD   rE   modesrG   rH   rI   rJ   rK   rL   rM   rh   dkeysro   s                          r1   r   r     s   n )<DJ(M(M%D+~!'400HF?""BD D D===$*=====EhT===$HeHHHH%**6**	f		d++hU>>>(::%:6::(--f--5<<YGGHHHJJ	ZB
jm$$A#C1b\\ L L

JJJqM4G4G4I4IJJJKKKK ]CF
'#,,C
yDJ%88TZ88899:cCF1b\\ # #Z]''))** 	 	AAq	A"1a(CF1I '#,,CyDJ&&% @ @TZ @ @ @AABGAJCF1II'""""r3   c                     | d         }t          dt          |                     D ]'}| |                                         D ]
\  }}||z  }(|S )aN  Inverse nD multiresolution analysis via summation.

    Parameters
    ----------
    mra_coeffs : list
        Multiresolution analysis coefficients as returned by `mra2`.

    Returns
    -------
    rec : ndarray
        The reconstructed signal.

    See Also
    --------
    mran

    References
    ----------
    .. [1] Donald B. Percival and Harold O. Mofjeld. Analysis of Subtidal
        Coastal Sea Level Fluctuations Using Wavelets. Journal of the American
        Statistical Association Vol. 92, No. 439 (Sep., 1997), pp. 868-880.
        https://doi.org/10.2307/2965551
    r   r   )r=   r<   rt   )rH   rM   rL   ro   rp   s        r1   r   r     sd    0 Q-C1c*oo&&  qM'')) 	 	DAq1HCC	Jr3   )Nr   r   r   )NrT   r   r   )NNr   r   )	functoolsr   r   numpyr,   _multilevelr   r   r   r	   r
   r   r   _swtr   r   r   r   r   r   r   _utilsr   r   __all__r   r   r   r   r   r   r*   r3   r1   <module>r      sx   % % % % % % % %    7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 D D D D D D D D D D D D D D D D D D 7 7 7 7 7 7 7 7
;
;
; 7<d d d dN2 2 26 >Dj j j jZ  > :@q q q qh    r3   