a
    f1b2                     @   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-   Clib/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floorZceilr8   r    r"   )v1v2nvhourinclude_lastthreshold_factorr#   Z_select_stepcycler+   r,   levsr*   r-   r-   r.   select_stepO   s4    
	  rH   r   c                 C   s:   | d |d  } }t | ||d||d\}}}|d ||fS )Nr   TrC   rD   rE   rH   )r@   rA   rB   rD   rE   rG   r*   r,   r-   r-   r.   select_step24   s    
rK   c                 C   s   t | ||d||dS )NFrI   rJ   )r@   rA   rB   rD   rE   r-   r-   r.   select_step360   s    
rL   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)selfrO   rD   r-   r-   r.   __init__   s    zLocatorBase.__init__Nc                 C   s   |d urt || _d S rN   )r8   rO   )rQ   rO   r-   r-   r.   
set_params   s    zLocatorBase.set_params)T)N)__name__
__module____qualname__rR   rS   r-   r-   r-   r.   rM      s   
rM   c                   @   s   e Zd Zdd ZdS )
LocatorHMSc                 C   s   t ||| j| jS rN   rK   rO   rP   rQ   r@   rA   r-   r-   r.   __call__   s    zLocatorHMS.__call__NrT   rU   rV   rZ   r-   r-   r-   r.   rW      s   rW   c                   @   s   e Zd Zdd ZdS )	LocatorHMc                 C   s   t ||| j| jddS Nr   rE   rX   rY   r-   r-   r.   rZ      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^   rX   rY   r-   r-   r.   rZ      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 rN   rL   rO   rP   rY   r-   r-   r.   rZ      s    zLocatorDMS.__call__Nr[   r-   r-   r-   r.   ra      s   ra   c                   @   s   e Zd Zdd ZdS )	LocatorDMc                 C   s   t ||| j| jddS r]   rb   rY   r-   r-   r.   rZ      s    zLocatorDM.__call__Nr[   r-   r-   r-   r.   rc      s   rc   c                   @   s   e Zd Zdd ZdS )LocatorDc                 C   s   t ||| j| jddS r`   rb   rY   r-   r-   r.   rZ      s    zLocatorD.__call__Nr[   r-   r-   r-   r.   rd      s   rd   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:   )rQ   r,   number_fractionZ	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-   )ru   f1)frac_fmtr-   r.   rw      rx   r   c                    s$   g | ]\}} j |t| f qS r-   )fmt_dr8   )ru   srv   rQ   r-   r.   rw      rx   c                    s(   g | ] \}}} j |t| |f qS r-   )fmt_dsr8   )ru   r|   rv   ry   r}   r-   r.   rw      s   r   c                    s"   g | ]\}}} j |||f qS r-   )fmt_d_m)ru   s1d1m1r}   r-   r.   rw      s   c                    s&   g | ]\}}}} j ||||f qS r-   )fmt_d_ms)ru   r|   r   r   ry   r}   r-   r.   rw      s   
r   r>   TFrs   c                    s   g | ]} j |f qS r-   )fmt_s_partial)ru   r   r}   r-   r.   rw     rx   c                    s   g | ]\}} j ||f qS r-   )fmt_ss_partial)ru   r   ry   r}   r-   r.   rw     s   rg   c                 S   s   g | ]}d t |f qS )z$%s^{\circ}$)strrt   r-   r-   r.   rw     rx   )	r    r!   Zsignrq   absdivmodzipfmt_d_m_partialappend)rQ   	directionr,   valuesZssZsignsro   Z	frac_partZfrac_strZdeg_partZmin_partZinverse_orderZl_hm_oldrZ	min_part_Zsec_partZsec_strr|   r   r   r   Zl_hmlr-   )rz   rQ   r.   rZ      sf    















zFormatterDMS.__call__N)rT   rU   rV   deg_markmin_marksec_markr{   r~   r   r   r   r   r   rq   rZ   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 fddZ  ZS )FormatterHMSz^\mathrm{h}z^\mathrm{m}z^\mathrm{s}rf   rg   rh   ri   rj   rk   rl   rm   rn   c                    s   t  ||t|d S )Nr   )superrZ   r!   Zasarray)rQ   r   r,   r   	__class__r-   r.   rZ   2  s    zFormatterHMS.__call__)rT   rU   rV   r   r   r   r{   r~   r   r   r   r   r   rZ   __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)rQ   r   r   r   r   r   r   r-   r-   r.   rR   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)Zinvalidr=   g     f@r   r   )r!   ZmeshgridZlinspacer   r   ZravelZerrstater   Znanminr   ZnanmaxZ_add_padminr   maxr   )rQ   Ztransform_xyZx1Zy1Zx2Zy2xyZlonZlatZlon0Zlat0Zlon_minZlon_maxZlat_minZlat_maxZmin0Zmax0r-   r-   r.   rZ   ^  s<    



2








zExtremeFinderCycle.__call__)r=   NNr   )rT   rU   rV   rR   rZ   r-   r-   r-   r.   r   6  s     
%r   )FTr   )Tr   )Tr   )Znumpyr!   r9   Z#mpl_toolkits.axisartist.grid_finderr   r/   r7   r<   rH   rK   rL   rM   rW   r\   r_   ra   rc   rd   re   r   r   r-   r-   r-   r.   <module>   s(     
1


h