U
    e»{j-  ã                   @   sº   d dl Z d dlmZ d dlZd dlmZ d dlmZm	Z	 d dl
mZ dddd	d
gZG dd„ dƒZG dd„ deƒZG dd„ dee jd�ZG dd„ deƒZG dd	„ d	eƒZG dd
„ d
eƒZdS )é    N)ÚOrderedDict)ÚrcParams)ÚLine2DÚPath)Ú	PathPatchÚRectangularFrame1DÚSpineÚ	BaseFrameÚRectangularFrameÚEllipticalFramec                   @   s|   e Zd ZdZddœdd„Zedd„ ƒZejdd„ ƒZed	d
„ ƒZejdd
„ ƒZedd„ ƒZ	e	jdd„ ƒZ	dd„ Z
dd„ ZdS )r   a„  
    A single side of an axes.

    This does not need to be a straight line, but represents a 'side' when
    determining which part of the frame to put labels and ticks on.

    Parameters
    ----------
    parent_axes : `~astropy.visualization.wcsaxes.WCSAxes`
        The parent axes
    transform : `~matplotlib.transforms.Transform`
        The transform from data to world
    data_func : callable
        If not ``None``, it should be a function that returns the appropriate spine
        data when called with this object as the sole argument.  If ``None``, the
        spine data must be manually updated in ``update_spines()``.
    N)Ú	data_funcc                C   s(   || _ || _|| _d | _d | _d | _d S ©N)Úparent_axesÚ	transformr   Ú_dataÚ_pixelÚ_world)Úselfr   r   r   © r   úb/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/visualization/wcsaxes/frame.pyÚ__init__(   s    zSpine.__init__c                 C   s"   | j d kr| jr|  | ¡| _| j S r   )r   r   Údata©r   r   r   r   r   1   s    z
Spine.datac              	   C   sb   || _ |d krd | _d | _nB| jj | j ¡| _tjdd�� | j | j ¡| _W 5 Q R X |  ¡  d S )NÚignore©Úinvalid©	r   r   r   r   Ú	transDatar   ÚnpZerrstateÚ_update_normal©r   Úvaluer   r   r   r   7   s    c                 C   s   | j S r   ©r   r   r   r   r   ÚpixelC   s    zSpine.pixelc                 C   sN   || _ |d krd | _d | _n.| jj ¡  | j¡| _| j | j¡| _|  ¡  d S r   ©r   r   r   r   r   Úinvertedr   r   r    r   r   r   r#   G   s    c                 C   s   | j S r   )r   r   r   r   r   ÚworldR   s    zSpine.worldc                 C   sH   || _ |d krd | _d | _n(| j |¡| _| jj | j¡| _|  ¡  d S r   )r   r   r   r   r   r   r   r    r   r   r   r&   V   s    c                 C   sb   | j dd …df | j d d…df  }| j dd …df | j d d…df  }t t || ¡¡| _d S )Né   r   éÿÿÿÿ)r#   r   ÚdegreesZarctan2Únormal_angle)r   ÚdxÚdyr   r   r   r   a   s    $$zSpine._update_normalc                 C   s´   | j dd…df | j dd…df  }}t dt t t |¡d t |¡d  ¡¡g¡}t |d d ||¡}t |d d ||¡}t ||d d ¡d }| j| d }|||fS )	zN
        Return the x, y, normal_angle values halfway along the spine
        Nr   r'   ç        é   r(   g       @g     €f@)	r#   r   ÚhstackZcumsumÚsqrtÚdiffÚinterpZsearchsortedr*   )r   Zx_dispZy_dispÚdZxcenZycenZiminr*   r   r   r   Ú_halfway_x_y_angleg   s    &*ÿzSpine._halfway_x_y_angle)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   Úsetterr#   r&   r   r4   r   r   r   r   r      s    	







c                   @   sD   e Zd ZdZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZdS )	ÚSpineXAlignedzÑ
    A single side of an axes, aligned with the X data axis.

    This does not need to be a straight line, but represents a 'side' when
    determining which part of the frame to put labels and ticks on.
    c                 C   s   | j S r   )r   r   r   r   r   r   ƒ   s    zSpineXAligned.datac              	   C   sr   || _ |d krd | _d | _nR| jj | j ¡| _tjdd��& | j | j d d …dd…f ¡| _W 5 Q R X |  ¡  d S )Nr   r   r   r'   r   r    r   r   r   r   ‡   s    *c                 C   s   | j S r   r"   r   r   r   r   r#   “   s    zSpineXAligned.pixelc                 C   s^   || _ |d krd | _d | _n>| jj ¡  | j¡| _| j | jd d …dd…f ¡| _|  ¡  d S ©Nr   r'   r$   r    r   r   r   r#   —   s     N)r5   r6   r7   r8   r9   r   r:   r#   r   r   r   r   r;   {   s   


r;   c                       s˜   e Zd ZdZeZd‡ fdd„	Zedd„ ƒZedd„ ƒZ	e	j
d	d„ ƒZ	d
d„ Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )r	   z|
    Base class for frames, which are collections of
    :class:`~astropy.visualization.wcsaxes.frame.Spine` instances.
    Nc                    sP   t ƒ  ¡  || _|| _td | _td | _|| _| jD ]}|  	||¡| |< q6d S )Nzaxes.linewidthzaxes.edgecolor)
Úsuperr   r   Ú
_transformr   Ú
_linewidthÚ_colorÚ_pathÚspine_namesÚspine_class)r   r   r   ÚpathÚaxis©Ú	__class__r   r   r   «   s    



zBaseFrame.__init__c                 C   s   | j  ¡ \}}||k rdS dS )NÚlowerÚupper)r   Úget_ylim)r   ÚyminÚymaxr   r   r   Úorigin·   s    zBaseFrame.originc                 C   s   | j S r   )r>   r   r   r   r   r   ¼   s    zBaseFrame.transformc                 C   s   || _ | D ]}|| | _q
d S r   )r>   r   )r   r!   rE   r   r   r   r   À   s    c                 C   s–   |   ¡  g g  }}| jD ]<}| | | jd d …df ¡ | | | jd d …df ¡ qt t |¡t |¡g¡ ¡ }| jd krŠt	|ƒ| _n|| j_
d S r<   )Úupdate_spinesrB   Úappendr   r   Úvstackr/   Ú	transposerA   r   Úvertices)r   ÚxÚyrE   rR   r   r   r   Ú_update_patch_pathÆ   s    


zBaseFrame._update_patch_pathc                 C   s"   |   ¡  t| j| jjtd dd�S )Nzaxes.facecolorÚwhite)r   Z	facecolorZ	edgecolor)rU   r   rA   r   r   r   r   r   r   r   ÚpatchÓ   s    üzBaseFrame.patchc                 C   s^   | j D ]R}| | jd d …df | | jd d …df  }}t||| j| jdd�}| |¡ qd S )Nr   r'   éè  ©Ú	linewidthÚcolorÚzorder)rB   r#   r   r?   r@   Údraw©r   ÚrendererrE   rS   rT   Úliner   r   r   r]   Ý   s    
.    ÿzBaseFrame.drawc                    s˜   |   ¡  tƒ }| D ]€}| | j}|  | j| j¡||< |jdkrˆt dd|j	d ¡‰ t dd|¡‰t 
‡ ‡fdd„|jD ƒ¡ ¡ || _q||| _q|S )Nr   r-   g      ð?c                    s   g | ]}t  ˆˆ |¡‘qS r   )r   r2   )Ú.0r3   ©ÚpZp_newr   r   Ú
<listcomp>ñ   s     z$BaseFrame.sample.<locals>.<listcomp>)rN   r   r   rC   r   r   Úsizer   ÚlinspaceÚshapeÚarrayÚTrQ   )r   Z	n_samplesZspinesrE   r   r   rb   r   Úsampleå   s    

ÿzBaseFrame.samplec                 C   s
   || _ dS )z�
        Sets the color of the frame.

        Parameters
        ----------
        color : str
            The color of the frame.
        N©r@   )r   r[   r   r   r   Ú	set_colorø   s    	zBaseFrame.set_colorc                 C   s   | j S r   rk   r   r   r   r   Ú	get_color  s    zBaseFrame.get_colorc                 C   s
   || _ dS )z¥
        Sets the linewidth of the frame.

        Parameters
        ----------
        linewidth : float
            The linewidth of the frame in points.
        N©r?   )r   rZ   r   r   r   Úset_linewidth  s    	zBaseFrame.set_linewidthc                 C   s   | j S r   rn   r   r   r   r   Úget_linewidth  s    zBaseFrame.get_linewidthc                 C   s$   |   ¡ D ]}|jr| |¡|_qd S r   )Úvaluesr   r   )r   Zspiner   r   r   rN     s    zBaseFrame.update_spines)N)r5   r6   r7   r8   r   rC   r   r9   rM   r   r:   rU   rW   r]   rj   rl   rm   ro   rp   rN   Ú__classcell__r   r   rF   r   r	   £   s&   



	)Ú	metaclassc                       s8   e Zd ZdZdZeZ‡ fdd„Zdd„ Zdd„ Z	‡  Z
S )	r   ú&
    A classic rectangular frame.
    Zbtc                    sb   | j  ¡ \}}| j  ¡ \}}t ||g||gf¡| d _t ||g||gf¡| d _tƒ  ¡  d S )NÚbÚt©r   Úget_xlimrJ   r   rh   r   r=   rN   ©r   ÚxminÚxmaxrK   rL   rF   r   r   rN   "  s
    z RectangularFrame1D.update_spinesc                 C   s€   |   ¡  | j ¡ \}}| j ¡ \}}|||||g}|||||g}t t |¡t |¡g¡ ¡ }| jd krtt	|ƒ| _n|| j_
d S r   )rN   r   rx   rJ   r   rP   r/   rQ   rA   r   rR   )r   rz   r{   rK   rL   rS   rT   rR   r   r   r   rU   +  s    
z%RectangularFrame1D._update_patch_pathc           	      C   sb   | j  ¡ \}}| j  ¡ \}}|||||g}|||||g}t||| j| jd| j jd�}| |¡ d S )NrX   )rZ   r[   r\   r   )r   rx   rJ   r   r?   r@   r   r]   )	r   r_   rz   r{   rK   rL   rS   rT   r`   r   r   r   r]   ;  s    úzRectangularFrame1D.draw)r5   r6   r7   r8   rB   r;   rC   rN   rU   r]   rr   r   r   rF   r   r     s   	c                       s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )r
   rt   Zbrtlc                    sš   | j  ¡ \}}| j  ¡ \}}t ||g||gf¡| d _t ||g||gf¡| d _t ||g||gf¡| d _t ||g||gf¡| d _tƒ  ¡  d S )Nru   Úrrv   Úlrw   ry   rF   r   r   rN   T  s    zRectangularFrame.update_spines)r5   r6   r7   r8   rB   rN   rr   r   r   rF   r   r
   M  s   c                       s4   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )	r   z
    An elliptical frame.
    Zchvc           
         sî   | j  ¡ \}}| j  ¡ \}}d||  }d||  }|| }|| }t ddtj d¡}	t ||t |	¡  ||t |	¡  g¡ 	¡ | d _
t t ||d¡t |d¡g¡ 	¡ | d _
t t |d¡t ||d¡g¡ 	¡ | d _
tƒ  ¡  d S )Ng      à?r-   r.   rX   ÚcÚhÚv)r   rx   rJ   r   rf   Úpirh   ÚcosÚsinrQ   r   Úrepeatr=   rN   )
r   rz   r{   rK   rL   ZxmidZymidr+   r,   ÚthetarF   r   r   rN   g  s"    "ÿÿÿzEllipticalFrame.update_spinesc                 C   s4   |   ¡  | d j}| jdkr(t|ƒ| _n|| j_dS )zjOverride path patch to include only the outer ellipse,
        not the major and minor axes in the middle.r~   N)rN   r   rA   r   rR   )r   rR   r   r   r   rU   ~  s
    

z"EllipticalFrame._update_patch_pathc                 C   sV   d}| | j dd…df | | j dd…df  }}t||| j| jdd�}| |¡ dS )zÎOverride to draw only the outer ellipse,
        not the major and minor axes in the middle.

        FIXME: we may want to add a general method to give the user control
        over which spines are drawn.r~   Nr   r'   rX   rY   )r#   r   r?   r@   r]   r^   r   r   r   r]   Š  s    .zEllipticalFrame.draw)	r5   r6   r7   r8   rB   rN   rU   r]   rr   r   r   rF   r   r   `  s
   )ÚabcÚcollectionsr   Únumpyr   Z
matplotlibr   Zmatplotlib.linesr   r   Zmatplotlib.patchesr   Ú__all__r   r;   ÚABCMetar	   r   r
   r   r   r   r   r   Ú<module>   s"   û	f(w3