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__/netcdf3.cpython-36.pyc
3

���hR�
@s�ddlZddlZddlmZmZddlmZddlm	Z	m
Z
mZdZe
ddd	d
ddd
dddddg�Zddd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�N�)�conventions�Variable)�ops)�
basestring�unicode_type�OrderedDictz_.@+- !"#$%&\()*,:;<=>?[]^`{|}~Zbyte�char�shortZushort�intZuint�int64Zuint64Z	floatreal�double�bool�stringZint32Zint8)rrcCs�t|j�}|tkrnt|}|j|�}d|ks4d|krB||kj�sXd|krhtj||�rhtd||f��|}n|jjdkr�t	j
jj|d�}|S)aeCoerce an array to a data type that can be stored in a netCDF-3 file

    This function performs the following dtype conversions:
        int64 -> int32
        float64 -> float32
        bool -> int8
        unicode -> string

    Data is checked for equality, or equivalence (non-NaN values) with
    `np.allclose` with the default keyword arguments.
    r�U�floatz/could not safely cast array from dtype %s to %szutf-8)
�str�dtype�_nc3_dtype_coercionsZastype�allrZallclose_or_equiv�
ValueError�kind�np�coreZdefchararray�encode)ZarrrZ	new_dtypeZcast_arr�r�7/tmp/pip-build-5_djhm0z/xray/xarray/backends/netcdf3.py�coerce_nc3_dtypes

rcCs>|jjdkr6|jjdkr6tj|�}|d|jdf}||fS)N�S�zstring%s���)rr�itemsizerZstring_to_char�shape)�data�dimsrrr�maybe_convert_to_char_array6s
r%cCsDt|t�r t|t�s@|jd�}n ttj|��}|jdkr@td��|S)Nzutf-8rz'netCDF attributes must be 1-dimensional)	�
isinstancerr�decoderrZ
atleast_1d�ndimr)�valuerrr�encode_nc3_attr_value=s


r*cCstdd�|j�D��S)NcSsg|]\}}|t|�f�qSr)r*)�.0�k�vrrr�
<listcomp>Isz$encode_nc3_attrs.<locals>.<listcomp>)r�items)�attrsrrr�encode_nc3_attrsHsr1cCs4t|j�}t||j�\}}t|j�}t||||j�S)N)rr#r%r$r1r0r�encoding)�varr#r$r0rrr�encode_nc3_variableMs

r4cCs|j�pt|jd��dkS)zrReturn True if the given UTF-8 encoded character is alphanumeric
    or multibyte.

    Input is not checked!
    zutf-8r)�isalnum�lenr)�crrr�
_isalnumMUTF8Tsr8cCs�t|t�sdSt|t�s"|jd�}t|jd��}tjd|�|ko�|tko�|dko�d|ko�|ddko�t	|d�s||ddko�t
d	d
�|D��S)arTest whether an object can be validly converted to a netCDF-3
    dimension, variable or attribute name

    Earlier versions of the netCDF C-library reference implementation
    enforced a more restricted set of characters in creating new names,
    but permitted reading names containing arbitrary bytes. This
    specification extends the permitted characters in names to include
    multi-byte UTF-8 encoded Unicode and additional printing characters
    from the US-ASCII alphabet. The first character of a name must be
    alphanumeric, a multi-byte UTF-8 character, or '_' (reserved for
    special names with meaning to implementations, such as the
    "_FillValue" attribute). Subsequent characters may also include
    printing special characters, except for '/' which is not allowed in
    names. Names that have trailing space characters are also not
    permitted.
    Fzutf-8�NFCr�/r� �_css|]}t|�p|tkVqdS)N)r8�
_specialchars)r+r7rrr�	<genexpr>ysz$is_valid_nc3_name.<locals>.<genexpr>r )r&rrr'r6r�unicodedata�	normalize�_reserved_namesr8r)�s�	num_bytesrrr�is_valid_nc3_name]s


rD)r?Znumpyr�rrrrZ
core.pycompatrrrr=�setrArrr%r*r1r4r8rDrrrr�<module>s