
;c]c           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l	 m
 Z
 d e
 f d     YZ e d	 d
 d	 d  Z e j e  d S(   s    Storage of image data in npz format. Not a great format, but at least
it supports volumetric data. And its less than 100 lines.
i    (   t   absolute_importt   print_functiont   divisionNi   (   t   formats(   t   Formatt	   NpzFormatc           B` sR   e  Z d  Z d   Z d   Z d e j f d     YZ d e j f d     YZ RS(   s   NPZ is a file format by numpy that provides storage of array
    data using gzip compression. This imageio plugin supports data of any
    shape, and also supports multiple images per file. 
    
    However, the npz format does not provide streaming; all data is
    read/written at once. Further, there is no support for meta data.

    Beware that the numpy npz format has a bug on a certain combination
    of Python 2.7 and numpy, which can cause the resulting files to
    become unreadable on Python 3. Also, this format is not available
    on Pypy.
    
    See the BSDF format for a similar (but more fully featured) format.
    
    Parameters for reading
    ----------------------
    None
    
    Parameters for saving
    ---------------------
    None
    c         C` s   | j  |  j k S(   N(   t	   extensiont
   extensions(   t   selft   request(    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt	   _can_read(   s    c         C` s   | j  |  j k S(   N(   R   R   (   R   R	   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt
   _can_write,   s    t   Readerc           B` s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C` sd   t  j |  j j    |  _ t |  j t  j j j  s< t	  d   } t
 |  j j d | |  _ d  S(   Nc         S` s   |  j  d  d S(   Nt   _i(   t   split(   t   x(    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   <lambda>8   t    t   key(   t   npt   loadR	   t   get_filet   _npzt
   isinstancet   libt   npyiot   NpzFilet   AssertionErrort   sortedt   filest   _names(   R   t   sorter(    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   _open3   s    !	c         C` s   |  j  j   d  S(   N(   R   t   close(   R   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   _close;   s    c         C` s   t  |  j  S(   N(   t   lenR   (   R   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   _get_length>   s    c         C` sN   | d k  s! | t  |  j  k r0 t d   n  |  j |  j | } | i  f S(   Ni    s)   Index out of range while reading from nzp(   R#   R   t
   IndexErrorR   (   R   t   indext   im(    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt	   _get_dataA   s    !c         C` s   t  d   d  S(   Ns*   The npz format does not support meta data.(   t   RuntimeError(   R   R&   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   _get_meta_dataI   s    (   t   __name__t
   __module__R    R"   R$   R(   R*   (    (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyR   2   s
   				t   Writerc           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s   g  |  _  d  S(   N(   t   _images(   R   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyR    P   s    c         C` s    t  j |  j j   |  j  d  S(   N(   R   t   savez_compressedR	   R   R.   (   R   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyR"   U   s    c         C` s   |  j  j |  d  S(   N(   R.   t   append(   R   R'   t   meta(    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   _append_dataY   s    c         C` s   t  d   d  S(   Ns*   The npz format does not support meta data.(   R)   (   R   R1   (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   set_meta_data\   s    (   R+   R,   R    R"   R2   R3   (    (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyR-   O   s   			(   R+   R,   t   __doc__R
   R   R   R   R-   (    (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyR      s
   		t   npzs   Numpy's compressed array formatt   iIvV(   R4   t
   __future__R    R   R   t   numpyR   R   R   t   coreR   R   t   formatt
   add_format(    (    (    s2   lib/python2.7/site-packages/imageio/plugins/npz.pyt   <module>   s   Q