
    |Le9                     p   d Z ddlZddlZddlZddlZddlZ	ddl
Z
 e
j        d          Zej        Zej                            ej                            e          d          Zd  e e	j        dd                    D             Z ej        dddd	          Z ej        d
d
dd	          ZdZedfedffZd Zd Zd ZefdZd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d  Z+e,d!k    r= e(            Z- e. e/e-0                                                      e)e-           dS dS )"z0Tests for antialiased line drawing in Datashader    Nzmatplotlib.cmdatac                 j    g | ]0}t          d  t          |          dd         D                       1S )c              3       K   | ]	}|d z  V  
dS )g     o@N ).0vs     ?lib/python3.11/site-packages/datashader/tests/test_antialias.py	<genexpr>z<listcomp>.<genexpr>   s&      //1$//////    N   )tuple)r   rgbs     r	   
<listcomp>r      sM     
0 
0 
0 //c

2A2///
/
/ 
0 
0 
0r      2   )r   1   )
plot_widthplot_heightx_rangey_range   )   "   ))T	antialias)Fnoaanormalclippedc                 (   t          j        |d         |d         g          t          j        |d         |d         g          }}t          j        ||dd          }|                     |ddt
          j                            d          |          S )	aJ  Draw a single line.

    Parameters
    ----------
    cvs: canvas
      A Datashader canvas
    p1: tuple
      The first vertex of the line
    p2: tuple
      The second vertex of the line
    antialias: boolean
      To anti-alias or not is the question

    Returns
    -------
    agg: A Datashader aggregator (xarray)

    r   r         @xyvalr!   r"   r#   aggr   )nparraypd	DataFramelineds
reductionsmax)cvsp1p2r   xsyspointss          r	   	draw_liner4      s    & Xr!uben%%rxA1'?'?B\C8899F88FC"-*;*;E*B*B'  ) ) )r   c           	          g }|D ]4\  \  }}\  }}|                     t          | ||f||f|                     5t          j        |d                              d          S )a  Draw multiple line.

    Parameters
    ----------
    cvs: canvas
      A Datashader canvas
    points: list of tuple of tuple
      The lines to render as a list of tuples, where each tuple represents a
      line consisting of two tuples each containing two scalars describing the
      two vertices of the line.
    antialias: boolean
      To anti-alias or not is the question

    Returns
    -------
    agg: A Datashader aggregator (xarray)
    stackdim)appendr4   xrconcatsum)r.   r3   r   aggsx1y1x2y2s           r	   
draw_linesrB      su    $ D & C C"b8BIcB8b"XyAABBBB9T7##''G'444r   c                    g g }}|D ]/\  }}|                     |           |                     |           0t          j        |          t          j        |          }}t          j        ||dd          }|                     |ddt          j                            d          |          }	t          j
        |	gd                              d          S )	at  Draw multi-line segment line.

    Parameters
    ----------
    cvs: canvas
      A Datashader canvas
    points: list of tuples
      List of tuples of two scalars that represent each of the vertices in the
      multi-segment line.
    antialias: boolean
      To anti-alias or not is the question

    Returns
    -------
    agg: A Datashader aggregator (xarray)
    r   r    r!   r"   r#   r$   r6   r7   )r9   r&   r'   r(   r)   r*   r+   r,   r-   r:   r;   r<   )
r.   r3   r   r!   r"   r>   r?   r1   r2   r%   s
             r	   draw_multi_segment_linerD      s    " rqA  R		Xa[["(1++B\C8899F
((63):):5)A)A'  ) )C 9cUG$$((W(555r   c                     t           j                            | |          }t           j                            |d          }|S )zShade/render the aggregator.

    Parameters
    ----------
    aggregators: xarray
      The aggregator(s)  to shade
    cmap: color map
      The colormap to use

    Returns
    -------
    img: xarray
      The shaded image.
    cmapz#ffffff)r+   transfer_functionsshadeset_background)aggregatorsrG   imgs      r	   rI   rI      s<     

%
%k
%
=
=C


.
.sI
>
>CJr   c                     t           j                            t          |dz             }t	          d|z              |                                                     |           dS )zSave a shaded image as PNG file.

    Parameters
    ----------
    img: xarray
      The image to save
    filename: unicode
      The name of the file to save to, 'png' extension will be appended.

    z.pngSaving: N)ospathjoindatadirprintto_pilsaverL   filenames     r	   save_to_imagerX      sS     w||GX%677H	*x
   JJLLhr   c                     t           j                            t          |dz             }t	          d|z              |                     |           dS )zSave a shaded image as NetCDF file.

    Parameters
    ----------
    img: xarray
      The image to save
    filename: unicode
      The name of the file to save to, 'nc' extension will be appended.

    .ncrN   N)rO   rP   rQ   rR   rS   	to_netcdfrV   s     r	   save_to_netcdfr\     sI     w||GX%566H	*x
   MM(r   c                 z    t           j                            t          | dz             } t	          j        |           S )zLoad a shaded image from NetCDF file.

    Parameters
    ----------
    filename: unicode
      The name of the file to load from.

    Returns
    -------
    img: xarray
      The loaded image.

    rZ   )rO   rP   rQ   rR   r:   open_dataarray)rW   s    r	   load_from_netcdfr_     s/     w||GX%566HX&&&r   c                  h    g } t          ddd          D ]}|                     dd|ff           | dfS )Nr   7      r   r   r   test_001ranger9   r3   as     r	   generate_test_001ri   .  sI    F1b!__ ) )vAw'((((:r   c                  h    g } t          ddd          D ]}|                     d|dff           | dfS )Nr   ra   rb   rc   r   test_002re   rg   s     r	   generate_test_002rl   4  sI    F1b!__ ) )v2w'((((:r   c                  h    g } t          ddd          D ]}|                     dd|ff           | dfS )Nr   ra   rb   r   r   test_003re   rg   s     r	   generate_test_003rp   :  I    F1b!__ * *x!Q()))):r   c                  h    g } t          ddd          D ]}|                     d|dff           | dfS )Nr   ra   rb   rn   test_004re   rg   s     r	   generate_test_004rt   @  rq   r   c                      g d} | dfS )N))rc   r   r   )rv      r   )rw   rx   r   )ry      r   )rz   r{   r   )r|      r   )r}   r~   r   )r      r   )r   r   r   )r       r   )r   r   r   )r   r   r   )r   rn   test_005r   r3   s    r	   generate_test_005r   F  s       F :r   c                      g d} | dfS )N)rc   rv   rw   ry   rz   r|   r}   r   r   r   r   r   r   rn   test_006r   r   s    r	   generate_test_006r   X  s       F  :r   c                      g d} | dfS )N))      ?r   )      ?     @H@)r   )r   r   )r   r   )     G@r   )r   )r   r   test_007r   r   s    r	   generate_test_007r   k  s       F :r   c                     i } t           D ]\  }}t          D ]\  }}t          t          t          t
          t          t          fD ]R} |            \  }}t          |||          }t          |t                    }	d                    |||          }
|	| |
<   St          fD ]R} |            \  }}t          |||          }t          |t                    }	d                    |||          }
|	| |
<   Sڌ| S )zGenerate all test images.

    Returns
    -------
    results: dict
      A dictionary mapping test case name to xarray images.
    rF   z{}_{}_{})antialias_optionscanvas_optionsri   rl   rp   rt   r   r   rB   rI   cmap01formatr   rD   )resultsr   aa_descriptorcanvascanvas_descriptorfuncr3   namerK   rL   description
aggregators               r	   generate_test_imagesr   t  s2    G%6 + + 	=)7 	+ 	+%F%****** + +  $tvv(CCKf555(//-):< <'*$$*- + +#tvv4VVYOO
JV444(//-):< <'*$$+	+, Nr   c                 z    |                                  D ]%\  }}t          ||           t          ||           &dS )zSave all images as  PNG and NetCDF files

    Parameters
    ----------
    images: dict
      A dictionary mapping test case names to xarray images.
    N)itemsrX   r\   )imagesr   rL   s      r	   save_test_imagesr     sM     #LLNN ) )Sc;'''sK(((() )r   c                 b    i }|                                  D ]\  }}t          |          ||<   |S )zLoad all images from NetCDF files

    Returns
    -------
    loaded: dict
      A dictionary mapping test case names to xarray images.
    )r   r_   )r   loadedr   _s       r	   load_test_imagesr     s>     F ,,.. < <Q.{;;{Mr   c                     t                      } t          |           }t          t          |                                                     |                                 D ](}| |         ||         k                                    sJ )dS )zTest case for all images.

    Will generate all test cases, then load all test cases from disk and
    compare them with each other

    N)r   r   rS   listkeysall)r   r   r   s      r	   test_antialiasingr     s     #$$Ff%%F	$v{{}}

{{}} B B{#vk'::??AAAAAAB Br   __main__)1__doc__rO   xarrayr:   
datashaderr+   pandasr(   numpyr&   pytestimportorskipcmbinaryrP   rQ   dirname__file__rR   linspacer   Canvasregular_cvsreduced_cvsr   r   r4   rB   rD   rI   rX   r\   r_   ri   rl   rp   rt   r   r   r   r   r   r   r   __name__r   rS   r   r   r   r   r	   <module>r      s   6 6t 
			                  V))	 ',,rwx00&
9
9
0 
0VKBK1--..
0 
0 
0 bi22 ': : : bi22 ((< < < ; )K+CD) ) )25 5 506 6 6: #    &        ' ' '&          $  &       D
) 
) 
)  B B B z""$$F	E$$v{{}}

V	 r   