a
    Df!                     @   s   d dl Zd dlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZmZ G d	d
 d
ee
ZG dd deeZG dd deeZG dd deee
ZG dd deZG dd deee
ZdS )    N   Dataset)	Dimensionprocess_dimensions)Element	Element2D)get_param_valuesunique_iterator   )Selection1DExprSelection2DExprc                       sn   e Zd ZdZdZdZd fdd	Zedd Zd fd	d
	Z	dddZ
dd Zd fdd	ZdddZ  ZS )StatisticsElementa  
    StatisticsElement provides a baseclass for Element types that
    compute statistics based on the input data, usually a density.
    The value dimension of such elements are therefore usually virtual
    and not computed until the element is plotted.
    TFNc                    s   t  trT jjdkrT|t  |p<  d t| j }t	 fdd|D  |t
|g dd t j fi | |stdg| _n2t|dkrtt| j dntd |d	 | _d S )
NZ	dataframec                 3   s   | ]}  |V  qd S )N)dimension_values.0ddata d/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/element/stats.py	<genexpr>       z-StatisticsElement.__init__.<locals>.<genexpr>F)kdimsvdims_validate_vdimsDensityr   z expects at most one vdim.r   )
isinstancer   	interfacedatatypeupdater	   
dimensionslenr   tupledictsuper__init__r   r   
ValueErrortype__name__r   )selfr   r   r   params	__class__r   r   r&      s    

zStatisticsElement.__init__c                 C   sj   ddl m} | jdu rBtt| j|j }|| dddg |d}|S t| j|sd|| fddi| jS | jS )z?
        The Dataset that this object was created from
        r   r   N)datasetZpipelineZ
transformsr   r   r   F) r   Z_datasetlistr
   r   r   )r*   r   r   r.   r   r   r   r.   '   s    

zStatisticsElement.datasetc                    s    |  || jv}t |||S )a  Return the lower and upper bounds of values along dimension.

        Args:
            dimension: The dimension to compute the range on.
            data_range (bool): Compute range from data values
            dimension_range (bool): Include Dimension ranges
                Whether to include Dimension range and soft_range
                in range calculation

        Returns:
            Tuple containing the lower and upper bound
        )get_dimensionr   r%   range)r*   dimZ
data_rangeZdimension_rangeZiskdimr,   r   r   r2   6   s    zStatisticsElement.rangec                 C   s<   | j |dd}|| jv r*tt| tjS | j| |||S )a  Return the values along the requested dimension.

        Args:
            dimension: The dimension to return values for
            expanded (bool, optional): Whether to expand values
                Whether to return the expanded values, behavior depends
                on the type of data:
                  * Columnar: If false returns unique values
                  * Geometry: If false returns scalar values per geometry
                  * Gridded: If false returns 1D coordinates
            flat (bool, optional): Whether to flatten array

        Returns:
            NumPy array of values along the requested dimension
        Tstrict)r1   r   npfullr"   nanr   values)r*   r3   expandedZflatr   r   r   r   F   s    
z"StatisticsElement.dimension_valuesc                 C   sD   |  |}|du rdS |jdur&|jS || jv r6tjS | j| |S )aB  Get the type of the requested dimension.

        Type is determined by Dimension.type attribute or common
        type of the dimension values, otherwise None.

        Args:
            dimension: Dimension to look up by name or by index

        Returns:
            Declared type of values along the dimension
        N)r1   r(   r   r6   float64r   Zdimension_type)r*   r3   r   r   r   get_dimension_type[   s    


z$StatisticsElement.get_dimension_typec                    sh   |r fdd|D }n j } fdd|D }|rZtdt jddd |D t |dS )a  Convert dimension values to DataFrame.

        Returns a pandas dataframe of columns along each dimension,
        either completely flat or indexed by key dimensions.

        Args:
            dimensions: Dimensions to return as columns
            multi_index: Convert key dimensions to (multi-)index

        Returns:
            DataFrame of columns corresponding to each dimension
        c                    s   g | ]} j |d dqS Tr4   r1   r   r*   r   r   
<listcomp>~   r   z,StatisticsElement.dframe.<locals>.<listcomp>c                    s   g | ]}| j v r|qS r   r   r   r?   r   r   r@      r   ^{} element does not hold data for value dimensions. Could not return data for {} dimension(s)., c                 S   s   g | ]
}|j qS r   namer   r   r   r   r@      r   F)r   r'   formatr(   r)   joinr%   dframe)r*   r!   Zmulti_indexr   r,   r?   r   rH   p   s    zStatisticsElement.dframec                    st   |du r j }n fdd|D } fdd|D }|r^tdt jddd |D t fdd|D S )	a  Convert dimension values to a dictionary.

        Returns a dictionary of column arrays along each dimension
        of the element.

        Args:
            dimensions: Dimensions to return as columns

        Returns:
            Dictionary of arrays for each dimension
        Nc                    s   g | ]} j |d dqS r=   r>   r   r?   r   r   r@      r   z-StatisticsElement.columns.<locals>.<listcomp>c                    s   g | ]}| j v r|qS r   rA   r   r?   r   r   r@      r   rB   rC   c                 S   s   g | ]
}|j qS r   rD   r   r   r   r   r@      r   c                    s   g | ]}|j  |fqS r   )rE   r   r   r?   r   r   r@      r   )r   r'   rF   r(   r)   rG   r$   )r*   r!   r   r   r?   r   columns   s    zStatisticsElement.columns)NN)TT)TT)NF)N)r)   
__module____qualname____doc__Z_StatisticsElement__abstractZ_auto_indexable_1dr&   propertyr.   r2   r   r<   rH   rI   __classcell__r   r   r,   r   r      s   

r   c                   @   sL   e Zd ZdZejd ddZejededgddZ	ejedgd	dZ
d
S )	Bivariatez
    Bivariate elements are containers for two dimensional data, which
    is to be visualized as a kernel density estimate. The data should
    be supplied in a tabular format of x- and y-columns.
    TdefaultZconstantxyr   r   rQ   Zboundsr   r   r   Nr)   rJ   rK   rL   paramStringgroupListr   r   r   r   r   r   r   rO      s   rO   c                   @   sF   e Zd ZdZejd ddZejedgddZ	ejedgddZ
d	S )
Distributionz
    Distribution elements provides a representation for a
    one-dimensional distribution which can be visualized as a kernel
    density estimate. The data should be supplied in a tabular format
    and will use the first column.
    TrP   Valuer   r   rU   r   rV   NrW   r   r   r   r   r\      s   r\   c                   @   sD   e Zd ZdZejd ddZejg ddZeje	dgddZ
dZdS )	
BoxWhiskerz
    BoxWhisker represent data as a distributions highlighting the
    median, mean and various percentiles. It may have a single value
    dimension and any number of key dimensions declaring the grouping
    of each violin.
    TrP   )r   NrU   rS   r^   N)r)   rJ   rK   rL   rX   rY   rZ   r[   r   r   r   Z_inverted_exprr   r   r   r   r_      s
   r_   c                   @   s   e Zd ZdZejd ddZdS )Violinz
    Violin elements represent data as 1D distributions visualized
    as a kernel-density estimate. It may have a single value dimension
    and any number of key dimensions declaring the grouping of each
    violin.
    TrP   N)r)   rJ   rK   rL   rX   rY   rZ   r   r   r   r   r`      s   r`   c                   @   s8   e Zd ZdZejd ddZejededgddZ	dS )	HexTilesa  
    HexTiles is a statistical element with a visual representation
    that renders a density map of the data values as a hexagonal grid.

    Before display the data is aggregated either by counting the values
    in each hexagonal bin or by computing aggregates.
    TrP   rR   rS   rT   rU   N)
r)   rJ   rK   rL   rX   rY   rZ   r[   r   r   r   r   r   r   ra      s
   ra   )numpyr6   rX   Z	core.datar   Zcore.dimensionr   r   Zcore.elementr   r   Z	core.utilr	   r
   Z	selectionr   r   r   rO   r\   r_   r`   ra   r   r   r   r   <module>   s    