U
    ?h                     @   s   d Z ddlmZ ddlZddlmZ ddlm	Z	 ddd	d
dgZ
dd Zdd Zdd Zdd Zdi ddfdd	Zdd Zdi ddfdd
ZdddZdS )z@Utilities used to generate various figures in the documentation.    )productN)pyplot   )padwavedec_keyswavedec2_keysdraw_2d_wp_basisdraw_2d_fswavedecn_basisboundary_mode_subplotc                 C   sZ   d}i }t | D ]<}dD ]}d||| < qd|d  }|| d k r|| qt| S )z6Subband keys corresponding to a wavedec decomposition. )adNr   r   rangepoplistkeyslevelZapproxZcoeffslevk r   A/var/www/html/venv/lib/python3.8/site-packages/pywt/_doc_utils.pyr      s    c                 C   sZ   d}i }t | D ]<}dD ]}d||| < qd|d  }|| d k r|| qt| S )z7Subband keys corresponding to a wavedec2 decomposition.r   )r   hvr   Nr   r   r   r   r   r   r   r      s    c                 C   sT   | d |d  }}| d |d  }}||||||||g}||||||||g}||fS )af  (x, y) coordinates for the 4 lines making up a rectangular box.

    Parameters
    ==========
    bl : float
        The bottom left corner of the box
    ur : float
        The upper right corner of the box

    Returns
    =======
    coords : 2-tuple
        The first and second elements of the tuple are the x and y coordinates
        of the box.
    r   r   r   )blurZxlZxrZybZytZbox_xZbox_yr   r   r   _box'   s&          r   c                 C   s   g }i }|D ]}d }}t |D ]H\}}|dkrH|| d d|d   7 }|dkr || d d|d   7 }q | d d|d   }	| d d|d   }
t|| f||	 | |
 f\}}|||f ||	d  | |
d  f||< q||fS )Nr   )r   r      r   )r   r   )	enumerater   append)shaper   coordscenterskeyZoffset_xZoffset_yncharsxZsyxcycr   r   r   _2d_wp_basis_coordsD   s"    
 r*   r   c                 C   s   t | |\}}|dkr(tdd\}}n| }|D ]}	||	d |	d | q4|  |d |dkr| D ]0\}
}t|
|krr|j	|d |d |
ddd qr||fS )4Plot a 2D representation of a WaveletPacket2D basis.Nr   r   squarecenterZhorizontalalignmentZverticalalignment)
r*   pltsubplots
get_figureplotset_axis_offaxisitemslentext)r!   r   fmtplot_kwargsaxlabel_levelsr"   r#   figcoordr$   cr   r   r   r   X   s     
c              	   C   s^  g }i }t t|ddD ]:}|\}}ddg}t| }t|D ]0\}	}
|
dkr>|d  | d d|	d   7  < q>t|D ]0\}}
|
dkrx|d  | d d|d   7  < qx| d d|	d   |d< | d d|d   |d< t|d |d  f|d |d  |d  |d  f\}}|||f |d |d d  |d  |d d  f|||f< q||fS )Nr   )repeatr   )r   r   )r   r   r   r   r   r    )r!   levelsr"   r#   r$   key0key1offsetswidthsZn0r&   Zn1r(   r)   r   r   r   _2d_fswavedecn_coordsm   s,    "" rE   c                 C   s   t | |\}}|dkr(tdd\}}n| }|D ]}	||	d |	d | q4|  |d |dkr| D ]@\}
}t	dd |
D }||krr|j
|d |d |
ddd qr||fS )	r+   Nr   r   r,   c                 S   s   g | ]}t |qS r   )r6   ).0r   r   r   r   
<listcomp>   s     z,draw_2d_fswavedecn_basis.<locals>.<listcomp>r-   r.   )rE   r/   r0   r1   r2   r3   r4   r5   npmaxr7   )r!   r@   r8   r9   r:   r;   r"   r#   r<   r=   r$   r>   r   r   r   r   r	      s"    
Tc                 C   s`  |dkr,t | d dkr,t| | d ff} dt |  }tt | d|  }t| ||f|d}|||d || |dkr||||t |  d  | dd d n||||t |   | d td}|}|rt | d }	td	d
}
n|d8 }t | }	td	d
}
|dkr"tdd}
|
D ]4}||||	  | |	 d |
 d gd q&dS )z<Plot an illustration of the boundary mode in a subplot axis.Zperiodizationr   r   )modezk.Nzr.   g      ?)ZsmoothZconstantzeror   zk-)r6   rH   ZconcatenateZaranger   r2   	set_titleZonesr   minrI   )xrK   r:   ZsymwZnpadtZxpo2leftsteprngrepr   r   r   r
      s,    
,



)T)__doc__	itertoolsr   numpyrH   Z
matplotlibr   r/   Z_dwtr   __all__r   r   r   r*   r   rE   r	   r
   r   r   r   r   <module>   s(    

