σ
;c]c           @` sΓ   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d l Z d a d   Z d. Z d/ Z d0 Z d) e
 f d*     YZ e d+ d, e d-  Z e j e  d S(1   s'    Storage of image data in tiff format.
i    (   t   absolute_importt   print_functiont   divisionNi   (   t   formats(   t   Formatc          C` s   t  j d k  rN y d d  l }  d d  l } WqN t k
 rJ t d   qN Xn  y d d  l a Wn! t k
 r d d l m a n Xt S(   Ni   i    st   The Imageio TIFF format has extra dependencies on Python 2.7. Install these using e.g. "pip install enum34 futures".i   (   t	   _tifffile(   i   (   t   syst   version_infot   enumt   concurrent.futurest   ImportErrort   tifffileR   t    (   R   t
   concurrent(    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt   load_lib   s    s   .tifs   .tiffs   .stks   .lsmt   photometrict   planarconfigt
   resolutiont   descriptiont   compresst   volumet
   writeshapet	   extratagst   datetimet   planar_configurationt   is_fluoviewt   is_niht	   is_contigt   is_micromanagert   is_omet   is_lsmis_palettet
   is_reducedt   is_rgbt   is_sgit	   is_shapedt   is_stkt   is_tiledt   is_mdgelresolution_unitt   compressiont
   is_mediacyt   orientationt   description1t	   is_imagejt   softwaret
   TiffFormatc           B` sR   e  Z d  Z d   Z d   Z d e j f d     YZ d e j f d     YZ RS(   s   Provides support for a wide range of Tiff images.
    
    Images that contain multiple pages can be read using ``imageio.mimread()``
    to read the individual pages, or ``imageio.volread()`` to obtain a
    single (higher dimensional) array.

    Parameters for reading
    ----------------------
    offset : int
        Optional start position of embedded file. By default this is
        the current file position.
    size : int
        Optional size of embedded file. By default this is the number
        of bytes from the 'offset' to the end of the file.
    multifile : bool
        If True (default), series may include pages from multiple files.
        Currently applies to OME-TIFF only.
    multifile_close : bool
        If True (default), keep the handles of other files in multifile
        series closed. This is inefficient when few files refer to
        many pages. If False, the C runtime may run out of resources.

    Parameters for saving
    ---------------------
    bigtiff : bool
        If True, the BigTIFF format is used.
    byteorder : {'<', '>'}
        The endianness of the data in the file.
        By default this is the system's native byte order.
    software : str
        Name of the software used to create the image.
        Saved with the first page only.

    Metadata for reading
    --------------------
    planar_configuration : {'contig', 'planar'}
        Specifies if samples are stored contiguous or in separate planes.
        By default this setting is inferred from the data shape.
        'contig': last dimension contains samples.
        'planar': third last dimension contains samples.
    resolution_unit : (float, float) or ((int, int), (int, int))
        X and Y resolution in dots per inch as float or rational numbers.
    compression : int
        Values from 0 to 9 indicating the level of zlib compression.
        If 0, data is uncompressed.
    orientation : {'top_left', 'bottom_right', ...}
        Oriented of image array.
    is_rgb : bool
        True if page contains a RGB image.
    is_contig : bool
        True if page contains a contiguous image.
    is_tiled : bool
        True if page contains tiled image.
    is_palette : bool
        True if page contains a palette-colored image and not OME or STK.
    is_reduced : bool
        True if page is a reduced image of another image.
    is_shaped : bool
        True if page contains shape in image_description tag.
    is_fluoview : bool
        True if page contains FluoView MM_STAMP tag.
    is_nih : bool
        True if page contains NIH image header.
    is_micromanager : bool
        True if page contains Micro-Manager metadata.
    is_ome : bool
        True if page contains OME-XML in image_description tag.
    is_sgi : bool
        True if page contains SGI image and tile depth tags.
    is_stk : bool
        True if page contains UIC2Tag tag.
    is_mdgel : bool
        True if page contains md_file_tag tag.
    is_mediacy : bool
        True if page contains Media Cybernetics Id tag.
    is_stk : bool
        True if page contains UIC2Tag tag.
    is_lsm : bool
        True if page contains LSM CZ_LSM_INFO tag.
    description : str
        Image description
    description1 : str
        Additional description
    is_imagej : None or str
        ImageJ metadata
    software : str
        Software used to create the TIFF file
    datetime : datetime.datetime
        Creation date and time

    Metadata for writing
    --------------------
    photometric : {'minisblack', 'miniswhite', 'rgb'}
        The color space of the image data.
        By default this setting is inferred from the data shape.
    planarconfig : {'contig', 'planar'}
        Specifies if samples are stored contiguous or in separate planes.
        By default this setting is inferred from the data shape.
        'contig': last dimension contains samples.
        'planar': third last dimension contains samples.
    resolution : (float, float) or ((int, int), (int, int))
        X and Y resolution in dots per inch as float or rational numbers.
    description : str
        The subject of the image. Saved with the first page only.
    compress : int
        Values from 0 to 9 controlling the level of zlib compression.
        If 0, data are written uncompressed (default).
    volume : bool
        If True, volume data are stored in one tile (if applicable) using
        the SGI image_depth and tile_depth tags.
        Image width and depth must be multiple of 16.
        Few software can read this format, e.g. MeVisLab.
    writeshape : bool
        If True, write the data shape to the image_description tag
        if necessary and no other description is given.
    extratags: sequence of tuples
        Additional tags as [(code, dtype, count, value, writeonce)].

        code : int
            The TIFF tag Id.
        dtype : str
            Data type of items in 'value' in Python struct format.
            One of B, s, H, I, 2I, b, h, i, f, d, Q, or q.
        count : int
            Number of data values. Not used for string values.
        value : sequence
            'Count' values compatible with 'dtype'.
        writeonce : bool
            If True, the tag is written to the first page only.
    c         C` s   | j  |  j k S(   N(   t	   extensiont
   extensions(   t   selft   request(    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt	   _can_readΡ   s    c         C` s   | j  |  j k S(   N(   R-   R.   (   R/   R0   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt
   _can_writeΥ   s    t   Readerc           B` s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         K` s   t  s t   n  |  j j j d  rG t |  j j   d  |  _ } n d  |  _ |  j j	   } t  j
 | |  |  _ i  |  _ d  S(   Ns   http://s   https://t   rb(   s   http://s   https://(   R   R   R0   t   filenamet
   startswitht   opent   get_local_filenamet   _ft   Nonet   get_filet   TiffFilet   _tft   _meta(   R/   t   kwargst   f(    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt   _openά   s    
"	c         C` s0   |  j  j   |  j d  k	 r, |  j j   n  d  S(   N(   R=   t   closeR9   R:   (   R/   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt   _closeκ   s    c         C` s.   |  j  j d d k r d St |  j j  Sd  S(   Ni   t   vV(   R0   t   modet   lenR=   t   pages(   R/   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt   _get_lengthο   s    c         C` s±   |  j  j d d k rL | d k r1 t d   n  |  j j   } |  j } n[ | d k  sj | |  j   k ry t d   n  |  j j | j   } |  j p€ |  j |  } | | f S(   Ni   RD   i    s-   Tiff support no more than 1 "volume" per files/   Index out of range while reading from tiff file(	   R0   RE   t
   IndexErrorR=   t   asarrayR>   RH   RG   t   _get_meta_data(   R/   t   indext   imt   meta(    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt	   _get_dataυ   s    c         C` s¬   |  j  j | p d } x< t D]4 } y t | |  |  j | <Wq t k
 rP q Xq WxM d D]E } y+ t j j | j | j	 d  |  j d <PWq\ t k
 r  q\ Xq\ W|  j S(   Ni    R   t   DateTimes   %Y:%m:%d %H:%M:%S(   R   RP   (
   R=   RG   t   READ_METADATA_KEYSt   getattrR>   t	   ExceptionR   t   strptimet   tagst   value(   R/   RL   t   paget   key(    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyRK     s    	(   t   __name__t
   __module__RA   RC   RH   RO   RK   (    (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyR3   Ϋ   s
   				t   Writerc           B` s5   e  Z d d d d   Z d   Z d   Z d   Z RS(   c         C` s   t  s t   n  y4 t  j |  j j   | | d | |  _ d  |  _ Wn; t k
 r t  j |  j j   | |  |  _ | |  _ n Xi  |  _	 d  S(   NR+   (
   R   R   t
   TiffWriterR0   R;   R=   R:   t	   _softwaret	   TypeErrorR>   (   R/   t   bigtifft	   byteorderR+   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyRA     s    
!c         C` s   |  j  j   d  S(   N(   R=   RB   (   R/   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyRC   .  s    c         C` ss   | r |  j  |  n  |  j d  k rG |  j j t j |  |  j  n( |  j j t j |  d |  j |  j d  S(   NR+   (   t   set_meta_dataR]   R:   R=   t   savet   npt
   asanyarrayR>   (   R/   RM   RN   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt   _append_data1  s
    "c         C` sF   i  |  _  x6 | j   D]( \ } } | t k r | |  j  | <q q Wd  S(   N(   R>   t   itemst   WRITE_METADATA_KEYS(   R/   RN   RX   RV   (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyRa   <  s    	N(   RY   RZ   R:   RA   RC   Re   Ra   (    (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyR[     s   		(   RY   RZ   t   __doc__R1   R2   R   R3   R[   (    (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyR,   M   s
   		?t   tiffs   TIFF formatt   iIvV(   s   .tifs   .tiffs   .stks   .lsm(	   R   R   R   R   R   R   R   R   R   (   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R   R)   R*   R+   (   Rh   t
   __future__R    R   R   R   R   R   R   t   coreR   t   numpyRc   R:   R   R   t   TIFF_FORMATSRg   RQ   R,   t   formatt
   add_format(    (    (    s7   lib/python2.7/site-packages/imageio/plugins/tifffile.pyt   <module>   sT   	                            χ