U
    Âmœd²C  ã                   @   sè   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lmZ d dlmZmZmZmZ d dlmZmZmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    N)Ú_api)ÚAxes©ÚCircle)ÚPath)Ú	FormatterÚNullLocatorÚFixedLocatorÚNullFormatter)ÚAffine2DÚBboxTransformToÚ	Transformc                       sø   e Zd ZdZG dd„ deƒZdZdd„ Z‡ fdd„Zd	d
„ Z	dd„ Z
d6dd„Zdd„ Zdd„ Zd7dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZeZd d!„ ZeZd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Z ‡  Z!S )8ÚGeoAxesz2An abstract base class for geographic projections.c                   @   s$   e Zd ZdZddd„Zd	dd„ZdS )
zGeoAxes.ThetaFormatterz‹
        Used to format the theta tick labels.  Converts the native
        unit of radians into degrees and adds a degree symbol.
        ç      ð?c                 C   s
   || _ d S ©N)Ú	_round_to)ÚselfZround_to© r   úS/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/matplotlib/projections/geo.pyÚ__init__   s    zGeoAxes.ThetaFormatter.__init__Nc                 C   s&   t t |¡| j ƒ| j }|d›d�S )Nz0.0fõ   Â°)ÚroundÚnpÚrad2degr   )r   ÚxÚposÚdegreesr   r   r   Ú__call__   s    zGeoAxes.ThetaFormatter.__call__)r   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   ÚThetaFormatter   s   
r"   éK   c                 C   s   t  | ¡| _t  | ¡| _d S r   )ÚmaxisZXAxisÚxaxisZYAxisÚyaxis©r   r   r   r   Ú
_init_axis    s    zGeoAxes._init_axisc                    s®   t ƒ  ¡  |  d¡ |  d¡ |  d¡ | j tƒ ¡ | j tƒ ¡ | j 	d¡ | j 	d¡ | jj
dd� |  tjd ¡ t | tj tj¡ t | tj d tjd ¡ d S )	Né   é   r#   ÚnoneT)Zlabel1Onz	axes.gridç       @)ÚsuperÚclearÚset_longitude_gridÚset_latitude_gridÚset_longitude_grid_endsr%   Zset_minor_locatorr   r&   Zset_ticks_positionZset_tick_paramsÚgridÚmplZrcParamsr   Úset_xlimr   ÚpiÚset_ylimr'   ©Ú	__class__r   r   r.   '   s    



zGeoAxes.clearc                 C   s0  |   | j¡| _|  ¡ | _t| jƒ| _| j| j | j | _t	ƒ  
d| jd ¡ d| j ¡| _| j| j | _t	ƒ  
dd¡| j t	ƒ  dd¡ | _t	ƒ  
dd¡| j t	ƒ  dd¡ | _t	ƒ  
tjd d¡ tj d¡}t	ƒ  
dd¡}|| j | _|| j || j | j  }|t	ƒ  dd¡ | _|t	ƒ  dd¡ | _d S )	Né   é   r   é   éüÿÿÿgš™™™™™ñ?iøÿÿÿé   )Ú_get_core_transformÚ
RESOLUTIONZtransProjectionÚ_get_affine_transformZtransAffiner   ZbboxZ	transAxesZ	transDatar   ÚscaleÚ_longitude_capÚ	translateÚ_xaxis_pretransformÚ_xaxis_transformÚ_xaxis_text1_transformÚ_xaxis_text2_transformr   r5   Ú_yaxis_transformÚ_yaxis_text1_transformÚ_yaxis_text2_transform)r   Zyaxis_stretchZyaxis_spaceZyaxis_text_baser   r   r   Ú_set_lim_and_transforms;   sr    
ÿþÿ ÿ þÿÿÿÿþÿÿþÿ ÿÿÿÿþþÿÿÿÿÿzGeoAxes._set_lim_and_transformsc                 C   sT   |   d¡}| tjdf¡\}}| dtjd f¡\}}tƒ  d| d| ¡ dd¡S )Nr9   r   r:   ç      à?)r>   Ú	transformr   r5   r   rA   rC   )r   rM   ZxscaleÚ_Zyscaler   r   r   r@   n   s    
 ÿ þzGeoAxes._get_affine_transformr2   c                 C   s   t jdddg|d� | jS ©NZtick1Ztick2r2   )Úwhich)r   Úcheck_in_listrE   ©r   rP   r   r   r   Úget_xaxis_transformv   s    zGeoAxes.get_xaxis_transformc                 C   s   | j ddfS )NÚbottomÚcenter)rF   ©r   Úpadr   r   r   Úget_xaxis_text1_transformz   s    z!GeoAxes.get_xaxis_text1_transformc                 C   s   | j ddfS )NÚtoprU   )rG   rV   r   r   r   Úget_xaxis_text2_transform}   s    z!GeoAxes.get_xaxis_text2_transformc                 C   s   t jdddg|d� | jS rO   )r   rQ   rH   rR   r   r   r   Úget_yaxis_transform€   s    zGeoAxes.get_yaxis_transformc                 C   s   | j ddfS )NrU   Úright)rI   rV   r   r   r   Úget_yaxis_text1_transform„   s    z!GeoAxes.get_yaxis_text1_transformc                 C   s   | j ddfS )NrU   Úleft)rJ   rV   r   r   r   Úget_yaxis_text2_transform‡   s    z!GeoAxes.get_yaxis_text2_transformc                 C   s
   t ddƒS )N©rL   rL   rL   r   r'   r   r   r   Ú_gen_axes_patchŠ   s    zGeoAxes._gen_axes_patchc                 C   s   dt j | dd¡iS )NZgeor`   rL   )ÚmspinesZSpineZcircular_spiner'   r   r   r   Ú_gen_axes_spines�   s    zGeoAxes._gen_axes_spinesc                 O   s   |d dkrt ‚d S )Nr   Zlinear)ÚNotImplementedError©r   ÚargsÚkwargsr   r   r   Ú
set_yscale�   s    zGeoAxes.set_yscalec                 O   s   t dƒ‚dS )z-Not supported. Please consider using Cartopy.zaChanging axes limits of a geographic projection is not supported.  Please consider using Cartopy.N)Ú	TypeErrorre   r   r   r   r4   –   s    zGeoAxes.set_xlimc                 C   sJ   t  ||g¡\}}|dkrdnd}|dkr.dnd}dt|ƒ|t|ƒ|f S )z1Return a format string formatting the coordinate.ç        ÚNÚSÚEÚWu   %fÂ°%s, %fÂ°%s)r   r   Úabs)r   ZlonZlatÚnsÚewr   r   r   Úformat_coord�   s    ÿzGeoAxes.format_coordc                 C   s>   t  d| d|¡}| j tt  |¡ƒ¡ | j |  |¡¡ dS )zH
        Set the number of degrees between each longitude grid.
        iLÿÿÿé´   N)r   Úaranger%   Úset_major_locatorr	   Údeg2radÚset_major_formatterr"   ©r   r   r2   r   r   r   r/   ¥   s    zGeoAxes.set_longitude_gridc                 C   s>   t  d| d|¡}| j tt  |¡ƒ¡ | j |  |¡¡ dS )zG
        Set the number of degrees between each latitude grid.
        i¦ÿÿÿéZ   N)r   rt   r&   ru   r	   rv   rw   r"   rx   r   r   r   r0   ®   s    zGeoAxes.set_latitude_gridc                 C   s4   t  |¡| _| j ¡  d| jd ¡ d| j ¡ dS )zS
        Set the latitude(s) at which to stop drawing the longitude grids.
        r   r,   rj   N)r   rv   rB   rD   r.   rA   rC   )r   r   r   r   r   r1   ·   s    
 þ ýzGeoAxes.set_longitude_grid_endsc                 C   s   dS )z+Return the aspect ratio of the data itself.r   r   r'   r   r   r   Úget_data_ratioÁ   s    zGeoAxes.get_data_ratioc                 C   s   dS )z—
        Return whether this Axes supports the zoom box button functionality.

        This Axes object does not support interactive zoom box.
        Fr   r'   r   r   r   Úcan_zoomÇ   s    zGeoAxes.can_zoomc                 C   s   dS )z—
        Return whether this Axes supports the pan/zoom button functionality.

        This Axes object does not support interactive pan/zoom.
        Fr   r'   r   r   r   Úcan_panÏ   s    zGeoAxes.can_panc                 C   s   d S r   r   )r   r   ÚyÚbuttonr   r   r   Ú	start_pan×   s    zGeoAxes.start_panc                 C   s   d S r   r   r'   r   r   r   Úend_panÚ   s    zGeoAxes.end_panc                 C   s   d S r   r   )r   r~   Úkeyr   r}   r   r   r   Údrag_panÝ   s    zGeoAxes.drag_pan)r2   )r2   )"r   r   r    r!   r   r"   r?   r(   r.   rK   r@   rS   rX   rZ   r[   r]   r_   ra   rc   rh   Z
set_xscaler4   r6   rr   r/   r0   r1   rz   r{   r|   r   r€   r‚   Ú__classcell__r   r   r7   r   r      s:   3

		
r   c                       s4   e Zd Zd ZZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_GeoTransformr:   c                    s   t ƒ  ¡  || _dS )zÁ
        Create a new geographical transform.

        Resolution is the number of steps to interpolate between each input
        line segment to approximate its path in curved space.
        N)r-   r   Ú_resolution©r   Ú
resolutionr7   r   r   r   å   s    
z_GeoTransform.__init__c                 C   s   d  t| ƒj| j¡S )Nz{}({}))ÚformatÚtyper   r…   r'   r   r   r   Ú__str__ï   s    z_GeoTransform.__str__c                 C   s    |  | j¡}t|  |j¡|jƒS r   )Zinterpolatedr…   r   rM   ZverticesÚcodes)r   ÚpathZipathr   r   r   Útransform_path_non_affineò   s    z'_GeoTransform.transform_path_non_affine)	r   r   r    Z
input_dimsZoutput_dimsr   rŠ   r�   rƒ   r   r   r7   r   r„   á   s   
r„   c                       sH   e Zd ZdZG dd„ deƒZG dd„ deƒZ‡ fdd„Zdd	„ Z‡  Z	S )
Ú
AitoffAxesZaitoffc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )zAitoffAxes.AitoffTransformzThe base Aitoff transform.c           
      C   sn   |j \}}|d }t |¡}t |t |¡ ¡}t |tj ¡}|t |¡ | }t |¡| }	t ||	g¡S )Nr,   )ÚTr   ÚcosZarccosZsincr5   ÚsinÚcolumn_stack)
r   ÚllÚ	longitudeÚlatitudeÚ	half_longÚcos_latitudeÚalphaZ
sinc_alphar   r}   r   r   r   Útransform_non_affineþ   s    

z/AitoffAxes.AitoffTransform.transform_non_affinec                 C   s   t  | j¡S r   )rŽ   ÚInvertedAitoffTransformr…   r'   r   r   r   Úinverted  s    z#AitoffAxes.AitoffTransform.invertedN©r   r   r    r!   r™   r›   r   r   r   r   ÚAitoffTransformû   s   r�   c                   @   s   e Zd Zdd„ Zdd„ ZdS )z"AitoffAxes.InvertedAitoffTransformc                 C   s   t  |t j¡S r   )r   Z	full_likeÚnan)r   Úxyr   r   r   r™     s    z7AitoffAxes.InvertedAitoffTransform.transform_non_affinec                 C   s   t  | j¡S r   )rŽ   r�   r…   r'   r   r   r   r›     s    z+AitoffAxes.InvertedAitoffTransform.invertedN©r   r   r    r™   r›   r   r   r   r   rš     s   rš   c                    s6   t jd | _tƒ j||Ž | jdddd� |  ¡  d S ©Nr,   rL   ÚboxÚC©Z
adjustableÚanchor©r   r5   rB   r-   r   Ú
set_aspectr.   re   r7   r   r   r     s    zAitoffAxes.__init__c                 C   s
   |   |¡S r   )r�   r†   r   r   r   r>   "  s    zAitoffAxes._get_core_transform)
r   r   r    Únamer„   r�   rš   r   r>   rƒ   r   r   r7   r   rŽ   ø   s
   rŽ   c                       sH   e Zd ZdZG dd„ deƒZG dd„ deƒZ‡ fdd„Zdd	„ Z‡  Z	S )
Ú
HammerAxesÚhammerc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )zHammerAxes.HammerTransformzThe base Hammer transform.c           
      C   sx   |j \}}|d }t |¡}t d¡}t d|t |¡  ¡}d| |t |¡  | }|t |¡ | }	t ||	g¡S )Nr,   r   )r�   r   r�   Úsqrtr‘   r’   )
r   r“   r”   r•   r–   r—   Zsqrt2r˜   r   r}   r   r   r   r™   ,  s    


z/HammerAxes.HammerTransform.transform_non_affinec                 C   s   t  | j¡S r   )r©   ÚInvertedHammerTransformr…   r'   r   r   r   r›   7  s    z#HammerAxes.HammerTransform.invertedNrœ   r   r   r   r   ÚHammerTransform)  s   r­   c                   @   s   e Zd Zdd„ Zdd„ ZdS )z"HammerAxes.InvertedHammerTransformc                 C   sn   |j \}}t d|d d  |d d  ¡}dt || dd|d  d   ¡ }t || ¡}t ||g¡S )Nr9   r;   r:   )r�   r   r«   ÚarctanÚarcsinr’   )r   rŸ   r   r}   Úzr”   r•   r   r   r   r™   =  s
    
"&z7HammerAxes.InvertedHammerTransform.transform_non_affinec                 C   s   t  | j¡S r   )r©   r­   r…   r'   r   r   r   r›   E  s    z+HammerAxes.InvertedHammerTransform.invertedNr    r   r   r   r   r¬   ;  s   r¬   c                    s6   t jd | _tƒ j||Ž | jdddd� |  ¡  d S r¡   r¦   re   r7   r   r   r   I  s    zHammerAxes.__init__c                 C   s
   |   |¡S r   )r­   r†   r   r   r   r>   O  s    zHammerAxes._get_core_transform)
r   r   r    r¨   r„   r­   r¬   r   r>   rƒ   r   r   r7   r   r©   &  s
   r©   c                       sH   e Zd ZdZG dd„ deƒZG dd„ deƒZ‡ fdd„Zdd	„ Z‡  Z	S )
ÚMollweideAxesZ	mollweidec                   @   s    e Zd ZdZdd„ Zdd„ ZdS )z MollweideAxes.MollweideTransformzThe base Mollweide transform.c                    s`  ‡ fdd„}|j \}}tjd t |¡ }|dk }| }tj|jtd�}| ¡ r´tjt || ¡ ‰ d||  }	||	ƒ\}
}t |¡r¨|	|  |
| 7  < ||	ƒ\}
}q||	d ||< | ¡ rþ|| }ddtj |d  d	  }tjd | t 	|| ¡ ||< tj|jtd�}dt 
d¡ tj | t |¡ |d d …d
f< t 
d¡t |¡ |d d …df< |S )Nc                    s4   | t  | ¡ ˆ   dt  | ¡  }|t  |¡dkfS )Nr9   gü©ñÒMbP?)r   r‘   r�   ro   )ÚthetaÚdelta©Zpi_sin_lr   r   Úd[  s    ÿz@MollweideAxes.MollweideTransform.transform_non_affine.<locals>.dr:   gƒÀÊ¡E¶?)Zdtyper,   rL   é   gUUUUUUÕ?r   r9   )r�   r   r5   ro   ÚemptyÚshapeÚfloatÚanyr‘   Úsignr«   r�   )r   r“   rµ   r”   r•   ÚclatZihighZilowZauxr²   r³   Zlarge_deltaÚerŸ   r   r´   r   r™   Y  s,    

 . z5MollweideAxes.MollweideTransform.transform_non_affinec                 C   s   t  | j¡S r   )r±   ÚInvertedMollweideTransformr…   r'   r   r   r   r›   {  s    z)MollweideAxes.MollweideTransform.invertedNrœ   r   r   r   r   ÚMollweideTransformV  s   "r¿   c                   @   s   e Zd Zdd„ Zdd„ ZdS )z(MollweideAxes.InvertedMollweideTransformc                 C   sp   |j \}}t |t d¡ ¡}tjdt d¡  | t |¡ }t d| t d| ¡ tj ¡}t ||g¡S )Nr:   )r�   r   r¯   r«   r5   r�   r‘   r’   )r   rŸ   r   r}   r²   r”   r•   r   r   r   r™   �  s
    
""z=MollweideAxes.InvertedMollweideTransform.transform_non_affinec                 C   s   t  | j¡S r   )r±   r¿   r…   r'   r   r   r   r›   ‹  s    z1MollweideAxes.InvertedMollweideTransform.invertedNr    r   r   r   r   r¾     s   
r¾   c                    s6   t jd | _tƒ j||Ž | jdddd� |  ¡  d S r¡   r¦   re   r7   r   r   r   �  s    zMollweideAxes.__init__c                 C   s
   |   |¡S r   )r¿   r†   r   r   r   r>   •  s    z!MollweideAxes._get_core_transform)
r   r   r    r¨   r„   r¿   r¾   r   r>   rƒ   r   r   r7   r   r±   S  s
   )r±   c                       sd   e Zd ZdZG dd„ deƒZG dd„ deƒZdddœ‡ fdd	„
Z‡ fd
d„Zdd„ Z	dd„ Z
‡  ZS )ÚLambertAxesZlambertc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	zLambertAxes.LambertTransformzThe base Lambert transform.c                 C   s   t  | |¡ || _|| _dS )zÔ
            Create a new Lambert transform.  Resolution is the number of steps
            to interpolate between each input line segment to approximate its
            path in curved Lambert space.
            N©r„   r   Ú_center_longitudeÚ_center_latitude©r   Úcenter_longitudeÚcenter_latituder‡   r   r   r   r   Ÿ  s    z%LambertAxes.LambertTransform.__init__c                 C   sº   |j \}}| j}| j}t |¡}t |¡}|| }t |¡}	t dt |¡|  t |¡| |	  d¡}
t d|
 ¡}|| t |¡ }|t |¡| t |¡| |	   }t ||g¡S )Nr9   gVçž¯Ò<r:   )	r�   rÂ   rÃ   r   r�   r‘   Úmaximumr«   r’   )r   r“   r”   r•   Úclongr¼   Zcos_latZsin_latZ	diff_longZcos_diff_longZinner_kÚkr   r}   r   r   r   r™   ©  s    



"þ$z1LambertAxes.LambertTransform.transform_non_affinec                 C   s   t  | j| j| j¡S r   )rÀ   ÚInvertedLambertTransformrÂ   rÃ   r…   r'   r   r   r   r›   ¼  s
    ýz%LambertAxes.LambertTransform.invertedN)r   r   r    r!   r   r™   r›   r   r   r   r   ÚLambertTransformœ  s   
rË   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )z$LambertAxes.InvertedLambertTransformc                 C   s   t  | |¡ || _|| _d S r   rÁ   rÄ   r   r   r   r   Å  s    z-LambertAxes.InvertedLambertTransform.__init__c              	   C   s¾   |j \}}| j}| j}t t ||¡d¡}dt d| ¡ }t |¡}t |¡}	t |	t |¡ || t |¡ |  ¡}
|t 	|| |t |¡ |	 |t |¡ |   ¡ }t 
||
g¡S )Ng•Ö&è.>r:   rL   )r�   rÂ   rÃ   r   rÇ   Úhypotr¯   r‘   r�   r®   r’   )r   rŸ   r   r}   rÈ   r¼   ÚpÚcZsin_cZcos_cr•   r”   r   r   r   r™   Ê  s    


ÿ*ÿz9LambertAxes.InvertedLambertTransform.transform_non_affinec                 C   s   t  | j| j| j¡S r   )rÀ   rË   rÂ   rÃ   r…   r'   r   r   r   r›   Û  s
    ýz-LambertAxes.InvertedLambertTransform.invertedN)r   r   r    r   r™   r›   r   r   r   r   rÊ   Ã  s   rÊ   r   )rÅ   rÆ   c                   sB   t jd | _|| _|| _tƒ j||Ž | jdddd� |  ¡  d S )Nr:   Úequalr¢   r£   r¤   )	r   r5   rB   rÂ   rÃ   r-   r   r§   r.   )r   rÅ   rÆ   rf   rg   r7   r   r   r   â  s    zLambertAxes.__init__c                    s   t ƒ  ¡  | j tƒ ¡ d S r   )r-   r.   r&   rw   r
   r'   r7   r   r   r.   ê  s    
zLambertAxes.clearc                 C   s   |   | j| j|¡S r   )rË   rÂ   rÃ   r†   r   r   r   r>   ï  s
    ýzLambertAxes._get_core_transformc                 C   s   t ƒ  d¡ dd¡S )Ng      Ð?rL   )r   rA   rC   r'   r   r   r   r@   õ  s    ÿ þz!LambertAxes._get_affine_transform)r   r   r    r¨   r„   rË   rÊ   r   r.   r>   r@   rƒ   r   r   r7   r   rÀ   ™  s   'rÀ   ) Únumpyr   Z
matplotlibr3   r   Zmatplotlib.axesr   Zmatplotlib.axisZaxisr$   Zmatplotlib.patchesr   Zmatplotlib.pathr   Zmatplotlib.spinesZspinesrb   Zmatplotlib.tickerr   r   r	   r
   Zmatplotlib.transformsr   r   r   r   r„   rŽ   r©   r±   rÀ   r   r   r   r   Ú<module>   s     S.-F