a
    v=ic.                     @   st   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZmZ dd	l	m
Z
 G d
d dejZG dd dejZdS )z3
    Implements support for HDF5 dimension scales.
    N   )h5ds)H5pyDeprecationWarning   )base)phil	with_phil)Datasetc                   @   s   e Zd ZdZeedd Zejedd Zedd Zedd Z	ed	d
 Z
edd Zedd Zedd Zdd Zdd Zdd Zdd Zdd Zedd ZdS )DimensionProxyz-
        Represents an HDF5 "dimension".
    c              	   C   s:   zt | j}|jd | j W S  ttfy4   Y dS 0 dS )z& Get or set the dimension scale label ZDIMENSION_LABELS N)r	   _idattrs
_dimensionKeyError
IndexErrorselfdset r   ^/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/h5py/_hl/dims.pylabel   s
    
zDimensionProxy.labelc                 C   s   t | j| j| | d S N)r   Z	set_labelr   r   _e)r   valr   r   r   r   )   s    c                 C   s   || _ || _d S r   )r   r   )r   Zid_	dimensionr   r   r   __init__/   s    zDimensionProxy.__init__c                 C   s   t t| | j| jfS r   )hashtyper   r   r   r   r   r   __hash__4   s    zDimensionProxy.__hash__c                 C   s   t | t |kS r   )r   )r   otherr   r   r   __eq__8   s    zDimensionProxy.__eq__c                 c   s   |   D ]
}|V  qd S r   )keys)r   kr   r   r   __iter__<   s    zDimensionProxy.__iter__c                 C   s   t | j| jS r   )r   Zget_num_scalesr   r   r   r   r   r   __len__A   s    zDimensionProxy.__len__c                    sn   t  tr0g }tjj|jd t|  S  fdd}tjj|d}|d u rbt t|S d S )Nr   c                    s   t |  kr| S dS )z- Iterate over scales to find a matching name N)r   get_scale_namer   )Zdsiditemr   r   r   fN   s    z%DimensionProxy.__getitem__.<locals>.f)	
isinstanceintr   iterater   r   appendr	   r   )r   r(   scalesr)   resr   r'   r   __getitem__E   s    
zDimensionProxy.__getitem__c                 C   s<   t $ t| j|j| j W d   n1 s.0    Y  dS )zo Attach a scale to this dimension.

        Provide the Dataset of the scale you would like to attach.
        N)r   r   attach_scaler   idr   r   r   r   r   r1   X   s    zDimensionProxy.attach_scalec                 C   s<   t $ t| j|j| j W d   n1 s.0    Y  dS )zq Remove a scale from this dimension.

        Provide the Dataset of the scale you would like to remove.
        N)r   r   detach_scaler   r2   r   r   r   r   r   r3   `   s    zDimensionProxy.detach_scalec                    s`   t H g }t dkr,t j j|jd  fdd|D W  d   S 1 sR0    Y  dS )zX Get a list of (name, Dataset) pairs with all scales on this
        dimension.
        r   c                    s$   g | ]}  t|t|fqS r   )Z_dr   r&   r	   ).0xr   r   r   
<listcomp>t   s   z(DimensionProxy.items.<locals>.<listcomp>N)r   lenr   r,   r   r   r-   )r   r.   r   r   r   itemsh   s    
zDimensionProxy.itemsc                 C   s:   t " dd |  D W  d   S 1 s,0    Y  dS )z7 Get a list of names for the scales on this dimension. c                 S   s   g | ]\}}|qS r   r   )r4   key_r   r   r   r6   |       z'DimensionProxy.keys.<locals>.<listcomp>Nr   r8   r   r   r   r   r"   y   s    zDimensionProxy.keysc                 C   s:   t " dd |  D W  d   S 1 s,0    Y  dS )z5 Get a list of Dataset for scales on this dimension. c                 S   s   g | ]\}}|qS r   r   )r4   r:   r   r   r   r   r6      r;   z)DimensionProxy.values.<locals>.<listcomp>Nr<   r   r   r   r   values~   s    zDimensionProxy.valuesc                 C   s"   | j s
dS d| j| jt| j f S )Nz"<Dimension of closed HDF5 dataset>z)<"%s" dimension %d of HDF5 dataset at %s>)r   r   r   r2   r   r   r   r   __repr__   s
    zDimensionProxy.__repr__N)__name__
__module____qualname____doc__propertyr   r   setterr   r   r!   r$   r%   r0   r1   r3   r8   r"   r=   r>   r   r   r   r   r
      s4   






r
   c                   @   sV   e Zd ZdZedd Zedd Zedd Zedd	 Zed
d Z	dddZ
dS )DimensionManagerz
        Represents a collection of dimension associated with a dataset.

        Like AttributeManager, an instance of this class is returned when
        accessing the ".dims" property on a Dataset.
    c                 C   s   |j | _dS )z Private constructor.
        N)r2   r   )r   parentr   r   r   r      s    zDimensionManager.__init__c                 C   s$   |t | d krtdt| j|S )z# Return a Dimension object
        r   zIndex out of range)r7   r   r
   r   )r   indexr   r   r   r0      s    zDimensionManager.__getitem__c                 C   s   t t| jjS )z3 Number of dimensions associated with the dataset. )r7   r	   r   shaper   r   r   r   r%      s    zDimensionManager.__len__c                 c   s    t t| D ]}| | V  qdS )z Iterate over the dimensions. N)ranger7   )r   ir   r   r   r$      s    zDimensionManager.__iter__c                 C   s   | j s
dS dt| j  S )Nz#<Dimensions of closed HDF5 dataset>z!<Dimensions of HDF5 object at %s>)r   r2   r   r   r   r   r>      s    zDimensionManager.__repr__r   c                 C   s   t jdtdd || dS )zo Create a new dimension, from an initial scale.

        Provide the dataset and a name for the scale.
        zTother_ds.dims.create_scale(ds, name) is deprecated. Use ds.make_scale(name) instead.r   )
stacklevelN)warningswarnr   Z
make_scale)r   r   namer   r   r   create_scale   s    zDimensionManager.create_scaleN)r   )r?   r@   rA   rB   r   r   r0   r%   r$   r>   rO   r   r   r   r   rE      s   




rE   )rB   rL   r   r   Zh5py_warningsr   r   r   r   Zdatasetr	   ZCommonStateObjectr
   rE   r   r   r   r   <module>
   s   t