o
    :a2                     @   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      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.   F/usr/lib/python3/dist-packages/mpl_toolkits/axisartist/angle_helper.pyselect_step_degree       r0   c                 C   r   )
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   r4   r   r5   r   r6   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!   r1   r9   c                 C   sz   dt t| d  }d| }d| | krd}||fS d| | kr'd}||fS d| | kr3d}||fS 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r'||\}	}
nt|| \}	}
|
| }
tjt| |
 |	 t||
 |	 d td|	 }t|}|
dkr|d |d | krt||	 }|rw|d td|d d|	  }n|d td|d|	  }t|}t	|||
fS )	Ng      8@     v@r   g      ?)Zdtyper   r   )
r9   r0   r>   r"   ZarangefloorZceilr:   r!   r#   )v1v2nvhourinclude_lastthreshold_factorr$   Z_select_stepcycler,   r-   levsr+   r.   r.   r/   select_stepO   s4   
	 rJ   r   c                 C   s:   | d |d } }t | ||d||d\}}}|d ||fS )Nr   TrE   rF   rG   rJ   )rB   rC   rD   rF   rG   rI   r+   r-   r.   r.   r/   select_step24   s   
rM   c                 C   s   t | ||d||dS )NFrK   rL   )rB   rC   rD   rF   rG   r.   r.   r/   select_step360   s   
rN   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)selfrQ   rF   r.   r.   r/   __init__   s   
zLocatorBase.__init__Nc                 C   s   |d urt || _d S d S rP   )r:   rQ   )rS   rQ   r.   r.   r/   
set_params   s   zLocatorBase.set_params)TrP   )__name__
__module____qualname__rT   rU   r.   r.   r.   r/   rO      s    
rO   c                   @      e Zd Zdd ZdS )
LocatorHMSc                 C      t ||| j| jS rP   rM   rQ   rR   rS   rB   rC   r.   r.   r/   __call__      zLocatorHMS.__call__NrV   rW   rX   r^   r.   r.   r.   r/   rZ          rZ   c                   @   rY   )	LocatorHMc                 C      t ||| j| jddS Nr   rG   r\   r]   r.   r.   r/   r^         zLocatorHM.__call__Nr`   r.   r.   r.   r/   rb      ra   rb   c                   @   rY   )LocatorHc                 C   rc   Nr   re   r\   r]   r.   r.   r/   r^      rf   zLocatorH.__call__Nr`   r.   r.   r.   r/   rg      ra   rg   c                   @   rY   )
LocatorDMSc                 C   r[   rP   rN   rQ   rR   r]   r.   r.   r/   r^      r_   zLocatorDMS.__call__Nr`   r.   r.   r.   r/   ri      ra   ri   c                   @   rY   )	LocatorDMc                 C   rc   rd   rj   r]   r.   r.   r/   r^      rf   zLocatorDM.__call__Nr`   r.   r.   r.   r/   rk      ra   rk   c                   @   rY   )LocatorDc                 C   rc   rh   rj   r]   r.   r.   r/   r^      rf   zLocatorD.__call__Nr`   r.   r.   r.   r/   rl      ra   rl   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   st   d }dD ]1}||kr ||fS || }t tt|}d| |kr5|dkr5|}|d|  }||f  S q||fS )N)r   r   r   r   r   )r:   r"   rA   r<   )rS   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r;t|d| \}}d|f   fdd|D }|dkr\|d u rOfddt||D S fd	dt|||D S |d
krt|d
\}	}
|d u rxfddt||	|
D S fddt||	|
|D S |dkr|d dkrd}|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 ]$\}}}}j|||f }||kr|}|| }nd| | }|| q|r|d d d S |S dd || D S )Nr   c                 S   s   g | ]
}|d k r
dndqS )r   - r.   .0vr.   r.   r/   
<listcomp>   s    z)FormatterDMS.__call__.<locals>.<listcomp>r   z%%0%ddc                    s   g | ]} |f qS r.   r.   )r}   f1)frac_fmtr.   r/   r      s    r   c                    s$   g | ]\}} j |t| f qS r.   )fmt_dr:   )r}   sr~   rS   r.   r/   r      s   $ c                    s(   g | ]\}}} j |t| |f qS r.   )fmt_dsr:   )r}   r   r~   r   r   r.   r/   r      s    r   c                    s"   g | ]\}}} j |||f qS r.   )fmt_d_m)r}   s1d1m1r   r.   r/   r      s    c                    s&   g | ]\}}}} j ||||f qS r.   )fmt_d_ms)r}   r   r   r   r   r   r.   r/   r      s    
r   r@   TFr{   c                    s   g | ]} j |f qS r.   )fmt_s_partial)r}   r   r   r.   r/   r     s    c                    s   g | ]\}} j ||f qS r.   )fmt_ss_partial)r}   r   r   r   r.   r/   r     s    ro   c                 S   s   g | ]	}d t |f qS )z$%s^{\circ}$)strr|   r.   r.   r/   r     s    )	r!   r"   signry   absdivmodzipfmt_d_m_partialappend)rS   	directionr-   valuesssZsignsrw   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.   )r   rS   r/   r^      sf   










zFormatterDMS.__call__N)rV   rW   rX   deg_markmin_marksec_markr   r   r   r   r   r   r   ry   r^   r.   r.   r.   r/   rm      s    rm   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}rn   ro   rp   rq   rr   rs   rt   ru   rv   c                    s   t  ||t|d S )Nr   )superr^   r"   Zasarray)rS   r   r-   r   	__class__r.   r/   r^   2  s   zFormatterHMS.__call__)rV   rW   rX   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)rS   r   r   r   r   r   r   r.   r.   r/   rT   9  s    
zExtremeFinderCycle.__init__c                 C   s  t t ||| jt ||| j\}}|t |t |\}}	t jdd0 | jd ur<t |}
|d||
 dk 8 }| j	d urPt |	}|	d|	| dk 8 }	W d    n1 sZw   Y  t |t 
|}}t |	t 
|	}}| ||||\}}}}| jrt||| j }| j	rt||| j	 }| jd ur| 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   )rS   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/   r^   ^  s@   














zExtremeFinderCycle.__call__)r?   NNr   )rV   rW   rX   rT   r^   r.   r.   r.   r/   r   6  s
    
%r   )FTr   )Tr   )Znumpyr"   r;   Z#mpl_toolkits.axisartist.grid_finderr   r0   r9   r>   rJ   rM   rN   rO   rZ   rb   rg   ri   rk   rl   rm   r   r   r.   r.   r.   r/   <module>   s*    

1

h