a
    1bd                     @   s$   d dl mZmZ G dd deZdS )   )
DataSourceSchemac                       sb   e Zd ZdZdZdZdZdZd fdd	Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Z  ZS )ZarrArraySourcezRead Zarr format files into an array

    Zarr is an numerical array storage format which works particularly well
    with remote and parallel access.
    For specifics of the format, see https://zarr.readthedocs.io/en/stable/
    ZndarrayZndzarrz0.0.1TNc                    s>   || _ |pi | _|| _|| _d| _d| _tt| j|d dS )ax  
        The parameters dtype and shape will be determined from the first
        file, if not given.

        Parameters
        ----------
        urlpath : str
            Location of data file(s), possibly including protocol
            information
        storage_options : dict
            Passed on to storage backend for remote files
        component : str or None
            If None, assume the URL points to an array. If given, assume
            the URL points to a group, and descend the group to find the
            array at this location in the hierarchy.
        kwargs : passed on to dask.array.from_zarr
        N)metadata)	urlpathstorage_options	componentkwargschunks_arrsuperr   __init__)selfr   r   r   r   r	   	__class__ 1lib/python3.9/site-packages/intake/source/zarr.pyr      s    
zZarrArraySource.__init__c                 C   s   dd l m} | jd u r`|j| jf| j| jd| j| _| jj| _| jj	| _	| jj
| _
| jj| _tt| j
| j	| j| j| jdS )N    )r   r   )dtypeshapeZextra_metadatanpartitionsr
   )Z
dask.arrayZarrayr   Z	from_zarrr   r   r   r	   r
   r   r   r   r   strr   )r   dar   r   r   _get_schema2   s     




zZarrArraySource._get_schemac                 C   s"   t |trt|}| jj|  S N)
isinstancelisttupler   Zblockscomputer   ir   r   r   _get_partitionA   s    
zZarrArraySource._get_partitionc                 C   s   |    | |S r   )r   r!   r   r   r   r   read_partitionF   s    zZarrArraySource.read_partitionc                 C   s   |    | jS r   )r   r   r   r   r   r   to_daskJ   s    zZarrArraySource.to_daskc                 C   s   |    | j S r   )r   r   r   r#   r   r   r   readN   s    zZarrArraySource.readc                 C   s   d | _ d | _d S r   )r   Z_mapperr#   r   r   r   _closeR   s    zZarrArraySource._close)NNN)__name__
__module____qualname____doc__	containernameversionZpartition_accessr   r   r!   r"   r$   r%   r&   __classcell__r   r   r   r   r      s     r   N)baser   r   r   r   r   r   r   <module>   s   