o
    ez                     @   s   d Z ddlmZ ddlZddlmZ ddlm	Z	 g d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   Z   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   ?D:\Projects\ConvertPro\env\Lib\site-packages\pywt/_doc_utils.pyr         
r   c                 C   r   )z7Subband keys corresponding to a wavedec2 decomposition.r   )r   hvr   Nr   r   r   r   r   r   r   r      r   r   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 ]j}d }}t |D ]$\}}|dv r$|| d d|d   7 }|dv r4|| 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u rtdd\}}n| }|D ]}	||	d |	d | q|  |d |dkrR| D ]\}
}t|
|krQ|j	|d |d |
ddd q9||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"   
r   c              	   C   s\  g }i }t t|ddD ]}|\}}ddg}t| }t|D ]\}	}
|
dv r6|d  | d d|	d   7  < qt|D ]\}}
|
dv rS|d  | d d|d   7  < q;| 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   s0      rG   c                 C   s   t | |\}}|du rtdd\}}n| }|D ]}	||	d |	d | q|  |d |dkrZ| D ] \}
}t	dd |
D }||krY|j
|d |d |
ddd q9||fS )	r-   Nr   r   r.   c                 S   s   g | ]}t |qS r   )r8   ).0r   r   r   r   
<listcomp>   s    z,draw_2d_fswavedecn_basis.<locals>.<listcomp>r/   r0   )rG   r1   r2   r3   r4   r5   r6   r7   npmaxr9   )r#   rB   r:   r;   r<   r=   r$   r%   r>   r?   r&   r@   r   r   r   r   r	      s$   
r	   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rV||||t |  d  | dd d n||||t |   | d td}|}|rzt | d }	td	d
}
n|d8 }t | }	td	d
}
|dv rtdd}
|
D ]}||||	  | |	 d |
 d gd qd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-)r8   rJ   ZconcatenateZaranger   r4   	set_titleZonesr   minrK   )xrM   r<   ZsymwZnpadtZxpo2leftsteprngrepr   r   r   r
      s.   
,


0r
   )T)__doc__	itertoolsr   numpyrJ   Z
matplotlibr   r1   Z_dwtr   __all__r   r   r   r,   r   rG   r	   r
   r   r   r   r   <module>   s$    

