
    bMh                         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 Zd	 Zd
 Zd Zdi ddfdZd Zdi ddfdZ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                     d}i }t          |           D ]5}dD ]
}d|||z   <   d|dz   z  }|| dz
  k     r|                    |           6t          |                                          S )z6Subband keys corresponding to a wavedec decomposition. )adNr   r   rangepoplistkeyslevelapproxcoeffslevks        O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pywt/_doc_utils.pyr   r      s    FFU||   	& 	&A!%F6A:a??JJv    c                     d}i }t          |           D ]5}dD ]
}d|||z   <   d|dz   z  }|| dz
  k     r|                    |           6t          |                                          S )z7Subband keys corresponding to a wavedec2 decomposition.r   )r   hvr   Nr   r   r   r   s        r   r   r      s    FFU||  % 	& 	&A!%F6A:a??JJvr   c                 r    | 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    )blurxlxrybytbox_xbox_ys           r   _boxr*   '   sj      UBqEBUBqEBE E 5>r   c                    g }i }|D ]}dx}}t          |          D ]5\  }}|dv r|| d         d|dz   z  z  z  }|dv r|| d         d|dz   z  z  z  }6| d         d|dz   z  z  }	| d         d|dz   z  z  }
t          || f||	z   | |
z
  f          \  }}|                    ||f           ||	dz  z   | |
dz  z
  f||<   ||fS )Nr   )r   r      r   )r   r   )	enumerater*   append)shaper   coordscenterskeyoffset_xoffset_yncharsxsyxcycs                r   _2d_wp_basis_coordsr;   D   s+   FG A A8 ~~ 	3 	3GAtz!!E!HAE
22z!!E!HAE
221XQU#1XQU#x(+"}xi"n57 7Br2h 27*XIa,?@7?r   r   c                    t          | |          \  }}|t          j        dd          \  }}n|                                }|D ]%}	|                    |	d         |	d         |           &|                                 |                    d           |dk    rS|                                D ]>\  }
}t          |
          |k    r&|	                    |d         |d         |
dd           ?||fS )4Plot a 2D representation of a WaveletPacket2D basis.Nr   r   squarecenterhorizontalalignmentverticalalignment)
r;   pltsubplots
get_figureplotset_axis_offaxisitemslentext)r/   r   fmtplot_kwargsaxlabel_levelsr0   r1   figcoordr2   cs               r   r	   r	   X   s    *%66OFG	z,q!$$RRmmoo ) )
a%(C((((OOGGHammoo 	4 	4FC3xx<''!adC,4*2  4 4 4 7Nr   c           	         g }i }t          t          |          d          D ];}|\  }}ddg}t          |           }t          |          D ](\  }	}
|
dv r|dxx         | d         d|	dz   z  z  z  cc<   )t          |          D ](\  }}
|
dv r|dxx         | d         d|dz   z  z  z  cc<   )| d         d|	dz   z  z  |d<   | d         d|dz   z  z  |d<   t	          |d         |d          f|d         |d         z   |d          |d         z
  f          \  }}|                    ||f           |d         |d         dz  z   |d          |d         dz  z
  f|||f<   =||fS )Nr,   )repeatr   )r   r   )r   r   r   r-   r*   r.   )r/   levelsr0   r1   r2   key0key1offsetswidthsn0r6   n1r9   r:   s                 r   _2d_fswavedecn_coordsr\   m   s   FG|F++A666 > >ta&e!$ 	6 	6HBu}}


eAh!b1f+55


!$ 	6 	6HBu}}


eAh!b1f+55


!HBF+q	!HBF+q	wqzGAJ;/qzF1I-
{VAY/FGI IBr2h!(fQi!m!;")!*vay1}!<!>t7?r   c                    t          | |          \  }}|t          j        dd          \  }}n|                                }|D ]%}	|                    |	d         |	d         |           &|                                 |                    d           |dk    rd|                                D ]O\  }
}t          j	        d |
D                       }||k    r&|
                    |d         |d         |
dd           P||fS )r=   Nr   r   r>   c                 ,    g | ]}t          |          S r!   )rJ   ).0r   s     r   
<listcomp>z,draw_2d_fswavedecn_basis.<locals>.<listcomp>   s    ...Q#a&&...r   r?   r@   )r\   rC   rD   rE   rF   rG   rH   rI   npmaxrK   )r/   rU   rL   rM   rN   rO   r0   r1   rP   rQ   r2   rR   r   s                r   r
   r
      s    ,E6::OFG	z,q!$$RRmmoo ) )
a%(C((((OOGGHammoo 	4 	4FC&..#...//Cl""!adC,4*2  4 4 4 7Nr   Tc                    |dk    r3t          |           dz  dk    rt          j        | | d         ff          } dt          |           z  }t          j        t          |           d|z  z             }t	          | ||f|          }|                    ||d           |                    |           |dk    r;|                    |||t          |           z   dz
           | dd         d           n/|                    |||t          |           z            | d           t          j        d          }|}|r#t          |           dz
  }	t          d	d
          }
n$|dz  }t          |           }	t          d	d
          }
|dv rt          d          }
|
D ]N}|                    |||	z  z   |z  |	                                dz
  |
                                dz   gd           OdS )z<Plot an illustration of the boundary mode in a subplot axis.periodizationr,   r   )modezk.Nzr.   g      ?)smoothconstantzerozk-)rJ   ra   concatenatearanger   rF   	set_titleonesr   minrb   )xrf   rN   symwnpadtxpo2leftsteprngreps               r   r   r      s    3q66A:??NA"y>**s1vv:D
	#a&&1t8#$$A	Qt4	(	(	(BGGAr4LL 
$tc!ff}q(()1SbS648888
$tc!ff}$%q$/// 
BD 1vvzBll1vvBll---Ahh P P
d
"b(26688b="&&((R-*H$OOOOP Pr   )T)__doc__	itertoolsr   numpyra   
matplotlibr   rC   _dwtr   __all__r   r   r*   r;   r	   r\   r
   r   r!   r   r   <module>r      s   F F           $ $ $ $ $ $      @ @ @
 
 

 
 
  :  ( '*rd"#   *  . 14*+   ,!P !P !P !P !P !Pr   