a
    ضaC                     @   s   d dl Zd dlmZ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rcParams)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   j/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/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yaxisZ_update_transScale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d  t| tj tj t| tj d tjd  d S )	N      r$   noneT)Zlabel1Onz	axes.grid       @)superclaset_longitude_gridset_latitude_gridset_longitude_grid_endsr&   Zset_minor_locatorr	   r'   Zset_ticks_positionZset_tick_paramsgridr   r   set_xlimr   piset_ylimr(   	__class__r   r   r/   '   s    



zGeoAxes.clac                 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:   sn    

 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@   m   s    
zGeoAxes._get_affine_transformr3   c                 C   s   t jg d|d | jS N)Ztick1Ztick2r3   )which)r   check_in_listrE   r   rP   r   r   r   get_xaxis_transformu   s    zGeoAxes.get_xaxis_transformc                 C   s   | j ddfS )NZbottomcenter)rF   r   padr   r   r   get_xaxis_text1_transformy   s    z!GeoAxes.get_xaxis_text1_transformc                 C   s   | j ddfS )NtoprT   )rG   rU   r   r   r   get_xaxis_text2_transform|   s    z!GeoAxes.get_xaxis_text2_transformc                 C   s   t jg d|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 )NrT   right)rI   rU   r   r   r   get_yaxis_text1_transform   s    z!GeoAxes.get_yaxis_text1_transformc                 C   s   | j ddfS )NrT   left)rJ   rU   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)	TypeErrorrd   r   r   r   r4      s    zGeoAxes.set_xlimc                 C   sN   t ||g\}}|dkr d}nd}|dkr2d}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   r3   r   r   r   r0      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.
        iZ   N)r   rs   r'   rt   r
   ru   rv   r#   rw   r   r   r   r1      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-   ri   N)r   ru   rB   rD   clearrA   rC   )r   r   r   r   r   r2      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)r3   )r3   )"r   r    r!   r"   r   r#   r?   r)   r/   rK   r@   rS   rW   rY   rZ   r\   r^   r`   rb   rg   Z
set_xscaler4   r6   rq   r0   r1   r2   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                    s:   t jd | _t j|i | | jdddd |   d S Nr-   rL   boxCZ
adjustableanchorr   r5   rB   r.   r   
set_aspectr/   rd   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 )

HammerAxesZ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   1  s    


z/HammerAxes.HammerTransform.transform_non_affinec                 C   s   t | jS r   )r   InvertedHammerTransformr   r(   r   r   r   r   <  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   B  s
    
"&z7HammerAxes.InvertedHammerTransform.transform_non_affinec                 C   s   t | jS r   )r   r   r   r(   r   r   r   r   J  s    z+HammerAxes.InvertedHammerTransform.invertedNr   r   r   r   r   r   @  s   r   c                    s:   t jd | _t j|i | | jdddd |   d S r   r   rd   r7   r   r   r   N  s    zHammerAxes.__init__c                 C   s
   |  |S r   )r   r   r   r   r   r>   T  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}| rt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   gMbP?)r   r   r   rn   )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   rn   emptyshapefloatanyr   signr   r   )r   r   r   r   r   clatZihighZilowZauxr   r   Zlarge_deltaer   r   r   r   r   ^  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   MollweideTransform[  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                    s:   t jd | _t j|i | | jdddd |   d S r   r   rd   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   X  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                   sF   t jd | _|| _|| _t j|i | | jdddd |   d S )Nr:   equalr   r   r   )	r   r5   rB   r   r   r.   r   r   r/   )r   r   r   re   rf   r7   r   r   r     s    zLambertAxes.__init__c                    s   t    | jt  d S r   )r.   r/   r'   rv   r   r(   r7   r   r   r/     s    
zLambertAxes.clac                 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   ) Znumpyr   Z
matplotlibr   r   Zmatplotlib.axesr   Zmatplotlib.axisZaxisr%   Zmatplotlib.patchesr   Zmatplotlib.pathr   Zmatplotlib.spinesZspinesra   Zmatplotlib.tickerr   r	   r
   r   Zmatplotlib.transformsr   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    Y.-F