
\c        <   @  sN'  d  Z  d d l m Z m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l Z y d d l Z Wn> e k
 r4y d d l j Z Wn e k
 r0e Z n Xn Xy) e rQd d l m Z n d d l Z Wn e k
 r~e j d  n Xd	 Z d
 Z  d d d d d d d d d d d f Z! d   Z" d e# f d     YZ$ d   Z% d e# f d     YZ& d e# f d     YZ' d e# f d     YZ( d e# f d     YZ) d e# f d      YZ* d e# f d!     YZ+ d" e, f d#     YZ- d$ e- f d%     YZ. d e# f d&     YZ/ d'   Z0 d(   Z1 d)   Z2 d*   Z3 d+   Z4 e d,  Z5 d-   Z6 d.   Z7 d/   Z8 d0   Z9 d1   Z: d2   Z; d3   Z< d4   Z= d5   Z> d6   Z? d7   Z@ d8   ZA d9   ZB d:   ZC d;   ZD d<   ZE d=   ZF d>   ZG e eH d? e e e d@  ZI e dA  ZJ dB   ZK eH dC  ZL e eH dD  ZM dE   ZN dF e e e dG  ZO eM dH  dI    ZP eM dJ  dK    ZQ eM dL  dM dN   ZR dO dP dQ dP f eS dR  ZT eM dS  dT    ZU eS dU  ZV dV   ZW dW   ZX dX dY  ZY dZ d[  ZZ d\   Z[ eH e d]  Z\ d^ d_  Z] d`   Z^ e da  Z_ db   Z` dc   Za dd   Zb de   Zc e j jd df  dg  Ze dM dh  Zf di   Zg dj   Zh dk e# f dl     YZi i dm dM 6dn d 6do dp 6dq dr 6ds dt 6du dP 6dv dQ 6dw dx 6dy dz 6d{ d| 6d} d~ 6d d 6d d 6d d 6Zj i e d 6d dp 6d dr 6d dt 6d dP 6d dQ 6d d 6d dx 6d dz 6d d| 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Zk i d   e 6e	 jl d 6e	 jl d 6eP d 6eQ d 6Zm e re jl em d <n  i d d 6d dp 6d dr 6d dt 6d dP 6d dQ 6d d 6d dx 6d dz 6d d| 6d d 6d d 6d d 6d d 6d d 6d d 6Zn i d d 6d dp 6d dr 6d dQ 6Zo i+ d d d f 6d d dp f 6d d dr f 6d d dt f 6d d dP f 6d d dQ f 6d d d f 6d d dx f 6d d dz f 6d d d| f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d dx f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d d f 6d d dP dQ dP f f 6Zp i d d 6d dp 6d dr 6d dt 6d dP 6d dQ 6d d 6d dx 6Zq i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d6dd6dd6dd 6dd6d	d
6dd6dd 6dd6Zr er js e, d  er jt   D   i
 dd6dd6dd6dd6dd6dd6dd 6dd6d d 6d!d"6Zu d#d$f d%df d&df d'df d(df d)df d*ddr d f f d+df d,df d-ddQ dr f f d.df d/df d0df d1df d2df d3df d4df d5d6df d7df g f d8d6df d7df g f d9df d:df d;ddQ f d<df d=d>f d?df d@dAf dBdf dCdf dDdf dEdf dFdf dGdf dHdf dIdf dJdf dKdf dLdf dMdNf dOdNf dPdf dQdf dRdAf dSdAf dTdf dUdVf dWdf g. Zv dXdYdZd[d\d]d^d_d`daf
 Zw dbdcdddedfdgf Zx dhdidjdkdldmdndodpdqdrdsf Zy dtdudvdwdxdydzd{d|d}d~f Zz ddddf Z{ iB de| f dM 6de| f d 6de| f dp 6de| f dr 6de f dt 6de f dP 6de} f dQ 6de} f d 6de| f dx 6de| f dz 6de f d| 6de| f d 6de| f d 6de| f d 6de| f d 6de| f d 6def f d 6def f d 6de| f d 6de f d 6de f d 6de f d 6de f d 6de f d 6de f d 6de} f d 6de| f d 6de| f d 6ddf d 6ddf d 6de f d 6de f d 6de f d 6de f d6de f d6de f d6de: f d6ddf d6de f d6de f d6ddf d6ddf d6de| f d6de| f d6de| f d6de| f d6de| f d6de| f d6de f d6de| f d6ddf d6de| f d6de f d6de f d6de| f d6de| f d6de| f d6de f d6de f d6de| f d6de| f d6de| f d6de f d6de f d6de| f d 6de| f d6Z~ ddf ddf ddf ddf ddf g Z ddf ddf ddf ddf ddf ddf ddf ddf ddf de d| f ddf ddf ddf ddf ddf d df ddf ddf ddf de f ddf ddf ddf g Z ddf ddf d	df d
df ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf d df d!df d"df d#df d$df d%df d&df d'df d(df d)df d*df d+df d,df d-df d.df d/df d0df d1df d2df d3df d4df d5df d6df d7df d8df d9df d:df d;df d<df d=d>f d?df d@dAf dBdf dCdDf g; Z i e@ dE6e> dF6e? dG6e< dH6e< dI6e< dJ6Z i dKdM 6dKd 6dKdp 6dLdr 6dMdt 6dLdP 6dMdQ 6dNd 6dOdx 6dLdz 6dKd| 6Z i d	d 6d
d 6dd 6dd 6dd 6d;d6d<d6Z i dPdM 6dQd 6dRdp 6dSdP 6Z i dTdM 6dUd 6dVdp 6dWdr 6Z i dXdY6dZd[6d\d]6d^d_6d`da6dbdc6ddde6dfdg6Z i dhdi6djdk6dldm6dndo6dpdq6drds6dtdu6dvdw6Z i ddx6dydz6d{d|6d}d~6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d d6dd6dd6dd6dd	6d
d6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6ddU6d
dV6dWdX6dYdZ6d[d\6d]d^6d_d`6dadb6dcdd6dedf6dgdh6didj6dkdl6d
dm6dndo6dpdq6drds6dtdu6dvdw6dxdy6dzd{6d|d}6d~d6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dWd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d
d6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d
d6dd6dyd6dd6dd6d!d6dd6dd6dd6dyd6dd6d!d6Z d'df ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf d df g* Z ddf ddf ddf ddf ddf ddf ddf ddf d df d	d
f dd
f ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf ddf d d!f d"d#f d$d#f d%d#f d&d'f d(d)f d*df d+df d,df d-df d.df d/df d0df d1df d2df d3df d4df d5df d6df d7df d8df d9df d:d
f d;d
f d<df g6 Z iR d=dM dt d ei   f d>6d?e dr d i d@dM 6dAd 6dBdp 6dCdr 6f dD6dEe dt d e f dF6dGe dt d e f dH6dd dr e e f dI6dJd dr d ek f dK6dLe dr d ej f dM6dNd dr d i dOd 6dPdp 6f dQ6dRe dp e e f dS6dTe dp e e f dU6dVe dp e e f dW6dXe dp e e f dY6dZe dt e e f d[6d\d dr d eq f d]6d^d dr d e f d_6d`dp d d dt d e f da6dbe dt e e f dc6dde dr e e f de6dfe dr e e f dg6dhe dP d e f di6dje dP d e f dk6dld dr d i dmd 6dndp 6f do6dpe dp e e f dq6dre dP d e f ds6dte dP d e f du6dvdp dt d i e d 6dwdp 6dxdr 6f dy6dze dr dp e f d{6d|e dp e e f d}6d~e dp e e f d6de dp e e f d6de dp e e f d6dd dr d i e d 6ddp 6d dr 6f d6de dP dp e f d6de dP dQ e f d6de dr e e f d6de dt d e f d6de dt d e f d6de dt e e f d6de dt e e f d6de dt e e f d6de dr e i ddM 6dd 6ddp 6f d6dd dr e eo f d6de e e e f d6de e e e f d6ddM dr d e f d6de d e e f d6dd d f dr dp e f d6dd d f dr d e f d6de dP d e f d6de e d e f d6de e e e f d6dd dt d e f d6de dt d e f d6de d e e f d6de dt d e f d6de dP d e f d6de dr e e f d6de dp e e f d6de dp e e f d6de dp e e f d6de dp e e f d6de dp e e f d6de d dr e f d6de d e e f d6de e d e f d6de dr e e f d6de d e e f d6de dp e e f d6de e d e f d6de e e e f d6de dp e e f d6de dp e e f d6de d dp e f d6de d d e f d6de d dr e f d6de d dr e f d6de d e e f d6de d d e f d6de d d e f d6de e e e f d6de dp e e f d6de dp e e f d6Z i de0 f d6de1 f d6de0 f d6de0 f d6de5 f d6de6 f d6de7 f d6de8 f d6deC f d6d e3 f d6de4 f d6de0 f d6de; f d6deB f d	6d
eB f d6deA f d6deD f d6de0 f d6de0 f d6de0 f d6de0 f d6de2 f d6Z dZ e dM e e e do e de ddd Z d  Z d   Z e d! Z e' Z e j dM dp k r'e} e f Z e} Z d"  Z d#d$ Z n% e} Z d%  Z d&e f d'    YZ e d(k rJ'e j e    n  d S()  s$  Read image and meta data from (bio)TIFF files. Save numpy arrays as TIFF.

Image and metadata can be read from TIFF, BigTIFF, OME-TIFF, STK, LSM, NIH,
SGI, ImageJ, MicroManager, FluoView, SEQ and GEL files.
Only a subset of the TIFF specification is supported, mainly uncompressed
and losslessly compressed 2**(0 to 6) bit integer, 16, 32 and 64-bit float,
grayscale and RGB(A) images, which are commonly used in bio-scientific imaging.
Specifically, reading JPEG and CCITT compressed image data, chroma subsampling,
or EXIF, IPTC, GPS, and XMP metadata is not implemented. Only primary info
records are read for STK, FluoView, MicroManager, and NIH Image formats.

TIFF, the Tagged Image File Format aka Thousands of Incompatible File Formats,
is under the control of Adobe Systems. BigTIFF allows for files greater than
4 GB. STK, LSM, FluoView, SGI, SEQ, GEL, and OME-TIFF, are custom extensions
defined by Molecular Devices (Universal Imaging Corporation), Carl Zeiss
MicroImaging, Olympus, Silicon Graphics International, Media Cybernetics,
Molecular Dynamics, and the Open Microscopy Environment consortium
respectively.

For command line usage run `python tifffile.py --help`

:Author:
  `Christoph Gohlke <http://www.lfd.uci.edu/~gohlke/>`_

:Organization:
  Laboratory for Fluorescence Dynamics, University of California, Irvine

:Version: 2017.01.12

Requirements
------------
* `CPython 2.7 or 3.5 <http://www.python.org>`_ (64-bit recommended)
* `Numpy 1.11 <http://www.numpy.org>`_
* `Matplotlib 1.5 <http://www.matplotlib.org>`_ (optional for plotting)
* `Tifffile.c 2017.01.10 <http://www.lfd.uci.edu/~gohlke/>`_
  (recommended for faster decoding of PackBits and LZW encoded strings)

Revisions
---------
2017.01.12
    Read Zeiss SEM metadata.
    Read OME-TIFF with invalid references to external files.
    Rewrite C LZW decoder (5x faster).
    Read corrupted LSM files missing EOI code in LZW stream.
2017.01.01
    Add option to append images to existing TIFF files.
    Read files without pages.
    Read S-FEG and Helios NanoLab tags created by FEI software.
    Allow saving Color Filter Array (CFA) images.
    Add info functions returning more information about TiffFile and TiffPage.
    Add option to read specific pages only.
    Remove maxpages argument (backwards incompatible).
    Remove test_tifffile function.
2016.10.28
    Pass 1944 tests.
    Improve detection of ImageJ hyperstacks.
    Read TVIPS metadata created by EM-MENU (by Marco Oster).
    Add option to disable using OME-XML metadata.
    Allow non-integer range attributes in modulo tags (by Stuart Berg).
2016.06.21
    Do not always memmap contiguous data in page series.
2016.05.13
    Add option to specify resolution unit.
    Write grayscale images with extra samples when planarconfig is specified.
    Do not write RGB color images with 2 samples.
    Reorder TiffWriter.save keyword arguments (backwards incompatible).
2016.04.18
    Pass 1932 tests.
    TiffWriter, imread, and imsave accept open binary file streams.
2016.04.13
    Correctly handle reversed fill order in 2 and 4 bps images (bug fix).
    Implement reverse_bitorder in C.
2016.03.18
    Fix saving additional ImageJ metadata.
2016.02.22
    Pass 1920 tests.
    Write 8 bytes double tag values using offset if necessary (bug fix).
    Add option to disable writing second image description tag.
    Detect tags with incorrect counts.
    Disable color mapping for LSM.
2015.11.13
    Read LSM 6 mosaics.
    Add option to specify directory of memory-mapped files.
    Add command line options to specify vmin and vmax values for colormapping.
2015.10.06
    New helper function to apply colormaps.
    Renamed is_palette attributes to is_indexed (backwards incompatible).
    Color-mapped samples are now contiguous (backwards incompatible).
    Do not color-map ImageJ hyperstacks (backwards incompatible).
    Towards supporting Leica SCN.
2015.09.25
    Read images with reversed bit order (fill_order is lsb2msb).
2015.09.21
    Read RGB OME-TIFF.
    Warn about malformed OME-XML.
2015.09.16
    Detect some corrupted ImageJ metadata.
    Better axes labels for 'shaped' files.
    Do not create TiffTags for default values.
    Chroma subsampling is not supported.
    Memory-map data in TiffPageSeries if possible (optional).
2015.08.17
    Pass 1906 tests.
    Write ImageJ hyperstacks (optional).
    Read and write LZMA compressed data.
    Specify datetime when saving (optional).
    Save tiled and color-mapped images (optional).
    Ignore void byte_counts and offsets if possible.
    Ignore bogus image_depth tag created by ISS Vista software.
    Decode floating point horizontal differencing (not tiled).
    Save image data contiguously if possible.
    Only read first IFD from ImageJ files if possible.
    Read ImageJ 'raw' format (files larger than 4 GB).
    TiffPageSeries class for pages with compatible shape and data type.
    Try to read incomplete tiles.
    Open file dialog if no filename is passed on command line.
    Ignore errors when decoding OME-XML.
    Rename decoder functions (backwards incompatible)
2014.08.24
    TiffWriter class for incremental writing images.
    Simplify examples.
2014.08.19
    Add memmap function to FileHandle.
    Add function to determine if image data in TiffPage is memory-mappable.
    Do not close files if multifile_close parameter is False.
2014.08.10
    Pass 1730 tests.
    Return all extrasamples by default (backwards incompatible).
    Read data from series of pages into memory-mapped array (optional).
    Squeeze OME dimensions (backwards incompatible).
    Workaround missing EOI code in strips.
    Support image and tile depth tags (SGI extension).
    Better handling of STK/UIC tags (backwards incompatible).
    Disable color mapping for STK.
    Julian to datetime converter.
    TIFF ASCII type may be NULL separated.
    Unwrap strip offsets for LSM files greater than 4 GB.
    Correct strip byte counts in compressed LSM files.
    Skip missing files in OME series.
    Read embedded TIFF files.
2014.02.05
    Save rational numbers as type 5 (bug fix).
2013.12.20
    Keep other files in OME multi-file series closed.
    FileHandle class to abstract binary file handle.
    Disable color mapping for bad OME-TIFF produced by bio-formats.
    Read bad OME-XML produced by ImageJ when cropping.
2013.11.03
    Allow zlib compress data in imsave function (optional).
    Memory-map contiguous image data (optional).
2013.10.28
    Read MicroManager metadata and little endian ImageJ tag.
    Save extra tags in imsave function.
    Save tags in ascending order by code (bug fix).
2012.10.18
    Accept file like objects (read from OIB files).
2012.08.21
    Rename TIFFfile to TiffFile and TIFFpage to TiffPage.
    TiffSequence class for reading sequence of TIFF files.
    Read UltraQuant tags.
    Allow float numbers as resolution in imsave function.
2012.08.03
    Read MD GEL tags and NIH Image header.
2012.07.25
    Read ImageJ tags.
    ...

Notes
-----
The API is not stable yet and might change between revisions.

Tested on little-endian platforms only.

Other Python packages and modules for reading bio-scientific TIFF files:

*  `python-bioformats <https://github.com/CellProfiler/python-bioformats>`_
*  `Imread <https://github.com/luispedro/imread>`_
*  `PyLibTiff <https://github.com/pearu/pylibtiff>`_
*  `SimpleITK <http://www.simpleitk.org>`_
*  `PyLSM <https://launchpad.net/pylsm>`_
*  `PyMca.TiffIO.py <https://github.com/vasole/pymca>`_ (same as fabio.TiffIO)
*  `BioImageXD.Readers <http://www.bioimagexd.net/>`_
*  `Cellcognition.io <http://cellcognition.org/>`_
*  `pymimage <https://github.com/ardoi/pymimage>`_

Acknowledgements
----------------
*   Egor Zindy, University of Manchester, for cz_lsm_scan_info specifics.
*   Wim Lewis for a bug fix and some read_cz_lsm functions.
*   Hadrien Mary for help on reading MicroManager files.
*   Christian Kliche for help writing tiled and color-mapped files.

References
----------
(1) TIFF 6.0 Specification and Supplements. Adobe Systems Incorporated.
    http://partners.adobe.com/public/developer/tiff/
(2) TIFF File Format FAQ. http://www.awaresystems.be/imaging/tiff/faq.html
(3) MetaMorph Stack (STK) Image File Format.
    http://support.meta.moleculardevices.com/docs/t10243.pdf
(4) Image File Format Description LSM 5/7 Release 6.0 (ZEN 2010).
    Carl Zeiss MicroImaging GmbH. BioSciences. May 10, 2011
(5) File Format Description - LSM 5xx Release 2.0.
    http://ibb.gsf.de/homepage/karsten.rodenacker/IDL/Lsmfile.doc
(6) The OME-TIFF format.
    http://www.openmicroscopy.org/site/support/file-formats/ome-tiff
(7) UltraQuant(r) Version 6.0 for Windows Start-Up Guide.
    http://www.ultralum.com/images%20ultralum/pdf/UQStart%20Up%20Guide.pdf
(8) Micro-Manager File Formats.
    http://www.micro-manager.org/wiki/Micro-Manager_File_Formats
(9) Tags for TIFF and Related Specifications. Digital Preservation.
    http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml

Examples
--------
>>> data = numpy.random.rand(5, 301, 219)
>>> imsave('temp.tif', data)

>>> image = imread('temp.tif')
>>> numpy.testing.assert_array_equal(image, data)

>>> with TiffFile('temp.tif') as tif:
...     images = tif.asarray()
...     for page in tif:
...         for tag in page.tags.values():
...             t = tag.name, tag.value
...         image = page.asarray()

i(   t   divisiont   print_functionN(   t   Fraction(   t   cElementTreei   (   t	   _tifffiles   ImportError: No module named '_tifffile'. Loading of some compressed images will be very slow. Tifffile.c can be obtained at http://www.lfd.uci.edu/~gohlke/s
   2017.01.12s   restructuredtext ent   imsavet   imreadt   imshowt   TiffFilet
   TiffWritert   TiffSequencet
   FileHandlet   lazyattrt   natural_sortedt
   decode_lzwt	   stripnullc         K  s   t  | d d d d d  } d | k r] d | k r] | j | j j d d
 k r] t | d <n  t |  |   } | j | |  Wd	 QXd	 S(   s  Write image data to TIFF file.

    Refer to the TiffWriter class and member functions for documentation.

    Parameters
    ----------
    file : str or binary stream
        File name or writable binary stream, such as a open file or BytesIO.
    data : array_like
        Input image. The last dimensions are assumed to be image depth,
        height, width, and samples.
    kwargs : dict
        Parameters 'append', 'byteorder', 'bigtiff', 'software', and 'imagej',
        are passed to the TiffWriter class.
        Parameters 'photometric', 'planarconfig', 'resolution', 'compress',
        'colormap', 'tile', 'description', 'datetime', 'metadata', 'contiguous'
        and 'extratags' are passed to the TiffWriter.save function.

    Examples
    --------
    >>> data = numpy.random.rand(2, 5, 3, 301, 219)
    >>> imsave('temp.tif', data, compress=6, metadata={'axes': 'TZCYX'})

    t   appendt   bigtifft	   byteordert   softwaret   imageji  i   i   Ni   (   t   parse_kwargst   sizet   dtypet   itemsizet   TrueR	   t   save(   t   filet   datat   kwargst   tifargst   tif(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   7  s    c           B  s  e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z i! d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6dA dB 6dC dD 6dE dF 6dG dH 6dI dJ 6dK dL 6dM dN 6dO dP 6dQ dR 6dS dT 6dU dV 6dW dX 6dY dZ 6d[ d\ 6Z e e e d] e d^  Z e e e e d_ e e e e i  f  d`  Z	 da   Z
 db   Z dc   Z e dd  Z de   Z df   Z RS(g   s  Write image data to TIFF file.

    TiffWriter instances must be closed using the 'close' method, which is
    automatically called when using the 'with' context manager.

    Examples
    --------
    >>> data = numpy.random.rand(2, 5, 3, 301, 219)
    >>> with TiffWriter('temp.tif', bigtiff=True) as tif:
    ...     for i in range(data.shape[0]):
    ...         tif.save(data[i], compress=6)

    i   t   Bi   t   si   t   Hi   t   Ii   t   2Ii   t   bi   t   hi	   t   ii
   t   2ii   t   fi   t   di   t   Qi   t   qi   t   new_subfile_typei   t   subfile_typei   t   image_widthi  t   image_lengthi  t   bits_per_samplei  t   compressioni  t   photometrici  t   document_namei  t   image_descriptioni  t   strip_offsetsi  t   orientationi  t   samples_per_pixeli  t   rows_per_stripi  t   strip_byte_countsi  t   x_resolutioni  t   y_resolutioni  t   planar_configurationi  t	   page_namei(  t   resolution_uniti1  R   i2  t   datetimei=  t	   predictori@  t	   color_mapiB  t
   tile_widthiC  t   tile_lengthiD  t   tile_offsetsiE  t   tile_byte_countsiR  t   extra_samplesiS  t   sample_formatiT  t   smin_sample_valueiU  t   smax_sample_valuei  t   image_depthi  t
   tile_depths   tifffile.pyc   
        s  | r-yt  | d d d d  } | j   } z y t | d d g w   | d k r t   f d   d' D  r t d   n    j }   j }   j }   j |  _   j	 r d } n  Wd QXWn) t k
 r }	 t d t |	    n XWd | j |  XWd QXWq-t t f k
 r)t } q-Xn  | d( k rLt d |   n  | d k rvt j d k rmd n d } n  | r| rt j d  n  | |  _ | |  _ t |  |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _  d |  _! d |  _" d |  _# | r^t$ |  _% d |  _& d |  _' d |  _( d |  _) d |  _* n6 t |  _% d |  _& d |  _' d |  _( d |  _) d |  _* | rt  | d d d d |  _+ |  j+ j d d   n t  | d d! d d |  _+ |  j+ j, i d" d 6d# d 6|  | r7|  j+ j, t- j. | d$ d% d d   n  |  j+ j, t- j. | d d&   |  j+ j   |  _ |  j+ j, t- j. | |  j) d   d S()   s  Open a TIFF file for writing.

        Existing files are overwritten by default.
        Use bigtiff=True when creating files larger than 2 GB.

        Parameters
        ----------
        file : str, binary stream, or FileHandle
            File name or writable binary stream, such as a open file
            or BytesIO.
            The file is created if it does not exist.
        append : bool
            If True and 'file' is an existing standard TIFF file, image data
            and tags are appended to the file.
            Appending data may corrupt specifically formatted TIFF files
            such as LSM, STK, ImageJ, NIH, or FluoView.
        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 file.
            Saved with the first page in the file only.
        imagej : bool
            If True, write an ImageJ hyperstack compatible file.
            This format can handle data types uint8, uint16, or float32 and
            data shapes up to 6 dimensions in TZCYXS order.
            RGB images (S=3 or S=4) must be uint8.
            ImageJ's default byte order is big endian but this implementation
            uses the system's native byte order by default.
            ImageJ does not support BigTIFF format or LZMA compression.
            The ImageJ file format is undocumented.

        t   modet   rbR   i    t   pagest   forcec         3  s"   |  ] } t    d  |  Vq d S(   t   is_N(   t   getattr(   t   .0t   a(   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    t   lsmt   stkR   t   niht   fluoviewt   micromanagers   contains metadataNs   can not append to file: %st   <t   >s   invalid byteorder %st   littles#   writing incompatible bigtiff ImageJi   i   R+   t   8si   i   R"   R#   t   4ss   r+bi   t   wbt   IIt   MMt   HHHi+   i*   (   RU   RV   R   RW   RX   RY   (   NRZ   R[   (/   R   t   tellR   t   anyt
   ValueErrorR   t
   is_bigtifft	   is_imagejt   _ifd_offsetRO   t   Nonet	   Exceptiont   strt   seekt   IOErrort   FileNotFoundErrort   Falset   syst   warningst   warnt
   _byteordert	   _softwaret   boolt   _imagejt	   _metadatat	   _colormapt   _description_offsett   _description_len_offsett   _description_lent   _tagst   _shapet   _data_shapet   _data_dtypet   _data_offsett   _data_byte_countst   _tag_offsetsR   t   _bigtifft   _offset_sizet	   _tag_sizet   _numtag_formatt   _offset_formatt   _value_formatt   _fht   writet   structt   pack(
   t   selfR   R   R   R   R   R   t   fht   post   e(    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __init__y  s    %  																													") i    c   4        s  |  j  } |  j   |  j } |  j  |  j  |  j  |  j } t j | d   | j	 j
 d d } | j d k r t d   n  |  j rp| s |  j d | j k s |  j | j	 k s | r |  j s | s t j | |  j  r8|  j   |  j   d |  _ d |  _ d |  _ d |  _ |  j rmt d   qmqp|  j d d f | j |  _ | sp| j |  d Sn  | dn k rt d |   n  | do k rt d |   n  | st } d } n | d k rt j } d } |  j rCt d   qCnJ d | k od k n s(t d |   n | rC| d  } d } n  |  j rm| rht j d  d } n  t } | j	 j
 d k rt d | j	 j
   n  | r| d k n d } | j	 j
 d k rt } n  t | j |  } | d dp k r"d } | j	 j
 d k r=t d  | j	 j
   q=n | d k r=d	 } d } n  | d k rXt d!   qm| rdd n d } n  | d k	 r| j	 j
 d" k rt d#   n  t j | d   d$ } | j d d% | j  d& f k rt d'   n  | |  _ n  | rvt! d(   | d  D  } t" |  d k } t" |  d% k  sd| d d) sd| d* d) sdt# d+   | D  rt d,   qn dq } t } | j } | d k rt$ | d  } n t$ | d%  } | j } d } d } | r| j% d k  rt } n  | d k	 rd } d } n  | d k rGd	 } | d k rO| j% d% k rD| d dr k rDd } qDqG| d k r| r| j% d k r| d- ds k rd } qD| j% d% k rD| d. dt k rDd } qDqG| j% d% k r| d du k rd } qG|  j rd	 } qG| r| j% d k r| d- dv k rd } qG| j% d% k rG| d. dw k rGd } qGn  | rzt" |  | rbd n d% k rzd } d	 } n  | d k rt" |  d k  rt d/   n  t" |  d k  rt } n  | d k r>| d dx k rd } q>| | rd- n d. dy k rd } q>| d | | r"d- n d. k r5d } q>d } n  | d k r}| j& dz | | rbd- n d.  } | j d } n4 | j& d{ | | rd- n d. d|  } | j d } | d k rh	| d } qh	n| d k rIt" |  d% k rt d0   n  t } d } | j& d} | d* d~  } d1 d2   | D k rh	t d3   qh	n| rt" |  | rdd n d% k r| d k r| j& d | | rd- n d.  } | j d } n4 | j& d | | rd- n d. d  } | j d } | d } n{ d } x0 t" |  d% k r%	| d d k r%	| d  } qWt" |  d k  rA	t } n  | j& d | | rY	d. n d* d  } t" | j  d k s	t'  t" | j  d4 k r	| j& | j d%  d | j d%  } n  | j } | r	| r	d | d* | d f } n  | d k r@
| d k s.
| s.
| d d k s.
| d d k r@
t d6   q@
n  | d k rg
| d% k rg
t d7   n  t( j) d d8 k r
t* n d9    g   | r
d: n d; } t+ j, | d< } t+ j, | d= } | |  _-   f d>    t       f d?  } d@ dA  } | r*| dB dC d | dD t. n  | s6i  n | |  _/ |  j rvt0 | | d d k |  j d k	 |  j/  } n9 | s| i  k rt1 | |  j d k	 |  j/  } n d } | r| dE dF 7} t" |  |  _2 | dB dC d | dD t. n  |  j3 r| dG dC d |  j3 dD t. d |  _3 n  |	 d k r:|  j4   }	 n  | dH dC d |	 j5 dI  dD t. | dJ d$ d |  | dK dL d | d*  | dM dL d | d.  | r| dN dL d | d  | dO dL d | d*  | d d k r| dP dL d | d-  | dQ dL d | d  qn  | dR dL d d  | dS d$ d i d dT 6d% dU 6d dV 6d5 dW 6| j	 j6  | dX d$ d i d d
 6d d	 6d% d 6d d 6dY d 6|  | d k	 r| dZ d$ | j |  n  | d[ d$ d |  | r1| d k r1| d\ d$ d | d k rd n d%  | d] d$ | | j	 j  d& f |  n | d] d$ d | j	 j  d&  | r| d k r| d k r| d^ d$ d d  q| d^ d$ | d |  n  |
 rB| d_ d` d | |
 d   | da d` d | |
 d   t" |
  d% k ri d d 6d% db 6d dc 6|
 d% } n |  j r&d } n d% } | dd d$ d |  n  | sb| de dL d | d.  n  | rK| d% | d d | d | d | d d | d | d | d% d | d% f } t7 |  | d } t7 |  | d | j	 j  g | }  | |  | |   | |  | d g |  t j8 | | d f d | j	 }! n[ | d j | j	 j  g | d }  | |  | d |   | |  | d d g | d  x | D] }" | |"   qWt9  df dg    |  j: p|  j r| j;   | j | j	 j  d k rt di   n  xt< | s-| r7| d n d  D]}# | j;   }$ | j= |  j>  | j?   |$   | j= |$  | j?  | t"     | j;   }% | j? dj j@ dk    D   | j;   |  _> | j?   d   x tA   D] \ }& }' |' d% r| j;   }$ | j= |% |& |  d  | j?   |$   | j= |$  |' d | k rx|$ }( n] |' d | k r|$ }) nD |' d dl k r|' d% jB dm  r|$ |  _ |% |& | d |  _ n  | j? |' d%  qqW| j;   }* | rg  }  n  | rx| |# D]}+ xt< | d  D]}, xt< | d  D]{}- xrt< | d%  D]`}. tC | d | d% |, | d  }/ tC | d | d |- | d  }0 tC | d% | d |. | d%  }1 d |! |/ d  |0 d  |1 d  f <|+ |, | d |, | d |/  |- | d |- | d |0  |. | d% |. | d% |1  f |! d |/  d |0  d |1  f <| r| |!  }" |  jD t" |"   | j? |"  q^| j |!  | jE   q^WqGWq0WqWnW | rxN | |# D]2 }+ | |+  }+ |  jD t" |+   | j? |+  qWn | j |  | j;   }$ xFtA   D]8\ }& }' |' d | k r|' d% r| j= |(  |* }2 xd |  D]& }3 | j?   |2   |2 |3 7}2 qWqy| j= |% |& |  d  | j?   |*   qA|' d | k rA| ru|' d% r;| j= |)  x^ |  D] }3 | j?   |3   qWqu| j= |% |& |  d  | j?   |  d   n  PqAqAW| j= |$  | jE   |# d k r>g   D] }' |' d s|' ^ q q>q>W| p| s |  _ n  | |  _F d | |  _ | j	 |  _ |* |  _G |  |  _H d S(   s'  Write image data and tags to TIFF file.

        Image data are written in one stripe per plane by default.
        Dimensions larger than 2 to 4 (depending on photometric mode, planar
        configuration, and SGI mode) are flattened and saved as separate pages.
        The 'sample_format' and 'bits_per_sample' tags are derived from
        the data type.

        Parameters
        ----------
        data : numpy.ndarray
            Input image. The last dimensions are assumed to be image depth,
            height (length), width, and samples.
            If a colormap is provided, the dtype must be uint8 or uint16 and
            the data values are indices into the last dimension of the
            colormap.
        photometric : {'minisblack', 'miniswhite', 'rgb', 'palette', 'cfa'}
            The color space of the image data.
            By default this setting is inferred from the data shape and the
            value of colormap.
            For CFA images, DNG tags must be specified in extratags.
        planarconfig : {'contig', 'planar'}
            Specifies if samples are stored contiguous or in separate planes.
            By default this setting is inferred from the data shape.
            If this parameter is set, extra samples are used to store grayscale
            images.
            'contig': last dimension contains samples.
            'planar': third last dimension contains samples.
        tile : tuple of int
            The shape (depth, length, width) of image tiles to write.
            If None (default), image data are written in one stripe per plane.
            The tile length and width must be a multiple of 16.
            If the tile depth is provided, the SGI image_depth and tile_depth
            tags are used to save volume data. Few software can read the
            SGI format, e.g. MeVisLab.
        contiguous : bool
            If True (default) and the data and parameters are compatible with
            previous ones, if any, the data are stored contiguously after
            the previous one. Parameters 'photometric' and 'planarconfig' are
            ignored.
        compress : int or 'lzma'
            Values from 0 to 9 controlling the level of zlib compression.
            If 0, data are written uncompressed (default).
            Compression cannot be used to write contiguous files.
            If 'lzma', LZMA compression is used, which is not available on
            all platforms.
        colormap : numpy.ndarray
            RGB color values for the corresponding data value.
            Must be of shape (3, 2**(data.itemsize*8)) and dtype uint16.
        description : str
            The subject of the image. Saved with the first page only.
            Cannot be used with the ImageJ format.
        datetime : datetime
            Date and time of image creation. Saved with the first page only.
            If None (default), the current date and time is used.
        resolution : (float, float[, str]) or ((int, int), (int, int)[, str])
            X and Y resolutions in pixels per resolution unit as float or
            rational numbers.
            A third, optional parameter specifies the resolution unit,
            which must be None (default for ImageJ), 'inch' (default), or 'cm'.
        metadata : dict
            Additional meta data to be saved along with shape information
            in JSON or ImageJ formats in an image_description tag.
            If None, do not write a second image_description tag.
        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, 2i, 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.

        R   t   ordert   Ci    s   can not save empty arrayi   s+   ImageJ does not support non-contiguous dataNt
   minisblackt
   miniswhitet   rgbt   palettet   cfas   invalid photometric %st   contigt   planars   invalid planarconfig %st   lzmaim  s&   ImageJ can not handle LZMA compressioni	   s   invalid compression level %sc         S  s   t  j |  |  S(   N(   t   zlibt   compress(   R   t   level(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   z  s    i  s&   not writing description to ImageJ filet   BHhfs&   ImageJ does not support data type '%s'R    ii   i   s.   ImageJ does not support data type '%s' for RGBs%   ImageJ does not support planar imagest   BHs#   invalid data dtype for palette modeR"   i   i   s   invalid color map shapec         s  s   |  ] } t  |  Vq d  S(   N(   t   int(   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i   ic         s  s   |  ] } | d  k  Vq d S(   i   N(    (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s   invalid tile shapeiis   not a RGB(A) images   invalid CFA imagei  c         s  s   |  ] } | d  Vq d S(   i    N(    (   RS   t   et(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s#   must specify DNG tags for CFA imagei   i   s#   invalid data shape for palette modes#   not a RGB image (samplesperpixel=2)t   2c         S  s    t  |  t  r t |  d  S|  S(   Ns   utf-8(   t
   isinstanceRk   t   bytes(   t   x(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   <lambda>  s    t   tilet   stript   _byte_countst   _offsetsc           s   t  j   |  |  S(   N(   R   R   (   t   fmtt   val(   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    c   	        s{  t  t j j |  |    }  y t j | } Wn! t k
 rO t d |   n X| } | d k r   |  d } t |  } } | j d  } | d k  r | } n
 | d 7} | f } n  t |  d k r | t  | d   9} | d } n   d |  |    |  g } d  } t
 j |  |  k r| d k rt | t t t j f  rc| d } n  | j    | |    qU| j    t |  | |    n | j   d   t | t j  r| j | k st  | j j | k st  | j   } n@ t | t t f  rF t |  | |  } n  | |  }  j |  d	 j |  | | f  d  S(
   Ns   unknown dtype %sR!   s    s     i    i   it   HHt    (   R   R	   t   TAGSt   gett   TYPESt   KeyErrorRe   t   lent   findRi   R   t   calcsizeR   t   tuplet   listt   numpyt   ndarrayR   Rk   R   t   AssertionErrorR   t   chart   tostringt   join(	   t   codeR   t   countt   valuet	   writeoncet   tifftypet   rawcountt   ifdentryt   ifdvalue(   t   bytestrt   offset_formatt   offset_sizeR   t   tagst   value_format(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   addtag"  sH    	
" i@B c         S  s]   y t  j |   } Wn( t k
 r= t  |  d |  d  } n X| j |  } | j | j f S(   Ni    i   (   R   t
   from_floatt	   TypeErrort   limit_denominatort	   numeratort   denominator(   t   argt   max_denominatorR)   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   rationalP  s    R5   R!   R   s    i    R   R@   s   %Y:%m:%d %H:%M:%SR2   R/   R#   R0   RC   RD   RK   RL   R-   RH   t   uR'   R)   t   cR3   i#  RB   R8   R=   R1   RG   R;   R$   R<   t   incht   cmR?   R9   t   keyc         S  s   |  d S(   Ni    (    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    i   s%   data too large for standard TIFF fileR   c         s  s   |  ] } | d  Vq d S(   i   N(    (   RS   t   t(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i  s       (   NR   R   R   R   R   (   NR   R   (   i   i   (    (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   ii   (   i(   i   (   ii   (   i   (   ii   (   i(   i   (   ii   (   i   (   i   i   (   i   (   i   i   (   i    (   i    i    I       i(   i   (I   R   Rs   R   R   R   R   R   R   t   asarrayR   R   R   Re   R~   t   shapeR   R|   t   array_equalRx   t   _write_remaining_pagest   _write_image_descriptionRy   Rz   Ri   Rv   t   write_arrayRo   R   R   Rq   Rr   t   imagej_shapeR   R   R   Rd   t
   reshape_ndt   ndimt   reshapeR   Rp   t   versionR   R	   R   R   R   Rw   t   imagej_descriptionR5   R{   Rt   t   _nowt   strftimet   kindt   productt   emptyt   sortedR   Rc   t   rangeRl   Rh   R   R   t	   enumeratet   endswitht   minR   t   flushR}   R   R   (4   R   R   R3   t   planarconfigR   t
   contiguousR   t   colormapt   descriptionR@   t
   resolutiont   metadatat	   extratagsR   t   numtag_formatt   tag_sizet   compress_tagt   volumet   ijrgbt   ijshapet
   data_shapeR   t   samplesperpixelt   extrasamplest   strip_or_tilet   tag_byte_countst   tag_offsetsR   R   R?   t   tilest   numtilesR:   t   chunkR   t	   pageindexR   t
   tag_offsett   tagindext   tagt   strip_offsets_offsett   strip_byte_counts_offsett   data_offsett   planet   tzt   tyt   txt   c0t   c1t   c2t   strip_offsetR   (    (   R   R   R   R   R   R   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s   U							%	

														 .				%				%	$				 		#!$#!%	!(	 		!.			-&		!%&""#) 
		#		###%C


*		c           s]  |  j  s d S|  j } |  j   |  j } |  j } |  j } |  j } |  j } t |  j	  } d j
 d   |  j  D  } |  j d |  j d d }	 | j   }
 |  j r |
 t |  |	 d k r |  j r t j d	  d St d
   n    f d   } x7t |	  D])} | j   }
 | j |  j  | j | | |
   | j |
  | j | | t |  j     | j   } | j |  | j   |  _ | j | | d   | | 7} x t |  j   D] \ } } | d r| j   }
 | j | | | | d  | j | | |
   | j |
  | d |  j k rB|
 } n  | j | d  qqW| j   }
 x t |  j   D] \ } } | d |  j k rv| d r| j |  | } xg |  j	 D]& } | j | | |   | | 7} qWn3 | j | | | | d  | j | | |   PqvqvW| j |
  qWd |  _  d |  _ d |  _ d |  _	 d S(   s(   Write outstanding IFDs and tags to file.NR   c         s  s   |  ] } | d  Vq d S(   i   N(    (   RS   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>:  s    i    i   i   i    i   s   truncating ImageJ files#   data too large for non-bigtiff filec           s   t  j   |  |  S(   N(   R   R   (   R   R   (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   D  s    i   I       I     (   R|   R   Rs   R   R   R   R   R   t   sumR   R   R}   R~   Rc   R   R   Rv   Rq   Rr   Re   R   Rl   Rh   R   R   R   Ri   R   (   R   R   R   R   R   R   R  t   page_data_sizet	   tag_bytest   numpagesR   R   t   _R	  R
  R  R  R  R   (    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   -  sr    								$	

	
			c         C  sF  |  j  s, |  j  d d k s, |  j d k r0 d S|  j d k	 } |  j ry |  j d d k } t |  j  | | |  j  } n t |  j  | |  j  } | |  j	 d  } |  j
 j   } |  j
 j |  j  |  j
 j |  |  j
 j |  j  |  j
 j t j |  j |  j t |  d   |  j
 j |  d |  _ d |  _ d |  _	 d S(   s)   Write meta data to image_description tag.i    i   Nii   i   (   i   i   (   R~   Ry   Rx   Ri   Rv   R}   R   Rw   R5   R{   R   Rc   Rl   R   Rz   R   R   Rs   R   R   (   R   t   colormappedt   isrgbR   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   z  s*    			c         C  s   t  j  j   S(   s   Return current date and time.(   R@   t   now(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    c         C  s.   | s |  j    n  |  j   |  j j   d S(   s>   Write remaining pages (if not truncate) and close file handle.N(   R   R   R   t   close(   R   t   truncate(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    
c         C  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt	   __enter__  s    c         C  s   |  j    d  S(   N(   R  (   R   t   exc_typet	   exc_valuet	   traceback(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __exit__  s    (   t   __name__t
   __module__t   __doc__R   R   Ro   Ri   R   R   R   R   R   R   R  R!  R%  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR	   [  s<   -4	s			  ?	M			c           s  t  | d d d d d  } t  | d  } t   t  rg t   f d   d D  rg t j      n    s| t d	   n  t   d
  r t    d k r   d   n  t   t  s t   d
  r t   |   } | j	 |   SWd QXn% t
   |   } | j	 |   SWd QXd S(   s  Return image data from TIFF file(s) as numpy array.

    Refer to the TiffFile class and member functions for documentation.

    Parameters
    ----------
    files : str, binary stream, or sequence
        File name, seekable binary stream, glob pattern, or sequence of
        file names.
    kwargs : dict
        Parameters 'multifile', 'multifile_close', 'pages', 'fastij', and
        'is_ome' are passed to the TiffFile class.
        The 'pattern' parameter is passed to the TiffSequence class.
        Other parameters are passed to the asarray functions.
        The first image series is returned if no arguments are provided.

    Examples
    --------
    >>> imsave('temp.tif', numpy.random.rand(3, 4, 301, 219))
    >>> im = imread('temp.tif', key=0)
    >>> im.shape
    (4, 301, 219)
    >>> ims = imread(['temp.tif', 'temp.tif'])
    >>> ims.shape
    (2, 3, 4, 301, 219)

    t	   multifilet   multifile_closeRO   t   fastijt   is_omet   patternc         3  s   |  ] } |   k Vq d  S(   N(    (   RS   R'   (   t   files(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s   ?*s   no files foundRl   i   i    N(   R   R   t
   basestringRd   t   globRe   t   hasattrR   R   R   R
   (   R.  R   t   kwargs_filet
   kwargs_seqR   t   imseq(    (   R.  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    +"c           B  s&   e  Z d  Z d Z d   Z d   Z RS(   s>   Lazy object attribute whose value is computed on first access.t   funcc         C  s   | |  _  d  S(   N(   R5  (   R   R5  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    c         C  sa   | d  k r |  S|  j |  } | t k rG t t | |  |  j j  St | |  j j |  | S(   N(   Ri   R5  t   NotImplementedRR   t   superR&  t   setattr(   R   t   instancet   ownerR   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __get__  s    (   R5  (   R&  R'  R(  t	   __slots__R   R;  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s   	c        	   B  s  e  Z d  Z d( d( d( e e d( e d( d  Z e d    Z e d    Z d   Z	 d( e d  Z
 d   Z d   Z d( d( e d( d  Z e d	    Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d( d( d  Z e d    Z e d    Z e d    Z e d    Z  e d    Z! e d    Z" e d    Z# e d    Z$ e d    Z% e d    Z& e d     Z' e d!    Z( e d"    Z) e d#    Z* e d$    Z+ e d%    Z, e d&    Z- e d'    Z. RS()   s  Read image and metadata from TIFF, STK, LSM, and FluoView files.

    TiffFile instances must be closed using the 'close' method, which is
    automatically called when using the 'with' context manager.

    Attributes
    ----------
    pages : list of TiffPage
        All TIFF pages in file.
    series : list of TiffPageSeries
        TIFF pages with compatible shapes and types.
    micromanager_metadata: dict
        Extra MicroManager non-TIFF metadata in the file, if exists.

    All attributes are read-only.

    Examples
    --------
    >>> with TiffFile('temp.tif') as tif:
    ...     data = tif.asarray()
    ...     data.shape
    (5, 301, 219)

    c
   
   
   C  s   |	 t  k r t  |  _ n  t | d d d | d | d | |  _ d |  _ g  |  _ t |  |  _ t |  |  _	 i |  |  j j
 6|  _ d |  _ y |  j | |  Wn! t k
 r |  j j     n Xd S(   s   Initialize instance from file.

        Parameters
        ----------
        arg : str or open file
            Name of file or open file object.
            The file objects are closed in TiffFile.close().
        name : str
            Optional name of file in case 'arg' is a file handle.
        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.
        pages : sequence of int
            Indices of the pages to read. If None (default) all pages are read.
            Can be used to read only the first page with pages=[0].
            Specifying pages might invalidate series based on metadata.
        fastij : bool
            If True (default), try to use only the metadata from the first page
            of ImageJ files. Significantly speeds up loading movies with
            thousands of pages.
        is_ome : bool
            If False, disable processing of OME-XML metadata.

        RM   RN   t   namet   offsetR   i    N(   Ro   R,  R   R   Ri   R   RO   Ru   t
   _multifilet   _multifile_closeR=  t   _filesRh   t	   _fromfileRj   R  (
   R   R   R=  R>  R   R)  R*  RO   R+  R,  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    %			c         C  s   |  j  S(   s   Return file handle.(   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt
   filehandle8  s    c         C  s
   |  j  j S(   s   Return name of file handle.(   R   R=  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   filename=  s    c         C  s4   x$ |  j  j   D] } | j j   q Wi  |  _  d S(   s   Close open file handle(s).N(   RA  t   valuesR   R  (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  B  s    c         C  s1  |  j  j d  y+ i d d 6d d 6|  j  j d  |  _ Wn t k
 rZ t d   n X|  j i d d 6d d	 6t j k |  _ t j	 |  j d
 |  j  j d   d } | d k rt j	 |  j d |  j  j d   \ |  _
 } | s |  j
 d k r0t d   q0n$ | d k r$d |  _
 n t d   |  j  j   |  _ g  |  _ d } x t r| d 7} | os| | k } y t |  |  } Wn t k
 rPn X| rqTn  |  j j |  | rT| j   rPn  t } qTqTW|  j  j   |  _ |  j rt |  j   |  _ n  |  j r-|  j   |  j   n  d S(   s0   Read TIFF header and all page records from file.i    RZ   R`   R[   Ra   i   s   invalid TIFF filet   bigR\   R"   i+   R   i   i   s   invalid BigTIFF filei*   s   not a TIFF fileii   N(   R   Rl   t   readR   R   Re   Rp   t
   _is_nativeR   t   unpackR   Rc   Rh   RO   R   t   TiffPaget   StopIterationR   t   _patch_imagejRo   t   is_micromanagert   read_micromanager_metadatat   micromanager_metadatat   is_lsmt   _fix_lsm_strip_offsetst   _fix_lsm_strip_byte_counts(   R   RO   R+  R   t   zeroR  t   skipt   page(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRB  H  sN    +)		
		
c   	      C  s   x |  j  D] } d } x5 d D]- } | j | d k r | | j | 9} q q Wt | j  | } x t | j  D]~ \ } } | | s d } d } n  g  } xA | j D]6 } | | k  r | d 7} n  | j | |  | } q Wt |  | _ qq Wq
 Wd S(	   s5   Unwrap strip offsets for LSM files greater than 4 GB.i   i    t   PMi   i    N(   i    i   I       (	   t   seriest   axesR   R   RO   R   R6   R   R   (	   R   RW  t	   positionsR'   RU  t   wrapt   previous_offsetR6   t   current_offset(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRQ  {  s"    
	
c           sC  |  j  s d Si    xe |  j  D]Z } t | j  t | j  k sG t  x- t | j | j  D] \ } } |   | <q] Wq Wt   j    } | j t	 | d   | d |  j
 j   xA t | d   D]/ \ } } t	   | | | d |    | <q Wx? |  j  D]4 } | j rt   f d   | j D  | _ qqWd S(   s   Set strip_byte_counts to size of compressed data.

        The strip_byte_counts tag in LSM files contains the number of bytes
        for the uncompressed data.

        Nii   c         3  s   |  ] }   | Vq d  S(   N(    (   RS   R>  (   t   strips(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   RO   R   R6   R:   R   t   zipR   t   keysR   R   R   R   R   R2   R   (   R   RU  R>  t	   bytecountt   offsetsR'   (    (   R]  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRR    s     	$,'	c      
   C  s  |  j  s t j g   S| d k r7 | d k r7 d } n  | d k	 rz y |  j | } Wn t t f k
 rm n X| j  } n	 |  j  } | d k r ny t | t  r | | g } nZ t | t	  r | | } n> t | t
 j  r g  | D] } | | ^ q } n t d   t |  s&t d   n  |  j r| d j rmt | d t d t } t | | d j  } qt | d | d | d t d t } nmt |  d k r| d j d |  } nB|  j rm|  j st d	   t d
   | D  r(t d   | D  } t j | j d t   }	 n  | rst j   4 }
 t j |
 | j d | j } | j d  } Wd QXn! t j  | j | j  j d  } d } d d d     Y} | |  |  j!  } x | D] } | j" |  | r | j d t d t d t  } n |	 } y! | j d  | | | | j# +Wn% t k
 rN} t$ j% d |  Pn X| | j# 7} qW| j&   n | d k r| r| j' r| r|  j( j) | j | j | j'  } q|  j( j* | j'  |  j( j+ | j t, | j   } n t | d | d | } | d k ry | j | _ Wqt k
 ry1 t$ j% d | j | j f  d | j | _ Wqt k
 rd | d j | _ qXqXn9 t |  d k r| d j | _ n d | d j | _ | S(   s  Return image data from multiple TIFF pages as numpy array.

        By default the first image series is returned.

        Parameters
        ----------
        key : int, slice, or sequence of page indices
            Defines which pages to return as array.
        series : int or TiffPageSeries
            Defines which series of pages to return as array.
        memmap : bool
            If True, return an read-only array stored in a binary file on disk
            if possible. The TIFF file is used if possible, else a temporary
            file is created.
        tempdir : str
            The directory where the memory-mapped file will be created.

        i    s&   key must be an int, slice, or sequences   no pages selectedR  t   squeezet   memmapt   tempdiri   s#   color mapping disabled for ome-tiffc         s  s   |  ] } | d  k Vq d  S(   N(   Ri   (   RS   t   p(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    c         s  s   |  ] } | r | Vq d  S(   N(    (   RS   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    R   iNt   KeepOpenc           B  s#   e  Z d    Z d   Z d   Z RS(   c         S  s   | |  _  | |  _ | |  _ d  S(   N(   t   mastert   parentt   _close(   R   Rh  R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    		c         S  si   |  j  re | re | j |  j k re |  j |  j k rF |  j j j   n  | j |  _ |  j j j   n  d  S(   N(   Ri  Rh  Rg  RC  R  t   open(   R   RU  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRj    s
    !c         S  s2   |  j  r. |  j |  j k r. |  j j j   n  d  S(   N(   Ri  Rh  Rg  RC  R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    (   R&  R'  R   Rj  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRf    s   		t   reopens   ome-tiff: %ss   failed to reshape %s to %s(    (   i(   i(   i(-   RO   R   t   arrayRi   RW  R   R   R   R   t   slicet   collectionst   IterableR   Re   t   is_niht
   is_indexedt   stack_pagesRo   t   apply_colormapRB   R   R,  R   Rd   t   nextt
   zeros_liket   tempfilet   NamedTemporaryFileRc  R   R   R   R   R@  Rj  R   Rq   Rr   R  R>  RC  t   memmap_arrayRl   t
   read_arrayR   (   R   R   RW  Rc  Rd  RO   t   kt   resultt	   firstpaget   nopageR   t   indexRf  t   keepRU  RT   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    			 		!!			c         C  s  |  j  s g  Sg  } |  j r+ |  j   } n` |  j rC |  j   } nH |  j r[ |  j   } n0 |  j rs |  j   } n |  j	 r |  j
   } n  | sg  } i  } d } x |  j  D] } | j s q n  | j r | d 7} n  | j | | j | j t k f } | | k r| | j |  q | j |  | g | | <q Wg  } xb| D]W} t | |  d k r|t | |  f | d  n | d  } t | |  d k rd | d n | d } | | d }	 |	 j ryt |	 j  }
 |
 d } d |
 k r1|
 d } t |  t |  k r!| } | } q1t j d  n  y t | | |  } | } Wqyt k
 ru} t j t |   qyXn  | j t | | | |	 j |   qEWn  x# t |  D] \ } } | | _ qWg  | D]! } t | j  d k r| ^ q} | S(	   s:   Return pages with compatible properties as TiffPageSeries.i    i   iR#   iR   RX  s   axes do not match shape(   RO   R,  t   _ome_seriest   is_fluoviewt   _fluoview_seriesRP  t   _lsm_seriesRg   t   _imagej_seriesRp  t   _nih_seriesR   t	   is_shapedRX  R2   t   TIFF_DECOMPESSORSR   R   t   image_description_dictRq   Rr   t   reshape_axesRe   Rk   t   TiffPageSeriesR   R   R~  R  (   R   RW  t   shapesRO   R~  RU  R   R!   RX  t   page0R   R   t   reaxesR   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRW  ,  sl    								1
.	

	
$.c           s   |  j  d } i	 d d 6d d 6d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6  t t | j j   } d j   f d   | D  } t d   | D  } t |  j  | | j |  g S(   s%   Return image series in FluoView file.i    t   Xt   Yt   Zt   TR   t
   WAVELENGTHt   TIMEt   Rt   XYt   Vt   EVENTt   Lt   EXPOSURER   c         3  sA   |  ]7 } | d  d  k r   j  | d j   j   d  Vq d S(   i   i    R+   N(   R   R   t   upper(   RS   R'   (   t   dims(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>v  s   c         s  s/   |  ]% } | d  d  k r t  | d   Vq d S(   i   N(   R   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>x  s    (	   RO   R   t   reversedt	   mm_headert
   dimensionsR   R   R  R   (   R   R  t   mmhdRX  R   (    (   R  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  n  s    c   
        s  |  j  d } | j   t   j } | j rM | j d d  j d d  } n  t   d  rx   j d k rx | d 7} n  t   d	  r   j d k r | d
 7} n  | d d d  } t	   f d   | D  } g  |  j  D] } | j
 s | ^ q } | d j } t | | | |  g } t |  t |  j   k rg  |  j  D] } | j
 rA| ^ qA} d } d }	 xD | t |  k  r|	 t |  d k  r| | |	 9} |	 d 7}	 qkW| |	  | d j } | |	  d } | d j } | j t | | | |   n  | S(   s    Return image series in LSM file.i    R   R   R  t   XYCt   dimension_pi   t   Pt   dimension_mt   MNic         3  s"   |  ] } t    t |  Vq d  S(   N(   RR   t   CZ_DIMENSIONS(   RS   R'   (   t   lsmi(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i   t   CYX(   RO   t   cz_lsm_infot   CZ_SCAN_TYPESt	   scan_typet   is_rgbt   replaceR1  R  R  R   t
   is_reducedR   R  R   R   R   (
   R   R  RX  R   Re  RO   R   RW  t   cpR'   (    (   R  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  {  s4    		!%%+c         C  s  g  } g  } |  j  d } | j } d | k rO | j | d  | j d  n  d | k r| | j | d  | j d  n  d | k r |  j o | j d t  r | j | d  | j d  n  | j d	 t |  j    | r t |  n d
 } | d
 k r | j |  | j d  n  | j d d k r^| j	 | j
 d
  | j	 | j d
  n | j d  d k r| j
 d d
 !t |  | j
 d } t | j d  | t | j d  } n  | j	 | j
  | j	 | j  t |  j  | | j |  g S(   s#   Return image series in ImageJ file.i    t   framesR  t   slicesR  t   channelst
   hyperstackR   t   imagesi   R#   i   t   SI(   RO   t   imagej_tagsR   R  R   Ro   R   R   RX  t   extendR   R   R   R  R   (   R   R   RX  R  t   ijt   remain(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s8    	%+c         C  sy   |  j  d } t |  j   d k r7 | j } | j } n& t |  j   f | j } d | j } t |  j  | | j |  g S(   s    Return image series in NIH file.i    i   R#   (   RO   R   R   RX  R  R   (   R   R  R   RX  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    	c   $        s3  |  j  d j d j } y t j |  } WnQ t j k
 r} } t j d |  | j d d  j	 d  } t j |  } n X| j
 j d d&  } i |  | 6|  _ |  j j } i  } g  } x^| D]V} | j j d  r t j d  Pn  | j j d	  rZxZ| D]O}	 |	 j
 j d
 d  j d  s.qn  x"|	 D]}
 x|
 D]	} x | D] } | j d  j d  sqqOn  | j d } | j
 j d d  } t | } d | j
 k r	t | j
 j d d   } t | j
 d  } t | j
 d  | } t j | | |  } n. g  | D]! } | j j d  r| j ^ q} | | f | | <qOWqBWq5WqWn  | j j d  srq n  x| D]} | j j d  sqyn  | j
     j d d&  } d j t   d   } t   f d   | D  } t | d   } d& g | |  j  d j } x| D]} | j j d  s7qn  | j
   t   j d d   } t   j d d   k rvd n d   } t   j d |   } g  | d  D]" } t   j d | d   ^ q} y t j | | d   } Wn! t k
 r
t j d   qn Xx| D]9} | j j d  s0qn  | j |  j k r|  j sOg  S| j
 d! } y t  t! j" j | |   }  Wn, t# t$ t f k
 rt j d" |  Pn X|  |  j | j <|  j% r|  j&   qn  |  j | j j  }! yC x< t' | r| n	 t( |!   D] }" |! | |" | | |" <qWWn t) k
 rIt j d#  n XPqW|  j  }! yC x< t' | rm| n	 t( |!   D] }" |! | |" | | |" <qzWWqt) k
 rt j d#  qXqWt* d$   | D  rqyn  t+ d%   | D  j, } | j- t. | | | | |    qyWq Wx | D] }# t |# j/  } x | j0   D] \ } \ } } |# j1 j2 |  }" t( |  } | |" | k r|# j1 j3 | | d  |# _1 qE| |" c | <| j4 |" d |  |# j1 j3 | | | d  |# _1 qEWt5 |  |# _/ q#Wx/ | D]' }# t6 |# j/ |# j1  \ |# _/ |# _1 qW| S('   s(   Return image series in OME-TIFF file(s).i    R5   s   ome-xml: %ss   utf-8t   ignoret   UUIDt
   BinaryOnlys$   ome-xml: not an ome-tiff master filet   StructuredAnnotationst	   NamespaceR   t   moduloit   Alongt   Typet   othert   Startt   Stepi   t   Endt   Labelt   Imaget   Pixelst   DimensionOrderc         3  s#   |  ] } t    d  |  Vq d S(   t   SizeN(   R   (   RS   t   ax(   t   atr(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    it   TiffDatat   IFDt	   NumPlanest
   PlaneCountt   Firsts   ome-xml: invalid TiffData indext   FileNames   ome-xml: failed to read '%s's   ome-xml: index out of rangec         s  s   |  ] } | d  k Vq d  S(   N(   Ri   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>+  s    c         s  s   |  ] } | r | Vq d  S(   N(    (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>.  s    N(7   RO   R   R   t   etreet
   fromstringt
   ParseErrorRq   Rr   t   decodet   encodet   attribR   Ri   RA  R   t   dirnameR  R   t   AXES_LABELSt   floatR   t   aranget   textR   R  R   R   R8   R   t   ravel_multi_indexRe   R?  R   t   ost   pathRm   Rn   R@  R  R   R   t
   IndexErrort   allRt  R   R   R  R   t   itemsRX  R~  R  t   insertR   t   squeeze_axes($   R   t   omexmlt   rootR   t   uuidR  R  RW  t   elementt   annotR   t   modult   alongt   axist   newaxist   stept   startt   stopt   labelst   labelt   pixelsR   RX  R   R   t   ifdsR   t   ifdt   numR  t   idxt   fnameR   RO   R'   t   serie(    (   R  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    
!#		*3		%	%'#%c         C  s   t  |  j  S(   s%   Return number of image pages in file.(   R   RO   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __len__A  s    c         C  s   |  j  | S(   s   Return specified page.(   RO   (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __getitem__E  s    c         C  s   t  |  j  S(   s   Return iterator over pages.(   t   iterRO   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __iter__I  s    c         C  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR!  M  s    c         C  s   |  j    d  S(   N(   R  (   R   R"  R#  R$  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR%  P  s    c           s  d   j  j t   j  j  i d d 6d d 6  j g }   j rS | j d  n  | j   f d   d D  t   j	  d k r | j d t   j	   n  t   j
  d k r | j d t   j
   n  t   j  d k r| j d t   j   n  d j |  S(   s0   Return string containing information about file.s   TIFF file: %ss   little endianRZ   s
   big endianR[   R   c         3  s(   |  ] } t    d  |  r | Vq d S(   RQ   N(   RR   (   RS   t   attr(   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>[  s    t   mdgelt   mediacyRV   RU   t   vistaR   RX   RY   RW   t   omet   scnt   tvipst   feit   semi   s   %i pagess	   %i seriess   %i filess   , (   R  R   RV   RU   R  R   RX   RY   RW   R  R  R  R  R  (   R   R=  t   format_sizeR   R   Rf   R   R  R   RO   RW  RA  R   (   R   R{  (    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __str__S  s    	 c         C  s  | d k r |  j } n& g  t |  D] } |  j | ^ q% } t |   g } xJ | D]B } | j t |   | d k rT | j | j d j    qT qT W| d k	 r| d k r |  j } n& g  t |  D] } |  j | ^ q } x$ | D] } | j | j    q Wn  d j |  S(   s3   Return string with detailed information about file.i    R  s   

N(   Ri   RW  t   sequenceRk   R   RO   t   infoR   (   R   RW  RO   R'   R{  R!   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR
  g  s    &!&c         C  s3   y t  j |  j j    SWn t k
 r. d  SXd  S(   N(   R  t   fstatR   t   filenoRj   Ri   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  ~  s    c         C  s   |  j  d k S(   s   File has BigTIFF format.i   (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRf     s    c         C  s    |  j  o t d   |  j  D  S(   s   File contains only RGB images.c         s  s   |  ] } | j  Vq d  S(   N(   R  (   RS   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   RO   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s    |  j  o t d   |  j  D  S(   s"   File contains only indexed images.c         s  s   |  ] } | j  Vq d  S(   N(   Rq  (   RS   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   RO   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRq    s    c         C  s   t  d   |  j D  S(   s   File has MD Gel format.c         s  s   |  ] } | j  Vq d  S(   N(   t   is_mdgel(   RS   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   Rd   RO   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  d   |  j D  S(   s/   File was created by Media Cybernetics software.c         s  s   |  ] } | j  Vq d  S(   N(   t
   is_mediacy(   RS   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   Rd   RO   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s    |  j  o t d   |  j  D  S(   s   File has MetaMorph STK format.c         s  s   |  ] } | j  Vq d  S(   N(   t   is_stk(   RS   Re  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   RO   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  o |  j d j S(   s(   File was created by Carl Zeiss software.i    (   R   RO   RP  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRP    s    c         C  s   t  |  j  o |  j d j S(   s   File was created by ISS Vista.i    (   R   RO   t   is_vista(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  o |  j d j S(   s   File has ImageJ format.i    (   R   RO   Rg   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRg     s    c         C  s   t  |  j  o |  j d j S(   s!   File was created by MicroManager.i    (   R   RO   RM  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRM    s    c         C  s   t  |  j  o |  j d j S(   s   File has NIH Image format.i    (   R   RO   Rp  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRp    s    c         C  s   t  |  j  o |  j d j S(   s%   File was created by Olympus FluoView.i    (   R   RO   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  o |  j d j S(   s   File has OME-TIFF format.i    (   R   RO   R,  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR,    s    c         C  s   t  |  j  o |  j d j S(   s   File has Leica SCN format.i    (   R   RO   t   is_scn(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  o |  j d j S(   s(   File was created using EM-MENU software.i    (   R   RO   t   is_tvips(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  o |  j d j S(   s$   File was created using FEI software.i    (   R   RO   t   is_fei(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  o |  j d j S(   s!   File contains Zeiss SEM metadata.i    (   R   RO   t   is_sem(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    N(/   R&  R'  R(  Ri   R   R   t   propertyRC  RD  R  RB  RQ  RR  Ro   R   R   RW  R  R  R  R  R  R  R  R  R!  R%  R  R
  R  Rf   R  Rq  R  R  R  RP  R  Rg   RM  Rp  R  R,  R  R  R  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     sT   		4	3		B			$		z						RJ  c        	   B  s  e  Z d  Z e d  Z e d  Z d   Z d   Z e e e e e e d d' d  Z	 e
 d	    Z d
   Z e
 d    Z d   Z d   Z d   Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z  e
 d    Z! e
 d     Z" e
 d!    Z# e
 d"    Z$ e
 d#    Z% e
 d$    Z& e
 d%    Z' e
 d&    Z( RS((   s  A TIFF image file directory (IFD).

    Attributes
    ----------
    index : int
        Index of page in file.
    dtype : str {TIFF_SAMPLE_DTYPES}
        Data type of image, color-mapped if applicable.
    shape : tuple
        Dimensions of the image array in TIFF page,
        color-mapped and with extra samples if applicable.
    axes : str
        Axes label codes:
        'X' width, 'Y' height, 'S' sample, 'I' image series|page|plane,
        'Z' depth, 'C' color|em-wavelength|channel, 'E' ex-wavelength|lambda,
        'T' time, 'R' region|tile, 'A' angle, 'P' phase, 'H' lifetime,
        'L' exposure, 'V' event, 'Q' unknown, '_' missing
    tags : TiffTags
        Dictionary of tags in page.
        Tag values are also directly accessible as attributes.
    color_map : numpy.ndarray
        Color look up table, if exists.
    cz_lsm_scan_info: Record(dict)
        LSM scan info attributes, if exists.
    imagej_tags: Record(dict)
        Consolidated ImageJ description and metadata tags, if exists.
    uic_tags: Record(dict)
        Consolidated MetaMorph STK/UIC tags, if exists.

    All attributes are read-only.

    Notes
    -----
    The internal, normalized '_shape' attribute is 6 dimensional:

    0. number planes/images  (stk, ij).
    1. planar samples_per_pixel.
    2. image_depth Z  (sgi).
    3. image_length Y.
    4. image_width X.
    5. contig samples_per_pixel.

    c         C  s~   | |  _  t | j  |  _ d |  _ |  _ d |  _ |  _ d |  _	 t
   |  _ d |  _ |  j |  | rp d S|  j   d S(   sh   Initialize instance from file.

        If skip, seek to next IFD offset without reading tags.

        R   i    N(    (   Rh  R   RO   R~  R   R}   Ri   R   t   _dtypeRX  t   TiffTagsR   t   _offsetRB  t   _process_tags(   R   Rh  RT  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    			c         C  s  |  j  j } |  j  j } |  j  j } | j   } i d d 6d d 6| } t j | | | j |   d } | s | j |  t	    n  | | j
 k r t j d  | j |  t	    n  | |  _ | j |  i d d 6d d 6| \ } } }	 yB t j | | | j |   d }
 |
 d k r7t d   n  Wn8 t k
 rrt j d |  | j |  t	    n X| r| j | | |
 |	  d S|  j } d } x t |
  D] } y t |  j   } Wn, t j k
 r} t j t |   qn X| | j k rt j d  n  | j } | j | k rA| | | j <qd } x7 t rd | j | f } | | k rJ| | | <PqJqJWqW| j   } |  j s|  j r|  j  j r|  j d j |   n  |  j rlxt j   D] \ } } y |  j d | } Wn t k
 rqn X| d k  r&qn  | j |  y t |  d | | |   Wqt k
 rdqXqWnr |  j  rd | k r| d j! r| d } | j | j"  t# t$ | | | j% | j& | d j&   | d _! n  | j |  d S(   s  Read TIFF IFD structure and its tags from file.

        The file cursor is left at the storage position of the offset to the
        next IFD (if any).

        Raises StopIteration if offset (first bytes read) is 0
        or a corrupted page list is encountered.

        R#   i   R+   i   i    s   invalid page offset > file sizeR"   i   i   i   i   s   suspicious number of tagss    corrupted page list at offset %iNs   tags are not ordered by codei   s   %s_%iR1   t   offset_t   cz_lsm_t   uic1tagt   uic2tag(   R"   i   i   (   R+   i   i   ('   Rh  RC  R   R   Rc   R   RI  RG  Rl   RK  R   Rq   Rr   R  Re   Rj   R   R   t   TiffTagt   ErrorRk   R   R=  R   RP  R~  t   _fix_lsm_bitspersamplet   CZ_LSM_INFO_READERSR  R  R   R8  R  R   t   value_offsett   Recordt   read_uic1tagR   R   (   R   RT  R   R   R   R   R   R>  R   t   tagsizet   numtagsR   t   tagcodeR  R  R   R'   R=  t   readerR  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRB    s    
#	!#			
	#
c           s	  |  j  } xt j   D] \ } \ } } } }   | | k r   ryb | | j d k rw t |  |   | | j  n- t |  | t   f d   | | j D   Wq t k
 r t d | | | j f   q Xqq | d' k	 r t |  |   r  | n |  q q Wd | k r| d } | j d k rC| j |  _
 q| j |  j   t  f d    D  r{ |  _
 q d |  _
 n  d | k r&| d } | j d k rt | j |  _ q&| j |  j   t  f d    D  rg   D] } t | ^ q|  _ q&t  d |  _ n  d	 | k r>d' |  _ n  d
 | k rd | k re|  j |  _ n  t t j t |  j |  j d  |  j   |  _ n	 d |  _ |  j |  j
 f }	 t j |	 d'  |  _ |  _ d
 |  j  k sd |  j  k r2d |  _ d |  _ d |  _ d |  _ d( |  _ d) |  _ d |  _  n  |  j! sG|  j" j! rSd |  _ n  |  j# r|  j  d j d |  _ t$ j% |  j& |  j  |  _& |  j& j'   }
 |
 d k  rt$ j( |  _ |  j& j) |  j  |  _& n  d* |  j& _ n  |  j } |  j } |  j } |  j } |  j* rN|  j d k s!t+  |  j  d j } |  j, r| d d | | | f |  _ | d k r| | | f |  _ d |  _  q| | | | f |  _ d |  _  nc | | d | | d f |  _ | d k r| | | f |  _ d |  _  n | | | | f |  _ d |  _  | d k r"|  j d |  _ nu t$ j- |  j. j/ d k  rPd |  j  |  _  nG t$ j- t$ j0 |  j. j1  d k  rd |  j  |  _  n d |  j  |  _  |  j# r	t2 st+ d   |  j& j d d |  j
 k r2| d k r| | | |  j& j d f |  _ n" | | | | |  j& j d f |  _ |  j  d |  _  qKt3 j4 d  t2 |  _# q	n6|  j# rd } d |  j  k r| |  j  d j 7} n  |  j, rd d | | | | f |  _ n d | | | | d f |  _ |  j& j d d |  j
 k rA| d k r| | |  j& j d f |  _ d |  _  q| | | |  j& j d f |  _ d |  _  q	t3 j4 d  t2 |  _# | d k r~| | f |  _ d |  _  q	| | | f |  _ d |  _  n|  j5 s| d k r'	|  j, r d d | | | | f |  _ | d k r| | | f |  _ d |  _  q| | | | f |  _ d |  _  nc d | | | | d f |  _ | d k re| | | f |  _ d |  _  n | | | | f |  _ d  |  _  t2 r	|  j5 r	d |  j  k r	|  j6 } |  j  d j d k r| f } n  xU | D]J } | d+ k r|  j, r	|  j d  d, |  _ n d- |  j d |  _ PqqWq	n] d d | | | d f |  _ | d k ri	| | f |  _ d |  _  n | | | f |  _ d |  _  |  j7 r	d% | k r	t8 |  j  |  j
 d& f |  _9 n  t: |  j  t: |  j   k s	t+  d' S(.   sv   Validate standard tags and initialize attributes.

        Raise ValueError if tag values are not supported.

        i   c         3  s   |  ] }   | Vq d  S(   N(    (   RS   R   (   t   validate(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s   %s.value (%s) not supportedR1   c         3  s   |  ] } |   d  Vq d S(   i    N(    (   RS   t   v(   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i    RH   c         3  s   |  ] } |   d  Vq d S(   i    N(    (   RS   R*  (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    R3   R0   R9   R/   R   RB   i   i   iR  t   YXt   YXSt   SYXR  R  R#   s   color mapping disabled for stki   t   Ss   palette cannot be appliedRG   t   ZYXSt   ZYXt   SZYXt
   unassalphat
   assocalphat   unspecifiedi   R:   i   N(    (    (   i   i(   R2  R3  R4  (   i   (   i   (;   R   t	   TIFF_TAGSR  R   R8  R   R   R   Re   Ri   R1   R8   Rd   t   TIFF_SAMPLE_FORMATSRH   R3   R0   R9   R   t   matht   floorR  t   strips_per_imaget   TIFF_SAMPLE_DTYPESR   R   R  R/   RK   R6   R}   R   RX  R  Rh  Rq  R   Rl  RB   t   maxt   uint8t   astypeR  R   t	   is_contigR  R  t
   z_distancet   difft   time_createdRo   Rq   Rr   R  RG   R2   R   R:   R   (   R   R   R   R=  t   defaultR   R   R  R*  R   t   dmaxR0   R/   RK   R8   t   planest   samplesRG   t   exs(    (   R)  R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  }  sF   	(%!'

 																		$														#c         C  s  |  j  s  |  j s  |  j j r$ d S|  j j d d  } | d k rI d S|  j \ } } |  j } |  j rw | d  } n  |  j j } | t	 |  |  j
 d k s | | | | j k r t |  _  t j d  d S|  j j } |  j j } | j   } i d d	 6d
 d 6| }	 t j | |	 | j |   d }
 | j |  |
 r[| | | |
 k r[d S|  j rjd n d } | f |  j | d _ | | f |  j | d _ | f |  j |  _ | f |  j d |  _ d |  j |  _ t S(   sc  Return if ImageJ data are contiguous and adjust page attributes.

        Patch 'strip_offsets' and 'strip_byte_counts' tags to span the
        complete contiguous data.

        ImageJ stores all image metadata in the first page and image data is
        stored contiguously before the second page, if any. No need to
        read other pages.

        NR  i    i   ii   s)   invalid ImageJ metadata or corrupted fileR#   i   R+   R   R   R   R   (   Rg   t   is_contiguousRh  R,  R  R   R   Rq  RC  R   R1   R   Ro   Rq   Rr   R   R   Rc   R   RI  RG  Rl   t   is_tiledR   R   R}   RX  R   (   R   R  R>  R   R   R   R   R   R   R   t   nextpaget   pre(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRL  W	  s<     			#i@   i   i   c   *   
     sA
   j  s d S| rD t  j   | k rD t d t  j     n   j d k rr t d  j  j f   n   j t	 k r t d  j   n  d  j
 k r  j
 d   j d k r t  f d    j D  r t d  j   q n   j rt d	   n   j j } | j }	 |	 rO| r@| j   qOt d
   n   j   j  }
  j }  j }  j }  j j    j    j d k }  j \ } }  j rq j }  j } d  j
 k r j n d } | | d | } | | d | } | | d | } |
 d |
 d | | | | | | |
 d f }
 | | | |
 d f } |  n |  | r j  | |  r| j!  |
 d | d } n j" r	| j# | d  | j$  t |
   } | j% d   } | r5t& |  q5n, j' r"  j( 9 n    d0 k rf   d rKt d   n       f d  } n9 t)   t*  r   f d   } n     f d   } t	  j }  j d k rd  j
 k r j+ n d    f d   } n   j r8t, j- |
   } d1 \ } } } } xt. | |  D]\ } } | j# |  | j/ |  } | rht& |  } n  | |  } | |  } y | | _0 Wnk t k
 rt1 j2 d  t, j3 |   j4 d  } t5 | j6 | j6  }  | |   | |  *| j4 |  } n X j7 d k r,t, j8 | d  d! d"  d# | n  j7 d$ k rGt    n  | | d | | | |  | | |  | | |  d d  f <~ | | 7} | |
 d% k r+d | | } } | |
 d& k r d | | } } | |
 d' k rd | d } } qq q+q+W| d( d |  d |  d |  d d  f } n  j9  j }!  j: d) k rg|!  j( 9}! n  t, j- |
   j4 d  } d }" x t. | |  D] \ } } | j# |  | j/ |  }# | rt& |#  }# n  | |#  }# | |#  }# t5 | j6 |# j6 |! | j6 |"  }$ |# |$  | |" |" |$ +~# |" |$ 7}" qW j  | _0  j7 r j oZ j" r j j; rw j rwq j7 d k rt, j8 | d  d! d"  d# | q j7 d$ k rt< |  } qn  | rD j= rD j> j0 d d'   k rM	t? | d d  d d  d d  d d  d d  d d  f  j>  } qM	n	| rM	 j@ rM	d*  j
 k rM	 jA }%  j
 d* j d k r|% f }% n  x tB |%  D]n \ }& }' |' d2 k r j' r| d( d d d' d& |& g f } n& | d d  d d d' d& |& g f } PqqW j' r.	| d( d d&  f } qM	| d d  d d&  f } n  | r	y  j0 | _0 Wq	t k
 r	t1 j2 d. t | j0  t  j0  f  q	Xn  | r*
 j jC r*
 j jD d }( |( jE d3 k r*
|( jF }) |) d |) d }) | j% d/  } |( jE d' k r
| d' C} n  | |) 9} q*
n  |	 r=
| jG   n  | S(4   s  Read image data from file and return as numpy array.

        Raise ValueError if format is unsupported.
        If any of 'squeeze', 'colormapped', or 'rgbonly' are not the default,
        the shape of the returned array might be different from the page shape.

        Parameters
        ----------
        squeeze : bool
            If True, all length-1 dimensions (except X and Y) are
            squeezed out from result.
        colormapped : bool
            If True, color mapping is applied for palette-indexed images.
        rgbonly : bool
            If True, return RGB(A) image without additional extra samples.
        memmap : bool
            If True, use numpy.memmap to read arrays from file if possible.
            For use on 64-bit systems and files with few huge contiguous data.
        reopen : bool
            If True and the parent file handle is closed, the file is
            temporarily re-opened (and closed if no exception occurs).
        scale_mdgel : bool
            If True, MD Gel data will be scaled according to the private
            metadata in the second TIFF page. The dtype will be float32.
        maxsize: int or None
            Maximum size of data before a ValueError is raised.
            Can be used to catch DOS. Default: 64 GB.

        Ns   data is too large %ss   data type not supported: %s%is   cannot decompress %sRH   i   c         3  s    |  ] } |   j  d  Vq d S(   i    N(   R   (   RS   R'   (   R  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>	  s    s   sample formats do not match %ss    chroma subsampling not supporteds   file handle is closedt   lsb2msbRL   i    iR>  t   =i   i   i    i@   i   s   data and sample size mismatchc           s    j  d k r  } n  y t j |  |  SWnQ t k
 r } t j d |  t |     d   d } t j |  |  |  SXd  S(   NR  s
   unpack: %si   (   RA   R   R  Re   Rq   Rr   R   (   R   t   typecodeR   t   xlen(   R1   R   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRI  	  s    	c           s   t  |      S(   N(   t
   unpack_rgb(   R   (   R1   RM  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRI  	  s    c           s   t  |       S(   N(   t   unpack_ints(   R   (   R1   t   runlenRM  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRI  	  s    t   jpegt   jpeg_tablesR   c           s   t  |     j  S(   N(   t   decode_jpegR3   (   R   (   R   t   table(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt
   decompress
  s    s   invalid tile datat
   horizontalR  iR   t   outR  i   i   i   .R   RG   R2  R3  R4  s   failed to reshape from %s to %st   float32(   i   i   i    i@   i   (   i    i    i    i    (   R2  R3  R4  (   i   i   (H   R}   R   Re   Rk   R   Ri   RH   R1   R2   R  R   R   Rd   R   t   is_chroma_subsampledt   NotImplementedErrorRh  RC  t   closedRj  Rm   R  R/   R0   RK   R   t
   fill_ordert   _byte_counts_offsetsRH  RC   RD   RL   t   _is_memmappableRx  RG  Rl   Ry  R=  t   reverse_bitorderR>  R8   R   R   RS  R   R   R^  RG  R   Rq   Rr   t   zerosR   R   R   RA   t   cumsumR9   R=   RP  t   decode_floatsRq  RB   Rs  R  RG   R   R  RO   t   md_file_tagt   md_scale_pixelR  (*   R   Rb  R  t   rgbonlyt   scale_mdgelRc  Rk  t   maxsizeR   R\  R   R/   R0   RK   RK  t   byte_countsRa  RC   RD   RL   t   twt   tlt   tdt
   tile_shapeR{  RI  RV  t   plR>  R`  R   R   R!   t
   strip_sizeR~  R   R   RG   R'   RF  R   t   scale(    (   R1   R   RQ  R   RU  R  RM  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   	  s8    	.											"				"@
	+"@		#&		'	c         C  s  d |  j  k r$ |  j } |  j } n |  j } |  j } d } x t t | |   D] \ } \ } } | d k r | d k r | | k r | | | <| | | <n  | d 7} qR | d k r | d k r t d   qR t j	 d  qR W| d k r d } n  | |  | |  f S(   s*   Return simplified byte_counts and offsets.RE   i    i   s   invalid offsets   empty byte count(
   R   RF   RE   R:   R6   R   R^  Re   Rq   Rr   (   R   Ri  Ra  t   jR'   R%   t   o(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR^  r
  s$    			(
	c         C  sz   |  j  j j oy |  j oy |  j d k s3 |  j  j oy |  j d k oy |  j oy |  j oy | oh d |  j	 k oy | ox |  j
 S(   s9   Return if page's image data in file can be memory-mapped.i   t   msb2lsbRG   (   Rh  RC  t   is_fileRG  R1   RH  R]  RA   RZ  R   Rq  (   R   Rf  R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR_  
  s    	

c           sD  |  j  s |  j d k r d S|  j r |  j |  j k sa |  j |  j sa |  j d sa |  j d re d Sd |  j k r d |  j k r |  j |  j k s |  j |  j	 r d S|  j
  |  j   n |  j  |  j   t   d k r  d	   d	 f S|  j s,t    f d
   t t   d  D  r@ d	 t    f Sd S(   s{   Return offset and size of contiguous data, else None.

        Excludes prediction, fill_order, and colormapping.

        i   i   i    i@   NRK   RL   i   i    c         3  sC   |  ]9 }  |   |  | d  k p:   | d  d k Vq d S(   i   i    N(    (   RS   R'   (   Ri  Ra  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>
  s   (   i   i   i    i@   (   R2   R1   RH  R/   RC   R0   RD   R   RK   RL   RE   RF   R6   R:   R   R  R  R   R  (   R   (    (   Ri  Ra  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRG  
  s(    				c         C  sC   | |  j  k r3 |  j  | j } t |  | |  | St |   d S(   s   Return tag value.N(   R   R   R8  t   AttributeError(   R   R=  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __getattr__
  s
    c           s   d j  d   d j  d     j D  t t j   j   d t   j  d   j k rb   j n d   j rw   j n d d	 j    f d
   d D  f D  } d   j	 | f S(   s0   Return string containing information about page.s   , c         s  s   |  ] } | r | Vq d  S(   N(    (   RS   R!   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>
  s    
R   c         s  s   |  ] } t  |  Vq d  S(   N(   Rk   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>
  s    s   %s bitR3   R   t   rawt   |c         3  s(   |  ] } t    |  r | d  Vq d S(   i   N(   RR   (   RS   R   (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>
  s    R  RP  Rp  R,  Rg   RM  R  R  R  R  t   is_sgiR  RH  RG  s   Page %i: %s(   R  RP  Rp  R,  Rg   RM  R  R  R  R  Ry  R  RH  RG  (
   R   R   Rk   R   R   R1   R   R3   R2   R~  (   R   R!   (    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  
  s       c         C  s   d j  t |   t |  j  f  g } |  j rV | j d |  j j |  j j f  n  xW d D]O } t |  |  r] | j d j  | j	   t t
 t |  |    f   q] q] W|  j r | j d t
 |  j   n  d j  |  S(   s3   Return string with detailed information about page.s   
s   Color Map: %s, %sR  t   cz_lsm_scan_infot   uic_tagsR  R  RO  t   nih_image_headert   tvips_metadatat   sfeg_metadatat   helios_metadatat   sem_metadatas   MICROMANAGER_FILE_METADATA
%ss   

(   R  Rz  R{  R  R  RO  R|  R}  R~  R  R  (   R   Rk   R   Rq  R   RB   R   R   R1  R  R#  RR   RM  RO  (   R   R{  R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR
  
  s    '	  
2		c         C  s  |  j  s t d   n  |  j } t   } | d j | _ d | k r^ |  j j d  | _ n  d | k r | j	 | d j
  n  d | k r | j	 | d j
  n  d | k r | j	 | d j
  n  | d j
 } | j | _ | j | _ | j | _ yf g  t | j | j  D] } t |   ^ q| _ g  t | j | j  D] } t |   ^ qB| _ Wn$ t k
 r} t j d |  n X| S(	   s   Consolidate UIC tags.R{  R  R5   s    R  t   uic3tagt   uic4tags   uic_tags: %s(   R  Ru  R   R#  R   t   number_planesR5   t   splitt   plane_descriptionst   updateR   R?  RA  t   time_modifiedR^  t   date_createdt   julian_datetimet   datetime_createdt   date_modifiedt   datetime_modifiedRe   Rq   Rr   (   R   R   R{  R  t   dtR   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR{  
  s2    			.2c         C  s   |  j  s t d   n  t |  j   } d |  j k r y7 | j t |  j d j |  j d j |  j j   Wq t	 k
 r } t
 j t |   q Xn  t |  S(   s   Consolidate ImageJ metadata.R  t   imagej_metadatat   imagej_byte_counts(   Rg   Ru  t   imagej_description_dictR   R  R  R   Rh  R   Rj   Rq   Rr   Rk   R#  (   R   R{  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  
  s    		c         C  s#   d |  j  k o" |  j  d j d k S(   s   Page contains a RGB image.R3   i   (   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s'   d |  j  k r# |  j  d j d k St S(   s   Page contains contiguous image.R=   i   (   R   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR>    s    c         C  s   |  j  s3 |  j s3 |  j j s3 |  j s3 |  j j r7 t S|  j rV d |  j k rl t Sn |  j j rl |  j j Sd |  j k o |  j d j d k S(   s   Page contains indexed, palette-colored image.

        Disable color-mapping for OME, LSM, STK, and ImageJ hyperstacks.

        RM   R3   i   (	   R  RP  Rh  R,  Ro   Rg   Rq  R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRq    s    	
c         C  s   d |  j  k S(   s   Page contains tiled image.RC   (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRH  ,  s    c         C  s!   d |  j  k o  |  j  d j d @S(   s'   Page is reduced image of another image.R-   i   (   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  1  s    c         C  s#   d |  j  k o" |  j  d j d k S(   s&   Page contains chroma subsampled image.t   ycbcr_subsamplingi   (   i   i   (   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRZ  7  s    c         C  s   d |  j  k S(   s   Page contains md_file_tag tag.Rd  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  =  s    c         C  s&   d |  j  k o% |  j  d j j d  S(   s'   Page contains Media Cybernetics Id tag.t   mc_ids   MC TIFF(   R   R   t
   startswith(   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  B  s    c         C  s   d |  j  k S(   s   Page contains UIC2Tag tag.R  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  H  s    c         C  s   d |  j  k S(   s"   Page contains LSM CZ_LSM_INFO tag.R  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRP  M  s    c         C  s   d |  j  k S(   s$   Page contains FluoView MM_STAMP tag.t   mm_stamp(   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  R  s    c         C  s   d |  j  k S(   s   Page contains NIH image header.R|  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRp  W  s    c         C  s   d |  j  k o d |  j  k S(   s,   Page contains SGI image and tile depth tags.RK   RL   (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRy  \  s    c         C  s#   d |  j  k o" |  j  d j d k S(   s   Software tag is 'ISS Vista'.R   s	   ISS Vista(   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  a  s    c         C  sE   d |  j  k r t S|  j  d j j   } | j d  oD | j d  S(   s/   Page contains OME-XML in image_description tag.R5   s   <?xml version=s   </OME>(   R   Ro   R   R   R  R   (   R   R*   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR,  g  s    c         C  sE   d |  j  k r t S|  j  d j j   } | j d  oD | j d  S(   s5   Page contains Leica SCN XML in image_description tag.R5   s   <?xml version=s   </scn>(   R   Ro   R   R   R  R   (   R   R*   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  o  s    c         C  s   d |  j  k r> |  j  d j } d | k s7 d | k r> | Sn  d |  j  k r| |  j  d j } d | k su d | k r| | Sn  d S(   s9   Return description containing shape if exists, else None.R5   s   "shape":s   shape=(t   image_description_1N(   R   R   (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  w  s    c         C  sn   d |  j  k r5 |  j  d j } | j d  r5 | Sn  d |  j  k rj |  j  d j } | j d  rj | Sn  d S(   s/   Return ImageJ description if exists, else None.R5   s   ImageJ=R  N(   R   R   R  (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRg     s    c         C  s   d |  j  k S(   s%   Page contains Micro-Manager metadata.RO  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRM    s    c         C  s   d |  j  k S(   s   Page contains TVIPS metadata.R}  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   d |  j  k p d |  j  k S(   s&   Page contains SFEG or HELIOS metadata.R~  R  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   d |  j  k S(   s!   Page contains Zeiss SEM metadata.R  (   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    i   @()   R&  R'  R(  Ro   R   RB  R  RL  R   R   R   R^  R_  RG  Rv  R  R
  R{  R  R  R>  Rq  RH  R  RZ  R  R  R  RP  R  Rp  Ry  R  R,  R  R  Rg   RM  R  R  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRJ    sL   +b		/						R  c        	   B  sc   e  Z d  Z d Z d
 e f d     YZ d   Z d d  Z d   Z	 d   Z
 d   Z d   Z RS(   s  A TIFF tag structure.

    Attributes
    ----------
    name : string
        Attribute name of tag.
    code : int
        Decimal code of tag.
    dtype : str
        Datatype of tag data. One of TIFF_DATA_TYPES.
    count : int
        Number of values.
    value : various types
        Tag data as Python object.
    value_offset : int
        Location of value in file, if any.

    All attributes are read-only.

    R   R=  R   R   R   R"  R  t   _valuet   _typeR  c           B  s   e  Z RS(    (   R&  R'  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s   c         K  s?   d |  _ t | d  r+ |  j | |  n |  j | |  d S(   s+   Initialize instance from file or arguments.R   N(   Ri   R  R1  RB  t	   _fromdata(   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    	c         C  se   t  |  |  _ | r | n	 t |  |  _ t | |  _ t  |  |  _ | |  _ | |  _ | |  _	 d S(   s#   Initialize instance from arguments.N(
   R   R   Rk   R=  t   TIFF_DATA_TYPESR   R   R   R  R  (   R   R   R   R   R   R=  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    		c         C  s  | j  } | j } | j   |  _ |  j | j d |  _ i d d 6d d 6| j \ } } | j |  } t j | | d  | d   \ } } t j | | d | d  \ }	 }
 |
 |  _	 | |  _
 | t k rt | \ } } } } } | r?| |	 k r?| }	 t j d |  q?n) | t k r3t | d	 } n t |  } y t |  j
 } Wn' t k
 ryt j d
 |  j
   n Xd | |	 t | d	  | d f } t j |  } | | j k s| t k r| j   } i d d 6d d 6| j } t j | | |
  d	 |  _ } | d	 k  s/| | j  j k rAt j d   n" | d k  rct j d |   n  | j |  | t k rt | d } | | | | |	  }
 t |
 t  rt |
  }
 qnO | t k s| d d k rt j | | j |   }
 n t | | | |	  }
 | j |  n t j | |
 |   }
 | t k ro| d k rot |
  d k ro|
 d	 }
 qon  | j d  rt |
 t  r|  j
 d k rt |
  }
 n  | |  _  | |  _! | |  _" |	 |  _# |
 |  _$ d S(   s7   Read tag structure from open file. Advance file cursor.i   t   HHI4si   t   HHQ8si   i   i   s   incorrect count for tag '%s'i    s   unknown tag data type %is   %s%i%si   R#   R+   s'   corrupt file - invalid tag value offsets   corrupt value offset for tag %iiR!   i  i  iD  iE  i  i  i   N(   R  i   (   R  i   (   i  i  iD  iE  i  i  (%   RC  R   Rc   R  R   R"  RG  R   RI  R  R  R5  Rq   Rr   t   CUSTOM_TAGSRk   R  R   R  R  R   R   R   Rl   R   t   dictR#  t
   read_numpyR   R   R   t
   stripasciiR   R=  R   R   R   (   R   Rh  R   R   R   R   R   R   R   R   R   R=  R  t   cout_R   t   tofR>  t   readfunc(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRB    sn    		!$$		%!					c         C  s   |  j  d k r |  j d k r t j d  | j } i d d 6d d 6| j } t j | |  j  d |  _	 | j
 |  j	  t j d	 | j d   |  _ n  d
 S(   s   Correct LSM bitspersample tag.

        Old LSM writers may use a separate region for two 16-bit values,
        although they fit into the tag value element of the tag.

        i  i   s    correcting LSM bitspersample tags   <Ii   s   <Qi   i    s   <HHN(   R   R   Rq   Rr   RC  R   R   RI  R  R"  Rl   RG  R   (   R   Rh  R   R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    	c         C  s0   |  j  d k r, t |  j  j d d  d Sd S(   s&   Return value as human readable string.i   s   
i   i    s   <undefined>(   R  Rk   R   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   as_str)  s    ,c           s    d j    f d     j D  S(   s/   Return string containing information about tag.t    c         3  s$   |  ] } t  t   |   Vq d  S(   N(   Rk   RR   (   RS   R!   (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>0  s    (   R   R<  (   R   (    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  .  s    (	   R   R=  R   R   R   R"  R  R  R  N(   R&  R'  R(  R<  Rj   R  R   Ri   R  RB  R   R  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    	
	G		R  c           B  sY   e  Z d  Z d d  Z e d  Z e d    Z d   Z	 d   Z
 d   Z d   Z RS(	   s  Series of TIFF pages with compatible shape and data type.

    Attributes
    ----------
    pages : list of TiffPage
        Sequence of TiffPages in series.
    dtype : numpy.dtype or str
        Data type of the image array in series.
    shape : tuple
        Dimensions of the image array in series.
    axes : str
        Labels of axes in shape. See TiffPage.axes.
    offset : int or None
        Position of image data in file if memory-mappable, else None.

    c         C  s   d |  _  | |  _ t |  |  _ d j |  |  _ t j |  |  _ | rW | |  _ n( t	 |  rv | d j |  _ n	 d  |  _ d  S(   Ni    R   (   R~  RO   R   R   R   RX  R   R   Rh  R   Ri   (   R   RO   R   R   RX  Rh  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   F  s    		c         C  s&   |  j  r" |  j  j d |  d |  Sd S(   s   Return image data from series of TIFF pages as numpy array.

        Parameters
        ----------
        memmap : bool
            If True, return an array stored in a binary file on disk
            if possible.

        RW  Rc  N(   Rh  R   (   R   Rc  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   T  s    
	c         C  s  t  |  j  d k r d St } |  j d j } d } x |  j D]x } | d k rU d S| j | |  sk d S| s | j d | j d } q? n  | | j d k r d S| | j d 7} q? W|  j d j d } | | t |  j  |  j	 j
 k r|  j d j rd S| S(   s5   Return offset to memory-mappable data in page series.i    Ni   (   R   RO   Ro   Rq  Ri   R_  RG  R   R   R   R   Rg   (   R   Rf  R  R   RU  R>  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR>  a  s*    #c         C  s   t  |  j  S(   s%   Return number of TiffPages in series.(   R   RO   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  |  s    c         C  s   |  j  | S(   s   Return specified TiffPage.(   RO   (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   t  |  j  S(   s)   Return iterator over TiffPages in series.(   R  RO   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   d j  d   d j  d   |  j D  t t j |  j   |  j d t |  j  |  j rf d |  j n d f D  } d |  j	 | f S(	   s,   Return string with information about series.s   , c         s  s   |  ] } | Vq d  S(   N(    (   RS   R!   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    R   c         s  s   |  ] } t  |  Vq d  S(   N(   Rk   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s   %i pagess   memmap-offset=%is   not mem-mappables   Series %i: %s(
   R   R   Rk   R   R   RX  R   RO   R>  R~  (   R   R!   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    N(   R&  R'  R(  Ri   R   Ro   R   R   R>  R  R  R  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  3  s   			c           B  s   e  Z d  Z i d d 6Z d e f d     YZ e d d  Z d   Z d   Z	 d   Z
 d	   Z d
   Z e d d  Z d   Z RS(   s  Sequence of image files.

    The data shape and dtype of all files must match.

    Attributes
    ----------
    files : list
        List of file names.
    shape : tuple
        Shape of image sequence.
    axes : str
        Labels of axes in shape.

    s  
            # matches Olympus OIF and Leica TIFF series
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))?
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))?
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))?
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))?
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))?
            _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))?
            RX  R  c           B  s   e  Z RS(    (   R&  R'  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s   c           sB  t  | t  r' t t j |   } n  t |  } | sH t d   n  t  | d t  sj t d   n  | |  _ t | d  r |     f d   } n  | |  _ |  j	 j
 | |  |  _ y# |  j   |  j s d |  _ n  Wn] |  j k
 r=d |  _ t |  f |  _ d	 |  _ t d   t t |   D  |  _ n Xd S(
   sE  Initialize instance from multiple files.

        Parameters
        ----------
        files : str, or sequence of str
            Glob pattern or sequence of file names.
            Binary streams are not supported.
        imread : function or class
            Image read function or class with asarray function returning numpy
            array from single file.
        pattern : str
            Regular expression pattern that matches axes names and sequence
            indices in file names.
            By default this matches Olympus OIF and Leica TIFF series.

        s   no files foundi    s   not a file nameR   c           s)     |    } | j  | |   SWd  QXd  S(   N(   R   (   R  t   argsR   t   im(   t   _imread(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    R#   c         s  s   |  ] } | f Vq d  S(   N(    (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    N(   i    (   R   R/  R   R0  R   Re   R.  R1  R   t	   _patternsR   R-  t   _parseRX  R  R   R   t   _start_indexR   R   t   _indices(   R   R.  R   R-  R  R   (    (   R  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s,    		
			c         C  sA   d j  |  j d d t |  j  d |  j d t |  j  g  S(   s4   Return string with information about image sequence.s   
i    s   * files: %is
   * axes: %ss   * shape: %s(   R   R.  R   RX  Rk   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s
    

c         C  s   t  |  j  S(   N(   R   R.  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c         C  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR!    s    c         C  s   |  j    d  S(   N(   R  (   R   R"  R#  R$  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR%    s    c         C  s   d  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    c      
   O  s1  |  j  |  j d | |  } |  j | j } | rn t j d |  % } t j | d | j d | } Wd QXn t j | d | j } | j	 d | j  } x t
 |  j |  j  D]o \ }	 }
 g  t
 |	 |  j  D] \ } } | | ^ q }	 t j |	 |  j  }	 |  j  |
 | |  } | | |	 <q W| | _ | S(   s'  Read image data from all files and return as single numpy array.

        If memmap is True, return an array stored in a binary file on disk.
        The args and kwargs parameters are passed to the imread function.

        Raise IndexError or ValueError if image shapes do not match.

        i    t   dirR   R   Ni(   R   R.  R   Rv  Rw  R   Rc  R   Ra  R   R^  R  R  R  (   R   Rc  Rd  R  R   R  R   R   R{  R~  R  R'   Rq  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    	'"/	c   	      C  s!  |  j  s |  j d   n  t j |  j  t j t j B } | j |  j d  } | sh |  j d   n  | d } t |  d r |  j d   n  d j	 d   | d	 d	 d  D  } | s |  j d   n  g  } x |  j D] } | j |  d } | d j	 d
   | d	 d	 d  D  k r6t
 d   n  | j g  | d d	 d  D] } | rPt |  ^ qP q Wt t j | d d  } t t j | d d  } t d   t | |  D  } t |  t |  j  k rt j d  n  | j   |  _ | |  _ | |  _ | |  _ d	 S(   s#   Get axes and shape from file names.s   invalid patterni    s!   pattern does not match file namesii   s*   pattern does not match axis name and indexR   c         s  s   |  ] } | r | Vq d  S(   N(    (   RS   t   m(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    Nc         s  s   |  ] } | r | Vq d  S(   N(    (   RS   R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>#  s    s+   axes do not match within the image sequencei   R  c         s  s#   |  ] \ } } | | d  Vq d S(   i   N(    (   RS   R'   Rq  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>(  s    s*   files are missing. Missing data are zeroed(   R-  R  t   ret   compilet
   IGNORECASEt   VERBOSEt   findallR.  R   R   Re   R   R   R   R   R;  R   R^  R   Rq   Rr   R  RX  R   R  R  (	   R   R-  t   matchesRX  t   indicesR  R  R   t   start_index(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s6    	
&,=		N(   R&  R'  R(  R  Rj   R  R   R   R  R  R!  R%  R  Ro   Ri   R   R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR
     s   

2					R#  c           B  s;   e  Z d  Z d Z d d  Z d   Z d   Z d   Z RS(   sd   Dictionary with attribute access.

    Can also be initialized with numpy.core.records.record.

    c         K  s   | r | } n | d  k r$ i  } n  y t j |  |  Wnl t t f k
 r xV t | j j  D]> \ } } | | } | j j d k r | n	 t	 |  |  | <qa Wn Xd  S(   NR.  (
   Ri   R  R   R   Re   R   R   t   namesR   R   (   R   R   R   R'   R=  R*  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   :  s    		
c         C  s   |  | S(   N(    (   R   R=  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRv  G  s    c         C  s   |  j  | |  d  S(   N(   t   __setitem__(   R   R=  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   __setattr__J  s    c      	   C  s  g  } g  } xHt  |   D]:} y | j d  r7 w n  Wn t k
 rK n X|  | } t | t t f  r t |  r t | d t  r | j | | f  q qt | d t	  rg  | D] } | r | j
 ^ q } qn> t | t  r| j d | t |  j d d  f  q n  | j d | t |  f j d d  d t  j    q Wxy | D]q \ } } g  } xF t |  D]8 \ } } | j d	 | | t |  j d d
  f  q}W| j d j |   q^Wd j |  S(   s   Pretty print Record.R  i    s   * %s:
%st   *s    *s   * %s: %ss   
i   s   * %s[%i]
  %ss   
  (   R   R  Ru  R   R   R   R   R#  R   RJ  R~  Rk   R  R  t   PRINT_LINE_LENt   rstripR   R   (   R   R!   t   listsRz  R*  R'   t   lt   w(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  M  s8    

!()#!(    N(	   R&  R'  R(  R<  Ri   R   Rv  R  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR#  2  s   		R  c           B  s   e  Z d  Z d   Z RS(   s,   Dictionary of TiffTag with attribute access.c         C  s   g  } x t  |  j   d d   D]j } d | j t | j d  | j d f } d | j | j | | j   f } | j | t	  j
    q" Wd j |  S(   s.   Return string with information about all tags.R   c         S  s   |  j  S(   N(   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   s  s    s   %i%si    i   s   * %i %s (%s) %ss   
(   R   RE  R   R   R   R   R=  R  R   R  t   lstripR   (   R   R!   R  RM  t   line(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  p  s    "+(   R&  R'  R(  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  m  s   c        	   B  s  e  Z d  Z d% Z d
 d& d& d& d  Z d   Z d d  Z d   Z d   Z	 d d d d  Z
 d d d  Z d d& d  Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z e d     Z e d!    Z e d"    Z e d#    Z e d$    Z RS('   s  Binary file handle.

    A limited, special purpose file handler that can:

    * handle embedded files (for CZI within CZI files)
    * re-open closed files (for multi file formats, such as OME-TIFF)
    * read and write numpy arrays and records from file like objects

    Only 'rb' and 'wb' modes are supported. Concurrently reading and writing
    of the same stream is untested.

    When initialized from another file handle, do not use it unless this
    FileHandle is closed.

    Attributes
    ----------
    name : str
        Name of the file.
    path : str
        Absolute path to file.
    size : int
        Size of file in bytes.
    is_file : bool
        If True, file has a filno and can be memory-mapped.

    All attributes are read-only.

    R   t   _filet   _modet   _namet   _dirR  t   _sizeRi  Rt  RN   c         C  s_   d |  _ | |  _ | |  _ | |  _ d |  _ | |  _ | |  _ t |  _	 t
 |  _ |  j   d S(   s  Initialize file handle from file name or another file handle.

        Parameters
        ----------
        file : str, binary stream, or FileHandle
            File name or seekable binary stream, such as a open file
            or BytesIO.
        mode : str
            File open mode in case 'file' is a file name. Must be 'rb' or 'wb'.
        name : str
            Optional name of file in case 'file' is a binary stream.
        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.

        R   N(   Ri   R   R  R  R  R  R  R  R   Ri  Ro   Rt  Rj  (   R   R   RM   R=  R>  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    									c         C  sS  |  j  r d St |  j t  r t j j |  j  |  _ t j j |  j  \ |  _ |  _	 t
 |  j |  j  |  _  t |  _ |  j d k rd |  _ qn	t |  j t  r|  j j  |  _  |  j d k r d |  _ n  |  j |  j j 7_ t |  _ |  j	 sO|  j r=t j j |  j j	  \ } } d | |  j | f |  _	 qO|  j j	 |  _	 n  |  j r||  j |  j j k r|t d   n  |  j j |  _ |  j j |  _ nt |  j d  ry |  j j   Wn t k
 rt d   n X|  j |  _  |  j d k r|  j j   |  _ n  t |  _ |  j	 sjy( t j j |  j  j  \ |  _ |  _	 Wqjt k
 rfd |  _	 qjXn  y |  j  j |  _ Wqt k
 rqXn t d   |  j r|  j  j |  j  n  |  j d k r|  j  j   } |  j  j |  j d	  |  j  j   |  _ |  j  j |  n  y |  j  j   t |  _ Wn t k
 rNt |  _ n Xd S(
   s   Open or re-open file.Ni    s   %s@%i%ss   FileHandle has wrong modeRl   s   binary stream is not seekables   Unnamed binary streamsN   The first parameter must be a file name, seekable binary stream, or FileHandlei   (   R   R   R  R/  R  R  t   realpathR  R  R  Rj  R  R   Ri  R  Ri   R   Ro   t   splitextRe   R1  Rc   Rj   R=  Ru  RM   Rl   R  R  Rt  (   R   R=  t   extR   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRj    sn    	!						(	ic         C  s1   | d k  r! |  j  r! |  j } n  |  j j |  S(   s5   Read 'size' bytes from file, or until EOF is reached.i    (   R  R  R   RG  (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRG    s    c         C  s   |  j  j |  S(   s   Write bytestring to file.(   R   R   (   R   t
   bytestring(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    c         C  s   |  j  j   S(   s"   Flush write buffers if applicable.(   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    i    t   rR   c         C  sM   |  j  s t d   n  t j |  j d | d | d |  j | d | d | S(   s+   Return numpy.memmap of data stored in file.s&   Can not memory-map file without filenoR   RM   R>  R   R   (   Rt  Re   R   Rc  R   R  (   R   R   R   R>  RM   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRx    s
    	R   c         C  s   y t  j |  j | | |  SWnd t k
 r | d k  rE |  j } n | t  j |  j } |  j j |  } t  j | | | |  SXd S(   s   Return numpy array from file.

        Work around numpy issue #2230, "numpy.fromfile does not accept
        StringIO object" https://github.com/numpy/numpy/issues/2230.

        i    N(	   R   t   fromfileR   Rm   R  R   R   RG  R  (   R   R   R   t   sepR   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRy    s    i   c         C  s   y% t  j j |  j | | d | } Wn t k
 r t  j |  } | d k rc |  j | j } n  t	 t
 |   | j } |  j j |  } t  j j | | | d | SX| d k r | d S| S(   s   Return numpy record from file.R   i   i    N(   R   t   recR  R   Rj   R   Ri   R  R   R   R	  RG  R  (   R   R   R   R   R  R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_record%  s    c         C  sB   y | j  |  j  Wn' t k
 r= |  j j | j    n Xd S(   s!   Write numpy array to binary file.N(   t   tofileR   Rj   R   R   (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   4  s    c         C  s   |  j  j   |  j S(   s   Return file's current position.(   R   Rc   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRc   <  s    c         C  s   |  j  rv | d k r3 |  j j |  j  | |  d S| d k rv |  j d k rv |  j j |  j  |  j | d  d Sn  |  j j | |  d S(   s   Set file's current position.i    Ni   (   R  R   Rl   R  (   R   R>  t   whence(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRl   @  s    	!c         C  s/   |  j  r+ |  j r+ |  j j   d |  _ n  d S(   s   Close file.N(   Ri  R   R  Ri   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  K  s    c         C  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR!  Q  s    c         C  s   |  j    d  S(   N(   R  (   R   R"  R#  R$  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR%  T  s    c         C  s-   |  j  r t j d |  n  t |  j |  S(   s-   Return attribute from underlying file object.s3   FileHandle: '%s' not implemented for embedded files(   R  Rq   Rr   RR   R   (   R   R=  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRv  W  s    	c         C  s   |  j  S(   N(   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR=  ^  s    c         C  s   |  j  S(   N(   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  b  s    c         C  s   t  j j |  j |  j  S(   N(   R  R  R   R  R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  f  s    c         C  s   |  j  S(   N(   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   j  s    c         C  s   |  j  d  k S(   N(   R   Ri   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR\  n  s    (	   R   R  R  R  R  R  R  Ri  Rt  N(   R&  R'  R(  R<  Ri   R   Rj  RG  R   R   Rx  Ry  R  R   Rc   Rl   R  R!  R%  Rv  R  R=  R  R  R   R\  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   {  s.    	D								c         C  s:   | d d k r d n | | d } |  j  | |  j   S(   s2   Read tag data from file and return as byte string.iR!   R%   (   Ry  R   (   R   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt
   read_bytess  s    $c         C  s4   | d d k r d n | | d } |  j  | |  S(   s2   Read tag data from file and return as numpy array.iR!   R%   (   Ry  (   R   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  y  s    $c         C  sX   |  j  |  } y  t j t t |  d   SWn" t k
 rS t j d |  n Xd S(   s2   Read JSON tag data from file and return as object.s   utf-8s   invalid JSON '%s'N(   RG  t   jsont   loadst   unicodeR   Re   Rq   Rr   (   R   R   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt	   read_json  s
     c         C  s   |  j  t d | S(   s;   Read MM_HEADER tag from file and return as numpy.rec.array.R   (   R  t	   MM_HEADER(   R   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_mm_header  s    c         C  s   |  j  | d d  S(   s8   Read MM_STAMP tag from file and return as numpy.ndarray.t   f8i   (   Ry  (   R   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_mm_stamp  s    c         C  s  | d k r | d k s t   i  } | d k r |  j d d |  j | d  } i | d d  d f | d d  d f d	 6} n | rx} t |  D]l } t j d
 |  j d   d } | d k r |  j d  q n  t |  | | d t \ }	 }
 |
 | |	 <q Wn  | S(   s|   Read MetaMorph STK UIC1Tag from file and return as dictionary.

    Return empty dictionary if plane_count is unknown.

    R$   t   1IRZ   s   <u4i   Ni    i   R?  s   <Ii   i   i   i%   i(   i)   R>  (   R$   R  (   i   i   i%   i(   i)   (	   R   Ry  R   R   R   RI  RG  t   read_uic_tagR   (   R   R   R   R   t   plane_countR{  RE  R  t   tagidR=  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR$    s    "4c         C  s   | d k r | d k s t   |  j d d |  j | d  } i | d d  d f | d d  d f d 6| d d  d	 f d
 6| d d  d f d 6| d d  d f d 6| d d  d f d 6S(   s>   Read MetaMorph STK UIC2Tag from file and return as dictionary.R$   RZ   s   <u4i   Ni    i   R?  i   R  i   RA  i   R  i   R  (   R   Ry  R   (   R   R   R   R  RE  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_uic2tag  s    "+c         C  so   | d k r | d k s t   |  j d d |  j | d  } i | d d  d f | d d  d f d 6S(	   s>   Read MetaMorph STK UIC3Tag from file and return as dictionary.R$   RZ   s   <u4i   Ni    i   t   wavelengths(   R   Ry  R   (   R   R   R   R  RE  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_uic3tag  s    "c         C  s   | d k r | d k s t   i  } xa t r t j d |  j d   d } | d k r\ Pn  t |  | | d t \ } } | | | <q' W| S(   s>   Read MetaMorph STK UIC4Tag from file and return as dictionary.R  RZ   s   <Hi   i    R>  (   R   R   R   RI  RG  R  Ro   (   R   R   R   R  R{  R  R=  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_uic4tag  s    	c           s  d   f d  } y t  | \ } } Wn t k
 rG d | |   f SX| r   j   } | t d f k r |   } | d k  r t j d | | f  | | f S  j |  q n  | d k r d | } |   }	 n| t k r |   }	 nt| t k r| d  }	 |	 d |	 d }	 nG| t	 k r=t	 | d    }	 n&| t
 k rXt
    }	 n| t k r|   }
 d |
 k od k  n rt j d
 |
   j |
   d d  }	 t |	  }	 qc| rd }	 t j d |  qct d |
   nq| d k rg  }	 x\t |  D] } |   }
 d |
 k o7d k  n rt j d
 |
   j |
   d d  } t |  } |	 j |  q| rt j d |  qt d |
   qWn d | } d | k r| | } n  d | k r   j | d  d }	 |	 j d d k rc|	 d |	 d }	 qcnC t j |   j t j |    }	 t |	  d k rc|	 d }	 n  | r}  j | d  n  | |	 f S(   sg   Read a single UIC tag value from file and return tag name and value.

    UIC1Tags use an offset.

    i   c           s;   t  j d |    j d |    } |  d k r7 | d S| S(   Ns   <%iIi   i   i    (   R   RI  RG  (   R   R   (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_int  s    #s	   _tagid_%ii   s#   invalid offset for uic tag '%s': %iR  i   i    i
   s   %isiR   s   corrupt string in uic tag '%s's   invalid string size %is   %ipRZ   s   %it   (.i   Ni   i   (   .i    (   .i   (   t   UIC_TAGSR   Rc   R   Ri   Rq   Rr   Rl   R   R  t   read_uic_image_propertyRk   R   RI  RG  R   Re   R   R   Ry  R   R   R   (   R   R  R  R>  R  R=  R   R   t   offR   R   R  t   string(    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    sv    		

	'	'
$c         C  s   t  j d |  j d   d } t  j d | |  j |   d d  } t  j d |  j d   \ } } | d k r t  j d |  j d	   } | d | d } nB t  j d |  j d   d } t  j d | |  j |   d } t d
 | d | d |  S(   s:   Read UIC ImagePropertyEx tag from file and return as dict.R    i   i    s   %isis   <IBi   R`   i   R=  t   flagsR   (   R   RI  RG  R  (   R   R   R=  R  t   propR   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  %  s    '!#c   	      C  s   | d k s t   t j d |  j d   \ } } | d k rN t d   n  |  j d d  | t j t  j	 k  r g  } d	 } xV t D]E \ } } | t j |  j	 7} | | k r Pn  | j
 | | f  q Wn t } |  j | d
 | S(   s=   Read CS_LSM_INFO tag from file and return as numpy.rec.array.RZ   s   <IIi   iLI iLI s   invalid CS_LSM_INFO structureii   i    R   (   iLI iLI (   R   R   RI  RG  Re   Rl   R   R   t   CZ_LSM_INFOR   R   R  (	   R   R   R   R   t   magic_numbert   structure_sizeR  R   R=  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_cz_lsm_info4  s    !c         C  s2   t  j d |  j d   d } |  j d d | S(   s>   Read LSM sequence of float pairs from file and return as list.s   <ii   i    s   <2f8R   (   R   RI  RG  Ry  (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_cz_lsm_floatpairsK  s    c         C  s2   t  j d |  j d   d } |  j d d | S(   s0   Read LSM positions from file and return as list.s   <Ii   i    s   <2f8R   (   R   RI  RG  Ry  (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_cz_lsm_positionsQ  s    c         C  sW   t  j d |  j d   \ } } | d d | k rD t d   n  |  j d d | S(   s2   Read LSM time stamps from file and return as list.s   <iii   s"   lsm_time_stamps block is too shorts   <f8R   (   R   RI  RG  Re   Ry  (   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_cz_lsm_time_stampsW  s    !c         C  s   t  j d |  j d   d } g  } xm | d k r t  j d |  j d   \ } } } t |  j | d   } | j | | | f  | d 8} q( W| S(   sC   Read LSM events from file and return as list of (time, type, text).s   <IIi   i   i    s   <IdIi   (   R   RI  RG  R   R   (   R   R   t   eventst   esizet   etimet   etypet   etext(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_cz_lsm_event_list`  s    $c   
      C  s  t    } | g } t j } d t j d |  j d   d k rO t d   n  |  j d  xt r| d |  j d   \ } } } | d	 k r t |  j |   } n\ | d k r | d
 |  j d   d } n1 | d k r | d |  j d   d } n d } | t k rH| j |  t | } g  }	 t	 | | |	  |	 } n | t
 k r| j |  t    }	 | j |	  |	 } nX | t k rt | } t	 | | |  n/ | d k r| j   } n t	 | d | |  | s_ Pq_ q_ W| S(   s9   Read LSM scan information from file and return as Record.i   s   <Ii   i    s   not a lsm_scan_info structurei   s   <IIIi   i   s   <ii   s   <dI    s
   entry_0x%x(   R#  R   RI  RG  Re   R   R   t   CZ_LSM_SCAN_INFO_ARRAYSR   R8  t   CZ_LSM_SCAN_INFO_STRUCTSt   CZ_LSM_SCAN_INFO_ATTRIBUTESt   pop(
   R   t   blockt   blocksRI  t   entryR   R   R   R=  t   newobj(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_cz_lsm_scan_infol  sF    			%	!
			
c   	      C  s%  t  |  j t d |  } | j d k rt  |  j t d |  } | j t d  k ri t d   n  x[ t D]S \ } } | j d  rp | | j	   j
 d d d } t | d	 d
 | | <qp qp WxW d D]. } | d | c d <| d | c d <q Wn | j d k r!t d   n  | S(   s0   Read TVIPS EM-MENU headers and return as Record.R   i   I    s   invalid TVIPS v2 magic numberR  t   utf16t   errorsR  t   nulls    t   xyt   physical_pixel_size_g    eAt   pixel_size_i   s   unknown TVIPS header version(   R#  R  t   TVIPS_HEADER_V1R   t   TVIPS_HEADER_V2t   magicR   Re   R  R   R  R   (	   R   R   R   R   t   headerR=  t   typestrR!   R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_tvips_header  s    c   	      C  s   t    } t    } x |  j |  j   D] } | j   } | j d  ro t    } | | t | d d ! <q( n  y | j d  \ } } Wn t k
 r q( n Xt |  | t |  <q( W| S(   s9   Read FEI SFEG/HELIOS headers and return as nested Record.t   [i   iRL  (	   R#  RG  t
   splitlinesR   R  t	   bytes2strR  Re   R=  (	   R   R   R   R   R{  t   sectionR  R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_fei_metadata  s    			c         C  s  t  i d d 6 } d	 } x|  j |  j   D]y} | j d  } | j   r_ | j   } q/ | ry | j d  \ } } Wn t k
 r q/ n X| j	   } d }	 yF | j   \ }
 } t
 |
 t t f  } | |
 k r | } | }	 n  Wn[ t
 | t t f  } | | k r| } n  | d
 k r2t } qK| d k rKt } qKn X| j	   | f | | <|	 r}| | c |	 f 7<n  d	 } q/ | d c t
 | t t f  f 7<q/ W| S(   s(   Read Zeiss SEM tag and return as Record.R   t   cp1252RL  t   Not   Offt   Yest   On(    N(   R  R  (   R  R  (   R#  Ri   RG  R  R  t   isuppert   lowerR  Re   R   R=  R   R  Ro   R   (   R   R   R   R   R{  R   R  R=  R   t   unitR*  R   t   number(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_sem_metadata  sB    			&c         C  sN   |  j  t d | } | j |  } | j | j  | _ | j | j  | _ | S(   sB   Read NIH_IMAGE_HEADER tag from file and return as numpy.rec.array.R   (   R  t   NIH_IMAGE_HEADERt   newbyteordert   xunitt
   _xunit_lent   umt   _um_len(   R   R   R   R   RT   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_nih_image_header  s
    c         C  s  |  j  d  y% i d d 6d d 6|  j d  } Wn t k
 rQ t d   n Xi  } |  j  d  t j | d	 |  j d
   \ } } } } } } }	 }
 |	 d k r t d   n  t |  | d |
  | d <| d k r t d   n  |  j  |  t j | d |  j d   \ } } | d k r8t d   n  t j | d | |  j d |   } i | d d d  d 6| d d d  d 6| d d d  d 6| d d d  d 6| d d d  d 6| d <| d k rt d   n  |  j  |  t j | d |  j d   \ } } | d  k r5t d   n  t |  | d |  | d! <| d" k rit d#   n  |  j  |  t j | d |  j d   \ } } | d$ k rt d#   n  t |  | d |  | d% <| S(&   s   Read MicroManager non-TIFF settings from open file and return as dict.

    The settings can be used to read image data without parsing the TIFF file.

    Raise ValueError if file does not contain valid MicroManager metadata.

    i    RZ   R`   R[   Ra   i   s   not a MicroManager TIFF filei   t   IIIIIIIIi    i$# s#   invalid MicroManager summary_headert   summaryiCs!   invalid MicroManager index_headeri4 t   IIIIIi   Ni   t   channeli   Rm  t   framei   t   positioni   R>  t	   index_mapis#   invalid MicroManager display_headeridt   display_settingsi}s$   invalid MicroManager comments_headeriet   comments(   Rl   RG  R  Re   R   RI  R  Ri   (   R   R   R{  t   index_headert   index_offsett   display_headert   display_offsett   comments_headert   comments_offsett   summary_headert   summary_lengthR	  R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRN    sH    %7%'</%%c           sP  t  j d d k  r t n d       f d   } d   } d   } i d | f d 6d | f d	 6d
 | f d 6d | f d 6d | f d 6d | f d 6} | j t d   | j   D   | s t d   n  |  d  d k r t d   n  | d } | d k  s| d k rt d   n  | d d } t j | d | |  d d | d ! }	 d | d }
 d } i  } x t	 |	 d d d  |	 d d d   D] \ } } g  } | j
 |   |  | f  \ } } xO t |  D]A } | d 7} |
 | | } | j | |  |
 | !|   | }
 qW| d k r8| d n | | | j   <qW| S(    s1   Return dictionary from ImageJ metadata tag value.i    i   c         S  s   t  |  d  S(   NR  (   Rk   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   )  s    c           s/     t  |  | d k r d n d d  d    S(   NRZ   i    i   i   (   R   (   R   R   (   t   _str(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_string+  s    c         S  s"   t  j | d t |   d |   S(   NR*   i   (   R   RI  R   (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   read_double.  s    c         S  s   t  j |  d  S(   NR<  (   R   R  (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  1  s    R
  R  t   lablt   rangest   rangt   lutst   rois   roi t   overlayst   overc         s  s.   |  ]$ \ } } | d  d  d  | f Vq d  S(   Ni(    (   RS   Rz  R*  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>=  s    s   no ImageJ metadatai   t   IJIJt   JIJIs   invalid ImageJ metadatai   i$  s#   invalid ImageJ metadata header sizei   t   4sINi   i   (   R=  R>  (   Rp   t   version_infoRk   R  R  R  Re   R   RI  R^  R   R   R   R   (   R   t
   bytecountsR   R4  R5  R  t   metadata_typest   header_sizet   ntypesR	  R   t   counterR{  t   mtypeR   RE  R=  R5  R  t   pos1(    (   R3  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  '  sF    "		
)6$

*c         C  s  d   } t  j d d k  r" t n d   } i  } x |  j   D] } y | j d  \ } } Wn t k
 rs q> n X| j   } | j   } x? t t | | f D]+ } y | |  } PWq t k
 r q Xq W| | | |  <q> Wd | k r t	 d   n  | S(   s;  Return dictionary from ImageJ image description byte string.

    Raise ValueError if not a valid ImageJ description.

    >>> description = b'ImageJ=1.11a\nimages=510\nhyperstack=true\n'
    >>> imagej_description_dict(description)  # doctest: +SKIP
    {'ImageJ': '1.11a', 'images': 510, 'hyperstack': True}

    c         S  s   i t  d 6t d 6|  j   S(   Nt   truet   false(   R   Ro   R  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   _boold  s    i    i   c         S  s   t  |  d  S(   NR  (   Rk   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   g  s    RL  t   ImageJs   not a ImageJ image description(
   Rp   R@  Rk   R  R  Rj   R   R   R  Re   (   R   RJ  R3  R{  R  R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  Z  s(    
	"s   1.11ac         K  s  | r t  d   n  t |  d | }  |  d d k } d | g } g  }	 | j d t |  d    | d k r t } |	 j d	  n |	 j d
 t |   |  d d k r | j d |  d  n  | d k r | r d } n  | r| r|	 j d |  n  |  d d k r*| j d |  d  n  |  d d k rn| j d |  d  | d k rn|	 j d  qnn  | d k	 r|	 j d t |   n  x7 | j   D]) \ }
 } |	 j d |
 j   | f  qWt	 d j
 | |	 d g   S(   sC  Return ImageJ image decription from data shape as byte string.

    ImageJ can handle up to 6 dimensions in order TZCYXS.

    >>> imagej_description((51, 5, 2, 196, 171))  # doctest: +SKIP
    ImageJ=1.11a
    images=510
    channels=2
    slices=5
    frames=51
    hyperstack=true
    mode=grayscale
    loop=false

    s!   ImageJ colormapping not supportedR   ii   i   s	   ImageJ=%ss	   images=%iis   hyperstack=trues   hyperstack=%si   i   s   channels=%it	   grayscales   mode=%ss	   slices=%ii    s	   frames=%is
   loop=falses   loop=%ss   %s=%ss   
R   (   i   i   N(   R[  R   R   R   Ri   R   Ru   R  R  t	   str2bytesR   (   R   R   t
   colormapedR   R  RM   t   loopR   R{  R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   |  s8    	!c         C  s  t  d   |  D  }  t |   } d | k o9 d k n rM t d   n  | d k rx |  d d k or | d k } n  | r |  d d k r t d	   n  | r | d k r |  d d k r t d
   n  | s |  d d k r d d | |  Sd d | |  d Sd S(   s   Return shape normalized to 6D ImageJ hyperstack TZCYXS.

    Raise ValueError if not a valid ImageJ hyperstack shape.

    >>> imagej_shape((2, 3, 4, 5, 3), False)
    (2, 3, 4, 5, 3, 1)

    c         s  s   |  ] } t  |  Vq d  S(   N(   R   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i   i   s1   invalid ImageJ hyperstack: not 2 to 6 dimensionalii   i   i   s*   invalid ImageJ hyperstack: not a RGB images.   invalid ImageJ hyperstack: not a non-RGB imagei   N(   i   i   (   i   i   (   i   (   i   (   i   (   R   R   Re   Ri   (   R   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    	#c         C  s   |  j  d  rB t d   |  d d !j d  D  } t d |  S|  j  d  rv |  j d  rv t j |  j d	   St d
   d S(   su  Return dictionary from image description byte string.

    Raise ValuError if description is of unknown format.

    >>> image_description_dict(b'shape=(256, 256, 3)')
    {'shape': (256, 256, 3)}
    >>> description = b'{"shape": [256, 256, 3], "axes": "YXS"}'
    >>> image_description_dict(description)  # doctest: +SKIP
    {'shape': [256, 256, 3], 'axes': 'YXS'}

    s   shape=c         s  s   |  ] } t  |  Vq d  S(   N(   R   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i   it   ,R   t   {t   }s   utf-8s   unknown image descriptionN(	   R  R   R  R  R   R  R  R  Re   (   R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    &c         K  s=   | r |  d }  n  | j  i |  d 6 t j |  j d  S(   s   Return image description from data shape and meta data.

    Return UTF-8 encoded JSON.

    >>> image_description((256, 256, 3), axes='YXS')  # doctest: +SKIP
    b'{"shape": [256, 256, 3], "axes": "YXS"}'

    i   R   s   utf-8(   i   (   R  R  t   dumpsR  (   R   RN  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR5     s    	c           sU   y d d l  m   Wn" t k
 r8 t j d  d   SX|  |    f d  } | S(   s2   Try replace decorated function by module.function.i(   t   import_modules!   could not import module importlibc         S  s   |  S(   N(    (   R5  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    c           s   yn | j  d  \ } }  r7   d | d  } n   |  } t | |  |  }  } | t   d |  j <Wn+ t k
 r | r t j d |  q n X|  S(   Nt   .t   packaget   __old_s   failed to import %s(   R  RR   t   globalsR&  Rj   Rq   Rr   (   R5  t   module_functionRr   t   modulet   functiont   oldfunc(   RT  RV  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   decorate  s    (   t	   importlibRT  t   ImportErrorRq   Rr   (   RY  RV  Rr   R]  (    (   RT  RV  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   _replace_by  s    c         C  s[  |  j  } |  j } t |  d k  r3 t d   n  | j d k rQ t d   n  |  j j d k p t j d k o |  j j d k } |  j d  }  | d	  d | d
 |  _  t j	 |  d d	 d d d |  | r | d	  d | d	 |  _  n  t j
 |  d d	  }  t j
 |  d	 d
  }  |  d d d d
  f }  t j |   }  |  j |  }  | |  _  |  S(   s  Decode floating point horizontal differencing.

    The TIFF predictor type 3 reorders the bytes of the image values and
    applies horizontal byte differencing to improve compression of floating
    point images. The ordering of interleaved color channels is preserved.

    Parameters
    ----------
    data : numpy.ndarray
        The image to be decoded. The dtype must be a floating point.
        The shape must include the number of contiguous samples per pixel
        even if 1.

    i   s   invalid data shapet   dfes   not a floating point imageRZ   R\   RL  R<  iiR  R   RX  i.N(   i(   i(   R   R   R   Re   R   R   Rp   t   viewR   Rb  t   swapaxest   ascontiguousarray(   R   R   R   t   littleendian(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRc    s(    		!	R   c         C  sG   d d l  m } | j |  |  } | d k r= | r= | r= n  | j   S(   sB   Decode JPEG encoded byte string (using _czifile extension module).i(   t   _czifileR   (   t   czifileRf  RT  R   (   t   encodedt   tablesR3   R  t   ycbcr_positioningRf  t   image(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRT  .  s
    s   _tifffile.decode_packbitsc         C  s  t  j d d k r t n d   } g  } | j } d } y x t r | |  |  d } | d 7} | d k  r | |  | | | ! | | 7} q= | d k r= | |  | | d !d |  | d 7} q= q= WWn t k
 r n Xt  j d d k r d j |  St |  S(   su   Decompress PackBits encoded byte string.

    PackBits is a simple byte-oriented run-length compression scheme.

    i    R   c         S  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   @  s    i   i   i  R   (   Rp   R   t   ordR  R   R  R   R   (   Rh  R5  R{  t   result_extendR'   t   n(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   decode_packbits9  s"    "		
s   _tifffile.decode_lzwc           s  t    } | d } t j  t j d d k rZ g  t d  D] } t |  ^ q? } n( g  t d  D] } t | g  ^ qg } | j d        f d   } i d d t	 d d	 d d
  f d 6d d t	 d d	 d d
  f d 6d d t	 d  d	 d d
  f d 6d d t	 d! d" d
  f d 6} | d \ }   d   | d k  rdt
 d   n  |   d k rt
 d   n  d } d }	 g  }
 |
 j } x1t r|   }   | 7  | d k s  | k rPn  | d k r>| } | j } d } | d \ }   |   }   | 7  | d k r-Pn  | | |  ng | | k  ri| | } | |	 | d  } n | |	 } | | d  7} | } | |  | |  | d 7} | }	 | | k r| | \ }   qqW| d k rt j d |  n  d j |
  S(#   s.  Decompress LZW (Lempel-Ziv-Welch) encoded TIFF strip (byte string).

    The strip must begin with a CLEAR code and end with an EOI code.

    This is an implementation of the LZW decoding algorithm described in (1).
    It is not compatible with old style LZW compressed files like quad-lzw.tif.

    i   i    R   i   c            s     d }   |  |  d !} y  d |  d } Wn6 t  k
 rj  d | d d t |   d } n X|   d K} |  M} |  ?S(   s@   Return integer of 'bitw' bits at 'bitcount' position in encoded.i   i   s   >Ii    s    (   Rj   R   (   R  R!   R   (   t   bitcountRh  t   maskt   shrRI  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt	   next_codeg  s    
)
i	   i   t   1t   0i   i   i
   i   i  i   i   i  i   i   i  i   s(   strip must be at least 4 characters longs    strip must begin with CLEAR codei  i  i   s&   unexpected end of lzw stream (code %i)R   (   i    i    t	   111111111t
   1111111111t   11111111111t   111111111111t   00000000000000000000(   R   R   RI  Rp   R   R   t   chrR   R  R   Re   R   R   Rq   Rr   R   (   Rh  t   len_encodedt   bitcount_maxR'   t   newtableRs  t   switchbitcht   bitwR   t   oldcodeR{  t   result_appendRU  t   table_appendt   lentablet   decodedt   newcode(    (   Rp  Rh  Rq  Rr  RI  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   S  sj    

	((!!! 			
		





s   _tifffile.unpack_intsi    c           s    d k r t  j |  d  }  t  j |   }  | d r} |  j d | d | d  }  |  d d  d |  f j d  }  n  |  j |  St  j |  }   d k r t  j |  |  S  d k  s   d k r t d	     n  | j d
 k r t d   n  t   f d   d D  } | | j	 k r8t d   n  | d k rWt
 |   | } n  |   d } | rxd | } n  | d   } t   d d | d  } d | j } t j }	 | t
 |   d |   | }
 t  j |
 f |  } d } x t t
 |   D] } | d } |  | | | !} y |	 | |  d } Wn6 t k
 ru|	 | | d | t
 |   d } n X| | d K} | | M} | | ?| | <|   7} | d | d k r| | 7} qqW| S(   sr  Decompress byte string to array of integers of any bit size <= 32.

    Parameters
    ----------
    data : byte str
        Data to decompress.
    dtype : numpy.dtype or str
        A numpy boolean or integer type.
    itemsize : int
        Number of bits per integer.
    runlen : int
        Number of consecutive integers, after which to start at next byte.

    i   s   |Bi   iNi   i    i@   s   itemsize out of range: %it   bius   invalid dtypec         3  s%   |  ] } d  |   k r | Vq d S(   i   N(    (   RS   R'   (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    i   i   s   dtype.itemsize too smalli    Rt  Ru  R[   s    (   i   i   i    i@   (   i   i   i   i   (   R   R  t
   unpackbitsR   R=  R   Re   R   Rt  R   R   R   R   R   RI  R   R   Rj   (   R   R   R   RQ  t	   itembytest   skipbitst   shrbitst   bitmaskt   dtypestrRI  R  R{  Rp  R'   R  R!   R   (    (   R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRP    sV    
(	 
)

s   <Bi   i   c   
        s  t  j    t t  j |       d k oI t  f d   | D  se t d t |    n  t   f d   d D  } t  j |   j	 |  }  t  j
 |  j t |  f  j  } x t |  D] \ } } |  t t  j | | d   ?} | t d d | d	  M} | r j d
 | d | }	 |	 |  j j d
 k rZ| j d  } n  | d	 |	 d d	 | d 9} | d	 |	  j d
 } n  | | d d  | f <q W| j d  S(   s  Return array from byte string containing packed samples.

    Use to unpack RGB565 or RGB555 to RGB888 format.

    Parameters
    ----------
    data : byte str
        The data to be decoded. Samples in each pixel are stored consecutively.
        Pixels are aligned to 8, 16, or 32 bit boundaries.
    dtype : numpy.dtype
        The sample data type. The byteorder applies also to the data stream.
    bitspersample : tuple
        Number of bits for each sample in a pixel.
    rescale : bool
        Upscale samples to the number of bits in dtype.

    Returns
    -------
    result : ndarray
        Flattened array of unpacked samples of native dtype.

    Examples
    --------
    >>> data = struct.pack('BBBB', 0x21, 0x08, 0xff, 0xff)
    >>> print(unpack_rgb(data, '<B', (5, 6, 5), False))
    [ 1  1  1 31 63 31]
    >>> print(unpack_rgb(data, '<B', (5, 6, 5)))
    [  8   4   8 255 255 255]
    >>> print(unpack_rgb(data, '<B', (5, 5, 5)))
    [ 16   8   8 255 255 255]

    i    c         3  s"   |  ] } |   j  d  k Vq d S(   i   N(   R   (   RS   R'   (   R   (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s   sample size not supported %sc         3  s1   |  ]' } t  j |  j d    k r | Vq d S(   i   N(   R   R   R   (   RS   R'   (   t   bits(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    t   BHIi   t   0bRt  i   i   R#   Ni(   R   R   R   R  R  Re   Rk   Rt  R  R   R   R   R   R   R   R   R=  R   (
   R   R   t   bitspersamplet   rescaleR  R{  R'   t   bpsR   Rr  (    (   R  R   sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRO    s$    !($!s   _tifffile.reverse_bitorderc         C  s|   d } y8 |  j  d  } t j t j | d d | d | Wn7 t k
 r[ |  j |  St k
 rw t d   n Xd S(   s  Reverse bits in each byte of byte string or numpy array.

    Decode data where pixels with lower column values are stored in the
    lower-order bits of the bytes (fill_order == 'lsb2msb').

    Parameters
    ----------
    data : byte string or ndarray
        The data to be bit reversed. If byte string, a new bit-reversed byte
        string is returned. Numpy arrays are bit-reversed in-place.

    s    @ `P0pH(hX8xD$dT4tL,l\<|B"bR2r
J*jZ:zF&fV6vN.n^>~A!aQ1q	I)iY9yE%eU5uM-m]=}C#cS3sK+k[;{G'gW7wO/o_?R<  R   RX  s   slices of arrays not supportedN(   Rb  R   t   takeR  Ru  t	   translateRe   R[  (   R   RU  Rb  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR`    s    )c         C  sL   t  j | |  d d }  t  j |  d |  j  }  | rH t  j |   }  n  |  S(   s  Return palette-colored image.

    The image values are used to index the colormap on axis 1. The returned
    image is of shape image.shape+colormap.shape[0] and dtype colormap.dtype.

    Parameters
    ----------
    image : numpy.ndarray
        Indexes into the colormap.
    colormap : numpy.ndarray
        RGB lookup table aka palette of shape (3, 2**bits_per_sample).
    contig : bool
        If True, return a contiguous array.

    Examples
    --------
    >>> image = numpy.arange(256, dtype='uint8')
    >>> colormap = numpy.vstack([image, image, image]).astype('uint16') * 256
    >>> apply_colormap(image, colormap)[-1]
    array([65280, 65280, 65280], dtype=uint16)

    R  i   i    (   R   R  t   rollaxisR   Rd  (   Rk  R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRs  B  s
    c         C  s  t  j | |  } | d k r" |  S| d k rN |  d d d d  d d  f S| d k r |  d d d d  d d  d d  f S| d k r |  d d d d  d d d  d d  f S| d k r t j |  d	 d
  S| d k rt j |  d	 d
  d d d d  d d  f S| d k rYt j |  d	 d
  d d d d  d d  d d  f S| d k rt j |  d	 d
  d d d d  d d d  d d  f Sd S(   s+  Return reoriented view of image array.

    Parameters
    ----------
    image : numpy.ndarray
        Non-squeezed output of asarray() functions.
        Axes -3 and -2 must be image length and width respectively.
    orientation : int or str
        One of TIFF_ORIENTATIONS keys or values.

    t   top_leftt	   top_right.Nit   bottom_leftt   bottom_rightt   left_topiit	   right_topt   left_bottomt   right_bottom(   t   TIFF_ORIENTATIONSR   R   Rc  (   Rk  R7   Rr  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   reorient`  s"     ),/8c         C  s8   |  j  | k r |  S|  j d | |  j  |  j  }  |  S(   sR  Return image array with at least ndim dimensions.

    Prepend 1s to image shape as necessary.

    >>> reshape_nd(numpy.empty(0), 1).shape
    (0,)
    >>> reshape_nd(numpy.empty(1), 2).shape
    (1, 1)
    >>> reshape_nd(numpy.empty((2, 3)), 3).shape
    (1, 2, 3)
    >>> reshape_nd(numpy.empty((3, 4, 5)), 3).shape
    (3, 4, 5)

    i   (   i   (   R   R   R   (   Rk  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    !R  c           sk   t  |   t  |  k r' t d   n  t   f d   t |  |  D   \ }  } t |   d j |  f S(   s   Return shape and axes with single-dimensional entries removed.

    Remove unused dimensions unless their axes are listed in 'skip'.

    >>> squeeze_axes((5, 1, 2, 1, 1), 'TZYXC')
    ((5, 2, 1), 'TYX')

    s)   dimensions of axes and shape do not matchc         3  s5   |  ]+ } | d  d k s) | d   k r | Vq d S(   i    i   N(    (   RS   R'   (   RT  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    R   (   R   Re   R^  R   R   (   R   RX  RT  (    (   RT  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    	+t   CTZYXc         C  s   x- | D]% } | | k r t  d |   q q W|  j } x7 t |  D]) } | | k rF | | } d | } qF qF W|  j |  }  |  j g  | D] } | j |  ^ q  }  |  S(   s   Return image with its axes permuted to match specified axes.

    A view is returned if possible.

    >>> transpose_axes(numpy.zeros((2, 3, 4, 5)), 'TYXC', asaxes='CTZYX').shape
    (5, 2, 1, 3, 4)

    s   unknown axis %si   (   i   (   Re   R   R  R   t	   transposeR~  (   Rk  RX  t   asaxesR  R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   transpose_axes  s    		
+c   	      C  s  t  |  } t  |  } t |   t |  k r? t d   n  t |  t |  k rp t d | | f   n  |  s~ | r d St d t |  t |   } | r | d	 | } n  t |  d } d } d } g  } x | d d d  D] } | | 9} x6 | d k r6| | d k r6| d k r6| d 8} qW| | | k r| | | | k r| | | 9} | j |  |  | d 8} q | j d  q Wd j t | |   S(
   s   Return axes matching new shape.

    Unknown dimensions are labelled 'Q'.

    >>> reshape_axes('YXS', (219, 301, 1), (219, 301))
    'YX'
    >>> reshape_axes('IYX', (12, 219, 301), (3, 4, 219, 1, 301, 1))
    'QQYQXQ'

    s   axes do not match shapes   can not reshape %s to %sR   i    i   NiR+   (   i   (   R   R   Re   R   R;  R   R   R  (	   RX  R   t   newshapet   lendiffR'   t   prodnst   prodsR{  t   ns(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s2    
+$c      
   O  sE  t  |   d k r! t d   n  t  |   d k rM |  d j d | | |  S|  d j | |   } t  |   f | j } | r t j d |  % } t j | d | j d | } Wd QXn t j	 | d | j } | | d <| r | j
   n  ~ xK t |  d  D]9 \ }	 }
 |
 j | |   | |	 d <| r| j
   qqW| S(	   s   Read data from sequence of TiffPage and stack them vertically.

    If memmap is True, return an array stored in a binary file on disk.
    Additional parameters are passsed to the page asarray function.

    i    s   no pagesi   Rc  R  R   R   N(   R   Re   R   R   Rv  Rw  R   Rc  R   R   R   R   (   RO   Rc  Rd  R  R   t   data0R   R   R   R'   RU  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRr    s&    '
s    c         C  s'   |  j  |  } | d k  r |  S|  |  S(   s   Return string truncated at first null character.

    Clean NULL terminated C strings. For unicode strings use null='\0'.

    i    (   R   (   R  R  R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    c         C  s   t  j d d k  r t n d   } t |   } xD | rn | d 8} d | |  |  k  ob d k  n r1 Pq1 q1 Wd } |  | d  S(   su   Return string truncated at last byte that is 7bit ASCII.

    Clean NULL separated and terminated TIFF strings.

    i    i   c         S  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    i   i   i   i(   Rp   R@  Rl  R   (   R  t   ord_R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    "	
&c         C  s^   | d k r t t t f } n  x9 | D]1 } y | |   SWq% t t t f k
 rU q% Xq% W|  S(   s,   Return argument as one of types if possible.N(   Ri   R   R  R  Re   R   t   UnicodeEncodeError(   R   t   typest   typ(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR=  #  s    c         C  s9   x2 d D]* } |  d k  r' d |  | f S|  d	 }  q Wd
 S(   s*   Return file size as string from byte size.R    t   KiBt   MiBt   GiBt   TiBt   PiBi   s   %.f %sg      @N(   R    R  R  R  R  R  (    (   R   R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  /  s    c         C  s.   y t  |   |  SWn t k
 r) |  f SXd S(   s{   Return tuple containing value if value is not a sequence.

    >>> sequence(1)
    (1,)
    >>> sequence([1])
    [1]

    N(   R   R   (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR	  7  s
    	
c         C  s%   d } x |  D] } | | 9} q W| S(   s   Return product of sequence of numbers.

    Equivalent of functools.reduce(operator.mul, iterable, 1).

    >>> product([2**8, 2**30])
    274877906944
    >>> product([])
    1

    i   (    (   t   iterablet   prodR'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   G  s    c           s.     f d   } t  j d    t |  d | S(   s   Return human sorted list of strings.

    E.g. for sorting file names.

    >>> natural_sorted(['f1', 'f2', 'f10'])
    ['f1', 'f2', 'f10']

    c           s;   g  t  j   |   D]$ } | j   r1 t |  n | ^ q S(   N(   R  R  t   isdigitR   (   R   R   (   t   numbers(    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   sortkeya  s    s   (\d+)R   (   R  R  R   (   R  R  (    (   R  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   X  s    	iZ
 c         C  s   | t  j |   S(   s   Return datetime object from timestamp in Excel serial format.

    Convert LSM time stamps.

    >>> excel_datetime(40237.029999999795)
    datetime.datetime(2010, 2, 28, 0, 43, 11, 999982)

    (   R@   t	   timedelta(   t	   timestampt   epoch(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   excel_datetimeg  s    	c         C  sd  |  d k r d S|  d } | d k rV t j | d d  } | d | | d 7} n  | | d k rk d n d } t j | d	 d
  } t j d
 |  } t j | | d  } | | t j d |  } | | d k  r d n d }	 | |	 d k r d n d }
 t | d  \ } } t | d  \ } } t | d  \ } } t j |
 |	 | | | | |  S(   s   Return datetime from days since 1/1/4713 BC and ms since midnight.

    Convert Julian dates according to MetaMorph.

    >>> julian_datetime(2451576, 54362783)
    datetime.datetime(2000, 2, 2, 15, 6, 2, 783)

    iOD i   i# g   @}<Ag    @i   i  i  gfffff^@g     v@gaTR'>@g      +@i   g      @il  ik  i  i<   Ni`  i6 i`  (   Ri   R7  t   trunct   divmodR@   (   t	   juliandayt
   milisecondRT   t   alphaR%   R   R*   R   t   dayt   montht   yeart   hourt   minutet   second(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  s  s$    	
c         O  s   i  } x2 | D]* } | |  k r |  | | | <|  | =q q WxH | j    D]: \ } } | |  k rx |  | | | <|  | =qH | | | <qH W| S(   sX  Return dict with keys from keys|keyvals and values from kwargs|keyvals.

    Existing keys are deleted from kwargs.

    >>> kwargs = {'one': 1, 'two': 2, 'four': 4}
    >>> kwargs2 = parse_kwargs(kwargs, 'two', 'three', four=None, five=5)
    >>> kwargs == {'one': 1}
    True
    >>> kwargs2 == {'two': 2, 'four': 4, 'five': 5}
    True

    (   R  (   R   R_  t	   keyvaluesR{  R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    
c         K  s:   x3 | j    D]% \ } } | |  k r | |  | <q q Wd S(   s   Update dict with keys and values if keys do not already exist.

    >>> kwargs = {'one': 1, }
    >>> update_kwargs(kwargs, one=None, two=2)
    >>> kwargs == {'one': 1, 'two': 2}
    True

    N(   R  (   R   R  R   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   update_kwargs  s    	t   TIFF_SUBFILE_TYPESc           B  s   e  Z d    Z RS(   c         C  s^   g  } | d @r  | j  d  n  | d @r: | j  d  n  | d @rT | j  d  n  t |  S(   Ni   t   reduced_imagei   RU  i   Rq  (   R   R   (   R   R   R{  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    


(   R&  R'  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s   R   R   R   i   R   i   Rq  i   t	   separatedt   ycbcrt   cielabi   t   icclabi	   t   itulabi
   R   i#  t   logliL  t   logluviM  t
   linear_rawiL  t   ccittrlet	   ccittfax3t	   ccittfax4t   lzwt   ojpegRR  i   t   adobe_deflatet   t85t   t43Rt  i  t	   ccittrlewi  t   packbitsi  t   thunderscani)  t   it8ctpadi  t   it8lwi  t   it8mpi  t   it8bli  t	   pixarfilmi  t   pixarlogi  t   deflatei  t   dcsi  t   jbigie  t   sgilogit  t   sgilog24iu  t   jp2000i  t   nefi  R   im  c         C  s   |  S(   N(    (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR     s    t   1Bt   1st   1HR  R$   t   1bt   1ht   1iR(   t   1fi   t   1di   i   t   1Qi   t   1qi   i   t   uintR   R  t   complext   ?R    R"   i   i   R#   i   i   i   i   i   i   i   i   i   i   i   i   i   i    R+   i@   R%   R&   R'   R,   R   R)   R*   t   Ft   Di   R  R  R  R  R  R  R  R  t   widthR  t   heightR  t   depthR  t   sampleR.  RW  t   timeR  R%  R   t   anglet   At   phaseR  R   R  t   lifetimet   lambdat   Et   exposureR  t   eventR  R  t   mosaicR  c         c  s!   |  ] \ } } | | f Vq d  S(   N(    (   RS   Rz  R*  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>u  s    t   i1t   int8t   i2t   int16t   i4t   int32t   u1R<  t   u2t   uint16t   u4t   uint32t   f4R  t   doublet   c8t   c16s   double-complext   fileidt   a8t   nlinest   pixelsperlineR   t
   oldlutmodet
   oldncolorst   colorst   oldcolorstartt
   colorwidtht   extracolorst   nextracolorst   foregroundindext   backgroundindext   xscalet   _x0t   _x1t   units_tt   p1R   t   yt   p2t
   curvefit_tt   ncoefficientst   coeffR   R  t   a15t   _x2t	   binarypict   b1t
   slicestartt   sliceendt   scalemagnificationt   nslicest   slicespacingt   currentslicet   frameintervalt   pixelaspectratiot
   colorstartt   colorendt   ncolorst   fill1t   3u2t   fill2t   colortable_tt	   lutmode_tt   invertedtablet   zeroclipR  R  t   a11t   stacktype_tt   CustomTablet   AppleDefaultt   Pseudo20t   Pseudo32t   Rainbowt   Fire1t   Fire2t   Icet   Grayst   Spectrumt   PseudoColort   OldAppleDefaultt   OldSpectrumt	   GrayScalet   ColorLutt   CustomGrayscalet   StraightLinet   Poly2t   Poly3t   Poly4t   Poly5t   ExpoFitt   PowerFitt   LogFitt
   RodbardFitt	   SpareFit1t   Uncalibratedt   UncalibratedODt
   Nanometerst   Micrometerst   Millimeterst   Centimeterst   Meterst
   Kilometerst   Inchest   Feett   MilesR  t
   OtherUnitst   VolumeStackt   RGBStackt
   MovieStackt   HSVStackt
   auto_scalet	   min_scalet	   max_scalet   spatial_calibrationt   x_calibrationt   y_calibrationt   calibration_unitsR=  t   thresh_statet   thresh_state_redt   tagid_10t   thresh_state_greent   thresh_state_bluet   thresh_state_lot   thresh_state_hit   zoomt   create_timet   last_saved_timet   current_buffert   gray_fitt   gray_point_countt   gray_xt   gray_yt   gray_mint   gray_maxt   gray_unit_namet   standard_lutt
   wavelengtht   stage_positions
   (%i,2,2)u4t   camera_chip_offsett   overlay_maskt   overlay_compresst   overlayt   special_overlay_maski!   t   special_overlay_compressi"   t   special_overlayi#   t   image_propertyi$   t   stage_labels   %ipi%   t   autoscale_lo_infoi&   t   autoscale_hi_infoi'   t
   absolute_zs   (%i,2)u4i(   t   absolute_z_valids   (%i,)u4i)   t   gammai*   t	   gamma_redi+   t   gamma_greeni,   t
   gamma_bluei-   t
   camera_bini.   t   new_luti/   t   image_property_exi0   t   plane_propertyi1   t   user_lut_tables	   (256,3)u1i2   t   red_autoscale_infoi3   t   red_autoscale_lo_infoi4   t   red_autoscale_hi_infoi5   t   red_minscale_infoi6   t   red_maxscale_infoi7   t   green_autoscale_infoi8   t   green_autoscale_lo_infoi9   t   green_autoscale_hi_infoi:   t   green_minscale_infoi;   t   green_maxscale_infoi<   t   blue_autoscale_infoi=   t   blue_autoscale_lo_infoi>   t   blue_autoscale_hi_infoi?   t   blue_min_scale_infot   blue_max_scale_infoiA   t   a16R   t   originR   R  t   a64t   header_flagt
   image_typet
   image_namet   a257t   offset_datat   palette_sizet   offset_palette0t   offset_palette1t   comment_sizet   offset_commentR  t   offset_positiont   map_typet   map_mint   map_maxt	   min_valuet	   max_valuet
   offset_mapR>  t   gray_channelt   offset_thumbnailt   voice_fieldt   offset_voice_fieldR  R  t   dimension_xt   dimension_yt   dimension_zt   dimension_channelst   dimension_timet	   data_typet   thumbnail_xt   thumbnail_yt   voxel_size_xt   voxel_size_yt   voxel_size_zt   origin_xt   origin_yt   origin_zR  t   spectral_scant   type_of_datat   offset_vector_overlayt   offset_input_lutt   offset_output_lutt   offset_channel_colorst   time_intervalt   offset_channel_data_typest   offset_scan_infot   offset_ks_datat   offset_time_stampst   offset_event_listt
   offset_roit   offset_bleach_roit   offset_next_recordingt   display_aspect_xt   display_aspect_yt   display_aspect_zt   display_aspect_timet   offset_mean_of_roi_overlayt   offset_topo_isoline_overlayt   offset_topo_profile_overlayt   offset_linescan_overlayt   offset_toolbar_flagst   offset_channel_wavelengtht   offset_channel_factorst   objective_sphere_correctiont   offset_unmix_parameterst   offset_acquisition_parameterst   offset_characteristicst   offset_palettet   time_difference_xt   time_difference_yt   time_difference_zt   internal_use_1R  R  t   dimensions_reservedt   16i4t   offset_tile_positionst
   reserved_1t   9u4t   offset_positionst
   reserved_2t   21u4t	   scan_infot   time_stampst
   event_listt   channel_colorsRY  t   tile_positionst   XYZCTt   XYTCZt   XYZTCt   XYCTZt   XYCZTs   varying data typess   8 bit unsigned integers   12 bit unsigned integers   32 bit floats   Original scan datas   Calculated datas   3D reconstructions   Topography height mapt   tracksi    t   lasersi   0t   detection_channelsi   `t   illumination_channelsI       t   beam_splittersI       t   data_channelsI       t   timersi   t   markersi   t   tracki   @t   laseri   Pt   detection_channeli   pt   illumination_channelI       t   beam_splitterI       t   data_channelI       t   timeri   t   markeri   i  R   i  t   notesi  t	   objectivei  t   processing_summaryi  t   special_scan_modei  i  t	   scan_modei  t   number_of_stacksi	  t   lines_per_planei
  t   samples_per_linei  t   planes_per_volumei  t   images_widthi  t   images_heighti  t   images_number_planesi  t   images_number_stacksi  t   images_number_channelsi  t   linscan_xy_sizei  t   scan_directioni  t   time_seriesi  t   original_scan_datai  t   zoom_xi  t   zoom_yi  t   zoom_zi  t	   sample_0xi  t	   sample_0yi  t	   sample_0zi  t   sample_spacingi  t   line_spacingi  t   plane_spacingi  t   plane_widthi  t   plane_heighti   t   volume_depthi!  t   nutationi#  t   rotationi4  t
   precessioni5  t   sample_0timei6  t   start_scan_trigger_ini7  t   start_scan_trigger_outi8  t   start_scan_eventi9  t   start_scan_timei@  t   stop_scan_trigger_iniA  t   stop_scan_trigger_outiB  t   stop_scan_eventiC  t   stop_scan_timeiD  t   use_roisiE  t   use_reduced_memory_roisiF  t   useriG  t   use_bc_correctioniH  t   position_bc_correction1iI  t   position_bc_correction2iP  t   interpolation_yiQ  t   camera_binningiR  t   camera_supersamplingiS  t   camera_frame_widthiT  t   camera_frame_heightiU  t   camera_offset_xiV  t   camera_offset_yiW  t
   rt_binningiY  t   rt_frame_widthiZ  t   rt_frame_heighti[  t   rt_region_widthi\  t   rt_region_heighti]  t   rt_offset_xi^  t   rt_offset_yi_  t   rt_zoomi`  t   rt_line_periodia  t   prescanib  t   scan_direction_zic  t   multiplex_typei  @t   multiplex_orderi  @t   sampling_modei  @t   sampling_methodi  @t   sampling_numberi  @t   acquirei  @t   sample_observation_timei  @t   time_between_stacksi  @i  @t   collimator1_namei  @t   collimator1_positioni  @t   collimator2_namei  @t   collimator2_positioni  @t   is_bleach_tracki  @t   is_bleach_after_scan_numberi  @t   bleach_scan_numberi  @t
   trigger_ini  @t   trigger_outi  @t   is_ratio_tracki  @t   bleach_counti  @t   spi_center_wavelengthi  @t
   pixel_timei  @t   condensor_frontlensi!  @t   field_stop_valuei#  @t   id_condensor_aperturei$  @t   condensor_aperturei%  @t   id_condensor_revolveri&  @t   condensor_filteri'  @t   id_transmission_filter1i(  @t   id_transmission1i)  @t   id_transmission_filter2i0  @t   id_transmission2i1  @t   repeat_bleachi2  @t   enable_spot_bleach_posi3  @t   spot_bleach_posxi4  @t   spot_bleach_posyi5  @t   spot_bleach_poszi6  @t   id_tubelensi7  @t   id_tubelens_positioni8  @t   transmitted_lighti9  @t   reflected_lighti:  @t   simultan_grab_and_bleachi;  @t   bleach_pixel_timei<  @i  Pi  Pt   poweri  Pt   integration_modei  pt   special_modei  pt   detector_gain_firsti  pt   detector_gain_lasti  pt   amplifier_gain_firsti  pt   amplifier_gain_lasti  pt   amplifier_offs_firsti  pt   amplifier_offs_lasti  pt   pinhole_diameteri	  pt   counting_triggeri
  pi  pt   point_detector_namei  pt   amplifier_namei  pt   pinhole_namei  pt   filter_set_namei  pt   filter_namei  pt   integrator_namei  pt   channel_namei  pt   detector_gain_bc1i  pt   detector_gain_bc2i  pt   amplifier_gain_bc1i  pt   amplifier_gain_bc2i  pt   amplifier_offset_bc1i  pt   amplifier_offset_bc2i   pt   spectral_scan_channelsi!  pt   spi_wavelength_starti"  pt   spi_wavelength_stopi#  pt   dye_namei&  pt
   dye_folderi'  pI      I      I      t   aquireI      t   detchannel_nameI      t	   power_bc1I      t	   power_bc2I      t
   filter_setI      t   filterI      I      I      I      t   colorI      t   sample_typeI      R1   I      t
   ratio_typeI      t   ratio_track1I      t   ratio_track2I	      t   ratio_channel1I
      t   ratio_channel2I      t   ratio_const1I      t   ratio_const2I      t   ratio_const3I      t   ratio_const4I      t   ratio_const5I      t   ratio_const6I      t   ratio_first_images1I      t   ratio_first_images2I      I      I      t   spectrumI      I      i  i  t   intervali  i  i  t   activation_timei  t   activation_numberi  i  i  i  i  t
   comment_v1t   a80t   high_tensiont   spherical_aberrationt   illumination_aperturet   magnifications   post-magnificationt   focal_lengtht   defocust   astigmatismt   astigmatism_directiont   biprism_voltaget   specimen_tilt_anglet   specimen_tilt_directiont   illumination_tilt_directiont   illumination_tilt_anglet
   image_modet   energy_spreadt   chromatic_aberrationt   shutter_typet   defocus_spreadt
   ccd_numbert   ccd_sizet   offset_x_v1t   offset_y_v1t   physical_pixel_sizet   binningt   readout_speedt   gain_v1t   sensitivity_v1t   exposure_time_v1t   flat_correctedt   dead_px_correctedt
   image_meant	   image_stdt   displacement_xt   displacement_yt   date_v1t   time_v1t	   image_mint	   image_maxt   image_statistics_qualityt   V160t   image_foldert   image_size_xt   image_size_yt   image_size_zt   image_size_et   image_data_typet   datet   commentt   V1024t   image_historyt   scalingt   16f4t   image_statisticst   16c16t   image_display_typet   pixel_size_xt   pixel_size_yt   image_distance_zt   image_distance_et
   image_misct   32f4t   tem_typet   tem_high_tensiont   tem_aberrationst
   tem_energyt   tem_modet   tem_magnificationt   tem_magnification_correctiont   post_magnificationt   tem_stage_typet   tem_stage_positiont   5f4t   tem_image_shiftt   2f4t   tem_beam_shiftt   tem_beam_tiltt   tiling_parameterst   7f4t   tem_illuminationt   3f4t   tem_shuttert   tem_misct   camera_typet   physical_pixel_size_xt   physical_pixel_size_yt   offset_xt   offset_yt	   binning_xt	   binning_yt   exposure_timet   gaint   readout_ratet   flatfield_descriptiont   sensitivityt   doset   cam_misct   fei_microscope_informationt   fei_specimen_informationR  R-   i   R.   t	   undefinedRk  R  RU  i   R/   i   R0   i  i  R2   i  R3   i  R]  Rs  RK  i
  R4   i  R5   i  t   makei  t   modeli  R6   i  R7   i  R8   i  R9   i  R:   i  t   min_sample_valuei  t   max_sample_valuei  R;   i  R<   i  R=   R   t   separatei  R>   i  t
   x_positioni  t
   y_positioni  R?   R   t
   centimeteri(  t   page_numberi)  R   i1  R@   i2  t   artisti;  t   host_computeri<  RA   RW  i=  t   white_pointi>  t   primary_chromaticitiesi?  RB   i@  RC   iB  RD   iC  RE   iD  RF   iE  t   sub_ifdsiJ  RG   R4  R3  R2  iR  RH   iS  RI   iT  RJ   iU  t   indexediZ  RS  i[  R  i  Rj  i  t   reference_black_whitei  t   sgi_matteingi  t   sgi_datatypei  RK   i  RL   i  t	   copyrighti  Rd  i  Re  i  t   md_color_tablei  t   md_lab_namei  t   md_sample_infoi  t   md_prep_datei  t   md_prep_timei  t   md_file_unitsi  t   model_pixel_scalei  t   model_tie_pointi  t   exif_ifdii  t   geo_key_directoryi  t   geo_double_paramsi  t   geo_ascii_paramsi  t   gps_ifdi%  t   user_commenti  t   gdal_metadatai  t   gdal_nodatai  t   mc_xy_positioniq  t   mc_z_positionir  t   mc_xy_calibrationis  t   mc_lens_lem_na_nit  t   mc_channel_nameiu  t   mc_ex_wavelengthiv  t   mc_time_stampiw  R  i  t
   fibics_xmliO  t   flex_xmli  t   xmpi  t	   photoshopiI  t   iptci  t   icc_profileis  R  i\  R  i]  R  i^  R  i_  R  iF  R  i9  R  i:  t   mm_user_blockiR  R  il  R~  ix  R  iz  R}  iJ  R|  i2  t	   mc_id_oldi  R  ip  t   mc_frame_propertiesix  R  i  RO  i  iO   i`   io   i    c           s  | dO k }  j     | dP k r6 t  d   n t  d    j   d k  ri t d   n d k r d  t } n | r  j d	 dQ k r t j  d	 d   t j  d d   n | rM j d  j d d k  rM j d  j d	 d k  rM j d d k  rMt j  d	 d   t j  d d   n  | oc j d dR k }  | rud n d 8 | r d d |  d |  d |  f  n  d d |  d |  f  | d k r| r j   } | d k r d L n   j	 d   n j
 j d k r| o< j
 j d k sL| d k ry+ t t j t j  j   d    } Wqt k
 r j
 j d } qXn" t | t  s j
 j d } n  d | } | r| d k  r d | K n | d k r
 | d L n   j	 d   qn  j
 j d k r j   } | r| d k r j
 j d k rs j	 d   n   |  qn<  j
 j d k rd } n!  j
 j d k rt d   n  | s| d k r| } n  | d k r j
 j d k rCt j  j
  j } t j   } | | k rCt j  | k  } qCn   j
 j d k rt j  j
  j } t j   } | | k rt j  | k  } qqd } qn  t j d }  d k ru| j d d d d  d! d" d | j d# | d$ dS d' t d( d) d* d+   y  j j j  j! |  Wn t k
 r;n X| j" d, d-  d d. d/ d0 d1 d2 d3 d4 d5 d6 d7  n  | j# |
  }
 | ry t$ | d8  } Wn t% k
 rn X| j! | d" d9 n  | d k r j
 j d: k s| d k rd; } n d< } | d k r| d= 7} qn  | j&  dT  j    d> | d? | d@ | dA | |  | sg| j'   n       f dB   } | | j(   _)  rt* dU    d  t+   j    g   g  t,   D]d } | j- | j. dC d- | d dD dE g  dF | d  j | d d d( dG dH dI  j | ^ q} x | D] } t | _/ q>W|      f dJ        f dK        f dL  }  j j0 dM |  x6 t1 |  D]% \ } } | j2 |  f dN   qWn   |
  f S(V   s  Plot n-dimensional images using matplotlib.pyplot.

    Return figure, subplot and plot axis.
    Requires pyplot already imported `from matplotlib import pyplot`.

    Parameters
    ----------
    bitspersample : int or None
        Number of bits per channel in integer RGB images.
    photometric : {'miniswhite', 'minisblack', 'rgb', or 'palette'}
        The color space of the image data.
    title : str
        Window and subplot title.
    figure : matplotlib.figure.Figure (optional).
        Matplotlib to use for plotting.
    subplot : int
        A matplotlib.pyplot.subplot axis.
    maxdim : int
        maximum image width and length.
    kwargs : optional
        Arguments for matplotlib.pyplot.imshow.

    R   R   R   R   i   i   s   not an imagei    ii   iii   i   .Ni   R    t   uii   R)   g      ?R*   R%   R   s   complex typeR'   s   matplotlib.pyplott   fontt   familys
   sans-serift   weightt   normalR   t   dpit   figsizeg$@g333333@t   frameont	   facecolors   1.0t	   edgecolorR  t   bottomgQ?t   topg?t   leftg?t   rightgffffff?t   hspaceg?t   wspaceg        s   Windows-1252i   t   ubft	   cubehelixt   coolwarmt   _rt   vmint   vmaxt   cmapt   interpolationc           s   t  |  d  }  t  | d  } yG  rK d   d | |  f  |  | f Sd  | |  f |  | f SWn t k
 r{ d SXd  S(   Ng      ?s   %s @ %s [%4i, %4i]i   s   %s @ [%4i, %4i]R   (   R   R  (   R   R*  (   t
   cur_ax_datt   currentR   R  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   format_coord  s    g      ?g333333?g?s   Dimension %is   0.5t   valfmts
   %%.0f [%i]c           s{   | t  |   j     d < j   d  x< t | |   D]+ \ } } t | _ | j |  t | _ q; W j j	   d  S(   Ni   (
   R   Rb  t   set_dataR^  Ro   t   eventsont   set_valR   t   canvast   draw(   Rp  t   slidersR   t   ctrlR~  (   Ro  t   figureRk  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt	   set_image  s    	c           s   t  t |    }  |   d <|  | | k r0 d  S|  | j | k rL d }  n  |  d k  rl | j | d }  n  |  | | < |  d  S(   Ni    i   (   R   t   roundR   (   R~  R  R   Rp  (   Ro  R{  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt
   on_changed  s    
	
c           s<  |  j  }   d } t |  d k r5  | |  n| d k rY  | | d |  n | d k r}  | | d |  n | d k r | t | j  d k r d n | d   d <n | d k r | d k r t | j  d n | d   d <nC | d k r | j | d |  n | d	 k r8 d |  n  d  S(
   Ni    t
   0123456789Rd  i   Rc  t   upt   downt   endt   home(   R   Rk   R   R   (   R  R   Rp  R   R  (   Ro  R}  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   on_keypressed*  s     	
00t   key_press_eventc           s     |  |  S(   N(    (   Rz  RT   (   R}  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   ?  s    (   R   R   (   R   R   (   i   i   (   i   i   (   g$@g333333@(   i    (   i    (3   Rb  R   R   Re   Ro   R   R   Rc  R;  R=  R   R   R   Ri   R   R7  t   ceilt   logRj   R   R   R[  t   iinfoR   t   finfoRp   t   modulest   rcRz  R   Rv  t   managert   windowt   titlet   subplots_adjustt   subplotR  R   R   t   colorbart   gcaRq  R   R   R   t   SliderRX  t   drawont   mpl_connectR   R}  (   R   R  Rk  Rl  Rm  R  R3   Rn  R\  Rz  R  t   maxdimR   R  t   datamaxt   dtmint   pyplotRq  R  Rx  t   sliderR  Ry  (    (   Ro  Rp  R   R  Rz  Rk  R}  R{  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR   i  s    		%+%+
			&t
 c          C  s   t  j d }  |  j   d S(   s)   Block the GUI. For use as skimage plugin.s   matplotlib.pyplotN(   Rp   R  t   show(   R  (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt	   _app_showD  s    c          K  s   y  d d l  m } d d l } Wn' t k
 rI d d l m } m } n X|   } | j   | j   | j |    } | j	   | S(   s4   Return file name(s) from Tkinter's file open dialog.i(   t   TkN(   R  t
   filedialog(
   t   TkinterR  t   tkFileDialogR_  t   tkinterR  t   withdrawR  t   askopenfilenamet   destroy(   R   R  R  R  t	   filenames(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR  J  s    	


c           s   t  t j d d ! d k  r; t d  t d t j  d S|  d k rS t j }  n  d d l } | j d d	 d
 d d d t  } | j	 } | d d d d d d d d d d | d d d d d d d d d d | d d d d d d t
 d d | d  d d! d d d t
 d d" | d# d d$ d% d& d d' d d( | d) d d* d d d d+ d d, | d- d d. d d d d d d/ | d0 d d1 d d d d d d2 | d3 d d4 d d d t
 d d5 | d6 d d7 d d d t
 d d8 | d9 d: d d; d d d t | d< d= d d; d d> | j   \ }   d? j      | j r`d d l } | j   d S  st d@ dA dB dd de df dg g      s| j dK  qn  t   f dL   dM D  rt j        st dN  d S  d   n  t dO dP d? t j   } y t   dQ | j } Wn< t k
 r`} | j rC  qat dR |  t j d  n Xt dS t j   | dT  | j rt | _ n  g  }	 | j s?t dU dP d? dV   }
 t j   } yG| j d k r | j dW | j  | | j f g }	 n | j d k rC| j d | j  |
 | j | j j   f g }	 n g  }	 x t! | j  D] \ } } y, |	 j" | j d |  |
 | j   f  WqYt# k
 r} |	 j" d |
 | j   f  | j r  qt dX | | f dP dY qYXqYWt dS t j   | dT  Wq?t k
 r;} | j r.  q<t |  q?Xn  | j$   t   t | j%    t   |	 r| j ry- d d l& } | j' dZ  d d[ l& m( } Wn$ t) k
 r} t* j+ d\ |  qXxA|	 D]9\ } } | d k rqn  | j, | j- } } d] | j. k rOy& t/ j0 | | t  | j1  k  } WqOt# k
 rKqOXn  | j2 ry | j3 d^ } | j3 d_ } Wn t4 k
 rqX| | k r| j, | j- } } qn  d` t5 |  t5 |  f } t6 | d@ | d. | d1 | da | j7 db | j8 dc | j9 d* | j: qW| j;   n  d S(h   s!   Command line usage main function.i    i   g@s2   This script requires Python version 2.7 or better.s   This is Python version %siNt   usages   usage: %prog [options] pathR   s!   Display image data in TIFF files.R   s	   %%prog %ss   -ps   --paget   destRU  t   typeR   RB  t   helps   display single pages   -ss   --seriesRW  s%   display series of pages of same shapes   --nomultifilet   nomultifilet   actiont
   store_trues*   do not read OME series from multiple filess   --noplott   noplots   do not display imagess
   --interpolt   interpolt   metavart   INTERPOLt   bilinears   image interpolation methods   --dpiR\  i`   s   set plot resolutions   --vminRk  s"   set minimum value for colormappings   --vmaxRl  s"   set maximum value for colormappings   --debugt   debugs   raise exception on failuress	   --doctestt   doctests   runs the docstring exampless   -vs	   --verboset   verboses   -qs   --quiett   store_falseR  R  s   Select a TIFF filet	   filetypess	   TIF filess   *.tifs	   LSM filess   *.lsms	   STK filess   *.stkt   allfilesR  s   No file specifiedc         3  s   |  ] } |   k Vq d  S(   N(    (   RS   R'   (   R  (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    s   ?*s   no files match the patterns   Reading file structure...R  R)  s   
s   %.3f msg     @@s   Reading image data... c         S  s   t  d   |  D  S(   Nc         s  s!   |  ] } | d  k	 r | Vq d  S(   N(   Ri   (   RS   R'   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pys	   <genexpr>  s    (   Rt  (   R   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   notnone  s    R   s   
* series %i failed: %s... R   t   TkAgg(   R  s   failed to import matplotlib.
%sRF  Rr  Rs  s   %s
 %sR  R3   Rn  (   s	   TIF filess   *.tif(   s	   LSM filess   *.lsm(   s	   STK filess   *.stk(   R  R  (<   R  Rp   R   t   printRi   t   argvt   optparset   OptionParsert   __version__t
   add_optionRo   R   t
   parse_argsR   R  t   testmodR  t   errorRd   R0  R  R   R  Rj   R  t   exitR,  t   norgbR  RU  R   RW  RO   R   R   Re   R  R
  t
   matplotlibt   useR  R_  Rq   Rr   Rk  Rl  R   R   R   RF  R  R{  R   Rk   R   R1   R3   R  R\  R  (   R  R  t   parsert   optt   settingsR  R  R   R   R  R  R'   R!   R  R  t   imgRU  Rk  Rl  R  (    (   R  sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   mainY  s    
			

				"&	 	
&				c         C  s   t  |  d  S(   NR  (   Rk   (   R%   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyR    s    s   latin-1c         C  s   |  j  |  S(   N(   R  (   R!   t   encoding(    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRM    s    c         C  s   |  S(   N(    (   R!   (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRM    s    Rn   c           B  s   e  Z RS(    (   R&  R'  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyRn     s   t   __main__(   R(  t
   __future__R    R   Rp   R  R  R0  R7  R   R  R  R   Rq   Rv  R@   Rn  t	   fractionsR   t	   xml.etreeR   R  R   R   R_  t   backports.lzmaRi   t   __package__R   R   Rr   R  t   __docformat__t   __all__R   t   objectR	   R   R   R   RJ  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!  RN  R  R  Ro   R   R   R  R5   R`  Rc  RT  Ro  R   RP  R   RO  R`  Rs  R  R   R  R  R  Rr  R   R  R=  R  R	  R   R   t   fromordinalR  R  R   R  R  t   TIFF_PHOTOMETRICSt   TIFF_COMPESSIONSRV  R  R  R6  R:  R  R  R  R  t   OME_PIXEL_TYPESR  t   NIH_COLORTABLE_TYPEt   NIH_LUTMODE_TYPEt   NIH_CURVEFIT_TYPEt   NIH_UNITS_TYPEt   NIH_STACKTYPE_TYPER   Rk   R  t   MM_DIMENSIONR  R  R!  R  R  t   CZ_DATA_TYPESt   CZ_TYPE_OF_DATAR  R  R  R  R  R5  R  R  R   R  R  R  t   TIFFfileR@  R   R/  R  R  RM  Rm   Rn   R&  R  (    (    (    sA   lib/python2.7/site-packages/skimage/external/tifffile/tifffile.pyt   <module>  s`  	$   Q	/     a;										Z								/			&			6	3	"	2		(
V	?5$			*!
					"		









#
																																																																																																																												







																																																																																														&$$++					