o
    g)                     @   s   d dl Z d dlZd dlmZ d dlmZmZ d dlZd dl	m
Z
mZmZmZmZ d dlmZ d dlmZ d dlmZ dd	 Zd
d Zdd Zdd Zedgdddd Zdd Zdd Zejddd Z dd Z!dd Z"dS )     N)assert_array_almost_equal)ImageTiffTags)collectionspathpyplot
transformsrcParams)imread)Figure)image_comparisonc                  C   s   t ddg} | d | jd t }| j||  dd |d | j||  dd |d t	t
t|d d	d
d d S )N   皙?)r   r   r         ?none)	facecolor	edgecolorr   r   r   )              ?r   r      )decimal)r   set_facecolorpatch	set_alphaioBytesIOsavefigget_facecolorseekr   tupler
   )figbuf r#   W/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/matplotlib/tests/test_agg.pytest_repeated_save_with_alpha   s$   



r%   c               
   C   sh   t  } t \}}ttddgddgddgddgddggg}|| |	dd t
|  d S )Ni   
   gMbP?r   )r   r   pltsubplotsr   PathCollectionr   Path
add_artistset_xlimr   )bufffax
collectionr#   r#   r$   !test_large_single_path_collection/   s   (
r3   c                  C   sV   t d\} }d}t|}|| |||d |d  t }| j|dd d S )Nr     g?g333333?pngformat)	r)   r*   nparangesemilogxfill_betweenr   r   r   )r!   r1   stepsdatar"   r#   r#   r$   test_marker_with_nan=   s   

r>   c                  C   sH   t  } t \}}tjd tjd}|| |j	| dd d S )Nr   ip r5   r6   )
r   r   r)   r*   r8   randomseedrandplotr   )r/   r!   r1   pointsr#   r#   r$   test_long_pathI   s   
rD   zagg_filter.pngT)remove_textc                     sr  dd d$fdd	G dd d} G dd	 d	| G fd
dd|  G  fddd| }t  \}}|jg dg ddddddddd	\}|jg dg ddddddddd	\}|d}||fD ];}| }| }	|||	\}
|
| tj| |j	dddd}|

| |
| d  |
| |
d  qc|d!d" |d!d" |jd# |jd# d S )%Nc                 S   sv   t jd| d  | |dd  | d| d  | d| d  f }t |}t j||  |dd}||d | d  S )N   r   r   same)mode)r8   r_hanningconvolvesum)x
window_lenswyr#   r#   r$   smooth1dU   s   6
z!test_agg_filter.<locals>.smooth1dr   c                    s:   t t|dd d }t d| |} t d| |} | S )Nr   rF   r   r   )maxintr8   apply_along_axis)AsigmarO   )rS   r#   r$   smooth2d]   s   z!test_agg_filter.<locals>.smooth2dc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z#test_agg_filter.<locals>.BaseFilterc                 S   s   dS )Nr   r#   selfdpir#   r#   r$   get_pade   s   z+test_agg_filter.<locals>.BaseFilter.get_padc                 S   s   t d)Nz"Should be overridden by subclasses)NotImplementedError)r[   
padded_srcr\   r#   r#   r$   process_imageh   s   z1test_agg_filter.<locals>.BaseFilter.process_imagec                 S   s@   |  |}t|||f||fdgd}| ||}|| | fS )Nr   constant)r]   r8   padr`   )r[   imr\   rb   r_   	tgt_imager#   r#   r$   __call__k   s   
z,test_agg_filter.<locals>.BaseFilter.__call__N)__name__
__module____qualname__r]   r`   re   r#   r#   r#   r$   
BaseFilterc   s    ri   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
z%test_agg_filter.<locals>.OffsetFilterr   c                 S   s
   || _ d S N)offsets)r[   rk   r#   r#   r$   __init__t   s   
z.test_agg_filter.<locals>.OffsetFilter.__init__c                 S   s   t t| jd | S )NH   )rU   rT   rk   rZ   r#   r#   r$   r]   w      z-test_agg_filter.<locals>.OffsetFilter.get_padc                 S   sH   | j \}}tj|t|d | dd}tj|t|d |  dd}|S )Nrm   r   )axisr   )rk   r8   rollrU   )r[   r_   r\   oxoya1a2r#   r#   r$   r`   z   s   
z3test_agg_filter.<locals>.OffsetFilter.process_imageN)r   rf   rg   rh   rl   r]   r`   r#   r#   r#   r$   OffsetFilterr   s    
rv   c                       s.   e Zd ZdZdddZdd Z fdd	Zd
S )z'test_agg_filter.<locals>.GaussianFilterzSimple Gaussian filter.      ?r   r   r   c                 S   s   || _ || _|| _d S rj   )rX   alphacolor)r[   rX   ry   rz   r#   r#   r$   rl      s   
z0test_agg_filter.<locals>.GaussianFilter.__init__c                 S   s   t | jd d | S Nr   rm   )rU   rX   rZ   r#   r#   r$   r]      rn   z/test_agg_filter.<locals>.GaussianFilter.get_padc                    sh   t |}| j|d d d d d df<  |d d d d df | j | jd | |d d d d df< |S r{   )r8   
empty_likerz   ry   rX   )r[   r_   r\   rd   rY   r#   r$   r`      s   
z5test_agg_filter.<locals>.GaussianFilter.process_imageN)rw   rx   )rf   rg   rh   __doc__rl   r]   r`   r#   r}   r#   r$   GaussianFilter   s
    
r   c                       s,   e Zd Zd fdd	Zdd Zdd	 Zd
S )z)test_agg_filter.<locals>.DropShadowFilter333333?rx   r   c                    s    |||| _ || _d S rj   )gauss_filteroffset_filter)r[   rX   ry   rz   rk   r   rv   r#   r$   rl      s   z2test_agg_filter.<locals>.DropShadowFilter.__init__c                 S   s   t | j|| j|S rj   )rT   r   r]   r   rZ   r#   r#   r$   r]      s   
z1test_agg_filter.<locals>.DropShadowFilter.get_padc                 S   s    | j ||}| j||}|S rj   )r   r`   r   )r[   r_   r\   t1t2r#   r#   r$   r`      s   z7test_agg_filter.<locals>.DropShadowFilter.process_imageN)r   rx   r   ru   r#   r   r#   r$   DropShadowFilter   s    r   )皙?rw   ?)r   r   rw   zbo-brQ   r&   r'   zLine 1)mecmfclwmewmslabel)rw   g?gffffff?zro-r   g      @g      rC   )rN   rR   unitsrw   Tr   r   F)r   )r)   r*   rB   	get_xdata	get_ydataupdate_frommtransformsoffset_copyget_transformfigureset_transform
set_zorder
get_zorderset_agg_filterset_rasterizedr.   set_ylimxaxisset_visibleyaxis)ri   r   r!   r1   line1line2gausslinexxyyshadowotr#   )r   rv   rS   rY   r$   test_agg_filterS   s<   


r   c                  C   sN   t jdd} t }tt | | W d    d S 1 s w   Y  d S )N)i,  r4   )figsize)r)   r   r   r   pytestraises
ValueErrorr   )r!   r/   r#   r#   r$   test_too_large_image   s
   "r   c                  C   sd   t d} t \}}|| t|  |j  t \}}dtd< || t|  |j  d S )N   i   zagg.path.chunksize)	ranger)   r*   rB   r8   sincanvasdrawr	   )rN   r!   r1   r#   r#   r$   test_chunksize   s   
r   Aggc                  C   sL   t g dg d t } t j| ddd t| }|jd dks$J d S )N)r   r   rF   )r   r   r   jpgr   )r7   r\   r\   )r   r   )r)   rB   r   r   r   r   openinfo)r"   rc   r#   r#   r$   test_jpeg_dpi   s
   
r   c                  C   s^   ddl m}  t }|  }|dd t j|dd|id t	|}|j
d dks-J d S )Nr   )PngInfoSoftwaretestr5   pnginfor7   
pil_kwargs)PIL.PngImagePluginr   r   r   add_textr)   r   r   r   r   r   )r   r"   r   rc   r#   r#   r$   test_pil_kwargs_png   s   
r   c                  C   sV   t  } ddi}t j| d|d t| }dd |j D }|d dks)J d S )Ndescriptionz
test imagetiffr   c                 S   s   i | ]\}}t j| j|qS r#   )r   TAGS_V2name).0kvr#   r#   r$   
<dictcomp>   s    z(test_pil_kwargs_tiff.<locals>.<dictcomp>ImageDescription)	r   r   r)   r   r   r   r   tag_v2items)r"   r   rc   tagsr#   r#   r$   test_pil_kwargs_tiff   s   
r   )#r   numpyr8   numpy.testingr   PILr   r   r   
matplotlibr   r   r   r)   r   r   r	   matplotlib.imager
   matplotlib.figurer   matplotlib.testing.decoratorsr   r%   r3   r>   rD   r   r   r   markbackendr   r   r   r#   r#   r#   r$   <module>   s*    

r

	
