a
    zn„fc'  ã                   @  s8   d Z ddlmZ ddlZG dd„ dƒZG dd„ dƒZdS )zY
This module defines the behaviors of ``TAxis``, an axis of a histogram or profile plot.
é    )ÚannotationsNc                   @  s8   e Zd ZdZdd„ Zdd„ Zedd„ ƒZedd	„ ƒZd
S )Ú
AxisTraitsz¢
    Describes read-only properties of a histogram axis.

    For example, ``axis.traits.discrete`` is True if the histogram has
    labels; False otherwise.
    c                 C  s
   || _ d S ©N©Ú_axis)ÚselfZaxis© r   úY/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/behaviors/TAxis.pyÚ__init__   s    zAxisTraits.__init__c                 C  s   d| j ›d�S )NzAxisTraits(ú)r   ©r   r   r   r	   Ú__repr__   s    zAxisTraits.__repr__c                 C  s   dS )zU
        True if the axis "wraps around" (always False for ROOT histograms).
        Fr   r   r   r   r	   Úcircular   s    zAxisTraits.circularc                 C  s0   | j  d¡}| j jddd�}|duo.t|ƒ|kS )zO
        True if bins are discrete: if they have string-valued labels.
        ÚfNbinsÚfLabelsT©Znone_if_missingN)r   ÚmemberÚlen)r   r   r   r   r   r	   Údiscrete    s    zAxisTraits.discreteN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Úpropertyr   r   r   r   r   r	   r      s   
r   c                   @  s¢   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZd"dd„Zd#dd„Zd$dd„Zd%dd„Zd&dd „Zd!S )'ÚTAxisz%
    Describes a histogram axis.
    c                 C  s
   |   d¡S )z1
        The number of bins in the axis.
        r   ©r   r   r   r   r	   Ú__len__/   s    zTAxis.__len__c           	      C  sÈ   |   d¡}| j ddd�}| j ddd�}|durFt|ƒ|krFt|| ƒS |du s^t|ƒ|d kr°|   d¡|   d	¡ }}|| | t|ƒ | }|| |d  t|ƒ | }||fS || ||d  fS dS )
zŽ
        Returns the label at ``where`` if it exists or the interval at ``where``.

        The indexing assumes that ``flow=False``.
        r   ÚfXbinsTr   r   Né   ÚfXminÚfXmax)r   r   ÚstrÚfloat)	r   Úwherer   r   r   r   r    ÚlowÚhighr   r   r	   Ú__getitem__5   s    
zTAxis.__getitem__c                 c  sT   |   d¡}| j ddd�}|durBt|ƒ|krB|D ]}t|ƒV  q0n|  ¡ E dH  dS )z=
        Iterate over the output of ``__getitem__``.
        r   r   Tr   N)r   r   r!   Ú	intervals)r   r   r   Úxr   r   r	   Ú__iter__K   s    
zTAxis.__iter__c                   s   t ‡ fdd„| D ƒƒS )zq
        Returns True if ``x`` is one of the labels or intervals for this axis;
        False otherwise.
        c                 3  s   | ]}ˆ |kV  qd S r   r   )Ú.0Úy©r(   r   r	   Ú	<genexpr>]   ó    z%TAxis.__contains__.<locals>.<genexpr>)Úany)r   r(   r   r,   r	   Ú__contains__X   s    zTAxis.__contains__c                 C  s¼   t | ƒt |ƒurdS |  d¡}| d¡}||kr4dS | jddd�}|jddd�}|duobt|ƒ|k}|duovt|ƒ|k}|r˜|r˜tdd„ t||ƒD ƒƒS |s´|s´t |  ¡ | ¡ ¡S dS dS )	zb
        Two axes are equal if they have the same type and ``list(self) == list(other)``.
        Fr   r   Tr   Nc                 s  s   | ]\}}||kV  qd S r   r   )r*   r(   r+   r   r   r	   r-   q   r.   zTAxis.__eq__.<locals>.<genexpr>)Útyper   r   ÚallÚzipÚnumpyZarray_equalÚedges)r   ÚotherZself_fNbinsZother_fNbinsZself_fLabelsZother_fLabelsZself_labeledZother_labeledr   r   r	   Ú__eq___   s    

zTAxis.__eq__c                 C  s   |   |¡ S )zL
        Some versions of Python don't automatically negate __eq__.
        )r7   )r   r6   r   r   r	   Ú__ne__w   s    zTAxis.__ne__c                 C  s   t | ƒS )z²
        Describes read-only properties of a histogram axis.

        For example, ``axis.traits.discrete`` is True if the histogram has
        labels; False otherwise.
        )r   r   r   r   r	   Útraits}   s    zTAxis.traitsc                 C  s
   |   d¡S )z²
        The low edge of the first normal (finite-width) bin.

        For ROOT histograms, numerical edges exist even if the axis also has
        string-valued labels.
        r   r   r   r   r   r	   r$   ‡   s    z	TAxis.lowc                 C  s
   |   d¡S )z²
        The high edge of the last normal (finite-width) bin.

        For ROOT histograms, numerical edges exist even if the axis also has
        string-valued labels.
        r    r   r   r   r   r	   r%   ‘   s    z
TAxis.highc                 C  sX   |   d¡}| j ddd�}|du s0t|ƒ|d krH|   d¡|   d¡ | S |  ¡  ¡ S dS )	zV
        The average bin width (or only bin width if the binning is uniform).
        r   r   Tr   Nr   r    r   )r   r   ÚwidthsÚmean)r   r   r   r   r   r	   Úwidth›   s
    
zTAxis.widthFc                 C  sZ   |   d¡}| j ddd�}|durRt|ƒ|krRdd„ |D ƒ}|rLdg|¢d	‘S |S ndS dS )
a™  
        Args:
            flow (bool): If True, include ``"underflow"`` and ``"overflow"``
                before and after the normal (finite-width) bin labels (if they
                exist).

        If string-valued labels exist, this returns them as a Python list of
        Python strings. Otherwise, this returns None.

        Setting ``flow=True`` increases the length of the output by two.
        r   r   Tr   Nc                 S  s   g | ]}t |ƒ‘qS r   )r!   )r*   r(   r   r   r	   Ú
<listcomp>¸   r.   z TAxis.labels.<locals>.<listcomp>Z	underflowÚoverflow)r   r   )r   Úflowr   r   Úoutr   r   r	   Úlabels¨   s    
zTAxis.labelsc                 C  s¤   |   d¡}| j ddd�}|du s0t|ƒ|d krNt |   d¡|   d¡|d ¡}|rŠtj|d	 tjd
�}tj |d< tj|d< ||dd…< ntj||j 	d¡d
�}|S )a³  
        Args:
            flow (bool): If True, include ``-inf`` and ``inf`` before and
                after the normal (finite-width) bin edges.

        Returns numerical edges between bins as a one-dimensional ``numpy.ndarray``
        of ``numpy.float64``.

        Even with ``flow=False``, the number of edges is *one greater than* the
        number of normal (finite-width) bins because they represent "fenceposts"
        between the bins, including one below and one above the full range.

        Setting ``flow=True`` increases the length of the output by two.

        For ROOT histograms, numerical edges exist even if the axis also has
        string-valued labels.
        r   r   Tr   Nr   r   r    é   ©Údtyper   éÿÿÿÿú=)
r   r   r4   ÚlinspaceÚemptyÚfloat64ÚinfZasarrayrD   Znewbyteorder©r   r?   r   r   r@   r   r   r	   r5   À   s    
ÿ
zTAxis.edgesc                 C  sê   |   d¡}| j ddd�}|du s0t|ƒ|d krNt |   d¡|   d¡|d ¡}|r¢tj|d	 d	ftjd
�}tj |d< tj|d< ||dd…df< ||dd…df< nDtj|d	ftjd
�}|dd… |dd…df< |dd… |dd…df< |S )aT  
        Args:
            flow (bool): If True, include ``[-inf, min]`` and ``[max, inf]``
                before and after the normal (finite-width) intervals.

        Returns low, high pairs for each bin interval as a two-dimensional
        ``numpy.ndarray`` of ``numpy.float64``.

        With ``flow=False``, the number of intervals is equal to the number of
        normal (finite-width) bins.

        Setting ``flow=True`` increases the length of the output by two.

        For ROOT histograms, numerical intervals exist even if the axis also has
        string-valued labels.
        r   r   Tr   Nr   r   r    é   rC   )r   r   )rE   r   r   rE   )r   r   r4   rG   rH   rI   rJ   rK   r   r   r	   r'   ä   s     
ÿ
zTAxis.intervalsc                 C  s(   | j |d�}|dd… |dd…  d S )a5  
        Args:
            flow (bool): If True, include ``-inf`` and ``inf`` before and after
                the normal (finite) bin centers.

        Returns bin center positions as a one-dimensional ``numpy.ndarray`` of
        ``numpy.float64``.

        With ``flow=False``, the number of bin centers is equal to the number of
        normal (finite-width) bins.

        Setting ``flow=True`` increases the length of the output by two.

        For ROOT histograms, numerical bin centers exist even if the axis also has
        string-valued labels.
        ©r?   r   NrE   g       @)r5   )r   r?   r5   r   r   r	   Úcenters
  s    zTAxis.centersc                 C  s‚   |   d¡}| j ddd�}|sZ|du s4t|ƒ|d krZ|   d¡|   d¡ | }t ||f¡S | j|d	�}|dd… |dd
…  S dS )a(  
        Args:
            flow (bool): If True, include ``-inf`` and ``inf`` before and after
                the normal (finite) bin widths.

        Returns bin widths as a one-dimensional ``numpy.ndarray`` of
        ``numpy.float64``.

        With ``flow=False``, the number of bin widths is equal to the number of
        normal (finite-width) bins.

        Setting ``flow=True`` increases the length of the output by two.

        For ROOT histograms, numerical bin widths exist even if the axis also has
        string-valued labels.
        r   r   Tr   Nr   r    r   rM   rE   )r   r   r4   Zbroadcast_tor5   )r   r?   r   r   r<   r5   r   r   r	   r:     s    
zTAxis.widthsN)F)F)F)F)F)r   r   r   r   r   r&   r)   r0   r7   r8   r   r9   r$   r%   r<   rA   r5   r'   rN   r:   r   r   r   r	   r   *   s(   
	
	
	


$
&
r   )r   Ú
__future__r   r4   r   r   r   r   r   r	   Ú<module>   s   