HOME


sh-3ll 1.0
DIR:/usr/local/lib/python3.6/site-packages/xarray/backends/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/xarray/backends/__pycache__/scipy_.cpython-36.pyc
3

���h��@s�ddlmZddlZddlZddlmZddlmZddl	m
Z
mZmZddl
mZmZddlmZd	d
lmZd	dlmZmZmZdd
�Zdd�ZGdd�de�ZGdd�de�ZdS)�)�BytesION�)�Variable)�
cf_encoder)�	iteritems�
basestring�OrderedDict)�Frozen�FrozenOrderedDict)�NumpyIndexingAdapter�)�WritableCFDataStore)�is_valid_nc3_name�encode_nc3_attr_value�encode_nc3_variablecCst|t�r|jdd�S|S)Nzutf-8�replace)�
isinstance�bytes�decode)�s�r�6/tmp/pip-build-5_djhm0z/xray/xarray/backends/scipy_.py�_decode_strings
rcCstdd�t|�D��S)Ncss*|]"\}}||dkr|nt|�fVqdS)Z
_FillValueN)r)�.0�k�vrrr�	<genexpr>sz _decode_attrs.<locals>.<genexpr>)rr)�drrr�
_decode_attrssrcs<eZdZdd�Zedd��Zedd��Z�fdd�Z�ZS)	�ScipyArrayWrappercCs||_||_dS)N)�netcdf_file�
variable_name)�selfr r!rrr�__init__szScipyArrayWrapper.__init__cCs|jj|jjS)N)r �	variablesr!�data)r"rrr�array#szScipyArrayWrapper.arraycCstj|jjjt|jjj��S)N)�np�dtyper&�kind�str�itemsize)r"rrrr(+szScipyArrayWrapper.dtypecs.tt|�j|�}|jj}tj||j|d�}|S)N)r(�copy)�superr�__getitem__r Zuse_mmapr'r&r()r"�keyr%r,)�	__class__rrr.0szScipyArrayWrapper.__getitem__)	�__name__�
__module__�__qualname__r#�propertyr&r(r.�
__classcell__rr)r0rrsrcs�eZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zddd�Z�fdd�Z
dd�Zdd�Z�ZS)�ScipyDataStorez�Store for reading and writing data via scipy.io.netcdf.

    This store has the advantage of being able to be initialized with a
    StringIO object, allow for serialization without writing to disk.

    It only supports the NetCDF3 file-format.
    �rNc	s�ddl}ddl}|dkr4|jdkr4tjd|jt�|dk	rDtd��|dksT|dkrZd}n|dkrhd	}ntd
|��t|t�r�|j	d�r�t
|�}|jj||||d�|_
tt|�j|�dS)
Nrr7z0.13zscipy %s detected; the minimal recommended version is 0.13. Older version of this library do not reliably read and write files.z7cannot save to a group with the scipy.io.netcdf backendZ
NETCDF3_64BITrZNETCDF3_CLASSICrz.invalid format for scipy.io.netcdf backend: %rZCDF)�mode�mmap�version)�scipyZscipy.io�__version__�warnings�warn�
ImportWarning�
ValueErrorrr�
startswithr�ior �dsr-r6r#)	r"Zfilename_or_objr8�format�group�writerr9r;r:)r0rrr#Bs&

zScipyDataStore.__init__cCst|jt|j|�t|j��S)N)r�
dimensionsrrCr�_attributes)r"�name�varrrr�open_store_variablecsz"ScipyDataStore.open_store_variablecst�fdd�t�jj�D��S)Nc3s"|]\}}|�j||�fVqdS)N)rK)rrr)r"rrrhsz/ScipyDataStore.get_variables.<locals>.<genexpr>)r
rrCr$)r"r)r"r�
get_variablesgszScipyDataStore.get_variablescCstt|jj��S)N)r	rrCrH)r"rrr�	get_attrskszScipyDataStore.get_attrscCst|jj�S)N)r	rCrG)r"rrr�get_dimensionsnszScipyDataStore.get_dimensionscCs.||jkrtdt|�j��|jj||�dS)Nz(%s does not support modifying dimensions)rGr@�typer1rCZcreateDimension)r"rI�lengthrrr�
set_dimensionqs
zScipyDataStore.set_dimensioncCst|�std��dS)NzNot a valid attribute name)rr@)r"r/rrr�_validate_attr_keywsz!ScipyDataStore._validate_attr_keycCs$|j|�t|�}t|j||�dS)N)rRr�setattrrC)r"r/�valuerrr�
set_attribute{s
zScipyDataStore.set_attributeFcCs�t|�}|r$|jr$tdt|j���|j|�|j}|jj||j|j	�|jj
|}x,t|j�D]\}}|j
|�t|||�q`W||fS)Nz)unexpected encoding for scipy backend: %r)r�encodingr@�listZset_necessary_dimensionsr%rCZcreateVariabler(Zdimsr$r�attrsrRrS)r"rI�variableZcheck_encodingr%Z	scipy_varrrrrr�prepare_variable�s


zScipyDataStore.prepare_variablecstt|�j�|jj�dS)N)r-r6�syncrC�flush)r")r0rrr[�szScipyDataStore.synccCs|jj�dS)N)rC�close)r"rrrr]�szScipyDataStore.closecCs|j�dS)N)r])r"rOrT�tbrrr�__exit__�szScipyDataStore.__exit__)r7NNNN)F)r1r2r3�__doc__r#rKrLrMrNrQrRrUrZr[r]r_r5rr)r0rr6:s 
r6)rBrZnumpyr'r=�rZconventionsrZ
core.pycompatrrrZ
core.utilsr	r
Z
core.indexingr�commonr
Znetcdf3rrrrrrr6rrrr�<module>s