a
    ضa                     @   s  d dl Zd dlmZmZmZ d dlm  mZ	 d dl
Z
d dlZd dlmZ d dl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e
jdg g fdgdgfddgddgfg dg dfg dg dfg dg dfgdd Zdd Zedgdd Z dd Z!dd  Z"d!d" Z#d#d$ Z$d%d& Z%d'd( Z&d)d* Z'd+d, Z(ed-gd.d/d0d1d2 Z)ed3gd.d4d0d5d6 Z*d7d8 Z+d9d: Z,e
jjd;ej-ej.gd<d=gd>d?d@ Z/dAdB Z0dCdD Z1dEdF Z2dGdH Z3dIdJ Z4dKdL Z5dMdN Z6dOdP Z7dQdR Z8dSdT Z9dS )U    N)assert_array_equalassert_array_almost_equalassert_array_less)Path)image_comparisonc            	      C   sP  d} d}t t dd| t dd|\}}| }| }| | }d| d  |d  }d|  | d|   d|  d }t||}t|j| t|j| t	|j
|ksJ t |j
dksJ t |j
|d ksJ t	|j|ksJ t |jdksJ t |j|d ksJ |j}d |_t|j| tt |j
t | d S )	N                    ?         r   )npmeshgridlinspaceravelmtriTriangulationr   xylen	trianglesminmaxedges	neighbors
_neighborsr   uniquearange)	Znxnyr   r   npointsZ
ntrianglesZnedgestriangr    r"   s/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/matplotlib/tests/test_triangulation.pytest_delaunay   s*    $ r$   c                  C   sx   d} d}d}t jd t j| }t j| }|| ||< || ||< t||}tt |jt t 	| | d S )N
      r      )
r   randomseedr   r   r   r   r   deleter   )r    Z	duplicateZduplicate_ofr   r   r!   r"   r"   r#   test_delaunay_duplicate_points9   s    r+   c                  C   sz   t ddd} t ddd}tt t| | W d    n1 sH0    Y  t | d} t |d}t| | d S )Nr	         $@          @g       @)r   r   pytestraisesRuntimeErrorr   r   appendr   r   r"   r"   r#   test_delaunay_points_in_lineM   s    *r4   zx, yr   r   r      )r   r   r   )r   r5   r   )r   r   r   )r   r5   r5   )r   r   r   r   r   r   )r   r   r   r5   r   r5   c                 C   s:   t t t| | W d    n1 s,0    Y  d S N)r/   r0   
ValueErrorr   r   r3   r"   r"   r#   !test_delaunay_insufficient_points[   s    r8   c               
      s   t ddgddgddgddgddgd	d
gddgg} t ddgddgddgddgddgddgddgg}dd   fdd}t| d d df | d d df }|D ]}|||dksJ qt| dd df | dd df }d S )NgLXz?g     gCM??g~9B.?g     g/7R?g9?g     ڿgHC?g     ڿgt?g     ڿg(\?gq=
ףpݿg?gzGڿffffff?gQ޿g)\(ܿ      ?皙?c                 S   s   t | |fj}t||S r6   )r   ZvstackTr   Zcontains_point)ZxtriZytrixy
tri_pointsr"   r"   r#   tri_contains_point   s    z0test_delaunay_robust.<locals>.tri_contains_pointc                    s   t  fdd jD S )Nc                 3   s&   | ]} j | j| V  qd S r6   r3   ).0tri)r?   r!   r=   r"   r#   	<genexpr>   s   zCtest_delaunay_robust.<locals>.tris_contain_point.<locals>.<genexpr>)sumr   r!   r=   r?   rD   r#   tris_contain_point   s    z0test_delaunay_robust.<locals>.tris_contain_pointr   r   )r   arrayasarrayr   r   )r>   Ztest_pointsrF   r!   Z
test_pointr"   rE   r#   test_delaunay_robustk   s0    $rI   ztripcolor1.pngc                  C   s   t g d} t g d}t g dg dg dg dg dg dg d	g d
g dg dg
}t| ||}| d|  }| |j jdd}||j jdd}d| | }td tj||dd t	d td tj||dd t	d d S )N)
r         ?r   r   rJ   r   r   rJ   r   r:   )
r   r   r   rJ   rJ   rJ   r   r   r   r:   r   r   r   )r   r   r   r   r   r   )r   r   r   )r   r   r5   )r   r&   r5   )r   r   	   )r&   r   rM   )   r&   rM   )r   rN   rM   rJ   r   Zaxisy   k)
edgecolorszpoint colorsz   )
facecolorsrR   rT   )
r   rH   r   r   r   meanpltZsubplotZ	tripcolortitle)r   r   r   r!   ZCpointsZxmidZymidZCfacesr"   r"   r#   test_tripcolor   s&    


rX   c                  C   sh   t jg dg dgt jd} t g d}|  }t|d d df |d d df | j t||  d S )Nr   r   r   )r   r   r   Zdtype))r   r   )r   g?)r   r   )r   r   r   r   )r   rG   int32copyr   r   r   r   )r   ZpointsZold_trianglesr"   r"   r#   test_no_modify   s
    (r]   c            
      C   s  t t dt d\} }|  } | }g dg dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg}t t|}d|dd< t| |||}| }g d}g d}t ||\}}| }| }|||}t	|g d ||d |d }t	|g d g d}g d}|||}t	|g d ddg}ddg}|||}t	|d d!g d}	g d"} d#d d d d |	dg}g d$g d%g d&g dg d'g d(g d)g d*g}t| ||}| }g d+}d,d-g}t ||\}}|||}t	|g d.g d/g d}	d#|	 d d d d dg} g d0}g d1g d2g d3g d4g d5g d6g d7g d*g}t| ||}| }d,d-g}g d+}t ||\}}|||}t	|d#d#gd d8gd d8gd d9gdd9gdd:gd#d#gg g d;} g d<}g d1g d=g}t| ||}| }g d>}g d?}|||}t	|g d@ |
dd g || kstJ |||}t	|g dA d S )BNr   r   r   r   r   r   r   r   r   r   r   r5   r   r   r   r5   r   r&   r5   r   r   rN   r   rM   rN   r   r5   rM   r5   r%   rM   r5   r&   r%   r&   r-   r%   rN   rM      rM      rk   rM   r%   rm   r%      rm   r%   r-   rp   r-      rp   r   rN   r%   )      ?      ?      @      
@)r   r   r   r5   rx   r%   rx   rk   rp      rx   rx   rx   rx   rx   rJ   )rx   rx   rx   rx   rx   r   r   r   rx   r&   rx   r-   rx   rm   rs      )rJ         ?      @rJ   r{   r|   r{   r{   r	   r
   r.         @)r	   r	   r	   r}   r}   r}   r
   r.   r{   r{   r{   r{   )r   r   r   rm   rs   rz   r   rp   r5   r&   r%   r-   r	   r}   r   rz   r{   r   r   r   r   r{   r{   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r5   r   r5   r   )皙皙??gffffff?gffffff?g333333@g333333@r   皙?)rx   r   r   r   r   r   rx   )rx   r5   r5   r5   r&   r&   rx   )r{   r{   r   r   r   r   r{   r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r5   r   )r   r5   r   r   r5   r&   r   r   r   r   r   r   r   r   r   r   r   )gɿ皙?r;   g333333?)rJ   rJ   rJ   rJ   )rx   r   r   rx   )rx   rx   r   rx   )r   r   r   r   zerosr   r   r   get_trifinderr   set_mask)
r   r   r   maskr!   	trifinderxsystrisdeltar"   r"   r#   test_trifinder   s    


	



(

r   c                     s  t t dt d\} }|  } | }d|  d|  }g dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg dg dg}t t|}d|dd< t| |||}t||}t	||}tj	||dd}t 
ddd}	g d}
t |	|
\}	}
|||fD ]&}||	|
}t|d|	 d|
   q.g d}	|	}
t |	|
\}	}
|||fD ](}||	|
}t|jd gd gd  q|t 
dd!d}	g d"}
t |	|
\}	}
|||fD ]T}||	|
}t|d|	 d|
   |	dk|	d#k |
dk |
d#k }t|j| qd$\  fd%d&} fd'd(}t g d)} t g d*}t g d+g d,g d-g d.g d/g d0g d1g d2g}t| ||}|| |}|| |}t 
d3d4d5}	t 
d3d4d5}
t |	|
\}	}
tj	||d6|d7}||	|
}t|||	|
 || |\}}|| |\}}t|| t|| d8}t t 
d3d4|d t 
d3d4|d \} }|  } | }|| |}tj| |t|d d9}t t 
d:d;d5t 
d:d;d5\}	}
|	 }	|
 }
t||}t	||}tj	||dd}||	|
}t ||	|
| }||fD ]Z}t ||	|
| }t |dt | ksrJ t ||d<t || ks<J q<d S )=Nr   Gz?)\(@r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rl   rn   ro   rq   rr   r   rN   r%   geomkindrt         @r5   )rt   r:   rv   r   )g      пru         ?rw   Tr   )rt   r:   ru   r   r   )r   g)\(333333?c                    s,    | d d  |d d   |  |  S )NrJ   r   r"   r3   abcr"   r#   quadT  s    ztest_triinterp.<locals>.quadc                    s0   d  | d  |  d |d  |   fS )Nr   rJ   r"   r3   r   r"   r#   gradient_quadW  s    z%test_triinterp.<locals>.gradient_quad)r   &jjZ? rh?r	   r
   r
   r	   )333333?HPs?X9v?r	   r	   r
   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r5   r   r   r5   r   r   r5   r   r   r	   r
   r   userr   dzr-   r   r   r   d   )r   r   r   r   r   r   r   r   LinearTriInterpolatorCubicTriInterpolatorr   r   r   r   matestrG   gradientmeshgrid_trianglesabsr   dot)r   r   zr   r   r!   linear_interpcubic_min_E
cubic_geomr   r   interpzsr   r   r   Z
cubic_userZ	interp_zsZinterp_dzsdxZinterp_dzsdyZdzsdxZdzsdynZdiff_linZ
diff_cubicr"   r   r#   test_triinterp%  s    


 





,
$

r   c                  C   s  ddd} d\}}d\}}d\}}t |||ddddg}t |||ddddg}t g dg d	g d
g dg dg dg dg dg}	t|||	}
tdD ]}t jdt jd}t jdt jd}t jdt jd}t jddgt jd}|d }d|||d f< |dkrd||< n.|dkr0d||d < n|dkrFd||d < tj|
|d||fd}| |||f|d d df  | |||f|d d df  | |||f|d d df  | ||| d || d f | ||| d || d f | ||| d || d f | ||| | d || | d f | |d| | | d d| | | d f | ||d|  | d |d|  | d f | ||| d|  d || d|  d f qd S )Nc              	   S   s  d}d}d}|\}}||t t ddt j |  }||t t ddt j |  }	| |g|gd }
| |g|g\}}|durt|
|d  t|d |d  t|d |d  | ||	|
 }| ||	\}}|| }|| }t|||  t|||  t|||  dS )	aJ  
        Checks the continuity of interpolator (and its derivatives) near
        location loc. Can check the value at loc itself if *values* is
        provided.

        *interpolator* TriInterpolator
        *loc* location to test (x0, y0)
        *values* (optional) array [z0, dzx0, dzy0] to check the value at *loc*
           绽|=g      Y@r	   r   r   Nr   )r   cosr   pisinr   r   r   )interpolatorlocvaluesZn_starepsilonrQ   Zloc_xZloc_yZstar_xZstar_yr   dzxdzyZdiff_zZtab_dzxZtab_dzyZdiff_dzxZdiff_dzyr"   r"   r#   check_continuity  s&    
""z;test_triinterpcubic_C1_continuity.<locals>.check_continuity)r   r   )r   r   )r   r   r	   r
   r   r   r   r   r   r   r   r   rM   r&   rZ   r   r   r   r   r   r   rJ   r}         @g      @)N)r   rG   r   r   ranger   float64r   )r   axaybxZbyZcxcyr   r   r   r!   Zidofr   r   r   r   Zcaser   r"   r"   r#   !test_triinterpcubic_C1_continuity  sH    





&..r   c                  C   sd  dd } d\}}t jj| || }|  | }t|| D ]T}tj|| tjd}d||< t jj	||t|| dd\}}t
t||| q>d\}	}
| ||\}}}}|d	||	k  d	||
k  }|d	||	k  d	||
k  }t||	|	d	 |
|
d	 gg}t||	d	 |	|
d	 |
gg}t|g d
g}t j||||| d || d f}|  | }t|| d D ]^}tj|| d tjd}d||< t jj	||t|| d dd\}}t
t||| qztjdtjd}tjg dtjd}tjg dtjd}d}t j||||}|  | }t
|tjg dg dg dgtjd d S )Nc                 S   s  ||  }t t j|t jdt j|d t jdt jd|t jdt j||  t jdt j| |t jdg}t t j|t jdt jd|t jdt j|d t jdt j| |t jdt j||  t jdg}t dt j|t jd t j|d t jd t j|d t jd t j||  t jd t j||  t jd g}d||d| d  |d d|< d|d| d d| d  |d d|< |||| | | | ffS )z
        Return the sparse, (n*m, n*m) matrix in coo format resulting from the
        discretisation of the 2-dimensional Poisson equation according to a
        finite difference numerical scheme on a uniform (n, m) grid.
        rZ   r   r   r	   r   Nr   )r   concatenater   r[   onesr   )r   mlrowscolsvalsr"   r"   r#   poisson_sparse_matrix  s&    """"(("*z<test_triinterpcubic_cg_solver.<locals>.poisson_sparse_matrix)rk   r   rZ   r
   r   )Ar   x0tol)rk   1   r   )r
   r
   r
   r
   r   rz   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r
   r.   r	   )r.   r
         @)r	   r   r
   )r   triinterpolateZ_Sparse_Matrix_cooZcompress_cscZto_denser   r   r   r   Z_cgr   r   r   r   rG   r[   )r   r   r   matZ	mat_denseZitestr   r   _Zi_zeroZj_zeror   r   r   Zdimr"   r"   r#   test_triinterpcubic_cg_solver  s^    



r   c                  C   sp  d\} }t | d|  ddg}t || ddg}t jdt jd}g dg dg}t dd	g}t dd	t j d
D ]}t || t ||  }t | | t ||  }	t	||	|}
tj
|
|dd}tj|}| }t |dd |dd d f< tdD ]6}t |dd	|d d |f   ||d d d f< qtt jt |ddt jddgt jd qtd S )N)r	   gˡE?rJ   r	   r
   r   rZ   )r   r   r   r   r   rp   r   r   r   r   r   rO   )r   rG   r   r   r   r   r   r   r   r   r   r   Z_DOF_estimator_geomZcompute_geom_weightsrC   r   r   r   r   )r   r   r   r   r   r   Zsum_wthetax_roty_rotr!   r   Zdof_estimatorweightsitrir"   r"   r#    test_triinterpcubic_geom_weights(  s&    4r   c               
   C   sj  d} t g d}t ddddd| dg}ddgddgddgddgddgddgg}|D ]}|d | |d |  }|d  | |d |  }|| }}d| d	|  }	g d
g dg dg dg dg dg dg dg}
t|||
}t t |jt |jd}t t |jt |jd}t 	||\}}|
 }|
 }| ||dk}t jjd| d	|  |d}t||	}t||	}tj||	dd}|||fD ]}|||}t|| qd}|j|df }|j|df }t |j| |j| d}t |j| |j| d}d| d	|  }|||fD ]2}|j|||t jdt jd d\}t|| q0qVd S )Nr	   r~   rx   r   r   r   r   r   r   r   r   r`   r   r   r   r      r   r   r   r   r%   rZ   )Z	tri_index)r   rG   r   r   r   r   r   r   r   r   r   r   mar   r   r   r   Z_interpolate_multikeysr   r[   )r   r   y0ZtransformationsZtransformationr   r   r   r   r   r   r!   r   r   Zmask_outZ	zs_targetr   r   r   r   r   r   Zpt1Zpt2r"   r"   r#   test_triinterp_colinearB  sJ    (


r   c                  C   s  d} d}d}dd }t |d|}t jd|  dt j |  | d	d
}t j|dt jf |dd}|d d dd df  t j|  7  < |t |  }|t |  }t	||}|||}	t ddd}
t ddd}t 
|
|\}
}|
 }
| }i }tdD ]}dt j |  | }t || t ||  }t | | t ||  }t ||
 t ||  }t | |
 t ||  }t	|||j}t||	}t||	}tj||	dd}|||d}dD ]B}|| }|dkr||
|||< n|||}t|||  q֐qd}dD ]}|dkrN|| }|}||
 }|}n|}|| }|
}|| }t	|||j}t||	}t||	}tj||	dd}|||d}dD ]$}|| ||}t|||  qq&d S )Nr   r%   333333?c                 S   s   t d|  d| }t d|  d| }t |  d | d }t |  d | d }dt |d d d  d t d|  t |d d d d t d|   d	| d |d     }t || t |t |  S 
NrJ   r   r   r%   r   g      >@      @g      &@r9   r   hypotarctan2expr   r   r   r   r   Zr1Ztheta1Zr2Ztheta2r   r"   r"   r#   r     s    *&z)test_triinterp_transformations.<locals>.zffffff?r   r   FZendpoint.r   rO         r
   r'   r   r   )ZlinZmin_Er   gZ$.Ar3   r   )r   r   r   repeatnewaxisr   flattenr   r   r   r   r   r   r   r   r   r   r   )n_anglesn_radii
min_radiusr   radiianglesr   r   triang0z0Zxs0Zys0Z	interp_z0Zi_angler   r   r   r   r   r!   r   r   r   Z
dic_interpZ
interp_keyr   ZinterpzZscale_factorZscaled_axisr"   r"   r#   test_triinterp_transformations  s    
$



r  ztri_smooth_contouring.pngTg;On?)Zremove_textr   c                  C   s<  d} d}d}dd }t |d|}t jd|  dt j |  | d	d
}t j|dt jf |dd}|d d dd df  t j|  7  < |t |  }|t |  }t	||}|||}	|
t ||j jdd||j jdd|k  t|}
|
j|	dd\}}t ddd}tj|ddd tj|||dd d S )Nr   r%   r   c                 S   s   t d|  d| }t d|  d| }t |  d | d }t |  d | d }dt |d d d  d t d|  t |d d d d t d|   d	| d |d     }t || t |t |  S r   r   r   r"   r"   r#   r     s    *&z%test_tri_smooth_contouring.<locals>.zr   r   r   Fr  .r   rO   r   subdivr	   r
   g?rJ   z0.5)Zlwcolorblack)levelscolors)r   r   r   r  r  r   r  r   r   r   r   r   r   rU   UniformTriRefinerrefine_fieldr   rV   triplot
tricontour)r  r  r  r   r	  r
  r   r   r  r  refinertri_refiz_test_refir  r"   r"   r#   test_tri_smooth_contouring  s0    $

r  ztri_smooth_gradient.pnggZd;O?c                  C   s  dd } d}d}d}t |d|}t jddt j |d	d
}t j|dt jf |dd}|d d dd df  t j| 7  < |t |  }|t |  }| ||}t	||}	|	
t ||	j jdd||	j jdd|k  t|	}
|
j|dd\}}t|	| }||	j|	j\}}t ||}t  t d tj|	dd t ddd}tjdd d}tj||||g dd tj|	j|	j|| || dddddddd  d S )!Nc                 S   sL   | d |d  }t || }t || }t || t |t |  S )zAn electric dipole potential V.r   )r   r   r   r   r   )r   r   Zr_sqr   r   r"   r"   r#   dipole_potential  s    z2test_tri_smooth_gradient.<locals>.dipole_potential   r%   r   r   r   r   Fr  .r   rO   r   r  equalz0.8)r  r	   r
   g{Gz?Zhot)nameZlut)r.   r
   r
   r
   )r  cmapZ
linewidthsr=   r,   bluegy&1|?r}   r   )ZunitsZscaleZzorderr  widthZ	headwidthZ
headlength)r   r   r   r  r  r   r  r   r   r   r   r   r   rU   r  r  r   r   r   r   rV   figureZgcaZ
set_aspectr  r   cmZget_cmapr  Zquiver)r  r  r  r  r	  r
  r   r   Vr!   r  r  r  ZtciZExZEyZE_normr  r   r"   r"   r#   test_tri_smooth_gradient  sD    $

r&  c                  C   s  t g d} t dddt d ddg}t jg dg dg d	gt jd
}t jg dtd
}tj| |||d}t|}t|j	t ddddt d   g t|j
ddt jdddt d  t jg| t g d} t g d}t jg dgt jd
}t| ||}t|}t|
 t dg d}dd }t dd|d } t || d|| d\} }|  } | }tj| |t|d d}t|}|d}t jdtd
}	g d}
d|	|
< t||	 t jdtd
}d|d< || |d}g d}d|	|< t||	 d S )Nr	   r
   rJ   r	   r.   r	   rJ   r}   r  r
   r   rK   rL   rZ   FFTr   F)Zrescaler.   )r	   r
   r.   )r
   r   r   rM   c                 S   s   t | | t |  S r6   )r   r   sign)r   r   r"   r"   r#   powerV  s    ztest_tritools.<locals>.powerr   rt   r   r      )r   r   r   r   rp   rs   ry   rz         "   #   ~                                    TP   ),   -   >   ?   N   O   r<  Q   R   S   b   c   t   u   )r   rG   sqrtr[   boolr   r   TriAnalyzerr   Zscale_factorsZcircle_ratiosr   Zmasked_arraynanr   r   r   r   Zget_flat_tri_maskr   r   r   )r   r   r   r   r!   analyserr   r*  Z	mask_flatZ
verif_maskZcorners_indexZcenter_indexr"   r"   r#   test_tritools9  sN    "

"





rO  c                  C   sj  d} d}t dd| d }t ||\}}| }| }t jd| d  td}d|| d d < tj||t| d |d}t	|}|j
|d	}|j}|j}	| |d  }
t dd|
d }t ||\}}| }| }t t |d
|  dt |d
|	  d}t|d |j}t j|j|j ddd }t j|j|j ddd }| }|||}|j| }t|| t g d}t g d}t||g dg dgt||g dg dgg}t |d |d }g }tdD ]r}t	|| }|j|dd	\}}t |j|j|fd }|t |d d df |d d df f }||g7 }qt|d |d  d S )Nr   r   r  r
   r   rZ   T)r   r   r  r|   rN   rO   r}   r	   r
   r	   r
   r	   r	   r
   r
   rK   rY   r   r   r   r   r   r   )r   r   r   r   r   rK  r   r   r   r  refine_triangulationr   r   Zin1dZaroundr   r   rC   r   r   rH   r   r   r  ZdstackZlexsortr   )r   r  r   r   r   r!   r  Zrefi_triangZx_refiZy_refiZn_refiZx_verifZy_verifZind1dZ	refi_maskZrefi_tri_barycenter_xZrefi_tri_barycenter_yZ
tri_finderZrefi_tri_indicesZrefi_tri_maskr   Zxyz_dataiZrefined_triangZ	refined_zZxyzr"   r"   r#   test_trirefiner  sn    



*rU  r   ZlinearZcubic)idsc                 C   sx   t jd dd df \}}t | d}t | d}t |}t||}t|}| ||}|j||dd d S )Nr   )Ztriinterpolatorr  )	r   Zmgridr  r  Z
zeros_liker   r   r  r  )r   r   r   r   rA   r  r   r"   r"   r#   test_trirefine_masked  s    


rW  c                 C   s   g }t | d D ]n}t | d D ]\}|||   }|d ||   }||d |   }|d |d |   }||||g|||gg7 }q qtj|tjdS )zU
    Return (2*(N-1)**2, 3) array of triangles to mesh (N, N)-point np.meshgrid.
    r   rZ   )r   r   rG   r[   )r   rA   rT  jr   r   r   dr"   r"   r#   r     s    r   c                  C   sL   t   } tjg dg dg dg dgd}| |dd usHJ dd S )NrP  rQ  rK   rY   r   zb-z(triplot should return the artist it adds)rV   r#  Zadd_subplotr   r   r  )r   r!   r"   r"   r#   test_triplot_return  s    rZ  c            
      C   s   t g dg dg} t | r$J t j| ddd}t |sBJ t g d}t g d}t||| }t|||}t|}t|}|jdd	}|jdd	}	t|j|	j d S )
NrR  )r   r   r   TF)r\   order)g(\?gzG?gQ?g{Gz?)gQ@@gzGA@gQA@gףp=
A@r   r  )	r   rG   Z	isfortranr   r   r  rS  r   r   )
Z
triangles1Z
triangles2r   r   Ztriang1Ztriang2Zrefiner1Zrefiner2Zfine_triang1Zfine_triang2r"   r"   r#   ,test_trirefiner_fortran_contiguous_triangles  s    

r]  c            
      C   s   t ddd} tt jt | | \}}||d k|dk @ |dk@ }|| ||  }}t d}|t | |t |  }|t | |t |  }t	||}|j
}d |_|j
}	t||	 d S )Nr   r   r   r   g333333g333333   )r   r   mapr   r   radiansr   r   r   r   r   r   r   )
xir   r   wr   x1y1r!   Zqhull_neighborsZown_neighborsr"   r"   r#   test_qhull_triangle_orientation  s    
re  c                  C   s   t g d} t dddt d ddg}t jg dg dg d	gt jd
}t jg dtd
}tj| |||d}t|}|  d S )Nr'  r	   rJ   r}   r  r
   r   rK   rL   rZ   r(  r   )	r   rG   rJ  r[   rK  r   r   rL  Z_get_compressed_triangulation)r   r   r   r   r!   rN  r"   r"   r#   #test_trianalyzer_mismatched_indices  s    "
rf  c                  C   sb   g d} g d}g d}t   tt$ t | ||ddg W d    n1 sT0    Y  d S )N)r	   r
   r
   )r	   r	   r
   )r   r   r   r
   r	   )rV   r#  r/   r0   r7   tricontourf)r   r   r   r"   r"   r#   "test_tricontourf_decreasing_levels  s    rh  c               
   C   s  ddl m}  tjtdd tj  W d    n1 s:0    Y  tjtdd, tjg dgg gd d d d W d    n1 s0    Y  g d}g d	}tjtd
d. tj||ddggd d d d W d    n1 s0    Y  g dg}tjtdd, tj|||ddgd d d W d    n1 s60    Y  tjtdd, tj|||d dggd d W d    n1 s0    Y  tjtdd, tj|||d d dggd W d    n1 s0    Y  tj|||d d d d}tjtdd |g  W d    n1 s 0    Y  tjtdd |	ddg W d    n1 s^0    Y  tjtdd tj
  W d    n1 s0    Y  tjtdd  tj
|dg W d    n1 s0    Y  g d}tj
||}tjtdd |dd W d    n1 s*0    Y  tjtdd tj  W d    n1 sd0    Y  tj|}tjtdd" |dgddg W d    n1 s0    Y  d S )Nr   )_triz.function takes exactly 7 arguments \(0 given\)matchz,x and y must be 1D arrays of the same lengthr   F)r   r   r   )r   r   r   z.triangles must be a 2D array of shape \(\?,3\)r   zCmask must be a 1D array with the same length as the triangles arrayz,edges must be a 2D array with shape \(\?,2\)zGneighbors must be a 2D array with the same shape as the triangles arrayrx   z<z array must have same length as triangulation x and y arrayz.function takes exactly 2 arguments \(0 given\)z?z must be a 1D array with the same length as the x and y arraysz(filled contour levels must be increasingz-function takes exactly 1 argument \(0 given\)z*x and y must be array-like with same shape)
matplotlibri  r/   r0   	TypeErrormplr   r7   Zcalculate_plane_coefficientsr   ZTriContourGeneratorZcreate_filled_contourZTrapezoidMapTriFinderZ	find_many)ri  r   r   r   r!   r   Ztcgr   r"   r"   r#   test_internal_cpp_api  s    (:<
<<<*.*0,*ro  c                  C   s\   t g d} t g d}d}t| |}t| | || }t|jt|jksXJ d S )N)r   r   r   r   rJ   )r   r   r   r   rJ   g    _B)r   rH   r   r   r   r   )r   r   offsetr!   Ztriang_offsetr"   r"   r#   test_qhull_large_offsetm  s    rq  c                  C   sF  g d} g d}t | |}t  tjtdd& t|dddtj	g W d    n1 s^0    Y  tjtdd( t|dddtj	 g W d    n1 s0    Y  tjtdd& t|dddtj
g W d    n1 s0    Y  tjtdd0 t|tjjg d	g d
d W d    n1 s80    Y  d S )Nr   r   zCz array must not contain non-finite values within the triangulationrj  r   r   r   z9z must not contain masked points within the triangulation)r   r   r   r   )r   r   r   r   r   )r   r   rV   r#  r/   r0   r7   rg  r   infrM  r   rG   )r   r   r!   r"   r"   r#   test_tricontour_non_finite_zx  s    464rs  c                  C   sp   g d} g d}g d}t  \}}|| ||}|| ||}|j|jksPJ |||}|j|jkslJ d S )N)r	   rJ   r
   )r	   r
   r	   )r
   r.   r}   )rV   Zsubplotsrg  r  Z_contour_generator)r   r   r   Zfigr   Ztcs1Ztcs2Ztcs3r"   r"   r#   test_tricontourset_reuse  s    rt  ):Znumpyr   Znumpy.testingr   r   r   Znumpy.ma.testutilsr   Z	testutilsr   r/   rl  rn  Zmatplotlib.cmr$  Zmatplotlib.pyplotZpyplotrV   Zmatplotlib.trirA   r   Zmatplotlib.pathr   Zmatplotlib.testing.decoratorsr   r$   r+   r4   markZparametrizer8   rI   rX   r]   r   r   r   r   r   r   r  r  r&  rO  rU  r   r   rW  r   rZ  r]  re  rf  rh  ro  rq  rs  rt  r"   r"   r"   r#   <module>   sn   *

-

g_VN>]
&
498


S