a
    r=ic2                     @   s   d dl Zd dlZd dlmZ dd Zdd Zdd Zd'ddZd(ddZ	d)ddZ
G dd d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G d!d" d"ZG d#d$ d$eZG d%d& d&eZdS )*    N)ExtremeFinderSimplec                 C   s   g d}g d}dgt | }g d}g d}t|d }dgt | }t|d }d	gt | }	g |||}
g |||}g |	||}t|
| }|| }|| }||fS )
N)
      ?            (   F   x   i  i  )
         
         -   Z      ih        ?)r         @      @            r   )r   r   r   r   r   r   r   r   <         N@        @lennparrayZsearchsorted)dvZdegree_limits_Zdegree_steps_Zdegree_factorsminsec_limits_minsec_steps_minute_limits_minute_factorssecond_limits_second_factorsZdegree_limitsZdegree_stepsnstepfactor r-   u/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/mpl_toolkits/axisartist/angle_helper.pyselect_step_degree   s     r/   c                 C   s   g d}g d}dgt | }g d}g d}t|d }dgt | }t|d }d	gt | }	g |||}
g |||}g |	||}t|
| }|| }|| }||fS )
N)	r   r   r   r   r   r   r      $   )	r   r   r         r      r      r   )r   r   r   g      @g      @r   r      r   r   r   )r   r   r   r2   r   r3   r   r4   r   r   r   r   r   r   r   r   )r#   Zhour_limits_Zhour_steps_Zhour_factorsr$   r%   r&   r'   r(   r)   Zhour_limitsZ
hour_stepsr*   r+   r,   r-   r-   r.   select_step_hour!   s     r7   c                 C   sh   dt t| d  }d| }d| | kr0d}n0d| | krBd}nd| | krTd}nd}d	| }||fS )
Ng      $@r   r   r   g      @r   g      @r   g?)intmathlog10)r#   tmpr,   r+   r-   r-   r.   select_step_sub;   s    r<   FTr   c                 C   s$  | |kr||  } }||  | }|r,t }d}nt}d}|d| krN||\}	}
nt|| \}	}
|
| }
tjt| |
 |	 t||
 |	 d td|	 }t|}|
dkr|d |d | krt||	 }|r|d td|d d|	  }n|d td|d|	  }t|}t	|||
fS )	Ng      8@     v@r   g      ?)Zdtyper   r   )
r7   r/   r<   r!   Zarangefloorceilr8   r    r"   )v1v2nvhourinclude_lastthreshold_factorr#   Z_select_stepcycler+   r,   levsr*   r-   r-   r.   select_stepO   s4    
	  rI   r   c                 C   s:   | d |d  } }t | ||d||d\}}}|d ||fS )Nr   TrD   rE   rF   rI   )rA   rB   rC   rE   rF   rH   r*   r,   r-   r-   r.   select_step24   s    
rL   c                 C   s   t | ||d||dS )NFrJ   rK   )rA   rB   rC   rE   rF   r-   r-   r.   select_step360   s    
rM   c                   @   s    e Zd ZdddZdddZdS )	LocatorBaseTc                 C   s   || _ || _d S N)nbins_include_last)selfrP   rE   r-   r-   r.   __init__   s    zLocatorBase.__init__Nc                 C   s   |d urt || _d S rO   )r8   rP   )rR   rP   r-   r-   r.   
set_params   s    zLocatorBase.set_params)T)N)__name__
__module____qualname__rS   rT   r-   r-   r-   r.   rN      s   
rN   c                   @   s   e Zd Zdd ZdS )
LocatorHMSc                 C   s   t ||| j| jS rO   rL   rP   rQ   rR   rA   rB   r-   r-   r.   __call__   s    zLocatorHMS.__call__NrU   rV   rW   r[   r-   r-   r-   r.   rX      s   rX   c                   @   s   e Zd Zdd ZdS )	LocatorHMc                 C   s   t ||| j| jddS Nr   rF   rY   rZ   r-   r-   r.   r[      s    zLocatorHM.__call__Nr\   r-   r-   r-   r.   r]      s   r]   c                   @   s   e Zd Zdd ZdS )LocatorHc                 C   s   t ||| j| jddS Nr   r_   rY   rZ   r-   r-   r.   r[      s    zLocatorH.__call__Nr\   r-   r-   r-   r.   r`      s   r`   c                   @   s   e Zd Zdd ZdS )
LocatorDMSc                 C   s   t ||| j| jS rO   rM   rP   rQ   rZ   r-   r-   r.   r[      s    zLocatorDMS.__call__Nr\   r-   r-   r-   r.   rb      s   rb   c                   @   s   e Zd Zdd ZdS )	LocatorDMc                 C   s   t ||| j| jddS r^   rc   rZ   r-   r-   r.   r[      s    zLocatorDM.__call__Nr\   r-   r-   r-   r.   rd      s   rd   c                   @   s   e Zd Zdd ZdS )LocatorDc                 C   s   t ||| j| jddS ra   rc   rZ   r-   r-   r.   r[      s    zLocatorD.__call__Nr\   r-   r-   r-   r.   re      s   re   c                   @   s   e Zd ZdZdZdZde d Zde d Zde d e d Zde d	 e d Z	de d e d
 Z
de d Zde d Zdd Zdd ZdS )FormatterDMSz^{\circ}z	^{\prime}z^{\prime\prime}$%d$$%d.%s$%s%d\,%02d	\,%02d.%s\,%02d%02d.%sc                 C   sn   d }dD ]\}||kr qf|| }t tt|}d| |kr|dkr|}|d|  }||f  S q||fS )N)r   r   r   r   r   )r8   r!   r?   r:   )rR   r,   number_fraction	thresholddZ	int_log_dr-   r-   r.   _get_number_fraction   s    z!FormatterDMS._get_number_fractionc                    s:  t |dkrg S t|}dd |D }|\}}t|}|d urvt|d| \}}d|f   fdd|D }|dkr|d u rfddt||D S fd	dt|||D S nz|d
krt|d
\}	}
|d u rfddt||	|
D S fddt||	|
|D S n |dkr$|d dkrPd}|d d d }|d d d }nd}d}g }t|d\}	}t|d
\}
}|d u rfdd|D }nfddt||D }t||	|
|D ]L\}}}}j|||f }||kr|}|| }nd| | }|| q|r|d d d S |S ndd || D S d S )Nr   c                 S   s   g | ]}|d k rdndqS )r   - r-   .0vr-   r-   r.   
<listcomp>       z)FormatterDMS.__call__.<locals>.<listcomp>r   z%%0%ddc                    s   g | ]} |f qS r-   r-   )rw   f1)frac_fmtr-   r.   ry      rz   r   c                    s$   g | ]\}} j |t| f qS r-   )fmt_dr8   )rw   srx   rR   r-   r.   ry      rz   c                    s(   g | ] \}}} j |t| |f qS r-   )fmt_dsr8   )rw   r~   rx   r{   r   r-   r.   ry      s   r   c                    s"   g | ]\}}} j |||f qS r-   )fmt_d_m)rw   s1d1m1r   r-   r.   ry      s   c                    s&   g | ]\}}}} j ||||f qS r-   )fmt_d_ms)rw   r~   r   r   r{   r   r-   r.   ry      s   
r   r>   TFru   c                    s   g | ]} j |f qS r-   )fmt_s_partial)rw   r   r   r-   r.   ry     rz   c                    s   g | ]\}} j ||f qS r-   )fmt_ss_partial)rw   r   r{   r   r-   r.   ry     s   rh   c                 S   s   g | ]}d t |f qS )z$%s^{\circ}$)strrv   r-   r-   r.   ry     rz   )	r    r!   signrs   absdivmodzipfmt_d_m_partialappend)rR   	directionr,   valuesssZsignsrp   Z	frac_partZfrac_strZdeg_partZmin_partZinverse_orderZl_hm_oldrZ	min_part_Zsec_partsec_strr~   r   r   r   Zl_hmlr-   )r|   rR   r.   r[      sf    















zFormatterDMS.__call__N)rU   rV   rW   deg_markmin_marksec_markr}   r   r   r   r   r   r   rs   r[   r-   r-   r-   r.   rf      s   rf   c                       s   e Zd ZdZdZdZde d Zde d Zde d e d Zde d	 e d Z	de d e d
 Z
de d Zde d Z fddZ  ZS )FormatterHMSz^\mathrm{h}z^\mathrm{m}z^\mathrm{s}rg   rh   ri   rj   rk   rl   rm   rn   ro   c                    s   t  ||t|d S )Nr   )superr[   r!   Zasarray)rR   r   r,   r   	__class__r-   r.   r[   2  s    zFormatterHMS.__call__)rU   rV   rW   r   r   r   r}   r   r   r   r   r   r   r[   __classcell__r-   r-   r   r.   r   "  s   r   c                   @   s   e Zd ZdddZdd ZdS )	ExtremeFinderCycler=   Nir   c                 C   s,   || | _ | _|| | _| _|| _|| _dS )aB  
        This subclass handles the case where one or both coordinates should be
        taken modulo 360, or be restricted to not exceed a specific range.

        Parameters
        ----------
        nx, ny : int
            The number of samples in each direction.

        lon_cycle, lat_cycle : 360 or None
            If not None, values in the corresponding direction are taken modulo
            *lon_cycle* or *lat_cycle*; in theory this can be any number but
            the implementation actually assumes that it is 360 (if not None);
            other values give nonsensical results.

            This is done by "unwrapping" the transformed grid coordinates so
            that jumps are less than a half-cycle; then normalizing the span to
            no more than a full cycle.

            For example, if values are in the union of the [0, 2] and
            [358, 360] intervals (typically, angles measured modulo 360), the
            values in the second interval are normalized to [-2, 0] instead so
            that the values now cover [-2, 2].  If values are in a range of
            [5, 1000], this gets normalized to [5, 365].

        lon_minmax, lat_minmax : (float, float) or None
            If not None, the computed bounding box is clipped to the given
            range in the corresponding direction.
        N)nxny	lon_cycle	lat_cycle
lon_minmax
lat_minmax)rR   r   r   r   r   r   r   r-   r-   r.   rS   9  s     zExtremeFinderCycle.__init__c                 C   s  t t ||| jt ||| j\}}|t |t |\}}	t jdd` | jd urxt |}
|d||
 dk 8 }| j	d urt |	}|	d|	| dk 8 }	W d    n1 s0    Y  t |t 
| }}t |	t 
|	 }}| ||||\}}}}| jrt||| j }| j	r2t||| j	 }| jd urf| jd }t||}| jd }t||}| jd ur| jd }t||}| jd }t||}||||fS )Nignore)invalidr=   g     f@r   r   )r!   ZmeshgridZlinspacer   r   ZravelZerrstater   Znanminr   ZnanmaxZ_add_padminr   maxr   )rR   Ztransform_xyx1y1Zx2y2xyZlonZlatZlon0Zlat0Zlon_minZlon_maxZlat_minZlat_maxZmin0Zmax0r-   r-   r.   r[   ^  s<    



2








zExtremeFinderCycle.__call__)r=   NNr   )rU   rV   rW   rS   r[   r-   r-   r-   r.   r   6  s     
%r   )FTr   )Tr   )Tr   )numpyr!   r9   Z#mpl_toolkits.axisartist.grid_finderr   r/   r7   r<   rI   rL   rM   rN   rX   r]   r`   rb   rd   re   rf   r   r   r-   r-   r-   r.   <module>   s(     
1


h