
    < j             (         % S r SSKJr  Sr/ SQrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
K J!r!  SSK"J#r#  SSK$r$ SSK%r%SSK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0  \+(       a*  SSKJ1r1J2r2J3r3  SSK4J5r5  SSK)J6r6J7r7J8r8  SSK9J:r:J;r;J<r<  SSK=J>r>  SSS 47r?SSS 47r@SSS 47rASSS 47rB0 rCS\DS'   \/ GSKSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS.!                                                                         GSLS jjj5       rE\/ GSKSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS.!                                                                         GSMS  jjj5       rE\/ GSKSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS!."                                                                         GSNS" jjj5       rE GSKSSS#SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS$.#                                                                           GSOS% jjjrE GSKSSSSS#SSS#SSSSSS#SSSSSSSSSSSSSSSS\CSS#S#SSSS#S&.&                                                                                 GSPS' jjjrFSSSSSSSS(S).                     GSQS* jjrG " S+ S,\H5      rI\. " S- S.5      5       rJ\. " S/ S05      5       rK\. " S1 S25      5       rL\. " S3 S45      5       rM\. " S5 S65      5       rN\. " S7 S8\\M\N-     5      5       rO\. " S9 S:5      5       rP\. " S; S<5      5       rQ\. " S= S>5      5       rR " S? S@\\M\N-  S-     5      rS\. " SA SB\\S   5      5       rT " SC SD\\U   5      rV\. " SE SF\V5      5       rW\. " SG SH5      5       rX\. " SI SJ5      5       rY\. " SK SL5      5       rZ\. " SM SN\\[   5      5       r\\. " SO SP5      5       r]\. " SQ SR5      5       r^ " SS ST\_5      r`\. " SU SV5      5       ra\. " SW SX\\[\SY\b4   4   5      5       rc\. " SZ S[\\[\SY\b4   4   5      5       rd " S\ S]\R                  5      rf " S^ S_\R                  5      rg " S` Sa\R                  5      rh " Sb Sc\R                  5      ri " Sd Se\R                  5      rk " Sf Sg\R                  5      rl " Sh Si\R                  5      rm " Sj Sk\R                  5      rn " Sl Sm\R                  5      ro " Sn So\R                  5      rp " Sp Sq\R                  5      rq " Sr Ss\R                  5      rr " St Su\R                  5      rs " Sv Sw5      rt\t" 5       ru0 SxSy_SzSy_S{Sy_S|S}_S~S}_SS}_SS}_SS}_SS}_SS_SS_SS_SS_SS_SS_SS_SS_SS0ErvS\DS'    GSRS jrwGSRS jrxGSRS jryGSRS jrzGSRS jr{GSRS jr|GSRS jr}GSRS jr~GSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrGSRS jrSSS.             GSSS jjr            GSTS jr            GSTS jr            GSTS jr            GSUS jr            GSVS jr            GSWS jr            GSWS jr            GSXS jr            GSTS jr            GSWS jr GSY             GSZS jjr            GS[S jr            GS[S jr            GS[S jr          GS\S jrGS]S jr            GSTS jrGS^S jrGS^S jrGS^S jrGS^S jrGS_S jrGS]S jrGS]S jrGS]S jr            GSTS jr            GSTS jr            GSTS jr            GSTS jr            GSTS jr            GSTS jr    GS`S jr GSK     GSaS jjr    GSbS jr    GScS jrGSdS jr      GSeS jr        GSfS jrGSgS jr GSKSS#S.           GShS jjjrSSS.       GSiS jjr          GSjS jrGSkS jrGSlS jrGSmS jrGSgS jr GSK     GSnS jjrGSgS jrGSgS jrGSoS jrGSgS jrGSpS jrGSqS jrGSrS jr GSs     GStS jjr      GSuS jrGSvS jr  GSwSS.         GSxS jjjrSS.       GSyS jjr   GSzSS.           GS{S jjjrGS|S jr          GS}S jr        GS~S jr                  GSS jr      GSS jrGSS jr\/      GSS j5       r\/GSS j5       r      GSS jr\/ GSK       GSS jj5       r\/ GSK       GSS jj5       r GSK       GSS jjr GSK       GSS jjr\/ GSK         GSS jj5       r\/ GSK         GSS jj5       r GSK         GSS jjrS#S.     GSS jjr      GSGS  jr\/ GS         GSGS jj5       r\/ GS         GSGS jj5       r  GS         GSGS jjrS#SGS.       GSGS jjrSSSSGS.             GSGS jjrGS	SSGS
.             GSGS jjrGSGS jrGSKGSGS jjr\/  GSw       GSGS jj5       r\/  GSw       GSGS jj5       r  GSw       GSGS jjr GSK     GSGS jjrGSGS jrGSGS jrGSGSGS jjrGSGS jrGSGS jrGSGS jrGSGS jrGSGS jrGSGS jr GS     GSGS jjrGSYGSGS jjr\GR                  GS:X  a  GSOGSrS\DGS '   GSGS! jrGSGS" jr GS       GSGS# jjrGSGS$ jrSSGS%GS&.         GSGS' jjrGS(GS)GS*GSSGS+.             GSGS, jjrGSGS- jrS#GS..GSGS/ jjrGSGS0 jrGSGS1 jrGS)GS2GS3SGS4.           GSGS5 jjr GSSSGS6.         GSGS7 jjjrGSGS8 jrGSGS9 jr        GSGS: jrGSGS; jrGSGS< jrGSGS= jr  GSw       GSGS> jjr   GSz         GSGS? jjGr SSSSSSSSSSSGS@.                           GSGSA jjGr GSKSSGSB.         GSGSC jjjGrSSSSSSSSSSSSGSDSSS#GSE.                                     GSGSF jjGrGSGSG jGrGSKGSGSH jjGr\KGr\+(       a  SGSIGKGJGrGJ	Gr	GJ
Gr
  G\GSJ:X  a  \GR                  " G\" 5       5        gg! \& a     SSK'J(r%   GN6! \& a	    SSK(r%  GNDf = ff = f(  uq  Read and write TIFF files.

Tifffile is a comprehensive Python library to

(1) store NumPy arrays in TIFF (Tagged Image File Format) files, and
(2) read image and metadata from TIFF-like files used in bioimaging.

Image and metadata can be read from TIFF, BigTIFF, OME-TIFF, GeoTIFF,
Adobe DNG, ZIF (Zoomable Image File Format), MetaMorph STK, Zeiss LSM,
ImageJ hyperstack, Micro-Manager MMStack and NDTiff, SGI, NIHImage,
Olympus FluoView and SIS, ScanImage, Molecular Dynamics GEL,
Aperio SVS, Leica SCN, Roche BIF, PerkinElmer QPTIFF (QPI, PKI),
Hamamatsu NDPI, Argos AVS, Philips DP, and ThermoFisher EER formatted files.

Image data can be read as NumPy arrays or Zarr arrays/groups from strips,
tiles, pages (IFDs), SubIFDs, higher-order series, and pyramidal levels.

Image data can be written to TIFF, BigTIFF, OME-TIFF, and ImageJ hyperstack
compatible files in multi-page, volumetric, pyramidal, memory-mappable,
tiled, predicted, or compressed form.

Many compression schemes, predictors, and data types are supported via the
imagecodecs library, including LZW, PackBits, Deflate, CCITT, PIXTIFF,
LZMA, LERC, Zstd, JPEG (8 and 12-bit, lossless), JPEG 2000, JPEG XR,
JPEG XL, WebP, PNG, EER, Jetraw, 24-bit floating-point, packed integers,
and horizontal differencing.

Tifffile can also be used to inspect TIFF structures, read image data from
multi-dimensional file sequences, write fsspec ReferenceFileSystem for
TIFF files and image file sequences, patch TIFF tag values, and parse
many proprietary metadata formats.

:Author: `Christoph Gohlke <https://www.cgohlke.com>`_
:License: BSD-3-Clause
:Version: 2026.5.2
:DOI: `10.5281/zenodo.6795860 <https://doi.org/10.5281/zenodo.6795860>`_

Quickstart
----------

Install the tifffile package and all dependencies from the
`Python Package Index <https://pypi.org/project/tifffile/>`_::

    python -m pip install -U tifffile[all]

Tifffile is also available in other package repositories such as Anaconda,
Debian, and MSYS2.

The tifffile library is type annotated and documented via docstrings::

    python -c "import tifffile; help(tifffile)"

Tifffile can be used as a console script to inspect and preview TIFF files::

    python -m tifffile --help

See `Examples`_ for using the programming interface.

Source code and support are available on
`GitHub <https://github.com/cgohlke/tifffile>`_.

Support is also provided on the
`image.sc <https://forum.image.sc/tag/tifffile>`_ forum.

Requirements
------------

This revision was tested with the following requirements and dependencies
(other versions may work):

- `CPython <https://www.python.org>`_ 3.12.10, 3.13.13, 3.14.4 64-bit
- `NumPy <https://pypi.org/project/numpy>`_ 2.4.4
- `Imagecodecs <https://pypi.org/project/imagecodecs/>`_ 2026.3.6
  (required for encoding or decoding LZW, JPEG, etc. compressed segments)
- `Xarray <https://pypi.org/project/xarray>`_ 2026.4.0
  (required only for reading xarray DataArrays)
- `Matplotlib <https://pypi.org/project/matplotlib/>`_ 3.10.9
  (required for plotting)
- `Lxml <https://pypi.org/project/lxml/>`_ 6.1.0
  (required only for validating and printing XML)
- `Zarr <https://pypi.org/project/zarr/>`_ 3.2.0
  (required only for using Zarr stores)
- `Kerchunk <https://pypi.org/project/kerchunk/>`_ 0.2.10
  (required only for opening ReferenceFileSystem files)

Revisions
---------

2026.5.2

- Change TiffFile.series from list to callable TiffSeries sequence (breaking).
- Remove TiffPageSeries squeeze dual-state (breaking).
- Remove TiffPageSeries.get_shape, get_axes, and get_coords (breaking).
- Remove ZarrTiffStore squeeze parameter (breaking).
- Update ZarrTiffStore to zarr format 3 and multiscales to NGFF 0.5 (breaking).
- Update multiscales zarr format 2 fsspec files to NGFF 0.4 (breaking).
- Remove generic TiffPage coords (breaking).
- Change dims and sizes to use single-char axis codes (breaking).
- Add zarr format 3 compatible Tiff codec.
- Add asxarray methods to TiffFile, TiffPage, TiffPageSeries (requires xarray).
- Add geotiff kind of TiffPageSeries.
- Add mpp and coord_offsets/scales/units properties to TiffPageSeries.
- Add attrs property to TiffPage and TiffPageSeries.
- Add kind and squeeze parameters to memmap.
- Add kind parameter to imwrite and TiffFile; deprecate ome, imagej, shaped.
- Add return_as parameter to imread; deprecate aszarr.
- Fix writing TIFF trees (#326).
- Fix wrong TiffTagRegistry entries (#323).
- Implement TiffPageSeries.coords property.
- Deprecate kwargs to FileSequence.asarray; use imreadargs.
- Require zarr>=3.2.0 for zarr support.
- Drop support for numpy 2.0 (SPEC0, #324).

2026.4.11

- Add option to write zarr format 3 fsspec reference file system.
- Support reading TIFF with embedded C2PA manifest.
- Sync API of imagecodecs fallback implementations (#320).
- Do not use defusedxml.
- Drop support for Python 3.11.

2026.3.3

- Do not convert TVIPS pixel sizes to m (#319).
- Support writing packed integers with imagecodecs > 2026.1.14.
- Support reading ccitt compressed images with imagecodecs > 2026.1.14.

2026.2.24

- Remove deprecated TiffPages.pages and FileSequence.files (breaking).
- Remove stripnull, stripascii, and bytestr functions (breaking).
- Rewrite command line interfaces (breaking).
- Support Experimenter and Project elements in OmeXml.
- Refactor TiffPages.
- Fix code review issues.

2026.2.20

- Fix rounding of high resolutions (#318).
- Fix code review issues.

2026.2.16

- Optimize reading multi-file pyramidal OME TIFF files.

2026.2.15

- Support reading multi-file pyramidal OME TIFF files (image.sc/t/119259).

2026.1.28

- Deprecate colormaped parameter in imagej_description (use colormapped).
- Fix code review issues.

2026.1.14

- …

Refer to the CHANGES file for older revisions.

Notes
-----

TIFF, the Tagged Image File Format, was created by the Aldus Corporation and
Adobe Systems Incorporated.

Tifffile supports a large subset of the TIFF6 specification, mainly 1-32,
and 64-bit integer, 16, 32, and 64-bit float, grayscale and multi-sample
images.
Specifically, OJPEG compression, chroma subsampling without JPEG compression,
color space transformations, samples with differing types, or IPTC, ICC,
and XMP metadata are not implemented.

Besides classic TIFF, tifffile supports several TIFF-like formats that do not
strictly adhere to the TIFF6 specification. Some formats extend TIFF
capabilities in various ways, including exceeding the 4 GB limit,
handling multi-dimensional data, or working around format constraints:

- **BigTIFF** is identified by version number 43 and uses different file
  header, IFD, and tag structures with 64-bit offsets. The format also adds
  64-bit data types. Tifffile can read and write BigTIFF files.
- **ImageJ hyperstacks** store all image data, which may exceed 4 GB,
  contiguously after the first IFD. Files > 4 GB contain one IFD only.
  The size and shape of the up to 6-dimensional image data can be determined
  from the ImageDescription tag of the first IFD, which is Latin-1 encoded.
  Tifffile can read and write ImageJ hyperstacks.
- **OME-TIFF** files store up to 8-dimensional image data in one or multiple
  TIFF or BigTIFF files. The UTF-8 encoded OME-XML metadata found in the
  ImageDescription tag of the first IFD defines the position of TIFF IFDs in
  the high-dimensional image data. Tifffile can read OME-TIFF files
  and write NumPy arrays to single-file OME-TIFF.
- **Micro-Manager NDTiff** stores multi-dimensional image data in one
  or more classic TIFF files. Metadata contained in a separate NDTiff.index
  binary file defines the position of the TIFF IFDs in the image array.
  Each TIFF file also contains metadata in a non-TIFF binary structure at
  offset 8. Downsampled image data of pyramidal datasets are stored in
  separate folders. Tifffile can read NDTiff files. Version 0 and 1 series,
  tiling, stitching, and multi-resolution pyramids are not supported.
- **Micro-Manager MMStack** stores 6-dimensional image data in one or more
  classic TIFF files. Metadata contained in non-TIFF binary structures and
  JSON strings define the image stack dimensions and the position of the image
  frame data in the file and the image stack. The TIFF structures and metadata
  are often corrupted or wrong. Tifffile can read MMStack files.
- **Carl Zeiss LSM** files store all IFDs below 4 GB and wrap around 32-bit
  StripOffsets pointing to image data above 4 GB. The StripOffsets of each
  series and position require separate unwrapping. The StripByteCounts tag
  contains the number of bytes for the uncompressed data. Tifffile can read
  LSM files of any size.
- **MetaMorph STK** files contain additional image planes stored
  contiguously after the image data of the first page. The total number of
  planes is equal to the count of the UIC2 tag. Tifffile can read STK files.
- **ZIF**, the Zoomable Image File format, is a subspecification of BigTIFF
  with SGI's ImageDepth extension and additional compression schemes.
  Only little-endian, tiled, interleaved, 8-bit per sample images with
  JPEG, PNG, JPEG XR, and JPEG 2000 compression are allowed. Tifffile can
  read and write ZIF files.
- **Hamamatsu NDPI** files use some 64-bit offsets in the file header, IFD,
  and tag structures. Single, LONG typed tag values can exceed 32-bit.
  The high bytes of 64-bit tag values and offsets are stored after IFD
  structures. Tifffile can read NDPI files > 4 GB.
  JPEG compressed segments with dimensions >65530 or missing restart markers
  cannot be decoded with common JPEG libraries. Tifffile works around this
  limitation by separately decoding the MCUs between restart markers, which
  performs poorly. BitsPerSample, SamplesPerPixel, and
  PhotometricInterpretation tags may contain wrong values, which can be
  corrected using the value of tag 65441.
- **Philips TIFF** slides store padded ImageWidth and ImageLength tag values
  for tiled pages. The values can be corrected using the DICOM_PIXEL_SPACING
  attributes of the XML formatted description of the first page. Tile offsets
  and byte counts may be 0. Tifffile can read Philips slides.
- **Ventana/Roche BIF** slides store tiles and metadata in a BigTIFF container.
  Tiles may overlap and require stitching based on the TileJointInfo elements
  in the XMP tag. Volumetric scans are stored using the ImageDepth extension.
  Tifffile can read BIF and decode individual tiles but does not perform
  stitching.
- **ScanImage** optionally allows corrupted non-BigTIFF files > 2 GB.
  The values of StripOffsets and StripByteCounts can be recovered using the
  constant differences of the offsets of IFD and tag values throughout the
  file. Tifffile can read such files if the image data are stored contiguously
  in each page.
- **GeoTIFF sparse** files allow strip or tile offsets and byte counts to be 0.
  Such segments are implicitly set to 0 or the NODATA value on reading.
  Tifffile can read GeoTIFF sparse files.
- **Tifffile shaped** files store the array shape and user-provided metadata
  of multi-dimensional image series in JSON format in the ImageDescription tag
  of the first page of the series. The format allows multiple series,
  SubIFDs, sparse segments with zero offset and byte count, and truncated
  series, where only the first page of a series is present, and the image data
  are stored contiguously. No other software besides Tifffile supports the
  truncated format.

Other libraries for reading, writing, inspecting, or manipulating scientific
TIFF files from Python are
`bioio <https://github.com/bioio-devs/bioio>`_,
`aicsimageio <https://github.com/AllenCellModeling/aicsimageio>`_,
`apeer-ometiff-library
<https://github.com/apeer-micro/apeer-ometiff-library>`_,
`bigtiff <https://pypi.org/project/bigtiff>`_,
`fabio.TiffIO <https://github.com/silx-kit/fabio>`_,
`GDAL <https://github.com/OSGeo/gdal/>`_,
`imread <https://github.com/luispedro/imread>`_,
`large_image <https://github.com/girder/large_image>`_,
`openslide-python <https://github.com/openslide/openslide-python>`_,
`opentile <https://github.com/imi-bigpicture/opentile>`_,
`pylibtiff <https://github.com/pearu/pylibtiff>`_,
`pylsm <https://launchpad.net/pylsm>`_,
`pymimage <https://github.com/ardoi/pymimage>`_,
`python-bioformats <https://github.com/CellProfiler/python-bioformats>`_,
`pytiff <https://github.com/FZJ-INM1-BDA/pytiff>`_,
`scanimagetiffreader-python
<https://gitlab.com/vidriotech/scanimagetiffreader-python>`_,
`SimpleITK <https://github.com/SimpleITK/SimpleITK>`_,
`slideio <https://gitlab.com/bioslide/slideio>`_,
`tiffslide <https://github.com/bayer-science-for-a-better-life/tiffslide>`_,
`tifftools <https://github.com/DigitalSlideArchive/tifftools>`_,
`tyf <https://github.com/Moustikitos/tyf>`_,
`xtiff <https://github.com/BodenmillerGroup/xtiff>`_, and
`ndtiff <https://github.com/micro-manager/NDTiffStorage>`_.

References
----------

- TIFF 6.0 Specification and Supplements. Adobe Systems Incorporated.
  https://www.adobe.io/open/standards/TIFF.html
  https://download.osgeo.org/libtiff/doc/
- TIFF File Format FAQ. https://www.awaresystems.be/imaging/tiff/faq.html
- The BigTIFF File Format.
  https://www.awaresystems.be/imaging/tiff/bigtiff.html
- MetaMorph Stack (STK) Image File Format.
  http://mdc.custhelp.com/app/answers/detail/a_id/18862
- Image File Format Description LSM 5/7 Release 6.0 (ZEN 2010).
  Carl Zeiss MicroImaging GmbH. BioSciences. May 10, 2011
- The OME-TIFF format.
  https://docs.openmicroscopy.org/ome-model/latest/
- UltraQuant(r) Version 6.0 for Windows Start-Up Guide.
  http://www.ultralum.com/images%20ultralum/pdf/UQStart%20Up%20Guide.pdf
- Micro-Manager File Formats.
  https://micro-manager.org/wiki/Micro-Manager_File_Formats
- ScanImage BigTiff Specification.
  https://docs.scanimage.org/Appendix/ScanImage+BigTiff+Specification.html
- ZIF, the Zoomable Image File format. https://zif.photo/
- GeoTIFF File Format. https://gdal.org/drivers/raster/gtiff.html
- Cloud optimized GeoTIFF.
  https://github.com/cogeotiff/cog-spec/blob/master/spec.md
- Tags for TIFF and Related Specifications. Digital Preservation.
  https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
- CIPA DC-008-2016: Exchangeable image file format for digital still cameras:
  Exif Version 2.31.
  http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf
- The EER (Electron Event Representation) file format.
  https://github.com/fei-company/EerReaderLib
- Digital Negative (DNG) Specification. Version 1.7.1.0, September 2023.
  https://helpx.adobe.com/content/dam/help/en/photoshop/pdf/DNG_Spec_1_7_1_0.pdf
- Roche Digital Pathology. BIF image file format for digital pathology.
  https://diagnostics.roche.com/content/dam/diagnostics/Blueprint/en/pdf/rmd/Roche-Digital-Pathology-BIF-Whitepaper.pdf
- Astro-TIFF specification. https://astro-tiff.sourceforge.io/
- Aperio Technologies, Inc. Digital Slides and Third-Party Data Interchange.
  Aperio_Digital_Slides_and_Third-party_data_interchange.pdf
- PerkinElmer image format.
  https://downloads.openmicroscopy.org/images/Vectra-QPTIFF/perkinelmer/PKI_Image%20Format.docx
- NDTiffStorage. https://github.com/micro-manager/NDTiffStorage
- Argos AVS File Format.
  https://github.com/user-attachments/files/15580286/ARGOS.AVS.File.Format.pdf

Examples
--------

Write a NumPy array to a single-page RGB TIFF file:

>>> import numpy
>>> data = numpy.random.randint(0, 255, (256, 256, 3), 'uint8')
>>> imwrite('temp.tif', data, photometric='rgb')

Read the image from the TIFF file as NumPy array:

>>> image = imread('temp.tif')
>>> image.shape
(256, 256, 3)

Use the ``photometric`` and ``planarconfig`` arguments to write a 3x3x3 NumPy
array to an interleaved RGB, a planar RGB, or a 3-page grayscale TIFF:

>>> data = numpy.random.randint(0, 255, (3, 3, 3), 'uint8')
>>> imwrite('temp.tif', data, photometric='rgb')
>>> imwrite('temp.tif', data, photometric='rgb', planarconfig='separate')
>>> imwrite('temp.tif', data, photometric='minisblack')

Use the ``extrasamples`` argument to specify how extra components are
interpreted, for example, for an RGBA image with unassociated alpha channel:

>>> data = numpy.random.randint(0, 255, (256, 256, 4), 'uint8')
>>> imwrite('temp.tif', data, photometric='rgb', extrasamples=['unassalpha'])

Write a 3-dimensional NumPy array to a multi-page, 16-bit grayscale TIFF file:

>>> data = numpy.random.randint(0, 2**12, (64, 301, 219), 'uint16')
>>> imwrite('temp.tif', data, photometric='minisblack')

Read the whole image stack from the multi-page TIFF file as NumPy array:

>>> image_stack = imread('temp.tif')
>>> image_stack.shape
(64, 301, 219)
>>> image_stack.dtype
dtype('uint16')

Read the image from the first page in the TIFF file as NumPy array:

>>> image = imread('temp.tif', key=0)
>>> image.shape
(301, 219)

Read images from a selected range of pages:

>>> images = imread('temp.tif', key=range(4, 40, 2))
>>> images.shape
(18, 301, 219)

Iterate over all pages in the TIFF file and successively read images:

>>> with TiffFile('temp.tif') as tif:
...     for page in tif.pages:
...         image = page.asarray()
...

Get information about the image stack in the TIFF file without reading
any image data:

>>> tif = TiffFile('temp.tif')
>>> len(tif.pages)  # number of pages in the file
64
>>> page = tif.pages[0]  # get shape and dtype of image in first page
>>> page.shape
(301, 219)
>>> page.dtype
dtype('uint16')
>>> page.axes
'YX'
>>> series = tif.series[0]  # get shape and dtype of first image series
>>> series.shape
(64, 301, 219)
>>> series.dtype
dtype('uint16')
>>> series.axes
'QYX'
>>> tif.close()

Inspect the "XResolution" tag from the first page in the TIFF file:

>>> with TiffFile('temp.tif') as tif:
...     tag = tif.pages[0].tags['XResolution']
...
>>> tag.value
(1, 1)
>>> tag.name
'XResolution'
>>> tag.code
282
>>> tag.count
1
>>> tag.dtype
<DATATYPE.RATIONAL: 5>

Iterate over all tags in the TIFF file:

>>> with TiffFile('temp.tif') as tif:
...     for page in tif.pages:
...         for tag in page.tags:
...             tag_name, tag_value = tag.name, tag.value
...

Overwrite the value of an existing tag, for example, XResolution:

>>> with TiffFile('temp.tif', mode='r+') as tif:
...     _ = tif.pages[0].tags['XResolution'].overwrite((96000, 1000))
...

Write a 5-dimensional floating-point array using BigTIFF format, separate
color components, tiling, Zlib compression level 8, horizontal differencing
predictor, and additional metadata:

>>> data = numpy.random.rand(2, 5, 3, 301, 219).astype('float32')
>>> imwrite(
...     'temp.tif',
...     data,
...     bigtiff=True,
...     photometric='rgb',
...     planarconfig='separate',
...     tile=(32, 32),
...     compression='zlib',
...     compressionargs={'level': 8},
...     predictor=True,
...     metadata={'axes': 'TZCYX'},
... )

Write a 10 fps time series of volumes with xyz voxel size 2.6755x2.6755x3.9474
micron^3 to an ImageJ hyperstack formatted TIFF file:

>>> volume = numpy.random.randn(6, 57, 256, 256).astype('float32')
>>> image_labels = [f'{i}' for i in range(volume.shape[0] * volume.shape[1])]
>>> imwrite(
...     'temp.tif',
...     volume,
...     kind='imagej',
...     resolution=(1.0 / 2.6755, 1.0 / 2.6755),
...     metadata={
...         'spacing': 3.947368,
...         'unit': 'um',
...         'finterval': 1 / 10,
...         'fps': 10.0,
...         'axes': 'TZYX',
...         'Labels': image_labels,
...     },
... )

Read the volume and metadata from the ImageJ hyperstack file
as xarray DataArray:

>>> with TiffFile('temp.tif') as tif:
...     volume = tif.asxarray()
...     imagej_metadata = tif.imagej_metadata
...
>>> volume
<xarray.DataArray '' (T: 6, Z: 57, Y: 256, X: 256)> Size: 90MB
array([[[[...]]]],
        shape=(6, 57, 256, 256), dtype=float32)
Coordinates:
    * T        (T) float64 48B 0.0 0.1 0.2 0.3 0.4 0.5
    * Z        (Z) float64 456B 0.0 3.947 ... 221.1
    * Y        (Y) float32 1kB 0.0 2.675 ... 682.3
    * X        (X) float32 1kB 0.0 2.675 ... 682.3
Attributes:
    photometric:    minisblack
    mode:           grayscale
...
>>> imagej_metadata['slices']
57
>>> imagej_metadata['frames']
6

Memory-map the contiguous image data in the ImageJ hyperstack file:

>>> memmap_volume = memmap('temp.tif')
>>> memmap_volume.shape
(6, 57, 256, 256)
>>> del memmap_volume

Create a TIFF file containing an empty image and write to the memory-mapped
NumPy array (note: this does not work with compression or tiling):

>>> memmap_image = memmap(
...     'temp.tif', shape=(256, 256, 3), dtype='float32', photometric='rgb'
... )
>>> type(memmap_image)
<class 'numpy.memmap'>
>>> memmap_image[255, 255, 1] = 1.0
>>> memmap_image.flush()
>>> del memmap_image

Write two NumPy arrays to a multi-series TIFF file (note: other TIFF readers
will not recognize the two series; use the OME-TIFF format for better
interoperability):

>>> series0 = numpy.random.randint(0, 255, (32, 32, 3), 'uint8')
>>> series1 = numpy.random.randint(0, 255, (4, 256, 256), 'uint16')
>>> with TiffWriter('temp.tif') as tif:
...     tif.write(series0, photometric='rgb')
...     tif.write(series1, photometric='minisblack')
...

Read the second image series from the TIFF file:

>>> series1 = imread('temp.tif', series=1)
>>> series1.shape
(4, 256, 256)

Successively write the frames of one contiguous series to a TIFF file:

>>> data = numpy.random.randint(0, 255, (30, 301, 219), 'uint8')
>>> with TiffWriter('temp.tif') as tif:
...     for frame in data:
...         tif.write(frame, contiguous=True)
...

Append an image series to the existing TIFF file (note: this does not work
with ImageJ hyperstack or OME-TIFF files):

>>> data = numpy.random.randint(0, 255, (301, 219, 3), 'uint8')
>>> imwrite('temp.tif', data, photometric='rgb', append=True)

Create a TIFF file from a generator of tiles:

>>> data = numpy.random.randint(0, 2**12, (31, 33, 3), 'uint16')
>>> def tiles(data, tileshape):
...     for y in range(0, data.shape[0], tileshape[0]):
...         for x in range(0, data.shape[1], tileshape[1]):
...             yield data[y : y + tileshape[0], x : x + tileshape[1]]
...
>>> imwrite(
...     'temp.tif',
...     tiles(data, (16, 16)),
...     tile=(16, 16),
...     shape=data.shape,
...     dtype=data.dtype,
...     photometric='rgb',
... )

Write a multi-dimensional, multi-resolution (pyramidal), multi-series OME-TIFF
file with optional metadata. Sub-resolution images are written to SubIFDs.
Limit parallel encoding to 2 threads. Write a thumbnail image as a separate
image series:

>>> data = numpy.random.randint(0, 255, (8, 2, 512, 512, 3), 'uint8')
>>> subresolutions = 2
>>> pixelsize = 0.29  # micrometer
>>> with TiffWriter('temp.ome.tif', bigtiff=True) as tif:
...     metadata = {
...         'axes': 'TCYXS',
...         'SignificantBits': 8,
...         'TimeIncrement': 0.1,
...         'TimeIncrementUnit': 's',
...         'PhysicalSizeX': pixelsize,
...         'PhysicalSizeXUnit': 'µm',
...         'PhysicalSizeY': pixelsize,
...         'PhysicalSizeYUnit': 'µm',
...         'Channel': {'Name': ['Channel 1', 'Channel 2']},
...         'Plane': {'PositionX': [0.0] * 16, 'PositionXUnit': ['µm'] * 16},
...         'Description': 'A multi-dimensional, multi-resolution image',
...         'MapAnnotation': {  # for OMERO
...             'Namespace': 'openmicroscopy.org/PyramidResolution',
...             '1': '256 256',
...             '2': '128 128',
...         },
...     }
...     options = dict(
...         photometric='rgb',
...         tile=(128, 128),
...         compression='jpeg',
...         resolutionunit='CENTIMETER',
...         maxworkers=2,
...     )
...     tif.write(
...         data,
...         subifds=subresolutions,
...         resolution=(1e4 / pixelsize, 1e4 / pixelsize),
...         metadata=metadata,
...         **options,
...     )
...     # write pyramid levels to the two subifds
...     # in production use resampling to generate sub-resolution images
...     for level in range(subresolutions):
...         mag = 2 ** (level + 1)
...         tif.write(
...             data[..., ::mag, ::mag, :],
...             subfiletype=1,  # FILETYPE.REDUCEDIMAGE
...             resolution=(1e4 / mag / pixelsize, 1e4 / mag / pixelsize),
...             **options,
...         )
...     # add a thumbnail image as a separate series
...     # it is recognized by QuPath as an associated image
...     thumbnail = (data[0, 0, ::8, ::8] >> 2).astype('uint8')
...     tif.write(thumbnail, metadata={'Name': 'thumbnail'})
...

Access image levels in the pyramidal OME-TIFF file:

>>> baseimage = imread('temp.ome.tif')
>>> second_level = imread('temp.ome.tif', series=0, level=1)
>>> with TiffFile('temp.ome.tif') as tif:
...     series = tif.series[0]
...     assert series.kind == 'ome'
...     assert series.sizes == {'T': 8, 'C': 2, 'Y': 512, 'X': 512, 'S': 3}
...     baseimage = series.asarray()
...     second_level = series.levels[1].asarray()
...     number_levels = len(series.levels)  # includes base level
...

Read image data from a generic kind of series, ignoring OME metadata:

>>> with TiffFile('temp.ome.tif') as tif:
...     series = tif.series(kind='generic')[0]
...     assert series.kind == 'generic'
...     assert series.sizes == {'I': 16, 'Y': 512, 'X': 512, 'S': 3}
...     image = series.asarray()
...

Iterate over and decode single JPEG compressed tiles in the TIFF file:

>>> with TiffFile('temp.ome.tif') as tif:
...     fh = tif.filehandle
...     for page in tif.pages:
...         for index, (offset, bytecount) in enumerate(
...             zip(page.dataoffsets, page.databytecounts)
...         ):
...             _ = fh.seek(offset)
...             data = fh.read(bytecount)
...             tile, indices, shape = page.decode(
...                 data, index, jpegtables=page.jpegtables
...             )
...

Use Zarr to read parts of the tiled, pyramidal images in the TIFF file:

>>> import zarr
>>> store = imread('temp.ome.tif', return_as='zarr')
>>> z = zarr.open(store, mode='r')
>>> z
<Group ZarrTiffStore>
>>> z['0']  # base layer
 <Array ZarrTiffStore/0 shape=(8, 2, 512, 512, 3) dtype=uint8>
>>> z['0'][2, 0, 128:384, 256:].shape  # read a tile from the base layer
(256, 256, 3)
>>> store.close()

Load the base layer from the Zarr store as a dask array:

>>> import dask.array
>>> store = imread('temp.ome.tif', return_as='zarr')
>>> dask.array.from_zarr(store, '0')
dask.array<...shape=(8, 2, 512, 512, 3)...chunksize=(1, 1, 128, 128, 3)...
>>> store.close()

Write the Zarr store to a fsspec ReferenceFileSystem in JSON format:

>>> store = imread('temp.ome.tif', return_as='zarr')
>>> store.write_fsspec('temp.ome.tif.json', url='file://', zarr_format=2)
>>> store.close()

Open the fsspec ReferenceFileSystem as a Zarr group and read the first layer:

>>> from kerchunk.utils import refs_as_store
>>> import imagecodecs.numcodecs
>>> imagecodecs.numcodecs.register_codecs(verbose=False)
>>> z = zarr.open(refs_as_store('temp.ome.tif.json'), mode='r')
>>> z['1']  # first layer
<Array <FsspecStore(ReferenceFileSystem, /)>/1 shape=(8, 2, 256, 256, 3) ...>

Create an OME-TIFF file containing an empty, tiled image series and write
to it via the Zarr interface (note: this does not work with compression):

>>> imwrite(
...     'temp2.ome.tif',
...     shape=(8, 800, 600),
...     dtype='uint16',
...     photometric='minisblack',
...     tile=(128, 128),
...     metadata={'axes': 'CYX'},
... )
>>> store = imread('temp2.ome.tif', mode='r+', return_as='zarr')
>>> z = zarr.open(store, mode='r+')
>>> z
<Array ZarrTiffStore shape=(8, 800, 600) dtype=uint16>
>>> z[3, 100:200, 200:300:2] = 1024
>>> store.close()

Read images from a sequence of TIFF files as NumPy array using two I/O worker
threads:

>>> imwrite('temp_C001T001.tif', numpy.random.rand(64, 64))
>>> imwrite('temp_C001T002.tif', numpy.random.rand(64, 64))
>>> image_sequence = imread(
...     ['temp_C001T001.tif', 'temp_C001T002.tif'], ioworkers=2, maxworkers=1
... )
>>> image_sequence.shape
(2, 64, 64)
>>> image_sequence.dtype
dtype('float64')

Read an image stack from a series of TIFF files with a file name pattern
as NumPy or Zarr arrays:

>>> image_sequence = TiffSequence('temp_C0*.tif', pattern=r'_(C)(\d+)(T)(\d+)')
>>> image_sequence.shape
(1, 2)
>>> image_sequence.axes
'CT'
>>> data = image_sequence.asarray()
>>> data.shape
(1, 2, 64, 64)
>>> store = image_sequence.aszarr()
>>> zarr.open(store, mode='r', ioworkers=2, maxworkers=1)
<Array ZarrFileSequenceStore shape=(1, 2, 64, 64) dtype=float64>
>>> image_sequence.close()

Write the Zarr store to a fsspec ReferenceFileSystem in JSON format:

>>> store = image_sequence.aszarr()
>>> store.write_fsspec('temp.json', url='file://')

Open the fsspec ReferenceFileSystem as a Zarr array:

>>> from kerchunk.utils import refs_as_store
>>> import tifffile.numcodecs
>>> tifffile.numcodecs.register_codec()
>>> zarr.open(refs_as_store('temp.json'), mode='r')
<Array <FsspecStore(ReferenceFileSystem, /)> shape=(1, 2, 64, 64) ...>

Inspect the TIFF file from the command line::

    $ python -m tifffile temp.ome.tif

    )annotationsz2026.5.2)L	CHUNKMODECOMPRESSIONDATATYPEEXTRASAMPLEFILETYPE	FILLORDER	OFILETYPEORIENTATIONPHOTOMETRICPLANARCONFIG	PREDICTORRESUNITSAMPLEFORMATTIFF_TIFF	FileCache
FileHandleFileSequenceNullContextOmeXmlOmeXmlErrorStoredShapeTiffFileTiffFileError
TiffFormat	TiffFrameTiffPageTiffPageSeries	TiffPages
TiffReaderTiffSequence
TiffSeriesTiffTagTiffTagRegistryTiffTags
TiffWriterTiledSequenceTimer__version__askopenfilenameastypecreate_outputenumargenumstrformat_sizehexdumpimagej_descriptionimagej_metadata_tagimreadimshowimwriteloggerlsm2binmatlabstr2pymemmapnatural_sortednullfuncparse_filenamesparse_kwargspformatproductrationalread_gdal_structural_metadataread_micromanager_metadataread_ndtiff_indexread_scanimage_metadata	repeat_ndreshape_axes
reshape_ndstrptimetiff2fsspectiffcommenttranspose_axesupdate_kwargsvalidate_jhovexml2dictN)CallableIterableMappingSequence)ThreadPoolExecutor)datetime)	timedelta)Fraction)cached_property   _imagecodecs)IOTYPE_CHECKINGClassVarcastfinaloverloadoverride)
Collection	ContainerIterator)TracebackType)AnyLiteralSelf)	ArrayLike	DTypeLikeNDArray	DataArray	ByteOrderc                     [         S   $ )N><)rh        b/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/tifffile/tifffile.pyro   ro     s    " "ru   
OutputTypec                 L    [         [        [           -  [        [           -  S -  $ N)strr\   bytesrl   rg   rt   ru   rv   rw   rw     s    #5	/GCL047 7ru   TagTuplec                 h    [         [        [        -  [        [        -  [        S -  [        [        4   $ ry   )tupleintrz   rg   boolrt   ru   rv   r|   r|     s#    cCisC$JTAB Bru   DecodeResultc                     [         [        [           S -  [         [        [        [        [        [        4   [         [        [        [        [        4   4   $ ry   )r~   rl   rg   r   rt   ru   rv   r   r     sC    ECL4	#sCc
!"	#sC
 ru   dict[str, Any]METADATA_DEFAULT)!	selectionkeyserieskindlevelsqueeze
maxworkers
buffersizemodenameoffsetsizepattern	axesorder
categoriesr4   
imreadargssort	container
chunkshape
chunkdtype	axestiled	ioworkers	chunkmode	fillvaluezattrsmultiscalesomexmlsuperresoutout_inplace
_multifile
_useframesc       "            g ry   rt   $filesr   	return_asr   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargss$                                       rv   r4   r4     s    \ ru   c       "            g ry   rt   r   s$                                       rv   r4   r4     s    \ -0ru   )"r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c       "            g ry   rt   r   s$                                       rv   r4   r4     s    \ ru   F)#r   r   aszarrr   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c       #        P   US:X  a  SnUS:H  n%U%(       a  Ub  Sn&[        U&5      eU=(       d    USLnU%(       a  U(       a  Sn&[        U&5      e[        U$/S U$ 5       Q76 n'Uc-  U$(       a&  SS	R                  S
 U$ 5       5      -   n&[	        U&5      eSn(UGc  [        U [        5      (       a$  SU ;   d  SU ;   a  U n([        R                  " U 5      n U (       d  Sn&[        U&5      e[        U [        5      (       a)  [        U [        5      (       d  [        U 5      S:X  a  U S   n [        U [        5      (       d  [        U [        5      (       d  [        U 4UUUUUUU"U#S.U'D6 n)U%(       aC  Ub"  [        U[        5      (       d  Sn&[        U&5      eU)R                  UUUUUU	U
S9sSSS5        $ U(       ac  Ub"  [        U[        5      (       d  Sn&[        U&5      eU)R                  UUUUUU	U
UUUUS9n*Uc  U*sSSS5        $ SSKJn+  U+" U*UU S9sSSS5        $ U)R!                  UUUUUU	U
U S9sSSS5        $ O[#        U S5      (       a  Sn&[        U&5      e[%        S UUUUUU	U
UU"U#S.
U'DU$D6n,U(b  U(n U%(       a  Sn&[        U&5      e['        U 4UUUUUS.[%        US9D6 n-U(       a?  U-R                  " S UUUUUUUS.U,D6n*Uc  U*sSSS5        $ SSKJn+  U+" U*UU S9sSSS5        $ U-R                   " S UUUUU!U S.U,D6sSSS5        $ ! , (       d  f       N= f! , (       d  f       g= f)!a  Return image from TIFF file(s) as NumPy array or Zarr store.

The first image series in the file(s) is returned by default.

Parameters:
    files:
        File name, seekable binary stream, glob pattern, or sequence of
        file names. May be ``None`` if ``container`` is specified.
    selection:
        Subset of image to be extracted.
        If not ``None``, a Zarr array is created internally, indexed with
        the ``selection`` value, and returned as a NumPy array (not a
        store).
        Only segments that are part of the selection will be read from
        file. Refer to the Zarr documentation for valid selections.
        Depending on selection size, image size, and storage properties,
        it may be more efficient to read the whole image from file and
        then index it.
    return_as:
        Return type of image data.
        If ``'xarray'``, return as :py:class:`xarray.DataArray`.
        Cannot be combined with ``selection``.
        Not supported for file sequences.
        If ``'zarr'``, return as Zarr store.
        When ``selection`` is not ``None``, a Zarr store is used
        internally regardless of this value, but a NumPy array is
        returned.
        If ``'numpy'`` or ``None`` (default), return as NumPy array.
    aszarr:
        Deprecated: use ``return_as='zarr'``.
    mode, name, offset, size, superres, omexml, _multifile, _useframes:
        Passed to :py:class:`TiffFile`.
    key, series, kind, level, squeeze, maxworkers, buffersize:
        Passed to :py:meth:`TiffFile.asarray`,
        :py:meth:`TiffFile.asxarray`, or :py:meth:`TiffFile.aszarr`.
        When ``return_as='zarr'`` or ``return_as='xarray'`` and reading a
        single file, ``key`` must be ``None`` or an integer.
    imread, container, sort, pattern, axesorder, axestiled, categories:
        Passed to :py:class:`FileSequence`.
    chunkmode, fillvalue, zattrs, multiscales:
        Passed to :py:class:`ZarrTiffStore`
        or :py:class:`ZarrFileSequenceStore`.
    chunkshape, chunkdtype, ioworkers:
        Passed to :py:meth:`FileSequence.asarray` or
        :py:class:`ZarrFileSequenceStore`.
    out_inplace:
        Passed to :py:meth:`FileSequence.asarray`.
    out:
        Passed to :py:meth:`TiffFile.asarray`,
        :py:meth:`FileSequence.asarray`, or :py:func:`zarr_selection`.
    imreadargs:
        Additional arguments passed to :py:attr:`FileSequence.imread`.
    **kwargs:
        Additional arguments passed to :py:class:`TiffFile` or
        :py:attr:`FileSequence.imread`.

Returns:
    Images from specified files, series, or pages.
    Zarr store instances must be closed after use.
    See :py:meth:`TiffPage.asarray` for operations that are applied
    (or not) to the image data stored in the file.

Raises:
    ValueError:
        No files matching the pattern were found.
        Binary IO streams are not supported with ``container``.
        ``key`` is not ``None`` or an integer when ``return_as='zarr'``
        or ``return_as='xarray'``.
        ``return_as='xarray'`` and ``aszarr`` are both set.
    NotImplementedError:
        ``return_as='xarray'`` and a file sequence is used.
        ``return_as='xarray'`` and ``selection`` are both specified.
    TypeError:
        Unexpected keyword arguments were passed.

zarrTxarrayNz*asxarray with selection is not implementedz*asxarray and aszarr are mutually exclusivec              3  :   #    U  H  oS S S:X  d  M  Uv   M     g 7f)N   is_rt   ).0ks     rv   	<genexpr>imread.<locals>.<genexpr>  s     %JARa5E>aas   	z*imread() got unexpected keyword arguments , c              3  .   #    U  H  nS U S 3v   M     g7f)'Nrt   )r   r   s     rv   r   r     s      G
"(3auAJ&   *?no files foundrY   r   )r   r   r   r   r   r   r   r   z.asxarray requires key to be None or an integerr   r   r   r   r   r   z,aszarr requires key to be None or an integer)r   r   r   r   r   r   r   r   r   r   r   )zarr_selectionr   )r   r   r   r   r   r   r   r   readzBinaryIO not supported)
r   r   r   r   r   r   r   r   r   r   z,asxarray is not supported for file sequences)r   r   r   r   r   r4   )r   r   r   r   r   r   r   )r   r   r   r   r   r   rt   )NotImplementedError
ValueErrorr>   join	TypeError
isinstancerz   globrS   lenr   r   asxarrayr   r   r   asarrayhasattrkwargs_notnoner"   ).r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   msgis_flagsglob_patterntifstorer   imread_kwargsimseqs.                                                 rv   r4   r4   9  s   x FH$HI):!#&&.	-FF:oFK%J%JKH~&:TYY G
"(G
 >
 
 n#LeS!!se|se| LIIe$E"CS/! uh''uc**E
a!HEeS!!E8)D)D!%%  z#s/C/CN(o-<<%!# '#-#- ( ! 2 z#s/C/CL(o-JJ%!# '#-#-"+"+%$/ ' E !($W Z 5)%D_ b {{!#)) # 	c  *Ez 
		&o"   M <!#&&	

 
'
 
LL 	##%%##	  	E  +
 
. -!%<3
 
4 }} 
!!#
 
5
 
o n
 
s8    AL+A	L>LL&LL$L
L
L%)&r   bigtiff	byteorderr   imagejomeshapedappendshapedtypephotometricplanarconfigextrasamples
volumetrictilerowsperstripbitspersamplecompressioncompressionargs	predictorsubsampling
jpegtables
iccprofilecolormapdescriptionrU   
resolutionresolutionunitsubfiletypesoftwaremetadata	extratags
contiguoustruncatealignr   r   returnoffsetc      &           Uc\  U
b  Uc  Sn([        U(5      e[        R                  " U5      n[        U
5      n
[	        U
5      UR
                  -  n)Uc  UR                  nO& UR                  n)Uc  UR                  R                  nUc9  U)S:  =(       a-    US:H  =(       d    U(       + =(       a    U#(       + =(       a    US;   n[        U UUUU	UUUUS9	 n*U*R                  " U40 SU
_S	U_S
U_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU _SU!_S U"_S!U#_S"U$_S#U%_S$U&_S%U'_6sSSS5        $ ! [         a    Sn) Nf = f! , (       d  f       g= f)&a/  Write array or image data to TIFF file.

A BigTIFF file is written if the data size is larger than 4 GB less
32 MB for metadata, and ``bigtiff`` is not ``False``, and ``imagej``,
``truncate`` and ``compression`` are not enabled.
Unless ``byteorder`` is specified, the TIFF file byte order is determined
from the dtype of ``data`` or the ``dtype`` argument.

Parameters:
    file:
        Passed to :py:class:`TiffWriter`.
    data:
        Image data to write.
        May be a NumPy array, an iterator of arrays, an iterator of
        encoded bytes, an iterator of ``(bytes, bytecount)`` tuples,
        or ``None`` to write an empty file.
        If ``None``, ``shape`` and ``dtype`` are required.
    shape:
        Shape of empty array when ``data`` is ``None``.
        Otherwise passed to :py:meth:`TiffWriter.write`.
    dtype:
        Data type of empty array when ``data`` is ``None``.
        Otherwise passed to :py:meth:`TiffWriter.write`.
    mode, append, byteorder, bigtiff, kind, imagej, ome, shaped:
        Passed to :py:class:`TiffWriter`.
    photometric, planarconfig, extrasamples, volumetric, tile,        rowsperstrip, bitspersample, compression, compressionargs, predictor,        subsampling, jpegtables, iccprofile, colormap, description, datetime,        resolution, resolutionunit, subfiletype, software,        metadata, extratags, maxworkers, buffersize,         contiguous, truncate, align:
        Passed to :py:meth:`TiffWriter.write`.
    returnoffset:
        Return offset and number of bytes of memory-mappable image data
        in file.

Returns:
    If ``returnoffset`` is ``True`` and the image data in the file are
    memory-mappable, a tuple of ``(offset, bytecount)``.
    Otherwise ``None``.

Raises:
    ValueError:
        ``data`` is ``None`` and ``shape`` or ``dtype`` is not provided.

Nz,missing required 'shape' or 'dtype' argumentr   l      | r   >   NNONENonenoner   rY   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   rU   r   r   r   r   r   r   r   r   r   r   r   r   )r   numpyr   r~   r@   itemsizer   nbytesAttributeErrorr'   write)+filedatar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU   r   r   r   r   r   r   r   r   r   r   r   r   r   datasizer   s+                                              rv   r6   r6   T  sR   F |=EM@CS/!E"e5>ENN2I	{{H  JJ00	 }$ DX%/0DD CC	 	 


 
yy 
 
  
 $	 

 & 
 & 
 " 
  
 & 
 ( 
 $ 
 , 
   
 $ 
 " 
  "! 
" # 
$ $% 
& ' 
( ") 
* *+ 
, $- 
. / 
0 1 
2  3 
4 "5 
6 7 
8 9 
: "; 
< "= 
> &? 


 

  	H	

 

s   !%E A+EEE
E(r+)r   r   pager   r   r   r   r   c         	     p   [         R                  " U 5      n Ub  [        U5      nUbz  Ubw  [        R                  " U5      nSU	;   a  UR                  U	S   5      nU	R                  SUUU[        R                  SS9  [        U 40 U	D6n
U
c  Sn[        U5      eU
S   nSnGOX[        U 40 U	D6 nUc  Uc  SnUc  SnUR                  U5      U   nU(       d  Uc#  UR                  S:w  a  UR                  USS	9U   nUR                  U   nUR                  c  Sn[        U5      eUR                   nUR                  nUR                  nOzUR"                  U   nUR$                  (       d  Sn[        U5      eUR&                  S   nUb  U(       a  UR                   OUR(                  nUR                  nUc  Sn[        U5      e[        R                  " UR*                  UR,                  -   5      nSSS5        Ub  Uc  Sn[        U5      e[        R.                  " XUWUS
5      $ ! , (       d  f       N;= f)a  Return memory-mapped NumPy array of image data stored in TIFF file.

Memory-mapping requires the image data to be stored in native byte order,
without tiling, compression, predictors, etc.
If both ``shape`` and ``dtype`` are provided, a new TIFF file is created
(overwriting or appending depending on the ``append`` keyword argument)
and the image data region is memory-mapped read-write.
Otherwise, the image data of a specified page or series in an existing
file are memory-mapped.
Call ``flush`` to write any changes in the array back to the file.

Parameters:
    filename:
        Name of TIFF file to create or memory-map.
    shape:
        Shape of array to create. Requires ``dtype``.
        If provided together with ``dtype``, a new TIFF file is written.
    dtype:
        Data type of array to create. Requires ``shape``.
    page:
        Index of page whose image data to memory-map.
        If provided, ``series``, ``kind``, and ``level`` are ignored.
    series:
        Index of page series to memory-map (default is 0).
        Ignored if ``page`` is set.
    kind:
        Series format kind, such as ``'ome'`` or ``'imagej'``.
        By default, the format is auto-detected.
        Ignored if ``page`` is set.
    level:
        Index of pyramid level to memory-map (default is 0).
        Ignored if ``page`` is set.
    squeeze:
        Remove length-1 dimensions from the memory-mapped array shape,
        except X and Y.
        If ``False``, preserve all dimensions.
        If ``None`` (default), remove length-1 dimensions except for
        ``'shaped'`` series.
        For single pages, ``None`` is treated as ``True``.
    mode:
        Memory-map file open mode for existing files.
        The default is 'r+' (read-write). Use 'r' for read-only or
        'c' for copy-on-write.
        When creating a new file (``shape`` and ``dtype`` provided), this
        argument is ignored and the file is always opened read-write.
    **kwargs:
        Additional arguments passed to :py:func:`imwrite` when creating
        a new file, or to :py:class:`TiffFile` when reading an existing
        file.

Returns:
    Image data in TIFF file as memory-mapped NumPy array.

Raises:
    ValueError: Image data in TIFF file are not memory-mappable.

Nr   T)r  r   r   r   r   r   z"image data are not memory-mappabler   r  r   r   C)osfspathr~   r   r   newbyteorderupdater   ALLOCATIONGRANULARITYr6   r   r   _get_seriesr   levels
dataoffsetr   pagesis_memmappabledataoffsetsr   r   charr:   )filenamer   r   r  r   r   r   r   r   r   resultr   r   r   s
tiffseriestiffpages                    rv   r:   r:     s1   N yy"HeU.E"& &&vk':;E,, 	 	
 ,V,>6CS/! h)&)S|>F=EOOD)&1w166X3Ed;FCAXXe_
((0>C$S/)"(("((#..99T?..>C$S/)!--a0  7 NN! 
 !=>C$S/)KK

 :;E? *@ }2o<<vucBBG *)s   .EH''
H5c                      \ rS rSrSrSrg)r   i  z-Exception to indicate invalid TIFF structure.rt   N__name__
__module____qualname____firstlineno____doc____static_attributes__rt   ru   rv   r   r     s    7ru   r   c            !         \ rS rSr% SrS\S'    S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S \S!'   S \S"'   S\S#'   S \S$'   S%\S&'   S%\S''   S \S('   S)\S*'   S+S,S+S,S+S,S+S+S-.                   S>S. jjr S?S+S+S+S+S+S,S+S+S+S+S+S+S+S+S+S+S+S+S+S+S+S+S+\S+S,S,S+S+S+S,S/.                                                                 S@S0 jjjrSAS1 jr	SBS2 jr
\SCS3 j5       rSBS4 jrSBS5 jr SD             SES6 jjrSFS7 jr      SGS8 jr\          SHS9 j5       rSIS: jr        SJS; jrSKS< jrS=rg+)Lr'   i  a   Write arrays and image data to TIFF file.

TiffWriter's main purpose is to save multi-dimensional NumPy arrays in
TIFF containers, not to create any possible TIFF format.
Specifically, ExifIFD and GPSIFD tags are not supported.

TiffWriter instances must be closed with :py:meth:`TiffWriter.close`,
which is automatically called when using the 'with' context manager.

TiffWriter instances are not thread-safe. All attributes are read-only.

Parameters:
    file:
        Specifies file to write.
    mode:
        Binary file open mode if ``file`` is a file name.
        The default is 'w', which opens files for writing, truncating
        existing files.
        'x' opens files for exclusive creation, failing on existing files.
        'r+' opens files for updating, enabling ``append``.
    bigtiff:
        Write 64-bit BigTIFF formatted file, which can exceed 4 GB.
        By default, a classic 32-bit TIFF file is written, which is
        limited to 4 GB.
        If ``append`` is ``True``, the format of the existing file is used.
        Using BigTIFF with ``kind='imagej'`` produces a non-conformant
        file and raises a UserWarning.
    byteorder:
        Endianness of TIFF format. One of '<', '>', '=', or '|'.
        The default is the system's native byte order.
    append:
        If ``file`` is an existing standard TIFF file, append image data
        and tags to the file.
        Pass ``'force'`` to append to files containing metadata (such as
        OME-TIFF), which may corrupt the existing metadata.
        Parameters ``bigtiff`` and ``byteorder`` are set from the existing
        file.
        Appending does not scale well with the number of pages already in
        the file and may corrupt specifically formatted TIFF files such as
        OME-TIFF, LSM, STK, ImageJ, or FluoView.
    kind:
        Kind of TIFF file to write.

        If ``'ome'``, write OME-TIFF compatible file.
        By default, the OME-TIFF format is used if the file name extension
        contains '.ome.' and ``description`` is not specified in the first
        call to :py:meth:`TiffWriter.write`.
        The format supports multiple image series up to 9 dimensions.
        The default axes order is TZC(S)YX(S).
        Refer to the OME model for restrictions of this format.

        If ``'imagej'``, write ImageJ hyperstack compatible file.
        This format handles data types uint8, uint16, or float32 and
        shapes up to 6 dimensions in TZCYXS order.
        RGB images (S=3 or S=4) must be ``uint8``.
        ImageJ hyperstacks do not support BigTIFF or compression.
        The ImageJ file format is undocumented.

        If ``'shaped'``, write tifffile "shaped" TIFF file.
        The image shape is stored in JSON format in an ImageDescription
        tag of the first page of a series.
        Suppresses auto-detection of OME-TIFF format from the file name
        extension.
        This is the default format used by tifffile if the file name
        extension does not contain '.ome.' and ``metadata=None`` is not
        passed to :py:meth:`TiffWriter.write`.

        If ``'generic'``, write generic TIFF file without extra metadata.
        Image series written to generic TIFF may not be recoverable.

        If ``None`` (default), ``'shaped'`` is used unless the file name
        extension contains '.ome.', in which case ``'ome'`` is used.
    imagej:
        Deprecated. Use ``kind='imagej'`` instead.
    ome:
        Deprecated. Use ``kind='ome'`` instead.
    shaped:
        Deprecated. Use ``kind='shaped'`` or ``kind='generic'`` instead.

Raises:
    ValueError:
        The file contains metadata and cannot be appended to
        without ``append='force'``.
        ``mode`` is not 'r+' when ``append`` is ``True``.
        ``byteorder`` is not a valid byte order character.

r   tiffr   _fhzOmeXml | None_omexmlbool | None_omer   _imagej	_tifffile	_truncatedict[str, Any] | None	_metadataNDArray[numpy.uint16] | None	_colormapz)list[tuple[int, bytes, Any, bool]] | None_tagstuple[int, ...] | None
_datashapenumpy.dtype[Any] | None
_datadtype
int | None_dataoffsetlist[int] | None_databytecounts_dataoffsetstagTiffTag | None_descriptiontagr   
_ifdoffset_subifds_subifds_tree_subifdslevel	list[int]_subifdsoffsets_nextifdoffsets	_ifdindexzStoredShape | None_storedshapeNFr   c              n	   US;   d%  [        U[        5      (       a  UR                  S:X  a  SnSnU(       a   [        USSS9 n
U
R                  5       n [	        U
5       nUS:w  a  UR
                  (       d  S	n[        U5      eUR                  nUR                  n[        [        UR                  R                  5      U l        S S S 5        U
R                  U5        SnS S S 5        U(       a  US;  a  Sn[        U5      eSnOUc  SnUb  US;   a  ["        R                  S:X  a  SOSnOUS;  a  SU< 3n[        U5      eUS:X  a-  U(       a  [$        R&                  O[$        R(                  U l        O,U(       a  [$        R,                  O[$        R.                  U l        S
U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l         S U l!        SU l"        SU l#        SU l$        / U l%        / U l&        SU l'        S U l(        S U l)        [        XSS9U l*        U(       a+  U RT                  R                  S[V        RX                  5        OU RT                  R[                  US:X  a  SOS5        U(       a6  U RT                  R[                  [\        R^                  " US-   SSS5      5        O3U RT                  R[                  [\        R^                  " US-   S5      5        U RT                  R                  5       U l        U RT                  R[                  [\        R^                  " U R*                  R`                  S5      5        U=S:X  a    SnS
nS
n	O?=S:X  a    SnS
nS
n	O1=S:X  a    S
nS
nSn	O#=S:X  a    S
nS
nS
n	Oc  O S U< 3n[        U5      eUc  S O
[c        U5      U l2        U Rd                  (       a  S
O
[c        U5      U l3        U Rf                  (       a  S
U l2        U Rd                  (       d  U Rf                  (       a  S
U l4        OU	c  SO
[c        U	5      U l4        U(       a'  U(       a  [j        Rl                  " U < S!3[n        S"S#9  g g g ! , (       d  f       GN= f! U
R                  U5        f = f! , (       d  f       GN= f! [        [         4 a    S
n GNf = f)$N>   r  r+brD  r  Trbr   )r   r   forcez)cannot append to file containing metadataF>   Nr  rD  zappend mode must be 'r+'w>   =|littlers   rr   >   rs   rr   zinvalid byteorder=   II   MMHHH+      H*   r   r   r   genericzinvalid kind=z% writing nonconformant BigTIFF ImageJ   
stacklevel)8r   r   _modetellr   is_appendabler   r   
is_bigtiffr_   r   r  next_page_offsetr:  seekOSErrorFileNotFoundErrorsysr   BIG_LE
CLASSIC_LEr"  BIG_BE
CLASSIC_BEr)  r+  r-  r.  r0  r2  r4  r6  r7  r9  r;  r<  r=  r?  r@  rA  r$  rB  r#  r  SEEK_ENDr   structpackoffsetformatr   r&  r'  r(  warningswarnUserWarning)selfr   r   r   r   r   r   r   r   r   fhposr   r   s                 rv   __init__TiffWriter.__init__  s    = tZ((TZZ5-@DF4a8B'')C%%b\S%09J9J$O !$ '1o 5(+I&)nnG.2 #SYY%?%?/DO * !F! 9( ..0 o%D\D	Z 7"}}8cIj('YL)CS/!'.DOODI'.DOODI
###!!! dA6HHMM!R[[)HHNNI$45%@v{{9u+<b!QGHv{{9s?B?@"hhmmoDOHHNN6;;tyy'='=qAB, &( o%KDT#Y	 $		utF|<<DI99"DN%+^TfDNgMM(?@ 6q *\  98" ./ s`   R RQ6 A&Q$Q6R!R $
Q3	.Q66R		R
RR R R43R4)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU   r   r   r   r   subifdsr   r   r   r   r   r   r   r   c               d   U[         L a  0 n[        SS9n!Sn"Sn#Sn$Sn%Sn&Sn'Sn(Sn)Sn*U R                  n+U R                  R                  n,UcI  Ub  Uc  Sn-[        U-5      eSn"Sn#[        U5      n.[        R                  " U5      R                  U,5      n/GO[        US5      (       aG  Ub  Uc  Sn-[        U-5      eUn#[        U5      n.[        R                  " U5      R                  U,5      n/GOw[        US5      (       Ga  [        [        R                  U5      nUn"[        R                  " UR                  5      R                  U,5      n/[        US5      (       d  [        R                  " UU/S5      n"O4 UR                  R                  (       a  [        R                  " UU/S5      n"U"R"                  n.Sn#Ub.  [        R                  " U5      U/:w  a  S	U< S
U/ 3n-[        U-5      eUb.  UU"R"                  :w  a  SU< SU"R"                   3n-[        U-5      eOK[        R                  " U5      R                  U,5      n/[        R                  " UU/S5      n"U"R"                  n.Sn#A[%        S U. 5       5      (       a  Sn-[        U-5      eU/R&                  S:H  n0U0(       aC  U.S   S:  a  SOSn1[)        U.SU1 5      n2U.U1   S-  (       a  U2U.U1   S-  S-   -  n2O$U2U.U1   S-  -  n2O[)        U.5      U/R*                  -  n2U2S:X  a  Sn"SnSn
Ub  SnU(       a  [-        U[.        5      (       d  US;   a  SnU(       a  [-        U[.        5      (       d  US;   a  SnU.n3U
SL=(       a    U
U/R*                  S-  :g  n4U R0                  Gb  U R2                  Gb  Ub  [        R                  " UU,S-   S9nU(       aj  U R0                  SS U.:w  dW  U R2                  U/:w  dG  Uc  U R4                  c7  U R4                  c  Uc'  [        R6                  " UU R4                  5      (       Gd  U R9                  5         U R:                  (       a  Sn-[        U-5      eU R<                  b  U R>                  S:  a  U R@                  c   eU RB                  c   eU R<                  RD                  " SPU R2                  U R0                  S   S:w  a  U R0                  OU R0                  SS U R@                  R"                  S.U RB                  D6  O3Ub0  U RG                  5         U+RI                  S[J        RL                  5        U RN                  (       a  U RP                  (       d  U(       a  Sn-[        U-5      eU =R>                  S-  sl        U R>                  U RN                  :X  a+  / U l)        / U l*        SU l        SU l'        SU l+        SU l,        OU(       a  Sn-[        U-5      eSU l        SU l        OU(       d  U4(       d  U(       a  Sn-[        U-5      eU R0                  S   S-   /U.Q7U l        U+R[                  5       n5U"c  U+R]                  U25        OU+R_                  U"U/5        U (       a  U5U24$ gU R`                  c  Uc  SU+Rb                  ;   U l0        OSU l0        U Rd                  (       d  U R:                  (       a  [/        U5      U l(        OU(       a  S n-[        U-5      eSU l(        U RP                  (       a"  U(       d  U4(       d  U(       a  S!n-[        U-5      eU2S:X  a   S"n.[f        Rh                  " U < S#3[j        S$S%9  U R                  Rl                  n6U R                  Rn                  n7U R                  Rp                  n8U R                  Rr                  n9[t        Rv                  n:[t        Rx                  n;[t        Rz                  n<[t        R|                  n=[t        R~                  n>[        R                  n?[        R                  n@Ub  [        [t        U5      nU(       a  [        [        U5      nUb0  [        S& [-        U[        [        45      (       a  UOU4 5       5      nU(       ab  [-        U[        5      (       a  UR                  5       nUS':X  a  SnO[-        U[.        5      (       a  Sn[        [        U5      R                  nASnOSnASnUc  0 nWAS:X  a  0 nO6WAS(;   a  SUS)'   O*WAS*:X  a$  UR                  S+S5        UR                  S,S5        Uc   eU(       Ga   U(       d  S-n-[        U-5      eWA[        R                  ;   a  S.[        WA5      < 3n-[        U-5      e[-        U[.        5      (       aG  U/R                  S/:X  a  S0nBOU/R                  S1;   a  U/R*                  S2::  a  S$nBOS.U/< 3n-[        U-5      e[        [        U5      nU/R                  S1;   a   UR                  S3;  a  U/R*                  S2::  d   U/R                  S/:X  a%  UR                  S4;  a  S5U< S6U/< 3n-[        U-5      eUR                  nBOSnBA[        R                  WB   n)U R`                  (       a  Ub   [f        Rh                  " U < S73[j        S$S%9  SnU R<                  c#  Uc  [        5       U l        O[        SP0 UD6U l        U(       d  U(       a  [        U5      S$:  a  S8n-[        U-5      eSnGO1U R:                  (       Ga  Ub   [f        Rh                  " U < S93[j        S$S%9  SnU/R&                  S:;  a  S;U/R&                  < 3n-[        U-5      eU(       d  U(       a  [        U5      S$:  a  S<n-[        U-5      eSnU(       a  UU<:H  OSnCU/R&                  S=:w  a  UU<:X  a  S;U/< S>3n-[        U-5      eSnCUb  SnCUc  SOUR                  S?5      nD[        U.WCUDS@9nEUW@:X  a  SAn-[        U-5      eWES   SB;   a  U<nOUc  Ub  U/R&                  S=:X  a  U>nOU:nSnWC(       a  U?OSnUGb  [        R                  " UU,S-   S9nUU l        U R:                  (       a  UR"                  SC:w  a  SDn-[        U-5      eU/R&                  S=:X  a  UU:U;1;   a  U>nGOU/R&                  S=:X  a  UU>:X  d>  U/R&                  SE;   a  UU:U;1;   d&  [f        Rh                  " U < SFU/ SGU< 3[j        S$S%9  SnOUcD  U/R&                  SH;   a4  U>nSnUR"                  S0S$U/R*                  S-  -  4:w  a  SIn-[        U-5      eO{UU>:X  aO  SnU/R&                  SH;  a  SJn-[        U-5      eUR"                  S0S$U/R*                  S-  -  4:w  a  SIn-[        U-5      eO&[f        Rh                  " U < SKU/ SGU< 3[j        S$S%9  SnU(       a  S[        U5      s=:  a  S2:  a4  O  O1US   SL-  (       d$  US   SL-  (       d  [%        SM U 5       5      (       a  SNU 3n-[        U-5      e[        SO U 5       5      nU(       a  [        U5      S$:X  a  S/UQ7n[        U5      S0:H  nOSPn[/        U5      n[-        U[        5      (       d   e[        U.[        R                  R                  US$5      5      n[        U5      nFU(       a  WFS0:  a  SnUGc  SnGU:nU0(       a  U;nOUU?:X  a!  WFS$:  a  US   SB;   a  U<nU/R&                  SH;  nGOUW@:X  a*  U(       a  WFS0:  a	  USQ   SB;   d  WFS$:  a  USR   SB;   a  U<nSnGOuWFS$:  a  US   SB;   a  U<nU?nU/R&                  SH;  nGORU R:                  (       d  U R`                  (       a  U:nSnO+U(       a  WFS0:  a	  USQ   SB;   d  WFS$:  a  USR   SB;   a  U<nW@nSnGWG(       a9  UU?:X  a  SSnHOSTnH[f        Rh                  " SUU. SVU/ SWWHS    SXUHS    SY3	[        S$S%9  AHAGA.Uc   e[        R                  U   nIU(       a"  [        U5      U(       a  S0OS$::  a
  SnWIS:  a  U:nWIS:  Ga  [        U5      S0:  a  SZU< S[3n-[        U-5      e[        U5      S2:  a  SnUcG  UU<:X  a  WIS21nJOWI1nJUS   WJ;   a  U?nO-X'(       a  SQOSR   WJ;   a  W@nOUS   X'(       a  SQOSR   :  a  W@nOU?nUU?:X  a0  US   U!lV        US   U!lW        USR   U!lX        U(       a
  USQ   U!lY        O:US   U!lW        US   U!lX        U(       a  USR   U!lY        USQ   U!lZ        O
USR   U!lZ        U!R                  WI:  a  U!R                  WI-
  U!l\        GOeU[t        R                  :X  a6  [        U5      S$:w  a  S\n-[        U-5      eSnSnUS   U!lW        US   U!lX        GOU(       Ga  [        U5      U(       a  S0OS$:  a  UU?:X  aq  Ub  [        U5      S:  a0  US   U!lV        US   U!lW        USR   U!lX        U(       a
  USQ   U!lY        OSnSU!lV        US   U!lW        US   U!lX        U(       a
  USR   U!lY        OgUS   U!lW        US   U!lX        Ub  [        U5      S:  a'  U(       a  USR   U!lY        USQ   U!lZ        O%USR   U!lZ        OSnSU!lZ        U(       a
  USR   U!lY        U!R                  S-
  U!l\        GOSnU Rd                  (       aE  U(       d  U0 :X  a8  [        U5      S$:  a(  US   S:X  a  USS n[        U5      S$:  a  US   S:X  a  M  O.U R:                  (       a  [        U5      S$:  a  US   S:X  a  USS n[        U5      S0:  a  SnU(       d&  US   U!lW        US   U!lX        U(       a
  USR   U!lY        OCUS   U!lV        US   U!lW        USR   U!lX        U(       a
  USQ   U!lY        U!R                  S-
  U!l\        U(       d3  U(       a,  [        U5      S0:X  a  US   S:  a  S]U!< S^U 3n-[        U-5      eUbD  US2-  (       a:  U0(       a  U!R                  S:X  a  US_;   d  S`n-[        U-5      e[t        R                  nSn4U0(       a  U
b  U
S:w  a  SaU
< Sb3n-[        U-5      eSn
GOWASc;   a@  U
c  UR                  SdU/Se:X  a  SfOS5      n
S$U
s=::  a  SL::  d  O  SaU
< Sg3n-[        U-5      eGODWASh;   ab  U
c  UR                  SdU/R*                  S-  5      n
U
SSSLSi.U/R*                     :  a  U
U/R*                  S-  ::  d  SaU
< SjU/< 3n-[        U-5      eOU
c  U/R*                  S-  n
OU/R                  Sk:w  d  U/R*                  S2:  a(  U
U/R*                  S-  :w  a  SaU
< SlU/< 3n-[        U-5      eU
SSSLSi.U/R*                     :  a  U
U/R*                  S-  ::  d  SaU
< SjU/< 3n-[        U-5      eU(       a&  U
U/R*                  S-  :w  a  SaU
< Sm3n-[        U-5      eOU
U/R*                  S-  :w  a  Sn4U!R                  S:X  a'  U!R                  nKUKS:X  a  SO[)        U35      WK-  U!l_        U2S:  a"  U!R                  (       d  SnU!< 3n-[        U-5      eUU>:X  a3  U!R                  S:w  d  U!R                  S:  a  SnU!< So3n-[        U-5      eO1U!R                  WI:  a!  SpU< SqWI SrU!R                   3n-[        U-5      eUb$  U!R                  U:w  a  U< SsU!< 3n-[        U-5      eAU"b  U"R                  U!R"                  5      n"/ nLU(       a  StnMSunNOSvnMSwnNWNU le        U R                  nOU R                  nPUc  SPnUb  WP" WLSxS$SUS5        U(       d  0 OUR                  5       U l!        U R<                  b+  [        U R<                  R                  5      S:X  a  SynGO<SnGO8U R:                  (       ay  [        U RB                  SzS{S|S}S~SSSSSSSSSSS5      nQ[        UQU,5       H  nRWP" WL/URQ76   M     [        U34U!R                  SB;   U R4                  SLS.U RB                  D6nUS-  nOU Rd                  (       aS  U(       d  U0 :X  aF  U RP                  (       a  U RB                  R                  SS9  [        U340 U RB                  D6nUS-  nOJUbG  [-        U[        5      (       d  UR                  S5      n[        U SSxS$[        U5      US5      U lr        SnUc  SU l2        O=UR                  S5      nWP" WLSxS$SUS5        [        U SSxS$[        U5      US5      U lr        AUc  SnU(       a  WP" WLSS$SUS5        U(       a  [-        U[        5      (       a&  [        U5      S:w  d	  USL   S:w  a  Sn-[        U-5      eOK[-        U[        5      (       a  UR                  S5      nO$[        R                  " 5       R                  S5      nWP" WLSS$SUS5        WP" WLSS0SWA5        UAS:X  aP  UR                  S5      c  SnSO,US   S:X  a  SnSO US   S:X  a  S$nSOSUS   < 3n-[        U-5      eWP" WLSS2S$S2WS45        ASWBS:w  a  WP" WLSS0SWB5        WP" WLSS2SU!R                  5        UP" ULSS2SU!R                  5        U(       a  WP" WLSS2SUS   5        UP" ULSS2SUS   5        U(       a,  WP" WLSS2SU!R                  5        U(       a  WP" WLSS2SUS   5        Ub  WP" WLSS2SU5        U(       d  U RN                  (       a  U R>                  S:  a  U RN                  (       a  U RN                  nO([        US5      (       a  [        U5      nO[        U5      nUS:  a
  U* nSU l+        UU l'        WP" WLSU8S2:  a  SOSU RV                  (       a  UOSS/U RV                  (       a  UOS-  5        U0(       dH  U/R                  Sk:w  a8  SS$S0SS.U/R                     nTWP" WLSS0U!R                  UT4U!R                  -  5        Ub  WP" WLSS0UR                  U5        Ub  WP" WLSS[        U5      U5        WP" WLSS0SU!R                  5        U0(       a'  U!R                  S:  a  WP" WLSS0SU!R                  5        OWU!R                  S:  a;  WP" WLSS0SU!R                  5        UP" ULSS0U!R                  U
4U!R                  -  5        OWP" WLSS0SU
5        U!R                  S:  a  UbU  U!R                  [        U5      :w  a&  SU!R                   S[        U5       3n-[        U-5      eWP" WLSS0[        U5      U5        OFUU<:X  a  U!R                  S:X  a  WP" WLSS0SS$5        O#WP" WLSS0U!R                  SU!R                  -  5        Ub  WP" WLSS[        U5      U5        WAS:X  Ga  U!R                  S:X  Ga  UU<U=1;   a  Uc  SnOUS;  a  SU< 3n-[        U-5      e[        U5      S-  nUU(       a*  US   WU-  (       d  US   WU-  (       a  SWU 3n-[        U-5      eU!R                  S:  a  Sn-[        U-5      eWP" WLSS0S$U5        [        [t        UR                  SS5      5      nVXS'   UR                  US'   UVR                  US'   UP" ULSS0SUV5        UVU=:X  a#  [        S U 5       5      (       a  WP" WLSSSS5        OuUS;  a   [        5       R                  U < SU< 35        SnSnUWP" WLSS0SUR                  5        UU=:X  a/  WP" WLSS0S$S5        [        S U 5       5      (       a  WP" WLSSSS5        Ub  [        [        U5      nO5U R:                  (       d  Uc  [        R                  nO[        R                  nUb?  WP" WLSSSG[        US   5      5        UP" ULSSSG[        US   5      5        UP" ULSS0SU5        O$WP" WLSSSS5        UP" ULSSSS5        UP" ULSS0SU5        U=(       d    U4=(       d    U0(       + nU(       Ga(  [        U5      S$:X  a  G[        GR                  " U!R                  US   -  5      G[        GR                  " U!R                  US   -  5      4nWU=(       a+    U!R                  US   :H  =(       a    U!R                  US   :H  nOG[        GR                  " U!R                  US   -  5      G[        GR                  " U!R                  US   -  5      G[        GR                  " U!R                  US$   -  5      4nWU=(       aD    U!R                  US   :H  =(       a+    U!R                  US   :H  =(       a    U!R                  US$   :H  n[)        WW5      U!R                  -  nX[)        U5      U!R                  -  U/R*                  -  /UX-  nYU GR                  UYWA5      nZWP" WLWMUZUXUY5        UP" ULWNU7UXS/UX-  5        UX UZ 3nZU(       dO  U"b  G[	        U"UWW5      n#O=U#c:  U(       d3  U4(       d,  U0(       d%  WXU!R                  -  WYS   4     SS jjn[U[" 5       n#Sn	GO:U(       a  U	b  U	U!R                  :  a  U!R                  U!R                  -  n\U!R                  U!R                  -  U!R                  -  U/R*                  -  /U\-  nYU GR                  UYWA5      nZWP" WLWMUZU\UY5        UP" ULWNU7U\S/U\-  5        UP" ULSS2SU!R                  5        U\ UZ 3nZU!R                  n	U\n]GOuU!R                  U!R                  -  U/R*                  -  n^WAS:X  a  U!R                  n	U	c  U(       a  SW^-  n	OU!R                  n	U	S:  a  WUn	OLU	U!R                  :  a  U!R                  n	O/U(       a(  U	WU-  (       a  G[        GR                  " U	WU-  5      UU-  n	U	c   eWP" WLSS2SU	5        U!R                  U	-   S-
  U	-  n_U_U!R                  -  U!R                  -  n]U	W^-  n`U`/U]-  nYU`U^U_U	-  U!R                  -
  -  -
  naG[        U_S-
  U]U_5       H  nbWaWYUb'   M
     U GR                  WYWA5      nZWP" WLWMUZW]UY5        UP" ULWNU7U]S/U]-  5        UZU]-  nZU"b  U(       d  G[        U"5      n#U#c  U(       d  Sn-[        U-5      eWL VRs1 s H  nRURS   iM
     ncnRUcR                  [        GR                  5        U H9  ndUdS   Wc;   a$  [        5       R                  U < SWdS    35        M0  WP" WL/WdQ76   M;     AcAG[        WLS S9nLSneSnfSngU#b  G[        U#5      u  nhn#[-        Uh[        5      (       a9  SngWhu  nhni[-        Uh[        5      (       d  SG[        Wh5      < S3n-G[        U-5      e[-        Wh[        5      nfUf(       d  [        R                  " Wh5      nhU(       a%  U!R                  S:X  a  WhR"                  S   S:w  a  SneWhR                  R&                  U/R&                  :w  a  SWhR                  < SU/< 3n-[        U-5      eOSnhU0(       aR  WAS:X  a  We4     SS jjnjUjn*OWAS;   a(  [        GR                  WA   WeU4         SS jjnkUkn*OSn-G[        U-5      eU(       ax  [        GR                  WA   nlUAS:X  a  WeUS'   U(       a  WlU4       SS jjn*O[WBS:  a  U)WlWeU4           SS jjn*O>U(       a  WlU4       SS jjn*O&WAS:  a  Wln*OSn*OU4(       a  U
We4       SS jjn*OSn*AU(       d  Wf(       d  U*b  SnfU(       aq  / UQU!R                  P7nm[)        Um5      U/R*                  -  nnG[        GR                  UWXU!R                  -  UnWA5      nG[!        UXU!R                  -  U#U*UmU/UUS5      n#OxG[        GR                  UW]U!R                  -  W`WA5      nG[#        U#U!GR$                  U/U	5      n#G[!        U]U!R                  -  U#U*U	U!R                  U!R                  4U/UUS5      n#U+R[                  5       noSnpG[        U(       a  SOU!R                  5       G
H+  nqWonrUrS$-  (       a  U+GR'                  S5        WrS-  nrU R>                  S:  a5  U+RI                  U GR(                  5        U+GR'                  WO" U7Wr5      5        U+RI                  Wr5        WqS$:  Ga	  Sn'G[*        GR,                  " 5       nsUsGR'                  WO" U6[        WL5      5      5        UsR[                  5       ntUsGR'                  SGR/                  S UL 5       5      5        UsR[                  5       nuUsGR'                  UO" U7S5      5        G[1        UL5       GH*  u  nvnwWtUvU9-  -   S2-   U8-   n5UwS   nxUwS$   nyUy(       Ga<  WsR[                  5       n(U(S$-  (       a  WsGR'                  S5        U(S-  n(WsRI                  U55        UsGR'                  WO" U7WrU(-   5      5        UsRI                  U(5        UsGR'                  Wy5        WxWN:X  a  U5U(4n%M  WxWM:X  a  U5U(4n&M  WxSx:X  a  U R                  b}  U R                  GR2                  S:X  a_  WyGR5                  U R                  R                  5      (       a1  WrWt-   WvU9-  -   U R                  l        UrU(-   U R                  l        GMJ  GMM  GMP  GMS  WxS:X  a  U5U(4n'GM`  GMc  WxWN:X  a  U5S4n%GMp  WxWM:X  a  U5S4n&GM}  WxSx:X  a  U R                  b  U R                  GR2                  S:X  al  U R                  R                  WwS   SQS ;   aI  WrWt-   WvU9-  -   U R                  l        U R                  GR2                  U8-   S2-   U R                  l        GM  GM  GM  GM  WxS:X  d  GM&  U5S4n'GM-     WsR[                  5       nzUzS$-  (       a  WsGR'                  S5        WzS-  nzU+RI                  Wz[J        GR8                  5        U+R[                  5       npUc  SLnUWpU-  -
  U-  n{U+RI                  U{[J        GR8                  5        UpU{-  npU(       a  U#b  Sn|Wf(       a   U# H  nhW|U+GR'                  Uh5      -  n|AhM     OPU!R                  U/R*                  -  n}U# H1  nhUhc  W|U+R]                  W}5      -  n|OW|U+R_                  WhU/5      -  n|AhM3     W|U2:w  a  SW| SU2 3n-[        U-5      eGO"U"c  U+R]                  U25        GOU+R_                  U"U/5        GOWg(       a  U#c   eS/U(       a  WXOW]-  n$Wpn5G[        U(       a  WXOW]5       HX  n~[        [        [        [        4   G[;        U#5      5      u  nhniUiWYU~'   U5U$U~'   U5[        Uh5      -  n5U+GR'                  Uh5        AhMZ     GOhWf(       a^  U#c   eG[        U(       a  WXOW]5       H>  n~[        [        G[;        U#5      5      nh[        Uh5      WYU~'   U+GR'                  Uh5        AhM@     GOU(       a  U#c   e/ UQU!R                  P7nm[)        Um5      U/R*                  -  nnG[        WX5       H  nG[;        U#5      nhUhc  SWYW'   M  [        GR<                  " WhU/5      nhUhGR>                  Wn:w  a\  WhGR>                  Wn:  a  Sn-[        U-5      e[        S G[A        WmWhR"                  SS9 5       5      n[        GRB                  " UhU5      nhU+R_                  Wh5        AhM     OSn-[        U-5      eU%c   eU%u  n5n(WsRI                  U55        U(b  WsGR'                  WO" U7WrU(-   5      5        UsRI                  U(5        U$c2  Wpn5WY H)  nWsGR'                  WO" U7US:  a  U5OS5      5        U5W-  n5M+     O<U$ H  n5WsGR'                  WO" U7U55      5        M     OWsGR'                  WO" U7Wp5      5        U*c
  U(       ag  U"cd  U&c   eU&u  n5n(WsRI                  U55        U(b-  WsGR'                  WO" U7WrU(-   5      5        UsRI                  U(5        WsGR'                  WO" WZ/WYQ76 5        U'bt  U'u  n5n(U(bM  WsRI                  U55        UsGR'                  WO" U7WrU(-   5      5        U RT                  GRE                  UrU(-   5        OU RT                  GRE                  WrU5-   5        U+R[                  5       noU+RI                  Wr5        U+GR'                  WsGRG                  5       5        U+GRI                  5         U R>                  S:  a  WrWu-   U l        GO,U+RI                  U RT                  U RX                     U R>                  U8-  -   5        U+GR'                  WO" U7Wr5      5        U RV                  (       d  U R>                  S:X  a   U RR                  GRE                  WrWu-   5        O]U+RI                  U RR                  U RX                     5        U+GR'                  WO" U7Wr5      5        UrWu-   U RR                  U RX                  '   U =RX                  S-  sl,        U =RX                  [        U RT                  5      -  sl,        U+RI                  Wo5        WqS:X  d  G
M  WL Vws/ s H  nwUwS   (       a  M  WwPM     nLnwG
M.     WpS:  d   eS/U3Q7U l        U/U l        WpU l        WYU l        U!U l         U(       a  WLU l        U (       a  WpG[Q        WY5      4$ g! [          a     G0Nf = fs  snRf s  snwf )a8  Write multi-dimensional image to series of TIFF pages.

Metadata in JSON, ImageJ, or OME-XML format are written to the
ImageDescription tag of the first page of a series by default,
such that the image can later be read back as an array of the
same shape.

The values of the ImageWidth, ImageLength, ImageDepth, and
SamplesPerPixel tags are inferred from the last dimensions of the
data's shape.
The value of the SampleFormat tag is inferred from the data's dtype.
Image data are written uncompressed in one strip per plane by default.
Dimensions higher than 2 to 4 (depending on photometric mode, planar
configuration, and volumetric mode) are flattened and written as
separate pages.
If the data size is zero, write a single page with shape (0, 0).

Parameters:
    data:
        Image data to write.
        If ``None``, an empty image is written, which size and type
        must be specified using ``shape`` and ``dtype`` arguments.
        This option cannot be used with compression, predictors,
        packed integers, or bilevel images.
        A copy of array-like data is made if it is not a C-contiguous
        NumPy or dask array with the same byteorder as the TIFF file.
        Iterators must yield ndarrays or bytes compatible with the
        file's byteorder as well as the ``shape`` and ``dtype``
        arguments.
        Iterator bytes must be compatible with the ``compression``,
        ``predictor``, ``subsampling``, and ``jpegtables`` arguments.
        If ``tile`` is specified, iterator items must match the tile
        shape. Incomplete tiles are zero-padded.
        Iterators of non-tiled images must yield ndarrays of
        ``shape[1:]`` or strips as bytes. Iterators of strip ndarrays
        are not supported.
        Writing dask arrays might be excruciatingly slow for arrays
        with many chunks or files with many segments.
        (https://github.com/dask/dask/issues/8570).
    shape:
        Shape of image to write.
        The default is inferred from the ``data`` argument if possible.
        A ValueError is raised if the value is incompatible with
        the ``data`` or other arguments.
    dtype:
        NumPy data type of image to write.
        The default is inferred from the ``data`` argument if possible.
        A ValueError is raised if the value is incompatible with
        the ``data`` argument.
    photometric:
        Color space of image.
        The default is inferred from the data shape, dtype, and the
        ``colormap`` argument.
        A UserWarning is logged if RGB color space is auto-detected.
        Specify this parameter to silence the warning and to avoid
        ambiguities.
        *MINISBLACK*: for bilevel and grayscale images, 0 is black.
        *MINISWHITE*: for bilevel and grayscale images, 0 is white.
        *RGB*: the image contains red, green and blue samples.
        *SEPARATED*: the image contains CMYK samples.
        *PALETTE*: the image is used as an index into a colormap.
        *CFA*: the image is a Color Filter Array. The
        CFARepeatPatternDim, CFAPattern, and other DNG or TIFF/EP tags
        must be specified in ``extratags`` to produce a valid file.
        The value is written to the PhotometricInterpretation tag.
    planarconfig:
        Interleaved or planar sample storage.
        *CONTIG*: the last dimension contains samples.
        *SEPARATE*: the 3rd or 4th last dimension contains samples.
        The default is inferred from the data shape and ``photometric``
        mode.
        If this parameter is set, extra samples are used to store
        grayscale images.
        The value is written to the PlanarConfiguration tag.
    extrasamples:
        Interpretation of extra components in pixels.
        *UNSPECIFIED*: no transparency information (default).
        *ASSOCALPHA*: true transparency with premultiplied color.
        *UNASSALPHA*: independent transparency masks.
        The values are written to the ExtraSamples tag.
    volumetric:
        Volumetric image stored on single page via SGI ImageDepth tag.
        The volumetric format is not part of the TIFF specification,
        and few software can read it.
        OME and ImageJ formats are not compatible with volumetric
        storage.
    tile:
        Shape ([depth,] length, width) of image tiles to write.
        By default, image data are written in strips.
        The tile length and width must be a multiple of 16.
        If a tile depth is provided, the SGI ImageDepth and TileDepth
        tags are used to write volumetric data.
        Tiles cannot be used to write contiguous series, except if
        the tile shape matches the data shape.
        The values are written to the TileWidth, TileLength, and
        TileDepth tags.
    rowsperstrip:
        Number of rows per strip.
        By default, strips are about 256 KB if ``compression`` is
        enabled, else rowsperstrip is set to the image length.
        The value is written to the RowsPerStrip tag.
    bitspersample:
        Number of bits per sample.
        The default is the number of bits of the data's dtype.
        Different values per samples are not supported.
        Unsigned integer data are packed into bytes as tightly as
        possible.
        Valid values are 1-8 for uint8, 9-16 for uint16, and 17-32
        for uint32.
        This setting cannot be used with compression, contiguous
        series, or empty files.
        The value is written to the BitsPerSample tag.
    compression:
        Compression scheme used on image data.
        By default, image data are written uncompressed.
        Compression cannot be used to write contiguous series.
        Compressors may require certain data shapes, types or value
        ranges. For example, JPEG compression requires grayscale or
        RGB(A), uint8 or 12-bit uint16.
        JPEG compression is experimental. JPEG markers and TIFF tags
        may not match.
        Only a limited set of compression schemes are implemented.
        'ZLIB' is short for ADOBE_DEFLATE.
        The value is written to the Compression tag.
    compressionargs:
        Extra keyword arguments for compression codec.
        Refer to the Imagecodecs implementation for supported
        arguments.
    predictor:
        Differencing predictor applied before compression.
        By default, no operator is applied.
        Predictors can only be used with certain compression schemes
        and data types.
        The value is written to the Predictor tag.
    subsampling:
        Chroma subsampling factors for JPEG-compressed RGB images.
        Values: (1, 1), (2, 1), (2, 2), or (4, 1).
        The default is *(2, 2)*.
        Currently applies to JPEG compression of RGB images only.
        Images are stored in YCbCr color space, the value of the
        PhotometricInterpretation tag is *YCBCR*.
        Segment widths must be a multiple of 8 times the horizontal
        factor. Segment lengths and rowsperstrip must be a multiple
        of 8 times the vertical factor.
        The values are written to the YCbCrSubSampling tag.
    jpegtables:
        JPEG quantization and Huffman tables.
        Use for copying pre-compressed JPEG segments.
        The value is written to the JPEGTables tag.
    iccprofile:
        ICC device profile characterizing image color space.
        The value is written verbatim to the InterColorProfile tag.
    colormap:
        RGB color values for corresponding data value.
        The colormap array must be of shape
        ``(3, 2\*\*(data.itemsize*8))`` (or ``(3, 256)`` for ImageJ)
        and dtype uint16.
        The image's data type must be uint8 or uint16 (or float32
        for ImageJ) and the values are indices into the last
        dimension of the colormap.
        The value is written to the ColorMap tag.
    description:
        Subject of image. Must be 7-bit ASCII.
        Cannot be used with the ImageJ or OME formats.
        The value is written to the ImageDescription tag of the
        first page of a series.
    datetime:
        Date and time of image creation.
        String in ``%Y:%m:%d %H:%M:%S`` format,
        ``datetime.datetime`` object, or ``True`` for now.
        The value is written to the DateTime tag of the first page
        of a series.
    resolution:
        Number of pixels per ``resolutionunit`` in X and Y directions.
        Values are float or rational numbers.
        The default is (1.0, 1.0).
        The values are written to the YResolution and XResolution tags.
    resolutionunit:
        Unit of measurement for ``resolution`` values.
        The default is *NONE* if ``resolution`` is not specified and
        for ImageJ format, else *INCH*.
        The value is written to the ResolutionUnit tags.
    subfiletype:
        Bitfield to indicate kind of image.
        Set bit 0 if the image is a reduced-resolution version of
        another image.
        Set bit 1 if the image is part of a multi-page image.
        Set bit 2 if the image is transparency mask for another
        image (photometric must be MASK, SamplesPerPixel and
        bitspersample must be 1).
    software:
        Name of software used to create file.
        Must be 7-bit ASCII. The default is 'tifffile.py'.
        Unless ``False``, the value is written to the Software tag of
        the first page of a series.
    subifds:
        Number of child IFDs to write per page (int or sequence).
        If a sequence is given, its length is used (for example,
        a ``TiffPage.subifds`` tuple).
        If greater than 0, the following ``subifds`` number of series
        are written as child IFDs of the current series as a SubIFD
        tree: all SubIFD offsets are stored directly in the parent's
        SubIFDs tag and all SubIFD NextIFD fields are zero, as
        required by DNG and TIFF-EP.
        If less than 0, ``abs(subifds)`` SubIFD levels are written as
        a SubIFD chain: only the first SubIFD offset is stored in the
        parent's SubIFDs tag, and subsequent SubIFDs are linked via
        their NextIFD fields.
        The number of IFDs written for each SubIFD level must match
        the number of IFDs written for the current series.
        All pages written to a certain SubIFD level of the current
        series must have the same hash.
        SubIFDs cannot be used with truncated or ImageJ files.
        SubIFDs in OME-TIFF files must be sub-resolutions of the
        main IFDs.
    metadata:
        Additional metadata for ImageDescription or IJMetadata tags.
        Metadata do not determine, but must match, how image data
        is written to the file.
        By default, the image shape and dtype are written in shaped
        format with no additional metadata keys.
        If ``None``, or the ``shaped`` argument to
        :py:class:`TiffWriter` is ``False``, no information in JSON
        format is written to the ImageDescription tag.
        The 'axes' item defines the character codes for dimensions in
        ``data`` or ``shape``.
        Refer to :py:class:`OmeXml` for supported keys when writing
        OME-TIFF.
        Refer to :py:func:`imagej_description` and
        :py:func:`imagej_metadata_tag` for items supported
        by the ImageJ format. Items 'Info', 'Labels', 'Ranges',
        'LUTs', 'Plot', 'ROI', and 'Overlays' are written to the
        IJMetadata and IJMetadataByteCounts tags.
        Strings must be 7-bit ASCII.
        Written with the first page of a series only.
    extratags:
        Additional tags to write. A list of tuples with 5 items:

        0. code (int): Tag Id.
        1. dtype (:py:class:`DATATYPE`):
           Data type of items in ``value``.
        2. count (int): Number of data values.
           Not used for string or bytes values.
        3. value (Sequence[Any]): ``count`` values compatible with
           ``dtype``. Bytes must contain count values of dtype packed
           as binary data.
        4. writeonce (bool): Write tag to first page of a series only.

        Duplicate and select tags in TIFF.TAG_FILTERED are not written
        if the extratag is specified by integer code.
        Extratags cannot be used to write IFD type tags.

    contiguous:
        Write data contiguously after the previous series.
        If ``False`` (default), write data to a new series.
        If ``True`` and the data and arguments are compatible with
        previous written ones (same shape, no compression, etc.),
        the image data are stored contiguously after the previous one.
        In that case, ``photometric``, ``planarconfig``, and
        ``rowsperstrip`` are ignored.
        Metadata such as ``description``, ``metadata``, ``datetime``,
        and ``extratags`` are written to the first page of a contiguous
        series only.
        Contiguous mode cannot be used with the OME or ImageJ formats.
    truncate:
        Write only first page of contiguous series if possible.
        If ``True``, only write first page of contiguous series
        if possible (uncompressed, contiguous, not tiled).
        Other TIFF readers will only be able to read part of the data.
        Cannot be used with the OME format.
    align:
        Byte boundary on which to align image data in file.
        The default is 16.
        Use mmap.ALLOCATIONGRANULARITY for memory-mapped data.
        Following contiguous writes are not aligned.
    maxworkers:
        Maximum number of threads for compressing tiles or strips.
        If ``None`` or *0*, use up to :py:attr:`_TIFF.MAXWORKERS` CPU
        cores for compressing large segments.
        Using multiple threads can significantly speed up this
        function if the bottleneck is encoding the data, for example,
        in case of large JPEG compressed tiles.
        If the bottleneck is I/O or pure Python code, using multiple
        threads might be detrimental.
    buffersize:
        Approximate number of bytes to compress in one pass.
        The default is :py:attr:`_TIFF.BUFFERSIZE` * 2.
    returnoffset:
        Return offset and byte count of memory-mappable image data.

Returns:
    If ``returnoffset`` is ``True`` and the image data in the file are
    memory-mappable, return the offset and number of bytes of the
    image data in the file.

rK  )framesNz-missing required 'shape' or 'dtype' arguments__next__r   reshaper  zdtype argument z does not match data dtype zshape argument z does not match data shape c              3  *   #    U  H	  oS :  v   M     g7f)        Nrt   )r   r   s     rv   r   #TiffWriter.write.<locals>.<genexpr>G	  s     8idz!i   zinvalid data shaper   rY   rP  r   FT)r   r   r   rY   >   r   r   r   rY   rQ  r   z8the ImageJ format does not support non-contiguous seriesr   r   storedshapez,SubIFDs cannot be used with truncated seriesz$SubIFDs in SubIFDs are not supportedz8contiguous mode cannot be used with compression or tilesz.ome.z7truncate can only be used with imagej or shaped formatsz<truncate cannot be used with compression, packints, or tilesr   r   z. writing zero-size array to nonconformant TIFFrT  rU  c              3  T   #    U  H  n[        [        [        U5      5      v   M      g 7fry   )r   r.   r   )r   xs     rv   r   rw  	  s-      !)  GK+,,)s   &(ZLIB>   阇        codecformatB  usecontainerlosslessz(cannot use predictor without compressionzcannot use predictor with fr   iu   >   rT  L  M     r   N  O  zcannot use z with z$ not writing description to OME-TIFFz$OME-TIFF does not support ImageDepthz' not writing description to ImageJ fileBHhfz-the ImageJ format does not support data type z-the ImageJ format does not support ImageDepthBz for RGBaxesrgbr  z1the ImageJ format does not support planar samples   r   r  )r      z!invalid colormap shape for ImageJHfz1 not writing colormap to ImageJ image with dtype=z and photometric=BHzinvalid colormap shapez$invalid data dtype for palette-imagez* not writing colormap with image of dtype=   c              3  *   #    U  H	  oS :  v   M     g7frY   Nrt   r   is     rv   r   rw  
  s     +d1udrx  zinvalid tile shape c              3  8   #    U  H  n[        U5      v   M     g 7fry   r   r  s     rv   r   rw  
  s     .AQ   rt   )zcontiguous sampleszparameter is)zseparate component planesz!and 'planarconfig' parameters arez,<tifffile.TiffWriter.write> data with shape z and dtype 'z' are stored as RGB with zl. Future versions will store such data as MINISBLACK in separate pages by default, unless the 'photometric' z specified.znot a z imagezinvalid CFA imagezcannot write z using volumetric tiles >   r   rY   r  zinvalid SubfileType MASKzbitspersample=z must be 1 for bilevel         r    r   uint16   z invalid for JPEG compression   r  R  r  r  r  r  )rY   rT  r  z out of range of datadtype=uz does not match datadtype=z  cannot be used with compressionzinvalid storedshape=z for palette modeznot enough samples for z: expected z, got z does not match storedshape=E  D        z    InfoLabelsRangesLUTsPlotROIOverlays
Propertiesinfolabelsrangeslutsplotroioverlayspropr  colormappedz@                                                                )	truncatedz                asciiztifffile.py1     :zinvalid datetime string%Y:%m:%d %H:%M:%S2    G  r   deflatezstdzinvalid LERC compression  =  r    B  C         __len__J        r  )r  r  r  cS  @  s  r        zwrong number of extrasamples  != R  r   [  rT  rT  >   rY   rY   r  rT  rY   r  rY   zinvalid subsampling factors ztile shape not a multiple of z'JPEG subsampling requires RGB(A) images  outcolorspacer   
colorspace  c              3  0   #    U  H  oS    S:g  v   M     g7fr     Nrt   r   ets     rv   r   rw    s      .'01y   r     )r   rY      rY      rY   r  rY   r  rY   r  rY   >   Nr  z cannot apply subsampling r  c              3  0   #    U  H  oS    S:g  v   M     g7fr  rt   r  s     rv   r   rw    s     8i!u|ir      (  c              3  N   #    [        U5      n[        U 5       H  nUv   M	     g 7fry   )r{   range)numtiles	bytecountchunk_s       rv   	dataiter_#TiffWriter.write.<locals>.dataiter_  s$     
 !&i 0!&xA"'K "1s   #%    i   z&cannot write non-contiguous empty filez not writing extratag c                    U S   $ Nr   rt   r  s    rv   <lambda>"TiffWriter.write.<locals>.<lambda>  s    !A$ru   r   ztype(iteritem)=z	 != byteszdtype of iterator z does not match dtype axisc                F    [         R                  " XS9R                  5       $ Nr  r   packbitstobytes)r  r  s     rv   compressionfunc1*TiffWriter.write.<locals>.compressionfunc1  s     !>>$:BBDDru   >   r    rP  P  ]  m  鲀  c                X    [         R                  " XS9R                  5       n U" U 40 UD6$ r  r  )r  
compressorr  r   s       rv   compressionfunc2*TiffWriter.write.<locals>.compressionfunc2  s+     !>>$:BBDD%d5f55ru   zcannot compress bilevel imager  c                    U" U 40 UD6$ ry   rt   r  r  r   s      rv   compressionfunc)TiffWriter.write.<locals>.compressionfunc      
 &d5f55ru   c                     U" XS9n U" U 40 UD6$ r  rt   )r  predictorfuncr  r  r   s        rv   r  r     s     )9D%d5f55ru   c                    U" U 40 UD6$ ry   rt   r  s      rv   r  r     r!  ru   c                x    U R                   S   nUS:X  a  X0R                   S   -  n[        R                  " XUS9$ )NrK  ry  runlen)r   imagecodecspackints_encode)r  bpsr  r'  s       rv   r  r     s@    
 B2:jjn,F"22f ru       ru   c              3  *   #    U  H	  oS    v   M     g7fr  rt   r   ts     rv   r   rw  f  s     "6AQ4rx  z(iterator contains wrong number of bytes ztile is too largec              3  2   #    U  H  u  pS X-
  4v   M     g7fr   Nrt   r   r  js      rv   r   rw    s#      $) J)   strictzunreachable code)r  r   r  r   returnIterator[bytes])r  rg   r  r   r6  r{   )
r  rg   r  rg   r  r   r   rg   r6  r{   )r  rg   r  rg   r   rg   r6  r{   )r  rg   r#  rg   r  rg   r  r   r   rg   r6  r{   )r  rg   r*  rg   r  r   r6  r{   )r   r   r#  r"  r   r   r~   r   r   r
  r   r_   ndarrayr   flagsf_contiguousr   r   anyr  r@   r   r   r   r0  r2  r-  array_equal_write_remaining_pagesr'  r$  r=  rB  r+  addimage_write_image_descriptionr\  r  rd  r;  r)  r@  r?  r<  rA  rX  write_emptywrite_arrayr&  	extensionr(  rh  ri  rj  tagnoformatrg  
offsetsizetagsizer   
MINISBLACK
MINISWHITERGBYCBCRPALETTEr   CONTIGSEPARATEr.   listrz   upperr   value
setdefaultr   IMAGE_COMPRESSIONSr   r   
PREDICTORSr   r   getimagej_shaperH   PHOTOMETRIC_SAMPLESDeprecationWarningcontig_sampleswidthlengthdepthseparate_samplessamplesr   CFAMASKrr  	page_sizeis_validRuntimeErrorr   rt  r7  _pack_addtagcopyimagesr>   r3   r2   r  shaped_descriptionr{   encoder$   r9  DateTimestrftimenowr   r   maxr   allr7   warningr   r   INCHrA   mathceil_bytecount_format
iter_tilesr  iter_imagesTAG_FILTEREDsortedpeek_iteratortyper   COMPRESSORSr   r'   _maxworkersencode_chunksiter_strips
page_shaper   r:  ioBytesIOr   	enumerater   
startswithvalueoffsetSEEK_CURnextascontiguousarrayr   zippadr   	getbufferflushr4  r6  r.  sum)rk  r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU   r   r   r   r   rp  r   r   r   r   r   r   r   r   r|  	dataarraydataiterr  dataoffsetsoffsetdatabytecountsoffsetsubifdsoffsetsrm  r#  r  rl  r   r   	datashape	datadtypebilevelindexr  
inputshapepackintsr   rC  rg  rD  rE  rF  rG  rH  rI  rJ  rK  rL  compressiontagpredictortagijrgbr  ijshapendim	deprecatemsgsphotometricsamplessamples_sets0tagstagbytecounts
tagoffsetsrf  addtag
ijmetadatar.  lerc_compressionsampleformatmaxsamplingr  tilesr  databytecountsbytecountformatr  count	numstripsrowsize
numstrips1	stripsizelaststripsizer  tagsetextratagcompressionaxis	bytesiter	tupleiteriteritemr  r  r  r  	tileshapetilesizefhposr  	pageindexifdposifd	tagoffset	ifdoffsettagindextagcoderO  ifdsizeskipbyteswrittenpagesize
chunkindex	tileindexr  r   s                                                                                                                                     rv   r   TiffWriter.write  s3   j
 ''H $/b#9 *.	AE(,;?>B8< 3759
 XXII''	<}E o%IHeIE*77	BIT:&&}E o%HeIE*77	BIT7##t,DIDJJ/<<YGI4++!MM$	3?	zz..$)MM$	3$G	 "IH U[[%79%D%eY /""+.  !o% Uioo%=%eY /""+//!24  !o%
 E*77	BIdIs;I!IH8i888&CS/!..C'#B-!+BEy%01H!#Ie,1A55Ie,11y)I,>,>>Hq=IK M#;--::K9d++88I
 % 8!3!3a!77 	 ??&4??+F# ==SI??12&)3??i/$)CNN*x/C((4>>BB ++-<<0  %S/)<<+))A-#00<<<#~~999-- 	"&// $(??1#5#: !%%)__QR%8(,(9(9(?(?	 #nn	 )113GGAr{{+==~~L(o-&&!+&))T]]:/1,/1,-/*()-1*)* D(o-"&!%DN  !o%
 $(??1#5#9"FI"F$NN8,NN9i8!8++99"#r||3	!	>>T\\!(^DNKCS/!"DN>>{h$N  S/!q=IMM(HI ii++yy--YY))
))## ++
 ++
oo!!%%$$(( "!+{;K"<>L#  ! ",>> !&)! L +s++)//1&("#KK..$[+>DDNKNK" OQ O;;-.OM*u$&&~u=&&z48***@ o%!8!88 1">257  !o%)T**>>S(#$L^^t+	0B0Ba0G#$L6ymDC$S/)#Iy9	NNd*!/@@!**a/NNc)!/@@'	}F9-HC$S/)(L599&hBC 
 #||###)8DL#)#5H#5DLds4y1}< o%J\\\ &hEF 
 #~~V+C ~~(*  !o%ds4y1}E o%J*5K3&4E~~$#%%%.M;  %S/)##+4f1ED"9%dCGx'I o%r{f$!$'INNc,A")K",K#%*6L }}XY_EH%DN||>>X-=C$S/)>>S([= . #*K^^s*{g/E!$.'J
+CC MM( #!!*+=@##$	  $H$4)?%#>>ay/A/AA/E)F%GG2C$S/) H '#>>-@C$S/)>>ay/A/AA/E)F%GG2C$S/) H h &K'9[N< 	   D	%A%8b=8b=+d++++D62 o%...Dc$i1nzDzTaJDj)J$&&&& t//33KC
 5z$(JI$K('!8b	V 3"%K )d :I)4!8b	V0C1Hrf!4"%K $IeBi61!%%NN$6	(#eBi6.AqU2Y&0!' 	6)?DD B9+ N""+,Ed1gYKAwi{	,
 '  &&&!55kBCJ
1BL!A%(!5zA~{oV4 o%5zA~"
##%#5q"9K#5"6K9+#)L24C#+L2YZrR!@@#+L#)Lv%-22Y*$)"I!%*2Y"(-b	K%$)"I!%*2Y"(-b	K%389K0389K0""%77''*<< ( KOO+5zQ) o%JL %b	K!&rK c%jACv%'3|+<q+@16rK.(-b	K%).rK&!,1"I)#'L12K.(-b	K%).rK&!,1"I)$)"I!%*2Y"'3|+<q+@!,1"I)7<Ry47<Ry4#'L34K0!,1"I)'2':':Q'>K$  L~~8x2~%j1nra!#2JE %j1nra#e*q.U2Y!^cr
5zA~"
$)"I!%*2Y"(-b	K%-22Y*$)"I!%*2Y"(-b	K%+6+>+>+B(ds4yA~$q'A+!+0HOCS/!"{U': ''1,9,0 o%%**K(]a-?'((>? o%M33 $ / 3 3#9+@Ra! ++'((EF o% , II $ / 3 3#Y%7%7!%;! A! 3I4F4F GG!Y%7%7!%;;'((D)F o% < "%..2MNNc!Y%7%7!%;y11A55#]$$?YLACS/!aB/	0B0BCC!3!3a!77#]$$@i\BCS/!	 2 2Q 66'((HI o% 7 i00144H#&&B&(Ag7:3F"3LKa< 4 4)[,-Cs##'!""a';+C+Ca+G- 00AB o% ,H   #55)+ 9./vk6I6I5JL  S/! $((L8!$$A[4DECS/! !))+*;*;<IMJMJ)zzI"4aK6 $,<<#4<<&&'1,0"\\%#J( )Y?t a  @,..&8 NN$6 ..	K ;&K^^X^~~%%%5,ZJ4>>JK;&K $k511)009#*aa[!1;$D  K"DN%,,W5K4aK6#*aa[!1;$D  $H4aHd3(C((x=B&(2,#*=3C$S/) +> Hh//#,,-@A#<<>223FG4aHd3tS!Q/U"""=19#$  /9<#$  /69#$  /&}58:  !o%41q*:&;< 14aL1tS!Q 1 12tS!Q 2 234aDH-4aDH-41k&7&78tUAq$q'2"4aK0t}}$*<*<q*@}}--),,g,g,{"(%*"#DM 1n"--1$"4"4w!< 9>>S0!";INNKL##+"5"55 4a9!43z?J?tS!Q 3 34""Q&tS!Q(@(@A  1$4aK$<$<=## ;#6#66 4aM2##a''++s</@@7&334D\9J8KM  %S/)tS!S%6E#(@(@A(EtS!Q* ,,;333 !4aZ*= a((A-U|+ "$$DD4[OD o%k*Q.KbK/48k3I5k]C o%''!+? o%4aK0#_00!DM .9M*,7,<,<OL)/</A/AOO,4aM2%# .'0. + + B .0  h8H KKc1a!2!2 e#tS!Q/8i888F %$Wn=N\\Z/$\\N$\\N!4aHZ]$;<4aHZ]$;<4aN34aF+4aF+4aN3 &<<W=
4yA~IIk0047:;IIk//$q'9:
  5#**d1g55#))T!W4  IIk//$q'9:IIk0047:;IIk//$q'9:  5#))T!W45#**d1g55 $))T!W4	  u~(D(DDH : ::Y=O=OON #44O m_h 4\8aS8^L!)
?*;<O())T5AH%8w )1;3E3E(E)7):("%(#&( )(  ){HL LK4F4F$F00;3D3DDE""##$,,- $$%
 N #44O 4O4\51#+F4aK$6$67!&'89O&--LI
 !!,,-$$% 
 &*11# #)W#4L#.#5#5La* 2 22*11!;IIl[89KG   +++4aL1 ""\1A5J [999K<M<MM  %w.I'[94N%\)K,>,>>) M :>9jA$1q! B"44O m_i 4\9qcIoN-	9O$Z&y1J:CS/! !%%1!A$%d''(!H{f$  h4Xa[MB t'h' " 
 d/  "		 !.x!8Hh(E** 	&.#)!(E22,T(^-Y7C#C.("8U3I ==2#22a7 r*a/ ')O>>&&)..8,X^^,> ?009}>  %S/)H" ,;EE%(EE
 #3#LL '+&6&6~&F /"1	66 #6 6  	6
 6 #3 6)#..)).9J&*9'  '1"166 #6  6 	6 ! *7&0 /"166#&6 !$6 	6
  6 6 ! '1"166 #6  6 	6  !#", #' )+


 
 	
 #O)0KI?d?K$>$>?	"9-	0B0BB'33{111"	
 ){111#	 (33 2 22"	
 '** 	 ) 2 22#$#))#22
  	 
 JqK4F4FGIFz!!!!A%(lF34GGFO 1}!%jjl		${CI67HHJ			#(("6"667HHJ			$|Q/0%.t_MHc&G);;a?*LFq6DFE!hhj7IIg.1HC(		$|Vc\"BC		%(:-06-!]2393;0!S[ $ 4 4 @$($8$8$?$?1$D$)$4$4$($8$8$>$>%" %"
 %+Y$6G9K$K !% 4 4 ; DJC< 4 4 @%" %E !A "S[-3S[N )+,2DL)./5t|, 00< $ 4 4 ; ;q @ $ 4 4 : :c!fRSk I !' 2X5G G !007 !% 4 4 ; ;j H1 L !00< !J !A = )/c &5d ((*Q;IIg&qLG GGGR[[) J}Z%/0E9DGGD"++&$J'#$L (0H(BHHX,>>L ( )1
 $/#8#89;M;M#M(0H'/ ,x0H H !-$,$-1" !" !) )1 $x/F+nD
<  )o- 0 &NN8,NN9i8+++ cX9E#"'Di"HJ*.eSj)4>+'Hi 2;N:..4K
+c(m+FHHX&  #I +++"'Di"HJ#E4>:H14XN:.HHX&  #I +++?d?K$>$>?	"9-	0B0BB!&xI#H~H'45y1 $66xKH(2 $??X5"5C",S/1# $(+ )8>>%)$  $)99Xs#;NN8, / "14 )"3'' %000+KFCHHV		$|Vc\:;&'F .		 vqI $	 !/ #.		$|V"<= #. 		$|Z89*t	8I+7772 ?IId<#>?HHSM		$@@A),?HHV$IId<#>?((//=((//@GGIEGGFOHHS]]_%HHJ!!A%"(9"4 ((8((:56 lF34 ))))Q.,,33FY4FG 4 4T^^ DElF!;<"Y. ,,T^^< !##d&:&:";;GGEN A~'+;t3r7t;} H@ A~~*z*#%-'DJ!3~#666k1 & Z" &p <s/   53CH? PCIGCIGCIH?
CIICIc                   U R                   c  Sn[        U5      eU R                  5         U R                   R                  USS9  SU l         g)z}Overwrite value of last ImageDescription tag.

Can be used to write OME-XML after writing images.
Ends a contiguous series.

Nzno ImageDescription tag foundFerase)r9  r   r=  	overwrite)rk  r   r   s      rv   overwrite_description TiffWriter.overwrite_descriptionb  sL     '1CS/!##%&&{%&@#ru   c                    U R                   (       d  U R                  5         U R                  5         [        R                  " [
        5         U R                  R                  5         SSS5        g! , (       d  f       g= f! [        R                  " [
        5         U R                  R                  5         SSS5        f ! , (       d  f       f = f= f)z,Write remaining pages and close file handle.N)r)  r=  r?  
contextlibsuppress	Exceptionr#  closerk  s    rv   r  TiffWriter.closep  su    	!>>++-))+$$Y/  0//$$Y/  0//s/   1B A11
A?CC8	C
CCc                    U R                   $ )z'File handle of TIFF file being written.r#  r  s    rv   
filehandleTiffWriter.filehandlez       xxru   c                `   U R                   (       a  U R                  (       d  U R                  c  gU R                  c   eU R                  c   eU R
                  c   eU R                  R                  U R                  S   -  S-
  nUS:  a  SU l         SU l        SU l        gU R                  nUR                  5       nUS-  (       a  UR                  S5        US-  n[        R                  nU R                  R                  nU R                  R                  nU R                  R                  nU R                  R                   nU R
                  n	[#        U R                  5      n
Sn[$        R&                  " 5       nUR                  U" U[)        U R                   5      5      5        UR                  5       nUR                  SR+                  S U R                    5       5      5        UR                  5       nUR                  U" US5      5        [-        U R                   5       H  u  nnXU-  -   U-   S-   nUS   nUS   nU(       a  UR                  5       nUS-  (       a  UR                  S5        US-  nUR/                  U5         UR                  U" XSU-   5      5        UR/                  U5        UR                  U5        UU R<                  :X  a  UU4nM  US:X  a  UU4nM  M  UU R<                  :X  a  US4nM  US:X  d  M  US4nM     UR                  5       nUS-  (       a  UR                  S5        US-  nUS:  aP  UUU-  -   S:  aD  U R2                  (       a&  [4        R6                  " U < S	3[8        SS
9  SU l        gSn[;        U5      e[$        R&                  " [?        UU-  5      5      nUn[A        U5       GH  nX-  n	Wu  nnUR/                  U5        Ub_  UR                  U" UUU-   5      5        UR/                  U5        U	nU R                   H   nUR                  U" UU5      5        UU-  nM"     OUR                  U" XY5      5        Ub(  Uu  nnU RB                  RE                  UUb  UOU-   5        U RF                  S:  ag  Ub4  Uu  nnUb,  UR/                  U5        UR                  U" UUU-   5      5        UU-  nUR/                  U5        UR                  U" UU5      5        GO.UR/                  U RB                  U RH                     U RF                  U-  -   5        UR                  U" UU5      5        U RJ                  (       d  U RF                  S:X  a  U RL                  RE                  UU-   5        O\UR/                  U RL                  U RH                     5        UR                  U" UU5      5        UU-   U RL                  U RH                  '   U =RH                  S-  sl$        U =RH                  [)        U RB                  5      -  sl$        UU-  nUR                  URO                  5       5        GM     UUUS-
  -  -  nUR/                  U5        UR                  U" US5      5        UR/                  U5        UR                  URO                  5       5        U RF                  S:  al  UR                  5       nUR/                  U RP                  5        UR                  U" XS5      5        URS                  5         UR/                  U5        X>-   U l(        SU l         SU l        SU l        g! [        R0                   aO  nU R2                  (       a+  [4        R6                  " U < S	3[8        SS
9  SU l         SnA  gSn[;        U5      UeSnAff = f)z(Write outstanding IFDs and tags to file.Nr   rY   rT  r+  ru   c              3  *   #    U  H	  oS    v   M     g7fr  rt   r-  s     rv   r   4TiffWriter._write_remaining_pages.<locals>.<genexpr>  s     4AQ4rx  r  z truncating ImageJ filerU  Tz#data too large for non-BigTIFF filer  rP  l    )*r.  r)  r0  rB  r6  r4  rr  r#  rX  r   re  rf  r"  rg  rD  rC  rE  r  r}  r~  r   r   r  r\  errorr'  rh  ri  rj  r   r7  r{   r  r?  r   r=  rA  r<  r@  r  r:  r  )rk  pagenorl  r  rf  rg  rD  rC  rE  r  pagedatasizer  r  r  r  r  r  r   r  rO  rm  excr   r  r  ifdsr  r   dataptrr   s                                 rv   r=  !TiffWriter._write_remaining_pages  s   zzT^^t/F  ,,,##///+++''..1CCaGA:DJ#D#'D XXWWY19HHWQJE{{ II22))..
9900yy((**
 4 458< jjl		${C

O45HHJ			#((4445HHJ			$|Q'(&tzz2MHcG!33j@1DFq6DFEhhj7IIg&1HC 3IId<=> 		% 4///(.%S[%+S[N ! ---$*DL!!'G 3J ((*Q;IIgqLG >eg&66C||h56 
 "&7CS/! zz%& 012vA&J+KFCHHV		$|Vc\:;$ 00DIId<9:tOG 1 		$|89),$$++S_c&A !!A%!-"0KFC(		$|Vc\"BC '!#		$|V45 ((8((:56 lF34 ))))Q.,,33FY4FG 4 4T^^ DElF!;<"Y. ,,T^^< !##d&:&:";;'! JJs}}'s x 	W
++			)

4a()

!"!'')CGGDOO$HHT,./HHJGGCL#/DO
#w || 
3|| #h&=>''(
 *.?C$S/s2
3s   ]

^-6^(^((^-c                   U R                   b  U R                  c  SU l        gU R                  c   eU R                  c   eU R                  b  U R
                  S:  a  U R                  c   eU R                  R                  " SU R                  U R                   S   S:w  a  U R                   OU R                   SS U R                  R                  S.U R                  D6  U R                  R                  SS9nOU R                   S   S:X  a  SU l        gU R                  (       aZ  U R                  c   eU R                  SLnU R                  R                  S;   n[        U R                   4UUS.U R                  D6nOHU R                  (       d  SU l        gU R                  c   e[        U R                   40 U R                  D6nU R                  R!                  UR#                  5       S	S
9  SU l        g)z'Write metadata to ImageDescription tag.Nr   rY   r{  Tdeclarationr  r  Fr  rt   )r0  r9  rB  r2  r$  r=  r+  r>  r   tostringr'  r-  r\  r2   r(  rf  r  rg  )rk  r   r  isrgbs       rv   r?  #TiffWriter._write_image_description5  s   ??"d&:&:&B#'D   ,,,***<<#!!A%~~111%% 	//  ??1-2 !__QR0 $ 1 1 7 7	 nn	 ,,//D/AK__Q1$#'D  \\>>---..4K%%--7E,' ..	K #'D >>---,T__OOK&&{'9'9';5&I#ru   c          	     	   U R                   n[        U[        5      (       d  [        R                  U   n [        [        U5      n[        R                  U   S   n	AUnUS:X  a  [        U[        5      (       a   UR                  S5      nO"[        U[        5      (       d  S
n
[        U
5      e[        U5      S:X  d	  USS S:w  a  US-  n[        U5      nUS:X  aU  [        UR!                  S5      5      nUS:  a  UnO4[#        U R$                  R&                  S-   US-   5      n[)        XK5      nOUnU4nOw[        U[        5      (       aG  [*        R,                  " U	5      n[        U5      U-  (       a  Sn
[        U
5      e[        U5      U-  nUnOUc  Sn
[        U
5      e[        U5      nUS;   a  [        U[        [.        R0                  45      (       de  [3        US5      (       aT  US:  aN  [5        [7        U5      S5      n[        U[8        [:        45      (       a  / nU H  nUR=                  U5        M     UnUS-  nU	S   n	U" SX(5      U" U R$                  R>                  U5      /nSn[*        R,                  " U	5      U-  U R$                  R&                  ::  a  U R$                  R&                   S3n[        U[        5      (       a  URA                  U" UU5      5        GObUS:X  aO  [        U[8        [:        [.        R0                  45      (       a  US   nURA                  U" UU" X5      5      5        GOURA                  U" UU" U U	 3/UQ76 5      5        OURA                  U" U R$                  R>                  S5      5        [        U[        5      (       a  UnO[        U[.        R0                  5      (       aU  URB                  U:w  a  Sn
[E        U
5      eURF                  RH                  U	:w  a  Sn
[E        U
5      eURK                  5       nO1[        U[8        [:        45      (       a  U" U U	 3/UQ76 nOU" X5      nURA                  USRM                  U5      UU45        g! [         a\     [        [        U5      n	U	S   S;   a  U	SS n	[        R                  U	   n GNT! [        [        4 a    SU< 3n
[        U
5      Sef = ff = f! [         a  nS	n
[        U
5      UeSnAff = f)zAppend (code, ifdentry, ifdvalue, writeonce) to tags list.

Compute ifdentry and ifdvalue bytes from code, dtype, count, value.

rK  r   <>rY   Nzunknown dtype=rT  r   TIFF strings must be 7-bit ASCIIz&TIFF string value must be str or bytesr+  r  s     invalid packed binary datazinvalid count   r  
   __iter__HHr  zvalue.size != countzvalue.dtype.char != dtyperu   )'rb  r   r   r   TAGSr_   DATA_FORMATSKeyErrorrz   DATA_DTYPESr   r   rg  UnicodeEncodeErrorr{   r   findrk  r"  rD  minre  calcsizer   r8  r   r  iterr~   rM  extendrg  r   r   ra  r   r  r  r   )rk  r  r  r   r  rO  	writeoncerf  datatype
dataformatr   rawcountr  r   firstflatpairifdentryifdvaluevalueformats                       rv   rc  TiffWriter._addtagg  ss    zz$$$99T?D	0C'H**84R8J q=%%%3!LL1E  u--> o%5zQ%*"7 JEs{uzz+67a<$H  #499#7#7!#;X\JH"53H HEu%%z2H5zH$2 o%J(*EH]!CS/!JEw uuemm&<==E:..AIT%[$/eeT]33&(D %D) !& EQJE#BJ t&''2

 ??:&.$))2F2FF!YY112!4K%''[% 89!eeT5==%ABB!!HE[$z2I JKdeWZL+A&JE&JK
 OOD!7!7;<%'' E5==11::&/C&s++;;##z15C&s++ ==?EE4=115'* 6??
2T388H-xCDY  	00!#u-
a=D(!+ABJ++J7i( 0') o4/0	0$ * 3<C$S/s23s5   &Q1 ;S 1
S<1R00#SS
S7$S22S7c                t    US   S;  a  U R                   R                  U-   n[        R                  " U/UQ76 $ )z2Return values packed to bytes according to format.r   r  )r"  r   re  rf  )rk  fmtvals      rv   rb  TiffWriter._pack  s6    q6))%%+C{{3%%%ru   c                   [        U5      S:X  a  U R                  R                  S   $ US   nUS:  a  US-  nUS:  a  gUS:  a  gU R                  R                  S   $ )zReturn small bytecount format.rY   r   r     rQ  rv  I)r   r"  rg  )rk  
bytecountsr   r  s       rv   rq  TiffWriter._bytecount_format  si     z?a99))!,,qM	?!BIuuyy%%a((ru   c                $   U b  U S:w  a  U $ US::  d  US:  d  US:  d  US:X  a  gUS:  a  US;   a  gUS:  a  US	;   a  gUS
:  a  US;   a  gUS:  a  US;   a  gUS:  a  US;   a  gUS:X  a  [        US5      $ [        U[        R                  5      $ )z,Return number of threads to encode segments.r   rY   rT     r  i   >   r  r  r  r  r  i   >   r  rP  r  r  r  i    >   RX  u  v     r  >   Q  r  r  r  )r  r   
MAXWORKERS)r   	numchunks	chunksizer   s       rv   ry  TiffWriter._maxworkers   s     !jAo11}4e# v+ 2
 #
 u 1
 "
 t 0
 !

 t 0
 !
 t 0
 !
 %y!$$9doo..ru   c                    U $ ry   rt   r  s    rv   	__enter__TiffWriter.__enter__<      ru   c                $    U R                  5         g ry   r  rk  exc_type	exc_value	tracebacks       rv   __exit__TiffWriter.__exit__?       	

ru   c                L    S[        U R                  R                  S5      < S3$ )Nz<tifffile.TiffWriter     rr   )snipstrr  r   r  s    rv   __repr__TiffWriter.__repr__G  s#    &wt/C/CR'H&K1MMru   )r-  r6  r2  r4  r7  r0  r9  r#  rA  r:  r'  r+  r@  r&  r$  rB  r;  r<  r=  r?  r.  r(  r)  r"  )r   /str | os.PathLike[Any] | FileHandle | IO[bytes]r   Literal['w', 'x', 'r+'] | Noner   r   r   ByteOrder | Noner   z
bool | strr   4Literal['generic', 'imagej', 'ome', 'shaped'] | Noner   r   r   r%  r   r%  r6  r   ry   )Br  `ArrayLike | Iterator[NDArray[Any] | None] | Iterator[bytes] | Iterator[tuple[bytes, int]] | Noner   Sequence[int] | Noner   DTypeLike | Noner   PHOTOMETRIC | int | str | Noner   PLANARCONFIG | int | str | Noner   (Sequence[EXTRASAMPLE | int | str] | Noner   r   r   r2  r   r3  r   r3  r   z%COMPRESSION | int | str | bool | Noner   r*  r   #PREDICTOR | int | str | bool | Noner   tuple[int, int] | Noner   bytes | Noner   r9  r   ArrayLike | Noner   str | bytes | NonerU   str | bool | DateTime | Noner   >tuple[float | tuple[int, int], float | tuple[int, int]] | Noner   RESUNIT | int | str | Noner   FILETYPE | int | Noner   str | bytes | bool | Nonerp  zint | Sequence[int] | Noner   r*  r   Sequence[TagTuple] | Noner   r   r   r   r   r3  r   r3  r   r3  r   r   r6  r8  )r   rz   r6  r   r6  r   r6  r   )F)r  z+list[tuple[int, bytes, bytes | None, bool]]r  	int | strr   rD  r  r3  rO  rg   r  r   r6  r   )r  rz   r	  rg   r6  r{   )r  Sequence[int]r   r   r6  rz   )
r   r3  r  r   r  r   r   r   r6  r   r6  ri   r"  type[BaseException] | Noner#  BaseException | Noner$  TracebackType | Noner6  r   r6  rz   )r  r  r  r  r  __annotations__rn  r   r   r  r  propertyr  r=  r?  rc  rb  rq  staticmethodry  r  r%  r+  r   rt   ru   rv   r'   r'     sB   Vp ,	O
MOO$$++44&&''%%##OMN$$ 04&*"EI"V=V
 -V V $V V CV V V V 
V@ J '+"&6:8<AE %)#'$(=A159=.2#'#'%)*.15 59-1.2.2*:/3  !%!%"UJJ $J  J 4J 6J ?J J  #!J" !#J$ "%J& ;'J( /)J* 7+J, ,-J. !/J0 !1J2 #3J4 (5J6 /7J: K;J> 3?J@ +AJB ,CJD ,EJF (GJH -IJJ KJL MJN OJP QJR SJT UJV 
 WJX>$!  s$l0$r  BE9BE BE 	BE
 BE BE BE 
BEH&)')69)	) 9/9/9/ 9/ 	9/
 
9/ 9/v, ( (	
 
Nru   r'   c            
         \ rS rSr% SrS\S'    S\S'    S\S'   S	\S
'   S \S'   S\S'   S\S'   S\S'   S\S'   S\S'   SSSSSSSSSS.	                       S^S jjr\S_S j5       r\S`S j5       r	\SaS j5       r
\SbS j5       r\ScS j5       rSdS jr SeSSSSSSSS.                 SfS  jjjr SeSSSSSSS!.               SgS" jjjr SeSSSSS#.             ShS$ jjjr\SiS% j5       r SeS&S'.     SjS( jjjrSdS) jrSdS* jrSdS+ jrSdS, jrSkS- jrSlS. jr        SmS/ jrSaS0 jrSaS1 jrSnSoS2 jjr\SpS3 j5       r\SqS4 j5       r\SqS5 j5       r \SqS6 j5       r!\SqS7 j5       r"\SqS8 j5       r#\SqS9 j5       r$\SqS: j5       r%\SqS; j5       r&\SqS< j5       r'\SrS= j5       r(\SsS> j5       r)\SsS? j5       r*\SsS@ j5       r+\SsSA j5       r,\SsSB j5       r-\SsSC j5       r.\SsSD j5       r/\StSE j5       r0\StSF j5       r1\StSG j5       r2\StSH j5       r3\StSI j5       r4\StSJ j5       r5\StSK j5       r6\StSL j5       r7\StSM j5       r8\StSN j5       r9\StSO j5       r:\StSP j5       r;\StSQ j5       r<\StSR j5       r=\StSS j5       r>\StST j5       r?\StSU j5       r@\StSV j5       rA\StSW j5       rB\StSX j5       rC\StSY j5       rD\StSZ j5       rE\StS[ j5       rF\SuS\ j5       rGS]rHg)vr   iK  ah  Read image and metadata from TIFF file.

TiffFile instances must be closed with :py:meth:`TiffFile.close`, which
is automatically called when using the 'with' context manager.

TiffFile instances are not thread-safe. All attributes are read-only.

Parameters:
    file:
        Specifies TIFF file to read.
        File objects must be open in binary mode and positioned at the
        TIFF header.
    mode:
        File open mode if ``file`` is file name. The default is 'rb'.
    name:
        Name of file if ``file`` is file handle.
    offset:
        Start position of embedded file.
        The default is the current file position.
    size:
        Size of embedded file. The default is the number of bytes
        from the ``offset`` to the end of the file.
    omexml:
        OME metadata in XML format, for example, from external companion
        file or sanitized XML overriding XML in file.
    superres:
        EER super-resolution level to decode.
        The default is 0 (no super-resolution).
    _multifile, _useframes, _root:
        Internal use.
    **is_flags:
        Override ``TiffFile.is_`` flags, for example:

        ``is_ome=False``: disable processing of OME-XML metadata.
        ``is_lsm=False``: disable special handling of LSM files.
        ``is_ndpi=True``: force file to be NDPI format.

Raises:
    TiffFileError: Invalid TIFF structure.

r   r"  r    r  r   r#  r   r   _root
str | Noner$  r   	_superreszdict[str | None, TiffFile]_filesz3dict[tuple[str | None, bool], list[TiffPageSeries]]_seriesz&dict[int, Callable[..., DecodeResult]]	_decodersN)	r   r   r   r   r   r   r   r   rP  c      	        
   UR                  5        HO  u  pUS S S:X  a3  USS  [        R                  ;   a  Ub  [        X[	        U5      5        M?  MA  SU 3n[        U5      e   US;  a  SU< 3n[        U5      eS U l        U(       a1  UR                  5       SS  S:w  a  Sn[        U5      eX`l        S	U l	        [        XX4US
9nXl        Uc  S	O
[	        U5      U l        UR                  U 0U l        0 U l        0 U l        U
c  U OU
U l        Uc  SO[%        S['        U5      5      U l         UR+                  S5        UR-                  S5      n SSSS.US S    n[2        R4                  " US-   USS 5      S   nUS:X  a~  [2        R4                  " US-   UR-                  S5      5      u  nnUS:w  d  US:w  a  SUU4 3n[1        U5      eUS:X  a  [        R6                  U l        GO[        R:                  U l        GOUS:X  a  US:X  a  [        R<                  U l        GOmUR?                  SUR@                  S:H  5      (       aE  UR?                  SS	5      (       a  [        RB                  U l        GO[        RD                  U l        GO[        RD                  U l        OUS:X  a2  US:X  a  [        R<                  U l        O[        RD                  U l        OUS:X  aF  US:X  a  Sn[1        U5      e[G        5       RI                  U < S35        [        RD                  U l        OjUS;   aS  [G        5       RI                  U < SUS  S!35        US:X  a  [        R<                  U l        O'[        RD                  U l        OS"U< 3n[1        U5      e[K        U 5      U l&        U RN                  (       ae  U RP                  RR                  S#:  d:  U RL                  S   RT                  S$:w  d  U RL                  S$   RT                  S$:w  a  U RW                  5         g U RX                  (       a-  U RZ                  (       d   U RL                  R]                  5         g U R`                  (       a   U Rc                  5         g U	(       a  S	U RL                  l2        g g ! [.         a    SU< 3n[1        U5      S ef = f! [^         a+  n[G        5       RI                  U < S%U<S& 35         S nAg S nAff = f! [^         a+  n[G        5       RI                  U < S'U<S& 35         S nAg S nAff = f! [^         a    URg                  5         e f = f)(Nr   r   zunexpected keyword argument: >   NrrE  r  rD  zinvalid mode=r  OME>zinvalid OME-XMLT)r   r   r   r   r   r  rs   rr   )rL  rM  s   EPrT  znot a TIFF file: header=rQ  rO  r  rP  zinvalid BigTIFF offset size rR  is_ndpiz.ndpiiRC  i1N  zinvalid NIFF filez NIFF format not supported>   RO  RS  U   z RAW format 0x04X not supportedzinvalid TIFF version=rv  rY   z) <TiffPages._load_virtual_frames> raised .128z <_ndpi_load_pages> raised )4itemsr   
FILE_FLAGSsetattrr   r   r   r$  stripis_omer   r#  r   r   rS  rU  rT  rP  rk  r   rR  r\  r   r  r   re  unpackrb  r"  r`  rc  rS  rB  NDPI_LEra  r7   r  r    r  is_lsmr  r   r   _lsm_load_pagesis_scanimagerZ  _load_virtual_framesr  rY  _ndpi_load_pages	useframesr  )rk  r   r   r   r   r   r   r   r   r   rP  r   r   rO  r   rl  headerr   versionrD  zeror  s                         rv   rn  TiffFile.__init__  s     #..*JC2Aw%CGt$>$DtE{3 % 6cU;n$ + 55"TG$CS/!||~bc"f,' o%!LDKdM","4$$z:Jwwo"]T
&.C3x=4I[	GGAJWWQZF3$'C@L	
 mmIOVAa[A!DG"}#)==T1A2771:#N 
D19
a8*d9K8LMC',,# $DI $DIB# $DI\\)R\\W-DEE||It44$(LL	$(OO	 $DIF"# $DI $DIF"#-C',,$)CDE OO	22hnWSMH # $DI $DI.gZ0#C(( #4DJ{{$$-::a=,,1::a=,,1$$&""4??JJ335 ))+ '+

$ c  31&5#C(d23F ! HNN( #""%/  ! HNN("=c\D\J   	HHJ	s   -"T! R J9T! "T! 9R1 T! &S) 7T! R..T! 1
S&;!S!T! !S&&T! )
T3!TT! TT! !T=c                .    U R                   R                  $ )zByteorder of TIFF file.)r"  r   r  s    rv   r   TiffFile.byteorder  s     yy"""ru   c                    U R                   $ )zFile handle of TIFF file.r  r  s    rv   r  TiffFile.filehandle  r  ru   c                .    U R                   R                  $ )zName of TIFF file.)r#  r   r  s    rv   r  TiffFile.filename  s     xx}}ru   c                    U R                   $ )zRoot TiffFile for OME multi-file series, else self.

In an OME-TIFF dataset that spans multiple files, all secondary
files hold a reference to the first-opened (root) file.
For single-file TIFFs this property returns the instance itself.

rP  r  s    rv   rootTiffFile.root"  s     zzru   c                     [         R                  " U R                  R                  5       5      $ ! [         a     gf = f)z<OS status of file handle descriptor, or None if unavailable.N)r  fstatr#  filenor]  r  s    rv   r|  TiffFile.fstat-  s3    	88DHHOO-.. 		s   -0 
==c                z    U R                   R                  5        H  nUR                  R                  5         M     g)zClose open file handle(s).N)rS  valuesr  r  )rk  r   s     rv   r  TiffFile.close5  s)    ;;%%'CNN  " (ru   )r   r   r   r   r   r   r   c               :	   U R                   (       d  [        R                  " / 5      $ Uc  Uc  SnUc  U R                   n	O=[        U[        5      (       d  U R                  U5      U   nUb  UR                  U   nUn	Uc  OUc  U	R                  U5      n	O[        U[        [        R                  45      (       a  U	[        U5         /n	Or[        U[        5      (       a  X   n	OX[        U[        5      (       a*  [        U[        5      (       d  U V
s/ s H  oU
   PM	     n	n
OS[        U5       3n[        U5      eU	b  [        U	5      S:X  a  Sn[!        U5      eUGc&  UGb"  UR"                  Gb  U R$                  UR&                  R(                  -   nU(       d  Uc4  UR*                  S:w  a$  [-        UR.                  UR0                  5      S   nOUR.                  nUR2                  R4                  (       aB  [        U[        5      (       a-  US:X  a'  U R6                  R9                  XUR"                  5      nOUb  [;        XmUR&                  5      nU R6                  R=                  UUR>                  UR"                  US9nO?[        U	5      S:X  a&  U	S   nUc  S	n[!        U5      eURA                  XgUS
9nO
[C        XXxS
9nUc   eUcb  Uc   eU(       d  Uc4  UR*                  S:w  a$  [-        UR.                  UR0                  5      S   nOUR.                  n URE                  USS9nU$ [        U	5      S:X  aJ  Uc  SnU	S   nUc  S	n[!        U5      eURE                  U(       a  UR.                  OURJ                  5      nU$ Uc  Sn [M        S U	 5       5      nUc   eURE                  U(       a  S/UR.                  Q7OS/URJ                  Q75      nU$ s  sn
f ! [          a  n [G        5       RI                  U < SUR.                   SU SU<S 35        URE                  S/UQ7SS9n SnAU$ ! [          a0    URE                  S/UR2                  R.                  Q7SS9n  SnAU$ f = fSnAff = f! [N         a  nSn[!        U5      UeSnAff = f)aW  Return images from select pages as NumPy array.

By default, the image array from the first level of the first series
is returned.

Parameters:
    key:
        Specifies which pages to return as array.
        By default, the image of the specified ``series`` and ``level``
        is returned.
        If not ``None``, the images from the specified pages in the
        whole file (if ``series`` is ``None``) or a specified series
        are returned as a stacked array.
        Requesting an array from multiple pages that are not
        compatible with respect to shape, dtype, compression etc.
        is undefined, that is, it may crash or return incorrect values.
    series:
        Specifies which series of pages to return as array.
        The default is 0.
    kind:
        Series format kind, such as ``'ome'`` or ``'imagej'``.
        By default, the format is auto-detected.
    level:
        Specifies which level of multi-resolution series to return
        as array. The default is 0.
    squeeze:
        Remove length-1 dimensions from image array, except X and Y.
        If ``False``, preserve all dimensions.
        Single pages are returned as 5D array of shape
        :py:attr:`TiffPage.shaped`.
        For series, the shape of the returned array also includes
        singlet dimensions specified in some file formats.
        For example, ImageJ series and most commonly also OME series,
        are returned in TZCYXS order.
        If ``None`` (default), remove length-1 dimensions except
        for ``'shaped'`` series.
    out:
        Output array, *'memmap'*, or file for image data.
        By default, a new NumPy array is created.
        If a *numpy.ndarray*, a writable array to which the image
        is copied.
        If *'memmap'*, directly memory-map the image data in the
        file if possible; else create a memory-mapped array in a
        temporary file.
        If a *string* or *open file*, the file used to create a
        memory-mapped array.
    maxworkers:
        Maximum number of threads to concurrently decode data from
        multiple pages or compressed segments.
        If ``None`` or *0*, use up to :py:attr:`_TIFF.MAXWORKERS`
        threads. Reading data from file is limited to the main thread.
        Using multiple threads can significantly speed up this
        function if the bottleneck is decoding compressed data,
        for example, in case of large LZW compressed LSM files or
        JPEG compressed tiled slides.
        If the bottleneck is I/O or pure Python code, using multiple
        threads might be detrimental.
    buffersize:
        Approximate number of bytes to read from file in one pass.
        The default is :py:attr:`_TIFF.BUFFERSIZE`.

Returns:
    Images from specified pages. See ``TiffPage.asarray``
    for operations that are applied (or not) to the image data
    stored in the file.

Nr   z0key must be an integer, slice, or sequence, not zno pages selectedr   r:   r   rY   zpage is None)r   r   r   Frd   <asarray> failed to reshape  to 	, raised r_  rK  Tc              3  .   #    U  H  oc  M  Uv   M     g 7fry   rt   r   ps     rv   r   #TiffFile.asarray.<locals>.<genexpr>  s     ?1QQ   	pages are all None)(r  r   arrayr   r   r  r  _getlistr   integerslicerS   rz   rw  r   r   r   r  r   r   r  r   squeeze_axesr   r  keyframer  r  memmap_arrayr-   
read_arrayr   r   stack_pagesrt  r7   rm  r   r  StopIteration)rk  r   r   r   r   r   r   r   r   r  r   r   typecoder   r  page0r  s                    rv   r   TiffFile.asarray:  s|   ^ zz;;r?";6>F
 >JJEfn55))$/7 u-E;^NN3'Ec5==1223s8_%EU##JEX&&z#s/C/C'*+s!1XsE+E C49+N  C. =CJ!O%CS/! K"!!-~~(9(99H7?v{{h/F$V\\6;;?B..sC((8O 55V%6%6
 ?'FLLAC33KK%%	 4  Z1_!HE}$ o%]]: # F !:F !!!;%%%7?v{{h/F$V\\6;;?BE:D ) Z1_!HE}$ o%^^7EKKMF  /??? $$$^^&-"ekk"B3F3FF A ,~  H$$("?!<<.UG9SL4LJ
 $^^RL%Lu^EF4 3 " #^^4foo3345 , F. 34 ! /* o3./sO   OO" Q= "
Q:-AP882Q2*Q51Q22Q55Q:=
RRRr   c                  U R                   (       d  Sn[        U5      eUcV  UcS  U R                  U5      S   n	U(       d  Uc#  U	R                  S:w  a  U R                  USS9S   n	U	R	                  UUUUS9$ Uc  U R                   n
O[        U[        5      (       dC  U R                  U5      U   n	U(       d  Uc#  U	R                  S:w  a  U R                  USS9U   n	U	nUc  UR	                  UUUUS9$ Ub  UR                  U   nUn
[        U[        [        R                  45      (       a  U
[        U5         nUR	                  XgS9$ Sn[        U5      e)	a  Return images from select pages as xarray DataArray.

By default, the image array from the first level of the first series
is returned.

Parameters:
    key:
        Specifies which page to return as DataArray.
        By default, the image of the specified ``series`` and ``level``
        is returned.
        If not ``None`` and an integer, the image from the specified
        page is returned.
        Requesting a DataArray from multiple pages (slice or sequence)
        is not supported.
    series:
        Specifies which series of pages to return as DataArray.
        The default is 0.
    kind:
        Series format kind, such as ``'ome'`` or ``'imagej'``.
        By default, the format is auto-detected.
    level:
        Specifies which level of multi-resolution series to return
        as DataArray. The default is 0.
    squeeze:
        Remove length-1 dimensions from image array, except X and Y.
        If ``False``, preserve all dimensions.
        If ``None`` (default), remove length-1 dimensions except
        for ``'shaped'`` series.
    maxworkers:
        Maximum number of threads to concurrently decode data.
        See :py:meth:`TiffFile.asarray` for details.
    buffersize:
        Approximate number of bytes to read from file in one pass.
        The default is :py:attr:`_TIFF.BUFFERSIZE`.

Returns:
    :py:class:`xarray.DataArray`
        Image data with coordinates, dimensions, and attributes.

z%empty xarray DataArrays not supportedr   r   Tr  )r   r   r   r   )r   r   z$key must be None or an integer index)r  r   r  r   r   r   r   r  r   r   r  )rk  r   r   r   r   r   r   r   r   r  r  r  s               rv   r   TiffFile.asxarray  sq   f zz9C%c**;6>  &q)A7?qvv/A$$T4$8;::%%	    >JJEfn55$$T*62w166X3E((t(<VDA{#))	 '    u-EcC/00).s3xD==J=NN4!#&&ru   )r   r   r   r   c                  U R                   (       d  Sn[        U5      eUcX  UcU  U R                  U5      S   nU(       d  Uc#  UR                  S:w  a  U R                  USS9S   nUR                  " SSU0UD6$ Uc  U R                   n	O[        U[        5      (       dC  U R                  U5      U   nU(       d  Uc#  UR                  S:w  a  U R                  USS9U   nUnUc  UR                  " SSU0UD6$ Ub  UR                  U   nUn	[        U[        [        R                  45      (       a  X   n
U
R                  " S0 UD6$ Sn[        U5      e)	a  Return images from select pages as Zarr store.

By default, the images from the first series, including all levels,
are wrapped as a Zarr store.

Parameters:
    key:
        Index of page in file or series to wrap as Zarr store.
        By default, a series is wrapped.
    series:
        Index of series to wrap as Zarr store.
        The default is 0 (if ``key`` is ``None``).
    kind:
        Series format kind, such as ``'ome'`` or ``'imagej'``.
        By default, the format is auto-detected.
    level:
        Index of pyramid level in series to wrap as Zarr store.
        By default, all levels are included as a multi-scale group.
    squeeze:
        Remove length-1 dimensions from image array, except X and Y.
        If ``False``, preserve all dimensions.
        If ``None`` (default), remove length-1 dimensions except
        for ``'shaped'`` series.
    **kwargs:
        Additional arguments passed to :py:meth:`TiffPage.aszarr`
        or :py:meth:`TiffPageSeries.aszarr`.

zempty Zarr arrays not supportedr   r   Tr  r   zkey must be an integer indexrt   )r  r   r  r   r   r   r   r  r   r   r  r   )rk  r   r   r   r   r   r   r   r  r  r  s              rv   r   TiffFile.aszarr`  sS   L zz3C%c**;6>  &q)A7?qvv/A$$T4$8;882%2622 >JJEfn55$$T*62w166X3E((t(<VDA{}};5;F;; u-EcC/00).D;;(((,nru   c                    [        U 5      $ )a  Series of pages with compatible shape and data type.

Call with parameters to get differently configured series::

    tif.series                    # default series, squeezed
    tif.series(squeeze=False)     # unsqueezed
    tif.series(kind='generic')    # specific kind

Notes:
    After accessing this property, ``TiffFile.pages`` might
    contain ``TiffPage`` and ``TiffFrame`` instead of only ``TiffPage``
    instances.

)r#   r  s    rv   r   TiffFile.series  s      $ru   Fr  c              L
   X4U R                   ;   a  U R                   X4   $ U(       Ga`  SnU R                  U5      n/ nU GH2  n[        UR                  UR                  5      u  pxn	XvR                  :X  a  UR                  U5        MI  [        R                  [        5      n
U
R                  R                  UR                  5        Xzl        Xl        UR                  R                  5        VVs0 s H  u  pX;   d  M  X_M     snnU
l
        U H  nU
R                  R                  US5        M!     U
/nUR                  SS  GH  n[        UR                  UR                  5      u  nnn	UUR                  :X  a  UR                  U5        MK  [        R                  [        5      nUR                  R                  UR                  5        UUl        UUl        UR                  R                  5        VVs0 s H  u  pUU;   d  M  X_M     snnUl
        U H  nUR                  R                  US5        M!     U/Ul        UR                  U5        GM     Xl        UR                  U
5        GM5     XPR                   US4'   U$ U R                  (       d  / U R                   US4'   / $ Ub   [        R                   U   nUS:w  a  ['        U SU-   S5      (       d  / $ U R                  R(                  c   eU R                  R*                  nU R                  R(                  R,                  nU" U 5      =(       d    / nUU R                  l        U R                  R/                  U5        [1        U5       H  u  nnUUl        M     UU R                   US4'   U$ U R                  R(                  c   eU R                  R*                  nU R                  R(                  R,                  nSn[        R                   R                  5        Ho  u  nnUS:X  a  M  ['        U SU-   S5      (       d  M%  U" U 5      nU(       d;  US	:X  a-  U R4                  (       a  U R                  R7                  5         Mg  US
:X  a  Mo    O   U(       d  [9        U 5      =(       d    / nUU R                  l        U R                  R/                  U5        Uc   e[1        U5       H  u  nnUUl        M     UU R                   US4'   U$ s  snnf s  snnf ! ["         a    SU< 3n[%        U5      Sef = f)a  Return list of series, computing and caching if necessary.

Parameters:
    kind:
        If ``None``, dispatch through format-specific parsers.
        If a string, compute the specified kind directly.
    squeeze:
        If ``True``, return series with length-1 dimensions removed.

)dimssizesr   r   coordscoord_scalescoord_offsetscoord_unitsmppattrsr  NrY   TFzunknown series kind=rS  r   r   mmstack)rT  r  r  _shape_axesr   r   __new____dict__r  _coordsr`  popr  r  r   SERIESr  r   getattrr  rl  r  set_keyframer  _index	is_imagej_clearseries_generic)rk  r   r   
attributes
unsqueezedsqueezedr  r   r  r   sqr   vattr	sq_levelsr   lshapelaxessq_levelfuncr   rl  r  r  r  r   skinds                              rv   r  TiffFile._get_series  sh   " ?dll*<<00J ))$/JH!-ahh!@QHH$OOA&#++N;""1::.!	/0yy/@N/@tqAIdad/@N
&DKKOOD$/ 'D	XXab\E'3ELL%++'N$FE1-!((/#1#9#9.#I ))00@*0). ).(;(;(=,(= Ez !AD(=,(
 %/D$--11$= %/+3*!((2# *$ &	#A  B *2LL$&Ozz*,DLL$'I0{{4( y ut|U)K)K	::&&222

,,Izz**00H$Z%2F#,DJJ JJ##H-!&)1 **0DLL$'Mzz""...JJ((	::&&,,.2;;,,.KE4	!tUU]E22d~$.. 

))+ 	)  /  #D)/RF(



) !!!f%DAqAH &&,dE]#e O,*  0-y1 o4/0s$   1S: S::T 

T 
2T T#c                p   U R                   nSUl        SUl        UR                  S5        UR                  S5        UR	                  S5        U R                  5         U R                  5         UR                  nUSSS2    H	  nX#l        M     [        [        US   5      nUSSS2    H	  nX#l        M     g)z%Read and fix all pages from LSM file.TrY   r   NrT  )r  cacherl  r  _load_lsm_fix_strip_offsets_lsm_fix_strip_bytecountsr   r  r_   r   )rk  r  r  r  s       rv   rh  TiffFile._lsm_load_pages7  s     

11D 	##%&&(;;#A#JD$M %(+!$Q$KD$M  ru   c                4   U R                   R                  S:  a  gU R                  n[        U5      nU R                  S   nUR
                  nSnS H  nXF   S;   d  M  XSR                  U   -  nM      [        R                  " U5      R                  S5      nUS:  a  SnS H  nXF   S	:X  d  M  UR                  U   n  O   U(       ar  [        US
U-  U-  5      u  pU
S:w  a  Sn[        U5      eXXU	S
4n[        R                  " [        U5      5      R                  U5      n[        R                  " USS5      nUS   R                  S   US   R                  S   :  a
  USSSS24   nSnSnUR                   H  nU[!        U5         n/ n[#        S UR                   5       5      (       a!  [%        5       R'                  U < SU 35          gUR                   H$  nUU:  a  US-  nUR)                  UU-   5        UnM&     [+        U5      Ul        M     g)z}Unwrap strip offsets for LSM files greater than 4 GB.

Each series and position require separate unwrapping (undocumented).

rv  Nr   rY   r   rY   PM)rK  rT  rY   rT  TrT  zmod != 0.rK  c              3  *   #    U  H	  oS :*  v   M     g7fr0  rt   r  s     rv   r   2TiffFile._lsm_fix_strip_offsets.<locals>.<genexpr>~  s     4#3a6#3rx  z" LSM file incompletely written at )r  r   r  r   r   r  r   r   arangert  divmodra  r@   moveaxisr  r  r   rl  r7   rm  r   r~   )rk  r  npagesr   r  	positionsr  indicesntimesdivmodr   r   wrappreviousoffsetnpir  r  currentoffsets                      rv   r  TiffFile._lsm_fix_strip_offsetsN  s    ??%' 

UQ{{ 	Aw$\\!_,	 
 ,,v&..w7q=F7c>#\\!_F  !&!i-&*@A!8$C&s++"C3,,wu~6>>uE..!Q7 8"U1X%9%9!%<<c4R4i(G <<CS?DK44#3#3444  h@G !%!1!1 >1EMD""=4#78!.	 "2
  %[1D  ru   c           	     @   U R                   R                  R                  S:X  a  g[        U R                   S S9n[	        U5      S-
  n[        U5       H  u  p4UR                  S-  (       a  M  UR                  nUR                  nX2:  a  XS-      R                  S   nO,[        US   SUS   -  -   U R                  R                  5      n[        [        [	        U5      S-
  5       Vs/ s H  oUS-      XX   -
  PM     snXuS   -
  /-   5      Ul        M     gs  snf )zSet databytecounts to size of compressed data.

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

rY   Nc                     U R                   S   $ r  )r  r  s    rv   r  4TiffFile._lsm_fix_strip_bytecounts.<locals>.<lambda>  s    q1Aru   r
  rT  r   rK  )r  r   r   ru  r   r  r  r  r  r  r#  r   r~   r  )	rk  r  r  r  r  offsetsr  
lastoffsetr2  s	            rv   r  "TiffFile._lsm_fix_strip_bytecounts  s    ::''1,tzz'ABUa 'GAzzA~&&G,,Jz"q5\55a8
 !BK!jn"44dhhmm
 #(6;CL1<L6MN6MQ'*,6MN+,-#D ( Os   +D
c                   U R                   nUR                  R                  R                  S5      nUb  US:  a  gSUl        SUl        UR                  5         U H  n[        U[        5      (       d   eUR                  R                  S5      nUb  US:  d  M@  [        R                  Ul        [        R                  Ul        SUl        S	Ul        ["        R$                  " ["        R&                  5      =Ul        Ul        UR*                  S
   S:  d  M  UR,                  SS
 Ul        UR.                  SS
 Ul        / UR*                  SS
 QSP7Ul        GM     g)a   Read and fix pages from NDPI slide file if CaptureMode > 6.

If the value of the CaptureMode tag is greater than 6, change the
attributes of TiffPage instances that are part of the pyramid to
match 16-bit grayscale data. TiffTag values are not corrected.

  Nr  TF  r   rY   r  rK  )r  r   r  valueofr  rl  r  r   r   r   rF  r   r   UINTr  samplesperpixelr   r   r   r  _dtyper   r  r   )rk  r  capturemoder  mags        rv   rk  TiffFile._ndpi_load_pages  s    

kk&&..u5+/DdH----))##E*C{cAg#.#9#9 $0$5$5!'($%'"+0;;u||+DD
T[;;r?Q& $		#2DI!%CRDJ"8DKK$4"8a"8DK ru   c               >   UR                  S5      (       a`  USS [        R                  ;   aI  U R                  (       d  g[	        [        U R                  R                  U5      5      n[        XU5        U$ U R                  R                  < SU< 3n[        U5      e)z.Return ``is_flag`` attributes from first page.r   r   NFz object has no attribute )r  r   
PAGE_FLAGSr  r   r  r   rb  	__class__r  r   )rk  r   rO  r   s       rv   __getattr__TiffFile.__getattr__  s}    ??5!!d12h$//&A::!1!1489ED&L((++DTHMS!!ru   c                    U $ ry   rt   r  s    rv   r  TiffFile.__enter__  r  ru   c                $    U R                  5         g ry   r   r!  s       rv   r%  TiffFile.__exit__  r'  ru   c                L    S[        U R                  R                  S5      < S3$ )Nz<tifffile.TiffFile r)  rr   )r*  r#  r   r  s    rv   r+  TiffFile.__repr__  s!    $WTXX]]B%?$B!DDru   c                "    U R                  5       $ ry   _strr  s    rv   __str__TiffFile.__str__      yy{ru   c                r  ^^ S[        U R                  R                  5      /n[        U R                  5      (       d!  UR                  SSS.U R                     5        U R                  (       a  UR                  S5        [        U R                  5      S:  a'  UR                  [        U R                  5       S35        [        U R                  5      S:  a'  UR                  [        U R                  5       S35        [        U R                  5      S:  a'  UR                  [        U R                  5       S	35        U R                  nS
U;   a*  [        U R                  5      S:X  a  UR                  S
5        UR                  SR                  S [        U5       5       5      5        SR                  U5      nUR                  [!        U R                  R"                  [%        STS-   [        U5      -
  5      5      5      nTS::  a  U$ U/nU R                  (       a1  UR                  SR                  S U R                   5       5      5        TS:  Ga  / n['        5       nU R                   GH(  n	[)        U	[*        5      (       a-  U	R,                  b  U	R.                  n
UR1                  U
5        SnO!U	R.                  n
X;   nUR1                  U
5        U(       a!  UR                  U	R3                  STS95        M  U(       a=  TS:  a  [        U5      S:  a  S/USS& UR                  SR                  U5      5        / nUR                  U	R3                  TTS95        U	R                  c  GM  UR5                  UU4S jU	R                   5       5        GM+     U(       a;  TS:  a  [        U5      S:  a  S/USS& UR                  SR                  U5      5        O|U R                  (       a'  UR5                  UU4S jU R                   5       5        ODU R                  (       a3  UR                  U R                  R6                  R3                  TTS95        TS:  ax  [        U R                  5       H_  n[9        XS-   5      (       d  M  [;        XS-   5      nU(       d  M/  UR                  UR=                  5        S[?        UTTS-  S 9 35        Ma     TS:  a  U R                  (       a  U R                   H  nUR@                  (       a?  UR                  [C        S!URD                   S"3[?        URF                  TTS-  S 95      5        URH                  (       d  Mf  UR                  [C        S!URD                   S#3[?        URH                  TTS-  S 95      5        M     S$R                  U5      $ )%aj  Return string containing information about TiffFile.

The ``detail`` parameter specifies the level of detail returned:

0: file info only.
1: all series and keyframe of each series with tags.
2: large tag values and file metadata (OME, ImageJ, etc.).
3: all pages; pages with duplicate structure are compacted.
4: all pages with full tag detail, no compaction.

zTiffFile '{}'zlittle-endianz
big-endian)rs   rr   BigTiffrY    Pagesz Seriesz FilesuniformrI  c              3  @   #    U  H  oR                  5       v   M     g 7fry   lowerr   r  s     rv   r    TiffFile._str.<locals>.<genexpr>  s     !C]''))]     r  rT  r   
c              3  8   #    U  H  n[        U5      v   M     g 7fry   rz   r   r  s     rv   r   r	  
  s     (EAQr  r   TdetailrX  r  r  ...r  c              3  D   >#    U  H  nUR                  TTS 9v   M     g7fr  Nr  )r   subifdr  rX  s     rv   r   r	  "  s%      +*4 #KKvUKC*4s    c              3     >#    U  HP  nUR                   R                  R                  R                  (       a  M4  UR                   R	                  TTS 9v   MR     g7fr  )r  parentr  closedr  )r   r  r  rX  s     rv   r   r	  +  sD      $Azz((33:: <

vU;$s
   3A!Ar+  z
_METADATA
   rX  heightzSeries z coordsz attrs

)%r0   r#  r   byteorder_isnativer   r   rZ  r   r  r   rS  r9  discardr   ru  formatr*  r   rk  setr   r   	_keyframehashaddr  r  r   r   r  rN  r?   r  indentr  r  _attrs)rk  r  rX  	info_listr9  r  detail_listframe_blockseen_hashesr  his_framer   mr  s    ``            rv   r  TiffFile._str  s    &
	 "$..11%L9$..I ??Y'tzz?QDJJ078t{{aDKK 019:t{{aDKK 0189

#djj/Q"6MM)$!CVE]!CCDyy#{{DHHMM3r519s4y+@#AB
 Q;Kf;;tyy(E(EEFQ;%'K$'EK

dI..~~1 II#*#H		A /HOOA&&&tyyy'GH"!A:#k*:R*?16K"-#**499[+AB&(&&tyyey'LMzz-#** +*.**+ ) #0 A:#k"2R"7).K"%""499[#9:[[  
 ZZ

  %%V5%A Q;tzz*4!344[&89Aq#**#zz|nK&qfrkJKM	 + A:$++[[99&&%ahhZw7#AHHE&2+N 888&&%ahhZv6#AHHE&2+N ! {{;''ru   c                    [         R                   Vs1 s H)  n[        U SU-   5      (       d  M  UR                  5       iM+     sn$ s  snf )z2Set of file flags.

May be expensive to compute.

r   )r   ra  r  r  rk  r   s     rv   r9  TiffFile.flagsO  sC     
'tUT\* DJJL'
 	
 

   AAc                   U R                   n UR                  nUR                  (       a  gUR                  (       d  UR
                  (       a  gSnUR                  n SUl        UR                  nS H+  nX   R                  5       R                  U:w  d  M%    XAl        g    XAl        g! [         a     gf = f! [         a    US:H  s XAl        $ f = f! XAl        f = f)z&File contains uniform series of pages.FTr   )rY   r  rK  rY   )	r  r   
IndexErrorrp  ri  is_nihrl  r#  aspage)rk  r  r  r  rl  r+  s         rv   
is_uniformTiffFile.is_uniform\  s     

	;;D <<OO			(#EO		A8??$))Q.  (O   (O%  		  	6M'O	 (OsA   B* 6B: B:  B: *
B76B7:C	C CC Cc                    U R                   =(       dX    U R                  =(       dE    U R                  =(       d2    U R                  =(       d    U R                  =(       d    U R
                  (       + $ )z1Pages can be appended to file without corrupting.)rd  rg  is_stkr  is_fluoviewis_micromanagerr  s    rv   rY  TiffFile.is_appendablez  s[    
 KK ${{${{$ ~~$ 	$
 ##
 	
ru   c                .    U R                   R                  $ )zFile has BigTIFF format.)r"  rZ  r  s    rv   rZ  TiffFile.is_bigtiff  s     yy###ru   c                H   U R                   nUb  UR                  SS5      S:  a  gU R                  R                  (       d  g[        R
                  R                  [        R
                  R                  U R                  R                  S5      5      nU(       a  SU l	        U$ )zFile has NDTiff format.MajorVersionr   rT  FNDTiff.indexT)
micromanager_metadatarS  r  is_filer  pathexistsr   dirnamer7  )rk  metaisndtiffs      rv   	is_ndtiffTiffFile.is_ndtiff  sx     ))<488NA6:&&77>>GGLL00.A
 "DOru   c                v    U R                   nUb*  SU;   a$  SU;   a  UR                  SS5      S:X  a  SU l        gg)z$File has Micro-Manager stack format.SummaryIndexMaprA  rY   r   TF)rC  rS  r7  )rk  rH  s     rv   
is_mmstackTiffFile.is_mmstack  sG     ))T!d"+q0 #DOru   c                    U R                   R                  R                  n U R                   R	                  SSS9R                  nU=(       d    UnU(       a  SU l        U$ ! [         a     gf = f! [         a    Sn N9f = f)zFile has MD Gel format.FrY   Tr  )r  r   is_mdgelr4  rS  r7  )rk  page0_is_mdgelpage1_is_mdgelismdgels       rv   rS  TiffFile.is_mdgel  s    
	!ZZ--66N	#!ZZ^^AT^:CCN !2N#DO  		  	#"N	#s"    A" $A2 "
A/.A/2B Bc                     U R                   R                  R                  =(       a.    U R                  R	                  5       R                  S5      (       + nU(       a  SU l        U$ ! [         a     gf = f)zFile is Olympus SIS format.z.vsiFT)r  r   is_sisr  r  endswithr4  r7  )rk  ississ     rv   rY  TiffFile.is_sis  sg    	

  '' ?++-66v>>  "DO	  		s   AA' '
A43A4c                     U R                   R                  nUR                  =(       a    UR                  $ ! [         a     gf = f)zFile is Aperio SVS format.F)r  r   r4  is_tiledis_svs)rk  r  s     rv   r_  TiffFile.is_svs  s?    	JJ$$E ~~.%,,.  		s   7 
AAc                    [        U R                  5      S:X  d  U R                  (       a  g U R                  R                  SSS9R	                  5       R
                  $ ! [         a     gf = f)zRFile contains embedded C2PA manifest in last page.

A potential expensive check.

rY   FrK  rR  )r   r  ri  rS  r6  is_c2par  r  s    rv   rb  TiffFile.is_c2pa  s\     tzz?a4#4#4	::>>"E>299;CCC 		s   1A 
A,+A,c                *   U R                   (       d  g/ nU R                   H\  nUR                  S:w  a  M  UR                  R                  c  M.  UR                  [        UR                  R                  5      5        M^     [        U5      =(       d    S$ )z<Tifffile metadata from JSON formatted ImageDescription tags.Nr   )	is_shapedr   r   r  rf  r   shaped_description_metadatar~   )rk  r  r  s      rv   shaped_metadataTiffFile.shaped_metadata  sr     ~~Avv!zz,,4MM+AJJ,I,IJ  V}$$ru   c                    U R                   (       d  gU R                  (       a  U R                  $ U R                  R                  R                  $ )z+OME XML metadata from ImageDescription tag.N)rd  r$  r  r   r   r  s    rv   ome_metadataTiffFile.ome_metadata  s5     {{<<<<zz+++ru   c                f    U R                   (       d  gU R                  R                  R                  $ )z1Leica SCN XML metadata from ImageDescription tag.N)is_scnr  r   r   r  s    rv   scn_metadataTiffFile.scn_metadata  $     {{zz+++ru   c                f    U R                   (       d  gU R                  R                  R                  $ )z2Philips DP XML metadata from ImageDescription tag.N)
is_philipsr  r   r   r  s    rv   philips_metadataTiffFile.philips_metadata  s$     zz+++ru   c                f    U R                   (       d  gU R                  R                  R                  $ )z2IndicaLabs XML metadata from ImageDescription tag.N)	is_indicar  r   r   r  s    rv   indica_metadataTiffFile.indica_metadata
  s$     ~~zz+++ru   c                f    U R                   (       d  gU R                  R                  R                  $ )z7PerkinElmer QPI XML metadata from ImageDescription tag.N)is_qpir  r   r   r  s    rv   qpi_metadataTiffFile.qpi_metadata  rp  ru   c                    U R                   (       d  gU R                  R                  R                  R	                  S5      n[        U[        5      (       a  UR                  S5      R                  5       $ U$ )z&Ventana BIF XML metadata from XMP tag.N  r+  )	is_bifr  r   r  r  r   r{   rstripdecoderk  rO  s     rv   bif_metadataTiffFile.bif_metadata  sX     {{

  %%--c2eU##<<(//11ru   c                    U R                   (       d  gU R                  R                  R                  R	                  S5      $ )z&Argos AVS XML metadata from tag 65000.N  )is_avsr  r   r  r  r  s    rv   avs_metadataTiffFile.avs_metadata"  /     {{zz$$,,U33ru   c                    U R                   (       d  gU R                  R                  R                  R	                  S5      $ )z!LSM metadata from CZ_LSMINFO tag.Nl  )rg  r  r   r  r  r  s    rv   lsm_metadataTiffFile.lsm_metadata)  r  ru   c           
        U R                   (       d  gU R                  R                  nUR                  n0 nUR                  (       a.  UR                  R                  S5      R                  S5      nXCS'   UR                  S5      nUc  SOUR                  US'   UR                  S5      nUb  UR                  U5        UR                  S5      nUb  UR                  U5        UR                  S	5      nUb  UR                  U5        UR                  S5      nUbi  US
   US
'   US   US'   US   US'   S HK  n [        R                  " [        USU-      USU-      SS9 V	s/ s H  n	[        U	6 PM     sn	SS9USU-   '   MM     U$ s  sn	f ! [         a7  n
SUSU-   '   [!        5       R#                  U < SU SU
<S 35         Sn
A
M  Sn
A
ff = f)zSTK metadata from UIC tags.N PlaneDescriptions]  rY   NumberPlanes\  ^  _  	ZDistanceTimeCreatedTimeModified)CreatedModifiedDateTimeTr4  zdatetime64[ns]rz  Datetimez STK Datetime raised r_  )r:  r  r   r  r   r  splitrS  r  r  r  r   r  r  julian_datetimer  r7   rm  )rk  r  r  r  dr  rO  uic2tagr   dtr  s              rv   stk_metadataTiffFile.stk_metadata0  s    {{zzyy!#  ''/55f=A*+&'hhuo&)ksyy~U#MM% U#MM% U#MM% ,,u%")+"6F;$+M$:F=!%,^%<F>"./4{{ '* ' 5 ' 5'+'' ,R0' /
0F:+, /$  ! /3F:+,H$$(-uHSL4LI s*   <)F%F	
7F	F
G,G

Gc                r   U R                   (       d  gU R                  R                  nUR                  c  g[	        UR                  5      nUR
                  R                  S5      nUb   UR                  U5        U$ U$ ! [         a,  n[        5       R                  U < SU<S 35         SnAU$ SnAff = f)z:ImageJ metadata from ImageDescription and IJMetadata tags.N  z <imagej_metadata> raised r_  )r  r  r   r2   imagej_description_metadatar  r  r  r   r7   rm  )rk  r  r  rO  r  s        rv   imagej_metadataTiffFile.imagej_metadata_  s     ~~zz""*,T-D-DE		!!%(e$
 v	    h8tE  	s   +B   
B6
!B11B6c                n   U R                   (       d  g0 nU R                  R                  nUR                  R	                  S5      nUb   UR                  U5        UR                  R	                  S5      nUb  X1S'   U$ ! [         a+  n[        5       R                  U < SU<S 35         SnANTSnAff = f)z3FluoView metadata from MM_Header and MM_Stamp tags.N9  z <fluoview_metadata> raised r_  :  Stamp)	r;  r  r   r  r  r  r   r7   rm  )rk  r  r  rO  r  s        rv   fluoview_metadataTiffFile.fluoview_metadatar  s     zz		!!%(e$ 		!!%(#7O %    h:3,,G s   
A? ?
B4	!B//B4c                    U R                   (       d  gU R                  R                  R                  R	                  S5      $ )z*NIHImage metadata from NIHImageHeader tag.N2  )r5  r  r   r  r  r  s    rv   nih_metadataTiffFile.nih_metadata  r  ru   c                   U R                   (       d  gU R                  R                  R                  n0 n[        R
                  " [        5         UR                  UR                  S5      5        SSS5        [        R
                  " [        5         UR                  UR                  S5      5        SSS5        U$ ! , (       d  f       NS= f! , (       d  f       U$ = f)z&FEI metadata from SFEG or HELIOS tags.Nx  z  )	is_feir  r   r  r  r  r   r  r  )rk  r  r  s      rv   fei_metadataTiffFile.fei_metadata  s     {{zz$$  +MM$,,u-. ,  +MM$,,u-. ,	 ,+++s   !B=!C=
C
Cc                    U R                   (       d  gU R                  R                  R                  R	                  S5      $ )zSEM metadata from CZ_SEM tag.NF  )is_semr  r   r  r  r  s    rv   sem_metadataTiffFile.sem_metadata  r  ru   c                   U R                   (       d&  U R                  R                  R                   (       d  gU R                  R                  R                  n0 nUR	                  S5      nUb  UR                  U5        UR	                  S5      n[        U[        5      (       a  UR                  U5        U=(       d    S$ )z9Olympus SIS metadata from OlympusSIS and OlympusINI tags.N鿂    )rY  r  r   r  r  r  r   dict)rk  r  r  rO  s       rv   sis_metadataTiffFile.sis_metadata  s     {{4::#3#3#:#:zz$$U#MM% U#eT""MM%  ~ru   c                   U R                   (       d  gSU R                  R                  R                  ;   a!  U R                  R                  R                  nO< [	        [
        U R                  S   5      nSUR                  ;   a  UR                  nOg0 n[        SS5       H3  nXA;  a  M
  [        R                  U   nUR                  U5      X5SS '   M5     U$ ! [         a     gf = f)z$MD-GEL metadata from MDFileTag tags.N饂  rY   i  rT  )rS  r  r   r  r_   r   r4  r  r   r  r  )rk  r  r  r  r  r   s         rv   mdgel_metadataTiffFile.mdgel_metadata  s     }}DJJ$$)))::##((DHdjjm4 		!yy%'D99T?D#||D1F8	 (
   s   C 
C('C(c                f    U R                   (       d  gU R                  R                  R                  $ )z#EER metadata from tags 65001-65009.N)is_eerr  r   eer_tagsr  s    rv   eer_metadataTiffFile.eer_metadata  s$     {{zz(((ru   c                f    U R                   (       d  gU R                  R                  R                  $ )z!Nuvu metadata from tags >= 65000.N)is_nuvur  r   	nuvu_tagsr  s    rv   nuvu_metadataTiffFile.nuvu_metadata  s$     ||zz)))ru   c                B    U R                   R                  R                  $ )zAndor metadata from Andor tags.)r  r   
andor_tagsr  s    rv   andor_metadataTiffFile.andor_metadata       zz***ru   c                B    U R                   R                  R                  $ )z&EPICS metadata from areaDetector tags.)r  r   
epics_tagsr  s    rv   epics_metadataTiffFile.epics_metadata  r  ru   c                    U R                   (       d  gU R                  R                  R                  R	                  S5      $ )zTVIPS metadata from tag.NJ  )is_tvipsr  r   r  r  r  s    rv   tvips_metadataTiffFile.tvips_metadata  s/     }}zz$$,,U33ru   c                x    U R                   (       d  g[        U R                  R                  R                  5      $ )z<MetaSeries metadata from ImageDescription tag of first page.N)is_metaseriesmetaseries_description_metadatar  r   r   r  s    rv   metaseries_metadataTiffFile.metaseries_metadata  s+     !!.tzz/?/?/K/KLLru   c                x    U R                   (       d  g[        U R                  R                  R                  5      $ )z+Pilatus metadata from ImageDescription tag.N)
is_pilatuspilatus_description_metadatar  r   r   r  s    rv   pilatus_metadataTiffFile.pilatus_metadata  s)     +DJJ,<,<,H,HIIru   c                P    U R                   (       d  g[        U R                  5      $ )z Non-TIFF Micro-Manager metadata.N)r<  rC   r#  r  s    rv   rC  TiffFile.micromanager_metadata  s     ##)$((33ru   c                    U R                   (       d  g0 n [        U R                  5      u  p#nXAS'   X!S'   UR                  U5        U$ ! [        [
        4 a     U$ f = f)zScanImage non-varying frame and ROI metadata.

The returned dict may contain 'FrameData', 'RoiGroups', and 'version'
keys.

Varying frame data can be found in the ImageDescription tags.

Nrn  	FrameData)ri  rE   r#  r  r   r   )rk  r  	framedataroidatarn  s        rv   scanimage_metadataTiffFile.scanimage_metadata
  sn       !#	*A$((*K'I '9"+;MM'"  :& 		s   1A	 	AAc                f    U R                   (       d  gU R                  R                  R                  $ )zGeoTIFF metadata from tags.N)
is_geotiffr  r   geotiff_tagsr  s    rv   geotiff_metadataTiffFile.geotiff_metadata   s$     zz,,,ru   c                    U R                   (       d  gU R                  R                  R                  R	                  S5      $ )z)GDAL XML metadata from GDAL_METADATA tag.N逤  )is_gdalr  r   r  r  r  s    rv   gdal_metadataTiffFile.gdal_metadata'  s/     ||zz$$,,U33ru   c                ,    [        U R                  5      $ )z"Non-TIFF GDAL structural metadata.)rB   r#  r  s    rv   gdal_structural_metadata!TiffFile.gdal_structural_metadata.  s     -TXX66ru   c                x    U R                   (       d  g[        U R                  R                  R                  5      $ )z-AstroTIFF metadata from ImageDescription tag.N)is_astrotiffastrotiff_description_metadatar  r   r   r  s    rv   astrotiff_metadataTiffFile.astrotiff_metadata3  s+       -djj.>.>.J.JKKru   c                    U R                   (       d  g[        U R                  R                  R                  U R
                  5      $ )z4Hamamatsu streak metadata from ImageDescription tag.N)	is_streakstreak_description_metadatar  r   r   r  r  s    rv   streak_metadataTiffFile.streak_metadata:  s4     ~~*JJ(($//
 	
ru   c                    U R                   (       d  gU R                  R                  S5      R                  5       R                  R                  S5      $ )z6C2PA manifest from C2PAManifestStore tag of last page.NrK  A  )rb  r  rS  r6  r  r  r  s    rv   c2pa_metadataTiffFile.c2pa_metadataC  s;     ||zz~~b!((*//77>>ru   )rU  r#  rS  r   r$  rP  rT  rR  rd  r7  r  r"  )r   r-  r   Literal['r', 'r+'] | Noner   rQ  r   r3  r   r3  r   rQ  r   r3  r   r%  r   r%  rP  TiffFile | Noner   r%  r6  r   )r6  Literal['>', '<']rC  rK  )r6  r   r6  rg   rB  ry   )r   "int | slice | Sequence[int] | Noner   int | TiffPageSeries | Noner   rQ  r   r3  r   r%  r   rw   r   r3  r   r3  r6  NDArray[Any])r   r  r   r  r   rQ  r   r3  r   r%  r   r3  r   r3  r6  rn   )r   r3  r   r  r   rQ  r   r3  r   r%  r   rg   r6  ZarrTiffStore)r6  r#   )r   rQ  r   r   r6  list[TiffPageSeries])r   rz   r6  rg   rF  rG  r   O   r  r   rX  r   r6  rz   r6  set[str]r6  r   )r6  z!tuple[dict[str, Any], ...] | Noner6  rQ  r6  r*  r6  r9  )Ir  r  r  r  r  rL  rn  rM  r   r  r  ry  rX   r|  r  r   r   r   r   r  rh  r  r  rk  r  r  r%  r+  r  r  r9  r7  rY  rZ  rJ  rO  rS  rY  r_  rb  rg  rj  rn  rs  rw  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rC  r  r  r  r   r  r
  r  r   rt   ru   rv   r   r   K  s   (T ))	OON&&@@55 +/!!#"&"&!%H=H
 (H H H H H H  H  H H  H 
HT # #        # 37I /3 #!%!%I/I ,	I
 I I I I I I 
IZ 37Y' /3 #!%!%Y'/Y' ,	Y'
 Y' Y' Y' Y' Y' 
Y'z B /3 #BB ,	B
 B B B B 
BH    &  
 
  
B%.:2x:9>	", ( (	
 
Ek(Z 

 

  : 

 

 $ $      "   / /   % % , , , , , , , , , ,   4 4 4 4 , ,\  $  < 4 4 
 
 4 4     . ) ) * * + + + + 4 4 M M J J 4 4  * - - 4 4 7 7 L L 
 
 ? ?ru   r   c                  2   \ rS rSr% SrSrS\S'    S\S'    S\S'    S	\S
'    S\S'    S	\S'    S\S'    S	\S'    S	\S'    S	\S'    S\S'    S\S'                         SS jr\SS j5       r	\SS j5       r
SS jrSS jrSS jrSS jrSrg) r   iK  zTIFF format properties.)_hashr   rg  rD  
tagformat1
tagformat2tagheaderformatrC  	tagnosizetagoffsetthresholdrE  rn  r   rn  r  r   rD  rz   rg  r'  rC  rE  r$  r%  r&  r(  r#  c                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        XSS  -   U l	        Xl
        [        XU45      U l        g NrY   )rn  r   rD  rg  r'  rC  rE  r$  r%  r&  r(  r#  r#  )rk  rn  r   rD  rg  r'  rC  rE  r$  r%  r(  s              rv   rn  TiffFormat.__init__  s[     "$("&$$)qrN:"47z:;
ru   c                     U R                   S:H  $ )zFormat is 64-bit BigTIFF.rO  )rn  r  s    rv   rZ  TiffFormat.is_bigtiff  s     ||r!!ru   c                L    U R                   S:H  =(       a    U R                  S:H  $ )z7Format is 32-bit TIFF with 64-bit offsets used by NDPI.rR  rP  )rn  rD  r  s    rv   rY  TiffFormat.is_ndpi  s!     ||r!:doo&::ru   c                    [        U[        5      (       d  [        $ U R                  U R                  U R
                  4UR                  UR                  UR
                  4:H  $ ry   )r   r   NotImplementedrn  r   rD  rk  others     rv   __eq__TiffFormat.__eq__  sR    %,,!!dnndoo>MMOOC
 
 	
ru   c                    U R                   $ ry   )r#  r  s    rv   __hash__TiffFormat.__hash__  s    zzru   c                    U R                   S:X  a  SOSnU R                  S:X  a  SOSnU R                  (       a  SOSnS	U S
U SU S3$ )NrR  3264rs   rJ  bigz with 64-bit offsets z<tifffile.TiffFormat z-bit z-endianrr   )rn  r   rY  )rk  bitsendianndpis       rv   r+  TiffFormat.__repr__  sO    ||r)tt!^^s2)-%2&tfE&aHHru   c                ^   ^  [        [        T 5      /U 4S j[        R                   5       Q76 $ )Nc              3  x   >#    U  H/  nUR                  S 5      (       a  M  U S[        TU5      < 3v   M1     g7f)r   : N)r  r  )r   r  rk  s     rv   r   %TiffFormat.__str__.<locals>.<genexpr>  s9      0Ds+ 34&74.120s   ::)r%  reprr   	__slots__r  s   `rv   r  TiffFormat.__str__  s/    J
&00
 	
ru   N)rn  r   r   r  rD  r   rg  rz   r'  r   rC  rz   rE  r   r$  rz   r%  rz   r(  r   r6  r   r  r3  objectr6  r   r6  r   rK  )r  r  r  r  r  rG  rL  rn  rM  rZ  rY  r4  r7  r+  r  r   rt   ru   rv   r   r   K  s   !I L!  #O%*N+0L%O7O8FEJ<< %< 	<
 < < < < < <  < 
<4 " " ; ;
I
ru   r   c                  
   \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'    S\S'    S\S'    S\S'    S	\S'    S	\S'    S\S'   S	\S'   SrS\S'    SrS\S'    SrS\S'    Sr	S\S'    Sr
S\S'    SrS\S'    SrS\S'    SrS\S'    SrS\S'    SrS\S '    S!rS\S"'    SrS\S#'    SrS\S$'    SrS\S%'    SrS\S&'    SrS\S''    S(rS	\S)'    S*rS+\S,'    S*rS-\S.'    S*rS/\S0'    S*rS/\S1'    S2rS\S3'    S2rS\S4'    S2rS\S5'    SrS6\S7'    S*S8.       SS9 jjrSS: jr \!  SS; j5       r"\#S<S<S<S<S<S<S=.             SS> jj5       r$\#S<S<S<S<S<S?.             SS@ jj5       r$S*S*S*SAS*S*S=.             SSB jjr$S*SCS*S*S*SD.           SSE jjr%SSF jr&SSG jr'SAS*SH.       SSI jjr(SSJ jr)SSK jr*\+SSL j5       r,\+SSM j5       r-\+SSN j5       r.\.R^                  SSO j5       r.\+SSP j5       r0\+SSQ j5       r1\!SSR j5       r2\!SSS j5       r3\!SST j5       r4\!SSU j5       r5\!SSV j5       r6\!SSW j5       r7\+SSX j5       r8\+SSY j5       r9\+SSZ j5       r:  S     SS[ jjr;\!SS\ j5       r<\+SS] j5       r=\+SS^ j5       r>\+SS_ j5       r?\!SS` j5       r@\!SSa j5       rA\!SSb j5       rB\!SSc j5       rC\!SSd j5       rD\!SSe j5       rE\!SSf j5       rF\!SSg j5       rGSSh jrHSSi jrISSSj jjrJSSk jrK\!SSl j5       rL\!SSm j5       rM\!SSn j5       rN\!SSo j5       rO\!SSp j5       rP\!SSq j5       rQ\!SSr j5       rR\!SSs j5       rS\!SSt j5       rT\!SSu j5       rU\+SSv j5       rV\+SSw j5       rW\+SSx j5       rX\+SSy j5       rY\+SSz j5       rZ\+SS{ j5       r[\+SS| j5       r\\+SS} j5       r]\+SS~ j5       r^\+SS j5       r_\+SS j5       r`\+SS j5       ra\+SS j5       rb\+SS j5       rc\+SS j5       rd\+SS j5       re\+SS j5       rf\+SS j5       rg\+SS j5       rh\+SS j5       ri\+SS j5       rj\+SS j5       rk\+SS j5       rl\+SS j5       rm\+SS j5       rn\+SS j5       ro\+SS j5       rp\+SS j5       rq\+SS j5       rr\+SS j5       rs\+SS j5       rt\+SS j5       ru\+SS j5       rv\+SS j5       rw\+SS j5       rx\+SS j5       ry\+SS j5       rz\+SS j5       r{\+SS j5       r|\+SS j5       r}\+SS j5       r~\+SS j5       r\+SS j5       r\+SS j5       r\+SS j5       r\+SS j5       r\+SS j5       r\+SS j5       rSrg*)r   i  a  TIFF image file directory (IFD).

TiffPage instances are not thread-safe. All attributes are read-only.

Parameters:
    parent:
        TiffFile instance to read page from.
        The file handle position must be at an offset to an IFD structure.
    index:
        Index of page in IFD tree.
    keyframe:
        Not used. For API compatibility with TiffFrame.

Raises:
    TiffFileError: Invalid TIFF structure.

r&   r  r   r  r   r   tuple[int, ...]r   r1  r   tuple[int, int, int, int, int]r   rz   r  r  r  r  r  r   r   
imagewidthimagelengthrY   
imagedepth	tilewidth
tilelength	tiledepthr  r   r      r   r   r   	fillorderr   r   rt   r   Nr8  r   r/  rp  r9  r   
jpegheaderr=  r   r   description1floatnodatar  c         	     $  ^&^'^( UR                   nXl        SU l        SU l        S =U l        U l        SU l        [        5       =U l        nSU l	        SU l
        [        U[        5      (       a	  U4U l        O[        U5      U l        UR                  nUR!                  5       U l         [$        R&                  " UR(                  UR+                  UR,                  5      5      S   nUS:  a  SU 3n	[5        U	5      eU R"                  UR,                  -   n
UR6                  =pUR+                  X-  5      m&[9        T&5      X-  :w  a  Sn	[5        U	5      eUR:                  (       a[  S	nUR=                  S
[>        R@                  5        UR+                  SU-  5      m'SRC                  U&U'4S j[E        U5       5       5      m&U* n[E        U5       H9  nX-  nT&XU-    n [F        RI                  XX-  -   US9nURM                  U5        M;     U(       d  g [9        U5      S:X  a  SU;   a  g [N        RP                  RS                  5        HF  u  nnURU                  U5      m(T(c  M  US;   a  [        T([V        5      (       d  M9  [Y        U UT(5        MH     URU                  SSS9m([        T([V        5      (       a  T(U l-        U R\                  S:X  a-  URU                  S5      m(T(S:X  a  SU l.        O^T(S:X  a  SU l.        OP[        U R\                  [        5      (       d1  [K        5       R_                  U < SU R\                  < 35        SU l.        URU                  S5      nUcG  URU                  S5      nUc3  URU                  S5      nUc  Sn[K        5       R/                  U < S35        UU l	        AURU                  S5      nUcG  URU                  S5      nUc3  URU                  S 5      nUc  Sn[K        5       R/                  U < S!35        UU l
        AU R`                  S";   a  [9        U R                  5      S:X  a  U R                  S   S:  a  U R                  (       a  U R                  S   S:X  ad  U R                  S   n U Rc                  5       nUU:  a  UU-
  4U l
        OURf                  U-
  4U l
        [K        5       R_                  U < S#35        U Rh                  S:X  a  U Rj                  S:X  a  U R                  (       a  U R                  (       a   UR=                  U R                  S   5        [m        UR+                  [o        U R                  S   S5      5      5      u  nnnnUU l5        UU l4        UU l8        S$U;  a  US
::  a  S
OS	U l9        S%U;  a  US:X  a  [t        Rv                  U l<        S&U;  a  [z        R|                  U l0        S'U;  a  UU l?        GO-U R`                  S(:X  am  S%U;  a  [t        Rv                  U l<        O%U Rx                  S:X  a  [t        Rv                  U l<        S$U;  a  S
U l9        S)U;  a  U Rx                  S*;   a  SU l8        GOU R                  (       d+  U R                  S:w  ae  U R                  R                  (       aJ  US$   R                  5         U R`                  S:X  a%  U R                  S:w  a  [        R                  U lC        GO*U R                  (       d+  U R                  S:w  a$  U R                  R                  (       a	  SU lG        GOU R                  (       d+  U R                  S:w  a+  U R                  R                  (       a  SU lG        SU lI        GOU R                  (       a  UR                  S+5      nUc   eUR=                  UR                  5        UR                  S,5      n [        UUR                  UR                  UR                  SUb  UR                  OSS-9UlP        GOUR                  (       a  U R`                  S/;   a  S=nnU R`                  S0:X  aJ  [        U R                  RU                  S1S5      5      n[        U R                  RU                  S2S5      5      nU =Rh                  S[o        UUR                  5      -  -  sl4        U =Rj                  S[o        UUR                  5      -  -  sl5        U =R~                  S[o        UUR                  5      -  -  sl?        UR                  S35      nUb4   [        UR                  US4   R                  UR                  5      UlP        URU                  S$5      m(T(by  U Rr                  S:w  a  OhUS$   R                  S:X  a  [        T(5      U l9        ODT(S U Rp                   m([        U(4S6 jT( 5       5      (       a  T(U l9        O[        T(S   5      U l9        URU                  S75      m(T(bu  US7   R                  S:X  a   [        T(5      U lU        OT(S U Rp                   m([        U(4S8 jT( 5       5      (       a   [        T(5      U lU        Ov [        T(S   5      U lU        OaU Rr                  S9:X  aQ  U R                  (       d+  U R                  S:w  a0  U R                  R                  (       a  [        R                  U lU        S:U;   a  SU l?        OUS;U;   aO  S'U;  d  US'   R                  S:  a  U Rj                  U l?        [o        U R~                  U Rj                  5      U l?        [N        R                  R                  U R                  U Rr                  4S 5      nUb  [        R                  " U5      OS nU=U l        U l        U Rj                  nU Rh                  nU R                  n U Rp                  nU Rx                  S:X  d  US:  a~  U R                  S:X  a7  SU UUU4U l        U S:X  a  UUU4U l        S<U l        O~U UUU4U l        S=U l        OkUU UUS4U l        U S:X  a  UUU4U l        S>U l        OGUU UU4U l        S?U l        O4SU UUS4U l        U S:X  a  UU4U l        S@U l        OU UU4U l        SAU l        U R                  (       dX  [        U R                  5      U Rr                  S
-  -  4U l
        U R`                  S:w  a  [K        5       R/                  U < SB35        U(       Ga9  U R~                  (       Ga'  U R                  (       Gd  [        R                  " UU R~                  -  5      U R                  -  n!U R                  S:X  a  U!U Rp                  -  n!U![9        U R                  5      :w  aJ  [K        5       R/                  U < SC[9        U R                  5       SDU! SE35        U R                  S U! U l
        U![9        U R                  5      :w  aJ  [K        5       R/                  U < SF[9        U R                  5       SDU! SE35        U R                  S U! U l	        URU                  SG5      m(T(b  Ub   [        UR                  S5      R                  5       5      n"T(R                  SHSI5      m(U"" T(5      U la        [        R                  " [        R                  " U R                  5      U5      (       d4  [K        5       R_                  U < SJU R                  < SKU 35        SU la        URU                  SM5      n#U#GbN  U R:                  (       Ga;  U#R                  [        R                  5      n#URU                  SN5      n$U$bF  U$R                  [        R                  5      n$U$S9-  n$U#U$R                  [        R                  5      -  n#UR=                  U R                  S   5        UR+                  U#S   5      n% [        U%5      u  U lj        U lk        U ll        [        R                  " U#U R                  S   SO9n[        UR                  5       5      U l
        U#U R                  S   -  n#[        U#R                  5       5      U l	        g g g ! [$        R.                  [0        [2        4 a   nSU R"                   3n	[5        U	5      UeS nAff = f! [4         a*  n[K        5       R/                  SU<S 35         S nAGM  S nAff = f! [d         a    Sn GNYf = f! [d         a     GNf = f! [d         a,  n[K        5       R_                  U < S.U<S 35         S nAGN"S nAff = f! [d         a,  n[K        5       R_                  U < S5U<S 35         S nAGNS nAff = f! [2         a    [        T(5      U lU         GNf = f! [2         a    [        T(5      U lU         GNf = f! [2         a    [        T(S   5      U lU         GNf = f! [2        [        [        4 a3  n[K        5       R_                  U < SLU<S 35        SU la         S nAGNS nAff = f! [2         a+  n[K        5       R_                  U < SPU<S 35         S nAg S nAff = f)QNrt   )r   r   r   r   r   r=  r   corrupted tag list @   suspicious number of tags zcorrupted IFD structurer  rP  r  ru   c              3  ^   >#    U  H"  nTUS -  US -  S -    TUS-  US-  S-    -   v   M$     g7f)r  r  Nrt   )r   r  r  exts     rv   r   $TiffPage.__init__.<locals>.<genexpr>  sC      %A QVa"frk*SQQ-CC%s   *-r   rm  z<TiffTag.fromfile> raised r_  rY   r  >   r  r  r  r  r  rT  r   z invalid self.subfiletype=r  r    z missing data offset tagr  r    z missing data ByteCounts tag   rT  r   r  z1 estimating ByteCounts for CCITT compressed stripr  r  r  r  r  r  >   r   rY   rT  r  r  r  )
planecountz  <tifffile.read_uic1tag> raised    r      rk      r    z# <tifffile.imagej_metadata> raised c              3  2   >#    U  H  oTS    -
  v   M     g7fr0  rt   r   r  rO  s     rv   r   rb  a       3U58|U   r  c              3  2   >#    U  H  oTS    -
  v   M     g7fr0  rt   rp  s     rv   r   rb  p  rq  rr  r)  r  r  YXSZYXSSYXSZYXYXZYXz missing ByteCounts tagz" incorrect StripByteCounts count (r  )z incorrect StripOffsets count (遤  ,.z, parsing GDAL_NODATA tag raised ValueError: z is not castable to z  parsing GDAL_NODATA tag raised     )r   z" <tifffile.ndpi_jpeg_tile> raised )or"  r  r   r   r   r  r  r&   r  r  r  r   r   r  r~   r  rX  r   re  re  rC  r   r'  r  r]  r   r   rE  r   rY  r\  r  r  r   r  r$   fromfiler7   r$  r   TAG_ATTRIBUTESr`  r  rz   rb  rX  r   rm  r   _nextifdr  r   rO  rP  
jpeg_shaper  r  r   r   rI  r   r   OJPEGr   rg  r  _fix_lsm_bitspersampler   r   r   is_vistarQ  rr  rT  r:  rS  r  read_uic1tagr   r  rO  rR  r  r;  r   r  rv  IEEEFPSAMPLE_DTYPESr   r   r@   ro  rp  rw  itemreplacerZ  can_castmin_scalar_typer   r   r,   int64uint64ndpi_jpeg_tilerS  rR  rW  difftolist))rk  r  r  r  r"  r  rl  tagnor  r   r  rE  tagsize_r  r  tagdatar  r  r   r  r  r  nextifd	precisionrP  rO  r  r  horzbitsvertbitsdtypestrr   rQ  	maxstripspytype	mcustartshighrW  r  ra  rO  s)                                         @@@rv   rn  TiffPage.__init__M  sO    {{
%#''
T[	#:%	D eS!! (DK,DK ggi	.  "''$.."9E 4<.ug6C$$KK$..0	!\\)www't9'+C$$<<GGGAr{{#''!e)$C88 u D
 8uAH8&89G&&q|#;G '  HHSM  t9>etm--335JD$LL&E}z!*UC*@*@D$& 6 S*eS!! %Dq LL%Ez#& !#' D,,c22Hx'B1A1A0CDE D ll3',,s+K""ll3/&"$KHNNdX-E#FG& c*!!\\#.N%!%c!2!)%'NHNNdX-I#JK, 	)D$$%*  #a'((D,?,?,Ba,G
 ))!,J--/ #'.';&=#')ww';&=#H(KL
 OOq   A%  ##4((+, rwws4+>+>q+A4'HIJ#
 $/ ",'6$d?.71n"D&d?!';'2'8'8D$d?'2'8'8D$d?(3D%"$#.#4#4 !!Q&#.#4#4 $%&"$4#3#3|#C'($[[TZZ1_1C1CI,,.1$1)<!*]]tzzQ4;;3G3GDO__qT[[5K5KDODN[[((5/C?"?GGCOO$hhuoG(NNIIII070Cw}}	 $"2"26K"K"##Hx5(tyy00:;tyy00:;OOqS63C3C%DEEOc(F4D4D&E FFs8V5E5E'F!GGhhuo?	+IIK%%NN	 S!!!Q&cA%%(Z" 4 4 453U333).D&),U1XD& S!Cy!#3(4U(;D% 4 4 453U3337,8,?):,8q,B) 2%NNtzzQ4;;3H3H !- 3 3D$; !DD[$$s)//A"5$($4$4! #D$5$5t7G7G HD %%)) 2 23T
 *2)=H%4#((
T[ &&__
__
..q Oa$7  A%# ?"-z?!KDJ %DI ##"'	"DJ !'DI $ ?"1;
!KDJ %DI ("#"	"DJ !'DIj+z1EDKQ):6
 	(+zB
!	""

#t'9'9Q'>?#D 1$$)@AB4,,,T[[[ 		+(9(99:T__L    A%T111	C 3 344h D//01i[C '+&9&9*9&E#C 0 011h D,,-.d9+Q@ $(#3#3JY#? U#!2$ejjm0023c3/$Um ~~))$++6  H$$("N;;/)=eWF #$DKLL'	 T\\\!((5I<<&D{{5<<0T[[55	GGD$$Q'(1.J=
 #:.	ONO "'d&9&9!&<" ',N,A,A,C&D#T--a00	#()9)9);#< 9 &2 Y gz2 	.(6C$#-	.B ! !;C<$<HIn  4  z    h>slTlK .    hA#N 4 " 3(+E
D%3 & 7,/J)7
 & :,/aM):` 	>:    h>slTlK  	 B    h@tM s0  (=AA AB!>AC AAC+ A AC<  3AD5 AE. AF AF0 AAG AH AABA>ABBABB!
ACB+ACCACCAC(C'AC(C+
AC9C8AC9C<
AD2D!AD-D-AD2D5
AE+D?!AE&E&AE+E.AFFAFFAF-F,AF-F0AGGAGGAHG)(AHHAHH
AIH)!AIIAIc                    U R                     g)a8  Initialize decode function from the main thread.

:py:meth:`decode` is a :py:func:`functools.cached_property` and is not
thread-safe on first access. Call this method from the main thread
before decoding segments concurrently to avoid a race condition where
multiple threads compute the decoder simultaneously.

Nr  r  s    rv   init_decodeTiffPage.init_decode  s     	ru   c                  ^ ^^^^^^^^^^^^^^^ ^!^"^#^$^%^&^'^(^)^*^+^,^-^.^/^0^1^2^3^4^5^6^7^8 T R                   T R                  R                  R                  ;   a-  T R                  R                  R                  T R                      $ U 4S jnT R                  b  T R
                  c,  ST R                   ST R                   S3nUS.S jnU" U5      $ ST R                  ;   a  S	 nU" U5      $ T R                  S
;   aK  T R                  R                  (       d0  [        [        T R                  5      5      SS nUS.S jnU" U5      $  T R                  S:X  a  SmO[        R                  T R                     m  T R                  S:X  a  Sm4O[        R                   T R                     m4 T R(                  R+                  S5      bQ  T R(                  S   m2T2R,                  S:w  a2  [/        U24S jT2R0                   5       5      (       a  U24S jnU" U5      $ T R2                  (       a+  T R                  S;  d  T R4                  S:X  a  S n	U" U	5      $ T R                  S:X  a  T R6                  S:X  a  SOS jn
U
mT R8                  (       aA  T R:                  T R<                  T R>                  T R4                  S:X  a  T R6                  OS4m.O6ST R@                  T RB                  T R4                  S:X  a  T R6                  OS4m.T.u  m,m-m/m*T R                  u  nmmm m*T RD                  m$T R                  mT R8                  (       a  [F        RH                  " T T/-  5      m8[F        RH                  " TT--  5      m#[F        RH                  " TT,-  5      mT8T#-  mTT-  m7    SPUUU#U,U-U.U/U7U84	S jjm!        SQUUU U*4S jjm(      SRU$4S jjm&    SSS jm'OS[F        RH                  " TT--  5      m#    SPUUU#U*U,U-U/4S jjm!        SQS jm(      SRU$U-4S  jjm&    SSU-4S! jjm'T R                  S;   a  T RJ                  S:X  a  [%        5       RM                  T < S"35        T4(       a  [%        5       RM                  T < S#35        S$T R(                  ;   a  [%        5       R'                  T < S%35        [O        T RP                  T R4                  T RR                  T RT                  5      u  mm%SSS&S'.           STUUU!U%U&U'U(4S( jjjnU" U5      $ T R                  S
;   a  S=mm6T R                  S):X  ap  [W        T R(                  RY                  S*S+5      5      m+[W        T R(                  RY                  S,S5      5      m[W        T R(                  RY                  S-S5      5      m6OT R                  S.:X  a  S+m+OS/m+T R                  RZ                  m0SSS&S'.           STUU!U'U+U0U64S0 jjjnU" U5      $ T R                  S1:X  a(  Tc   eSSS&S'.           STUU!U'4S2 jjjnU" U5      $ T R                  S3;   a  T RJ                  S:H  m5T R                  S:X  a  [\        R^                  mOPT R                  S4:X  a0  [W        T R(                  RY                  S5S5      5      m1SS6.U14S7 jjmO[\        R`                  mSSS&S'.           STUU!U&U'U(U/U54S8 jjjnU" U5      $ T R                  [        R"                  ;   a  T RJ                  S:X  a)  [%        5       RM                  T < S9T R                   35        T4(       a)  [%        5       RM                  T < S:T R                   35        Tc   eSSS&S'.           STUU!U&U'U(4S; jjjnU" U5      $ [b        R                  " T R                  Rd                  T R
                  Rf                  -   5      mT R                  S<:X  a  T4b  S=n[i        U5      e[b        R                  " T R                  Rd                   S>T R                  S?-   35      m"[b        R                  " T R                  Rd                   S@TRj                  S-   35      mSUUUU"4SA jjm3OT R                  SB;   ap  T R                  T/-  T*-  S/-  (       a  SCn[m        U5      eT R                  SD;   a*  [b        R                  " T R
                  Rf                  5      mTS/-  mSUUU4SE jjm3Oq[o        T R                  [p        5      (       a
  SUUU 4SF jjm3OHT R                  SG:X  a)  TRf                  S@:X  a  T4b  SHn[i        U5      eSUU 4SI jjm3OT/T*-  m)SUUUU)4SJ jjm3TRf                  mTRj                  mT RJ                  S:H  m5Tc#  T4c   SSS&S'.           STUU!U&U'U(U3U54SK jjjnOvTb%  T4c"  SSS&S'.           STUUUU!U&U'U(U3U54	SL jjjnONTc$  T4b!  SSS&S'.           STUU!U&U'U(U3U4U54SM jjjnO'Tc   eSSS&S'.           STUUUU!U&U'U(U3U4U54
SN jjjnU" U5      $ ! [         a'  n[        U5      SS nUS.S jnU" U5      s SnA$ SnAff = f! [         av  nT R                  [        R"                  ;   a1  [%        5       R'                  T < ST R                   35        Sm4 SnAG	N![        U5      SS nUS.S jnU" U5      s SnA$ SnAff = f)Vav  Return decoded segment, its shape, and indices in image.

The decode function is implemented as a closure and has the following
signature:

Parameters:
    data (Union[bytes, None]):
        Encoded bytes of segment or ``None`` for empty segments.
    index (int):
        Index of segment in Offsets and Bytecount tag values.
    jpegtables (Optional[bytes]):
        For JPEG compressed segments only, value of JPEGTables tag
        if any.

Returns:
    - Decoded segment or ``None`` for empty segments.
    - Position of segment in image array of normalized shape
      (separate sample, depth, length, width, contig sample).
    - Shape of segment (depth, length, width, contig samples).
      The shape of strips depends on their linear index.

Raises:
    ValueError or NotImplementedError:
        Decoding is not supported.
    TiffFileError:
        Invalid TIFF structure.

c               b   > U TR                   R                  R                  TR                  '   U $ ry   )r  ry  rU  r#  )r  rk  s    rv   r  TiffPage.decode.<locals>.cacheD  s&    4:DKK&&tyy1Mru   Nz&data type not supported (SampleFormat r   z-bit))r   c                    [        U 5      ery   r   r   argsr   s      rv   decode_raise_dtype+TiffPage.decode.<locals>.decode_raise_dtypeO       o%ru   r   c                     Sn[        U5      e)Nzempty imager  r  r   r   s      rv   decode_raise_empty+TiffPage.decode.<locals>.decode_raise_emptyV  s    # o%ru   ri  rY   rK  c                    [        U 5      ery   r  r  s      rv   decode_raise_compression1TiffPage.decode.<locals>.decode_raise_compressionc  r  ru   c                    [        U 5      ery   r  r  s      rv   r  r  p  r  ru   z ignoring predictor c                    [        U 5      ery   r  r  s      rv   decode_raise_predictor/TiffPage.decode.<locals>.decode_raise_predictor  s    $S/)ru   r  c              3  F   >#    U  H  oTR                   S    -
  v   M     g7fr0  rO  )r   r  r  s     rv   r   "TiffPage.decode.<locals>.<genexpr>  s     %J	1#))A,&6	   !c                 8   > STR                    3n[        U5      e)Nzsample formats do not match )rO  r   )r  r   r   r  s      rv   decode_raise_sampleformat2TiffPage.decode.<locals>.decode_raise_sampleformat  s    8DC$S/)ru   r  rT  c                     Sn[        U5      e)Nz9chroma subsampling not supported without JPEG compressionr   r  s      rv   decode_raise_subsampling1TiffPage.decode.<locals>.decode_raise_subsampling  s    O  *#..ru   r  r  c                .    [         R                  " U SUS9$ )NT)hasalphar   )r(  webp_decode)r  r   r   s      rv   decompress_webp_rgba-TiffPage.decode.<locals>.decompress_webp_rgba  s    "..tdLLru   c               L   >	 U T-  U T-  T-  T-  U T	-  T-  T-  U T	-  T-  S4T4$ r  rt   )
segmentindexarearZ  rY  stdepthstlengthstshapestwidthvolumerX  s
    rv   r   TiffPage.decode.<locals>.indices  sU     %.%-6@%.&88C$u,w6 	 	ru   c          	     Z  > US   US   -  US   -  US   -  nU R                   S:X  a  U R                  U:  a  U S U n U R                  U:X  a  U R                  U5      $  U R                  [        TUS   -
  US   5      [        TUS   -
  US   5      [        TUS   -
  US   5      T45      $ ! [         a     Of = f U R                  [        TUS   -
  US   5      [        TUS   -
  US   5      US   T45      $ ! [         a     Of = fSU SU R
                   SU 3n[        U5      e)Nr   rY   rT  r   zcorrupted tile @ z cannot be reshaped from r  )r  r   rt  r  r   r   r   )	r  r  r   r   r   imdepthimlengthimwidthr\  s	        rv   rt   TiffPage.decode.<locals>.reshape  s{    Qx%(*U1X5a@99>dii$&6;D99$  <<..  <<'!* 4eAh?71: 5uQx@'!* 4eAh?#	  "   <<'!* 4eAh?71: 5uQx@!!H#	  "  (y0Izzl$ug/  $C((s%    AB. .
B;:B;?=C= =
D
	D
c                  > U R                   U:X  a  X4$ [        XR                   SS9 VVs/ s H  u  p#SX#-
  4PM     nnn[        R                  " XTS9n X4$ s  snnf )NTr4  r   constant_values)r   r  r   r  )r  r   r  r2  padwidthrZ  s        rv   r  TiffPage.decode.<locals>.pad  sh     ::&;&+.ujj+N+N41QJ+N   yyH{"	s   Ac                   U $ ry   rt   r   s    rv   pad_none!TiffPage.decode.<locals>.pad_none  s	     ru   c               n   > U TT-  -  U T-  T-  T-  U T-  T-  SS4nT[        TTUS   -
  5      T	T4nX4$ )Nr   rT  )r  )
r  
segindicesr   r  r  rY  r\  r  r  r  s
      rv   r  r    sn     !Vg%56!V+w6@ 6)H4
 (Z]":;	 "((ru   c                  US   US   -  US   -  US   -  nU R                   S:X  a  U R                  U:  a  U S U n U R                  U:X  a  U R                  U5      $ U R                  n U R                  US   SUS   US   4SS9n U S S 2S US   24   n U R                  USS9n U $ ! [         a     Of = fSU S	U 3n[        U5      e)
Nr   rY   rT  r   rK  Fr  z(corrupted strip cannot be reshaped from r  )r  r   rt  r   r   r   )r  r  r   r   r  r   s         rv   rt  r  .  s    Qx%(*U1X5a@99>dii$&6;D99$<<.. JJ	
 <<q2uQxq: ( D  :U1X:.D<<E<:D  K " 
 ? keW.  $C((s   +;B( (
B54B5c                  > US   TUS   US   4nU R                   U:X  a  X4$ SSTU R                   S   -
  4SS/n[        R                  " XTS9n X4$ )Nr   rT  r   r}  rY   r  )r   r   r  )r  r   r  rZ  r  s      rv   r  r  N  sr     q8U1XuQx@::&;&4::a=01	 yyH{"ru   c               "   > U S   TU S   U S   4$ )Nr   rT  r   rt   )r   r  s    rv   r  r  ^  s      a(E!HeAh??ru   z disabling LSB2MSB for JPEGz disabling predictor for JPEG p  z@ SonyRawFileType might need additional unpacking (see issue #95)F)r   rW  	_fullsizec                 > T
" U5      u  pVU c  U(       a  T" U5      nXU4$ [         R                  " U TUUT	TUSS S9nT" XuU5      nU(       a
  T" Xv5      u  pvXuU4$ )NrY   r   )r   tablesrm  r  r  r   )r(  jpeg_decode)r  r  r   rW  r  r  r   
data_arrayr   r  r  r  r  r  rt  s           rv   decode_jpeg$TiffPage.decode.<locals>.decode_jpeg|  s     '.en#<  (u44+6+B+B"/%%)"/!*,
 %ZuE
(+J(>%J!66ru   rk    r  rl  rm  rj  rP  c         	        > T	" U5      u  pVU c  U(       a  T
" U5      nXU4$ [         R                  " U USS TTTTS9nUR                  U5      XV4$ )NrY   r   )r   )r(  
eer_decodert  )r  r  r   rW  r  r  r   r  r  r  r  skipbitsr   r  s           rv   
decode_eer#TiffPage.decode.<locals>.decode_eer  sm     '.en#<  (u44(33!AJ%
 "))%0,EEru   r  c                 > T	" U5      u  pVU c  U(       a  T
" U5      nXU4$ [         R                  " U[         R                  5      nT" XS9  UR                  U5      XV4$ )Nr   )r   zerosr  rt  )r  r  r   rW  r  r  r   r  
decompressr  r  s           rv   decode_jetraw&TiffPage.decode.<locals>.decode_jetraw  s_     '.en#<  (u44"[[=
40!))%0,EEru   rg  r   $  r   c              2   > [         R                  " XUTUS9$ )N)	t4optionsr   )r(  ccittfax3_decode)r  r  rX  r   r  s       rv   ccitt_decompress)TiffPage.decode.<locals>.ccitt_decompress  s!     '77eyc ru   c                 > T	" U5      u  pVU c  U(       a  T" U5      nXU4$ T(       a  [         R                  " U 5      n T" XS   T5      nT" XuU5      nU(       a
  T
" Xv5      u  pvXuU4$ r*  )r(  bitorder_decode)r  r  r   rW  r  r  r   r  r  r  r  r  rt  r  use_bitorders           rv   decode_ccitt%TiffPage.decode.<locals>.decode_ccitt  s|     '.en#<  (u44&66t<D+;(G,
 %ZuE
(+J(>%J!66ru   z# disabling LSB2MSB for compression z% disabling predictor for compression c                 > T	" U5      u  pVU c  U(       a  T" U5      nXU4$ T" U 5      nT" XuU5      nU(       a
  T
" Xv5      u  pvXuU4$ ry   rt   )r  r  r   rW  r  r  r   r  r  r  r  r  rt  s           rv   decode_image%TiffPage.decode.<locals>.decode_image  s^     '.en#<  (u44'-
$ZuE
(+J(>%J!66ru   r  z+unpredicting complex integers not supportedr  r  r  c               n   > [         R                  " U T5      R                  T5      R                  T5      $ ry   )r   
frombufferr,   view)r  r   ftypeitypes    rv   re  TiffPage.decode.<locals>.unpack@  s,    ''e4;;EBGGNNru   >   rP  r  r)  @   r  zdata and sample size mismatchr  c                  >  [         R                  " U T5      $ ! [         a.    [        U 5      T-  T-  n[         R                  " U S U T5      s $ f = fry   )r   r  r   r   )r  r   r*  r   s     rv   re  r  Q  sY    @ ++D%88! @I,3D ++D$K??@s    5AAc               2   > [        U TTR                  5      $ ry   )
unpack_rgbr   )r  r   rk  s    rv   re  r  ^  s    !$t/A/ABBru   r  z"unpredicting float24 not supportedc               V   > [         R                  " U TR                  R                  S9$ )Nr   )r(  float24_decoder  r   )r  rk  s    rv   re  r  i  s%    "11DKK$9$9 ru   c               2   > [         R                  " U TTTS9$ )Nr&  )r(  packints_decode)r  r   r   r'  s    rv   re  r  s  s    "22%v ru   c                 > T	" U5      u  pVU c  U(       a  T" U5      nXU4$ T(       a  [         R                  " U 5      n T" U 5      nT" XuU5      nUR                  ST-   SS9nU(       a
  T
" Xv5      u  pvXuU4$ )NrH  Fr  r(  r  r,   )r  r  r   rW  r  r  r   r  	dtypecharr  r  r  rt  re  r   s           rv   decode_other%TiffPage.decode.<locals>.decode_other  s     '.en#<  (u44&66t<D#D\
$ZuE
'..sYU.K
(+J(>%J!66ru   c              0  >	 T" U5      u  pVU c  U(       a  T" U5      nXU4$ T(       a  [         R                  " U 5      n US   US   -  US   -  US   -  nT	" XT-  S9n T" U 5      nT" XU5      nUR                  ST
-   SS9nU(       a
  T" X5      u  pXU4$ )	Nr   rY   rT  r   r   rH  Fr  r  )r  r  r   rW  r  r  r   r   r  r  r  dtypeitemsizer  r  r  rt  re  r   s            rv   r  r    s     '.en#<  (u44&66t<DQx%(*U1X5a@!$=,@A#D\
$ZuE
'..sYU.K
(+J(>%J!66ru   c                 > T	" U5      u  pVU c  U(       a  T" U5      nXU4$ T(       a  [         R                  " U 5      n T" U 5      nT" XuU5      nUR                  ST-   SS9nT" USUS9nU(       a
  T
" Xv5      u  pvXuU4$ )NrH  Fr  ry  r  r   r  )r  r  r   rW  r  r  r   r  r  r  r  r  rt  re  	unpredictr   s           rv   r  r    s     '.en#<  (u44&66t<D#D\
$ZuE
'..sYU.K
&z
K
(+J(>%J!66ru   c              @  >
 T" U5      u  pVU c  U(       a  T" U5      nXU4$ T(       a  [         R                  " U 5      n US   US   -  US   -  US   -  nT	" XT-  S9n T" U 5      nT" XU5      nUR                  ST
-   SS9nT" US	US
9nU(       a
  T" X5      u  pXU4$ )Nr   rY   rT  r   r   rH  Fr  ry  r  r  )r  r  r   rW  r  r  r   r   r  r  r  r  r  r  r  rt  re  r  r   s            rv   r  r    s     '.en#<  (u44&66t<DQx%(*U1X5a@!$=,@A#D\
$ZuE
'..sYU.K
&z
K
(+J(>%J!66ru   ry   )r  r   r6  z@tuple[tuple[int, int, int, int, int], tuple[int, int, int, int]])r  r  r  rN  r   tuple[int, int, int, int]r6  r  )r  r  r   r   r6  z.tuple[NDArray[Any], tuple[int, int, int, int]])r   r   r6  r   )r  zbytes | bytearray | Noner  r   r   r9  rW  r9  r  r   r6  r   )r  zbytes | bytearrayr6  r  )9r#  r  ry  rU  r   r  r  r   r   r   r  rz   r  r   DECOMPRESSORSr   UNPREDICTORSrQ  r7   rm  r  rS  r  r;  rO  is_subsampledr   r  r^  rT  rS  rR  r   rO  rZ  ro  rp  rV  debugjpeg_decode_colorspacer   r   is_jfifr   r  rR  r(  ccittrle_decodeccittfax4_decoder   r   r  r   r   r   r   r~   )9rk  r  r   r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r   r*  r  r  r  rZ  r   r  r  r	  r  r  r  r  r  r
  rY  rZ  r  r  r  rt  r'  r\  r  r  r  r  r  r   r  r  re  r  r   r  r  rX  s9   `                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@rv   r  TiffPage.decode!  s_   @ 99((222;;##--dii88	 ::!4!!%!2!2 32%%&e-  /2 & +,,& +,,  55KK&&ht//01!B7C47 & 122	31$!
!//0@0@A
	5~~" 	 --dnn=	  99==)))C.CyyA~#%J		%J"J"J* 677$88  A%/ 122u$)=)=)BM .J ==(,(9(9Q(>$$A	G !!(,(9(9Q(>$$A	G /6+7G15.7Hgw**==IIg/0EYYx(23FIIg/0E6>DE\F! "-)"-)7-) 1-)
 -) -)^
#"
#+D
#?
#0* YYx(23F)!)) )*)")7) 1)
 )@#"#+D#?# # @0@*@ 33~~"$)DEF$)FGH		!  h 0 0 )?  !!!!	)%J ,0+/"'7.77
 )7 )7  7 7 7: %%44"##Hx5(tyy00:;tyy00:;tyy00:;!!U*{{,,H ,0+/"'F.FF
 )F )F  F F F2 $$u$))) ,0+/"'F.FF
 )F )F  F F F& ''y(  >>Q.L1$#.#>#> !!Q&		 1 1#q 9:	 48  $/#?#?  ,0+/"'7.77
 )7 )7  7 7 72 &&t666~~"h 99=9I9I8JL h ;;?;K;K:LN ))) ,0+/"'7.77
 )7 )7  7 7 7. &&DKK11DKK4D4DDE!$C)#..KK;;(()4+=+=+C*DEE KK;;(()5>>Q+>*?@EO O #77 ""W,w6!;5 o%~~!22 DKK$4$451$C@ @ **E22C C 2%%***;$:)#..  w&F  JJ	~~*)"3 ,0+/"'7.77
 )7 )7  7 7 70 #	(9 ,0+/"'7.77
 )7 )7  7 7 7 76 I$9 ,0+/"'7.77
 )7 )7  7 7 7 76 ))) ,0+/"'7.77
 )7 )7  7 7 7 7: \""G  	3c(1R.C47 & 122	3  	54#:#::  h24>>2BC !	 #hqn69 * 344	5sO   h> h> 9i2 i2 >
i/i*$i/*i/2
k2<A	k-k-'k2-k2.)lockr   r  r   r   r  c                   g ry   rt   rk  r*  r   r  r   r   r  s          rv   segmentsTiffPage.segments  s     "%ru   )r*  r   r   r   r  c                   g ry   rt   r,  s          rv   r-  r.    s     ru   Fc             #    #    U R                   nU R                  R                  nUc  UR                  nUc  UR                  nSU0n	UR
                  S;   a  U R                  U	S'   UR                  U	S'   UR                  n
Uc  X4S jnOU	U
U4S jn[        U R                  5      nUb  US:  a  UR                  nUS	:  a;  UR                  U R                  U R                  UUUUS
S9 H  nU" U5      v   M     g[        U5       nUR                  U R                  U R                  UUUUSS9 H  nUR!                  X5       Sh  vN   M     SSS5        g N! , (       d  f       g= f7f)a  Return iterator over decoded tiles or strips.

Parameters:
    lock:
        Reentrant lock to synchronize file seeks and reads.
    maxworkers:
        Maximum number of threads to concurrently decode segments.
        The default is :py:attr:`TiffPage.maxworkers`.
    func:
        Function to process decoded segment.
        The default yields each decoded result unmodified.
    sort:
        Read order by file offset rather than segment index.
    buffersize:
        Approximate number of bytes to read from file in one pass.
        The default is :py:attr:`_TIFF.BUFFERSIZE`.
    _fullsize:
        Internal use.

Yields:
    - Decoded segment or ``None`` for empty segments.
    - Position of segment in image array of normalized shape
      (separate sample, depth, length, width, contig sample).
    - Shape of segment (depth, length, width, contig samples).
      The shape of strips depends on their linear index.

Nr  r  r   rW  c                    U" U 0 UD6$ ry   rt   )r  
decodeargsdecode_funcs      rv   r  !TiffPage.segments.<locals>.decode?  s    "D7J77ru   c                    U" U" U 0 UD65      $ ry   rt   )r  r2  r3  r  s       rv   r  r4  D  s     K<<==ru   rY   rT  T)rY  r*  r   r   r  F)r  r  r  r*  r^  r   r   rW  r  r@   chunkedr   read_segmentsr  r  rT   map)rk  r*  r   r  r   r   r  r  rl  r2  r3  r  number_segmentssegmentexecutorr  s                   rv   r-  r.  
  s    J ==[[##<77D ))I&19%=
#77'+J|$'/':':J|$oo<(2 8 &'	> "$,,/a!,,J>++  ##&% ,  Wo% $J/8--$$''*) . E  (||F::: 0/ ; 0/s1   DE/	AE
EE	E/E
E,(E/T)r   r   r*  r   r   c                  U R                   nSUR                  ;   d  UR                  cB  [        R                  " SUR                  b  UR                  5      $ [        R
                  5      $ [        U R                  5      S:X  a  Sn[        U5      eU R                  R                  nUc  UR                  nSn	[        U[        5      (       a  US:X  a  UR                  (       a  U   UR                  n	U	(       a.  [         R"                  " U < S3[$        SS	9  UR'                  5         UR)                  UR                  R*                  UR                  R,                  -   UR                  U R                  S   S
9n
SSS5        GOTUR.                  (       Gas  UR0                  (       a  Sn[3        U5      eUb   [5        XR                  UR                  5      nU   UR                  n	U	(       a.  [         R"                  " U < S3[$        SS	9  UR'                  5         UR7                  U R                  S   5        UR9                  UR                  R*                  UR                  R,                  -   [;        UR                  5      US9n
SSS5        UR<                  S:X  a  [>        R@                  " W
U
S9n
URB                  S:w  aB  [D        RF                  URB                     nURB                  S:X  a
  U" W
SU
S9n
GOU" W
SU
S9U
SS& GOURH                  Gb  X`L Ga  SU RJ                  ;   Ga  U RL                  (       a  U RN                  S::  a  U RP                  S::  a  U   UR                  n	U	(       a.  [         R"                  " U < S3[$        SS	9  UR'                  5         UR7                  U RJ                  S   RR                  S   5        URU                  U RJ                  S   RR                  S   5      nSSS5        [D        RV                  U RX                     nU" WU RZ                  US9n
AOU   UR                  n	U	(       a.  [         R"                  " U < S3[$        SS	9  UR'                  5         UR]                  5         SSS5        [5        XR                  UR                  5      n
UU
4       SS jjnU R_                  UUUUSSS9 H  nM     W
Ra                  UR                  SS9n
U(       a   U
Ra                  URb                  SS9n
U	(       a  URk                  5         U
$ ! , (       d  f       Nc= f! , (       d  f       GN= f! , (       d  f       GN_= f! , (       d  f       N= f! [d         aE  n[g        5       Ri                  U < SU
Rb                   SURb                   SU<S 35         SnANSnAff = f)a  Return image from page as NumPy array.

Parameters:
    out:
        Output array, *'memmap'*, or file for image data.
        By default, a new NumPy array is created.
        If a *numpy.ndarray*, a writable array to which the image
        is copied.
        If *'memmap'*, directly memory-map the image data in the
        file if possible; else create a memory-mapped array in a
        temporary file.
        If a *string* or *open file*, the file used to create a
        memory-mapped array.
    squeeze:
        Remove length-1 dimensions from image array, except X and Y.
        If ``False``, return the image array with normalized
        5-dimensional shape :py:attr:`TiffPage.shaped`.
    lock:
        Reentrant lock to synchronize seeks and reads from file.
        The default is the lock of the parent's file handle.
    maxworkers:
        Maximum number of threads to concurrently decode segments.
        If ``None`` or *0*, use up to :py:attr:`_TIFF.MAXWORKERS`
        threads. See remarks in :py:meth:`TiffFile.asarray`.
    buffersize:
        Approximate number of bytes to read from file in one pass.
        The default is :py:attr:`_TIFF.BUFFERSIZE`.

Returns:
    NumPy array of decompressed, unpredicted, and unpacked image data
    read from Strip/Tile Offsets/ByteCounts, formatted according to
    shape and dtype metadata found in tags and keyword arguments.
    Photometric conversion, premultiplied alpha, orientation, and
    colorimetry corrections are not applied.
    Specifically, CMYK images are not converted to RGB, MinIsWhite
    images are not inverted, color palettes are not applied,
    gamma is not corrected, and CFA images are not demosaiced.
    Exceptions are YCbCr JPEG compressed images, which are converted to
    RGB.
    Return an empty, two-dimensional array if the page contains no
    image or is missing required tags.

Raises:
    TiffFileError:
        Missing data offset or invalid TIFF structure.
    ValueError:
        Format of image in file is not supported and cannot be decoded.

r   Nr}  zmissing data offsetFr:   z reading array from closed filerT  rU  r   z chroma subsampling not supportedr   rY   ry  r  r    r  )r   r   c           	        U u  nu  pEpgpUc(  UR                   UXEXYS   -   2XfU	S   -   2XwU	S   -   24'   g US UR                  U-
  2S UR                  U-
  2S UR                  U-
  24   UXEXYS   -   2XfU	S   -   2XwU	S   -   24'   g )Nr   rY   rT  )rZ  rQ  rP  rO  )
decoderesultr  r  r:  r  r  r+  rG  r   r   s
             rv   r  TiffPage.asarray.<locals>.func  s     3?/!a? ! q8|+QU1X-=quQx<?OO  1(--112(..221(--113 q8|+QU1X-=quQx<?OOru   T)r  r*  r   r   r   r  r  r  r  r  r_  )r@  r   r  r   r  r  r6  r   )6r  r   r  r   emptybool_r   r  r   r  r  r*  r   rz   r  r  rh  ri  rj  openr  r   r  is_contiguousr#  r   r-   r\  r  r@   rV  r(  r  r   r   r"  rW  r  r^  rO  rP  rO  r   r!  r   r   r  r-  rt  r   r   r7   rm  r  )rk  r   r   r*  r   r   r  r   rl  r  r  r  r  r  r  r   r  s                    rv   r   TiffPage.asarrayk  s   t ==8??#:;;  2 OO 
   t A%'C$$[[##<77D sC  x'' MM("AB##$
 GGIOO--0D0DDOO++A. )   ###%%8)#..#C(//JMM("AB##$
 GGI((+,OO--0D0DDHOO, '   !!Q&$44VH!!Q& --h.@.@A	%%*&vBFCF !*&rv FF1I + tyy 5(  E) MM("AB##$
 GGI		#,,Q/0wwtyy~33A67  ++D,<,<=J"00F  MM("AB##$
 GGI$$&  #3IF &.'-*" % 	, ]]%% #   e<UC HHJU , H , b    h;||nD(8	#O sL   'BT/B/U "BU5AU$<U5 /
T= 
U
U!$
U25
W?;V??Wc                    SSK Jn  U" U R                  " S0 UD6U R                  U R                  U R
                  U R                  S9$ )zReturn image data from page as xarray DataArray.

Parameters:
    **kwargs: Passed to :py:meth:`asarray`.

Returns:
    :py:class:`xarray.DataArray`
        Image data with coordinates, dimensions, and attributes.

r   rm   r  r  r   r  rt   )r   rn   r   r  r  r   r  )rk  r   rn   s      rv   r   TiffPage.asxarrayL  s?     	%LL"6";;**
 	
ru   c                     SSK Jn  U" U 40 UD6$ )zgReturn image from page as Zarr store.

Parameters:
    **kwargs: Passed to :py:class:`ZarrTiffStore`.

rY   r  r   r  rk  r   r  s      rv   r   TiffPage.aszarra       	(T,V,,ru   )uint8alphac                  U R                   " S0 UD6nU R                  nUR                  [        R                  :X  a  UR
                  nUc  Sn[        U5      eUR                  S   SUR                  -  :  d'  UR                  b  UR                  R                  S;  a  Sn[        U5      eU(       a8  UR                  5       S:  a  US-	  nUR                  [        R                  5      nS	UR                  ;   a  UR                   S:X  a  US
   OUS   n[#        XF5      nU$ UR                  [        R$                  :X  a  UR&                  (       af  Uc  [(        n[+        UR&                  5       HA  u  pU	[(        ;   d  M  UR                   S:X  a  USSSSSU-   /4   nOUSS2SSSSU-   /4   n  U$     U$ UR                   S:X  a  USSS24   nU$ USS2SS24   n U$ [,        e)zGReturn image as RGB(A). Work in progress. Do not use.

:meta private:

Nzno colormaprY   rT  r  zcannot apply colormapr  rP  S.r   r   .r   rt   )r   r  r   r   rJ  r   r   r   r   r   r  rk  r,   r   rP  r  r   apply_colormaprH  r   r   r  r   )
rk  rP  rQ  r   r  r  r   r   r  exss
             rv   asrgbTiffPage.asrgbl  s    ||%f%==;#6#66((H# o%q!Ax'='=$==>>)>>&&d2- o%<<>C''1}H#??5;;7hmm#'/'<'<'AtF|tAw!$1D6 3 !![__4$$='E'(=(=>FAk)#00A5#'aAq1u-=(=#>D#'Aq!QU+;(;#<D + ?*  &&!+C!G}  ArrE{  &%ru   c                   U R                   R                  nU R                   R                  nUR                  U R                  5        [
        R                  " UR                  UR                  UR                  5      5      S   nUR                  (       a2  UR                  U R                  UR                  -   US-  -   S-   5        O7UR                  U R                  UR                  -   X2R                  -  -   5        [        [
        R                  " UR                  UR                  UR                  5      5      S   5      $ )$Return offset to next IFD from file.r   r  rP  )r  r  r"  r\  r   re  re  rC  r   r'  rY  rE  r   rg  rD  )rk  rl  r"  r  s       rv   r  TiffPage._nextifd  s    [[##{{
d..0GHK<< GGDKK$..052:=ABGGDKK$..05<<3GGHMM$++RWWT__-EFqI
 	
ru   c                    U $ )zReturn TiffPage instance.rt   r  s    rv   r6  TiffPage.aspage  s    ru   c                     U R                   S   $ )zIndex of page in IFD chain.rK  r  r  s    rv   r  TiffPage.index       {{2ru   c                    U R                   $ )zIndex of page in IFD tree.r_  r  s    rv   	treeindexTiffPage.treeindex       {{ru   c                    U $ )z#Self; TiffPage is its own keyframe.rt   r  s    rv   r  TiffPage.keyframe  s	     ru   c                    g ry   rt   )rk  r  s     rv   r  rg    s    ru   c                t    [        U R                  5      S:  a  U R                  OU R                  S   nSU 3$ )Name of image array.rY   r   	TiffPage r   r  rk  r  s     rv   r   TiffPage.name  s4      #4;;/!3Q5'""ru   c                ,    [        U R                  5      $ z$Number of dimensions in image array.r   r   r  s    rv   r  TiffPage.ndim       4::ru   c                >    [        [        U R                  5      5      $ z-Character codes of dimensions in image array.r~   unique_stringsr  r  s    rv   r  TiffPage.dims       ^DII.//ru   c                R    [        [        U R                  U R                  SS95      $ z4Ordered map of dimension character codes to lengths.Tr4  r  r  r  r   r  s    rv   r  TiffPage.sizes        C		4::d;<<ru   c           	        0 nSU R                   ;   nU(       a  U R                  5       n[        U R                  U R                  SS9 H  u  pEUS:X  a  M  US:X  a/  U R                  5       nUb  [        R                  " U5      X'   M@  MB  U(       d  MK  US:X  a  WS   nOUS:X  a  WS   nOMe  US:  d  Mm  [        R                  " SXW-  US	[        R                  S
9X'   M     U$ )zOrdered map of dimension character codes to coordinate arrays.

Only axes with physical coordinate information are included.
Axes without resolution tags or sample names are omitted.

r  Tr4  r   rS  XYrY   F)endpointr   )
r  get_resolutionr  r  r   _sample_namesr   r   linspacefloat32)rk  r  has_resolutionr   axr   namessteps           rv   r  TiffPage.coords  s     +-		),,.JDIItzz$?HBqySy**,$!&u!5FJ %9%a=D3Y%a=D !8!&!&#mm"FJ# @0 ru   c                   0 n[        [        U R                  5      R                  R	                  5       US'   U R
                  b'  U R                  U R
                  R                  S-  :w  a  U R                  US'   U R                  R                  S5      nUb+  [        [        U5      R                  R	                  5       US'   U R                  (       a  U R                  US'   U R                  nUb  UR                  5       US'   U R                  nU(       a2  US   S	;  a)  UR                  S
5      (       d  [!        U5      S:  a  XAS'   U$ )z$Metadata dictionary for image array.r   rP  r   r  r   rZ  rU   r   z{<)ImageJr   r  r   )r.   r   r   r   r  r   r   r   r  r  r   rZ  rU   	isoformatr   r  r   )rk  r  resunitr  descs        rv   r  TiffPage.attrs  s    !#&)) 

$uuw 	m ::!3!3tzz7J7JQ7N!N%)%7%7E/" ))##C(&-gw&?&D&D&J&J&LE"#;;"kkE(O]]> "E*Qt#OO$788D	D #'- ru   c                ,    [        U R                  5      $ z"Number of elements in image array.r@   r   r  s    rv   r   TiffPage.size*       tzz""ru   c                d    U R                   c  gU R                  U R                   R                  -  $ )Number of bytes in image array.r   )r   r   r   r  s    rv   r   TiffPage.nbytes/  s*     ::yy4::....ru   c                8    U R                   R                  S5      $ )zValue of Colormap tag.r  r  r  r  s    rv   r   TiffPage.colormap6       yy  %%ru   c                8    U R                   R                  S5      $ )zValue of InterColorProfile tag.r  r  r  s    rv   r   TiffPage.iccprofile;  s     yy  ''ru   c                8    U R                   R                  S5      $ )zValue of TransferFunction tag.-  r  r  s    rv   transferfunctionTiffPage.transferfunction@  r  ru   c                :   SSSSSS.nUbH  [        [        U5      n Uc  U R                  R                  SS	S
9nX4   nX1   nX%-  S:X  a  X%-  nO
X%-  nOUc  Sn/ nS HT  n U R                  R                  USS
9u  pU
S:X  a  X-  nOX-  S:X  a  X-  U-  nOX-  U-  n UR                  U5        MV     [        US   5      [        US   5      4$ ! [         a-  n[        5       R                  U < SU<S 35        Sn SnANSnAff = f! [         a    Sn Nyf = f)a5  Return number of pixels per unit in X and Y dimensions.

By default, the raw XResolution and YResolution rational tag values
are returned without any unit conversion.
Missing tag values are set to 1.

Parameters:
    unit:
        Unit of measurement of returned values.
        If specified, values are converted using the ResolutionUnit
        tag (default INCH) as the stored unit.
        Accepts a :py:class:`RESUNIT` member, its integer value,
        or a case-insensitive name string such as ``'inch'``.
    scale:
        Multiplier applied to raw rational tag values.
        If ``unit`` is also given, ``scale`` overrides reading the
        ResolutionUnit tag and is used as the source scale
        (pixels per meter for the stored unit), which is then
        divided by the scale for ``unit``.
        If only ``scale`` is given (``unit=None``), it is applied
        directly to the raw tag values.
        The default, when neither ``unit`` nor ``scale`` is given,
        is 1 (no conversion).

Returns:
    Number of pixels per unit in X and Y dimensions.

rY   gz^C@d     i@B )rY   rT  r   r  r  Nr  rT  defaultr   z <get_resolution> raised r_  )r  r  r        ?)	r.   r   r  r  r  r7   rm  r   rY  )rk  unitscalescalesr   scale2r  r   r  nr  rO  s               rv   r  TiffPage.get_resolutionE  sb   D 
 7D)D=%)YY%6%6sA%6%FN"2E>Q&$EOE ]E"$
D	yy((v(>6IEUaZFUNEEEME e$  Z]#U:a=%999+    h7|d|D 	$  s;   1C C !&DDD
D#DDDDc                "    U R                  5       $ z:Number of pixels per resolutionunit in X and Y directions.)r  r  s    rv   r   TiffPage.resolution  s    
 ""$$ru   c                6    U R                   R                  SSS9$ ),Unit of measurement for X and Y resolutions.r  rT  r  r  r  s    rv   r   TiffPage.resolutionunit  s     yy  a 00ru   c                    U R                   R                  S5      nUc  g [        U5      $ ! [        [        4 a     gf = f) Date and time of image creation.r  N)r  r  rI   r   r   r  s     rv   rU   TiffPage.datetime  sI     		!!#&=	E?":& 		s   
, ??c                    U R                   (       d  gU R                  S:  a#  U R                  U R                  U R                  4$ U R                  U R                  4$ )ATile length and width, or depth, length, and width if volumetric.NrY   )r^  rT  rS  rR  r  s    rv   r   TiffPage.tile  sF     }}>>ANNDOOT^^DD00ru   c                   / nU R                   S:  a  UR                  U R                   5        U R                  (       a(  UR                  U R                  U R
                  45        O'UR                  U R                  U R                  45        U R                  S:X  a+  U R                  S:  a  UR                  U R                  5        [        U5      $ )Shape of single tile or strip.rY   )rT  r   r^  r  rS  rR  r   rO  r   r  r~   rk  r   s     rv   chunksTiffPage.chunks  s     >>ALL(==LL$//4>>:;LL$++T__=>!d&:&:Q&>LL--.U|ru   c                   / nU R                   S:X  a+  U R                  S:  a  UR                  U R                  5        U R                  (       a  U R                  S:  a<  UR                  [
        R                  " U R                  U R                  -  5      5        UR                  [
        R                  " U R                  U R                  -  5      5        UR                  [
        R                  " U R                  U R                  -  5      5        OU R                  S:  a  SU R                  < S3n[        U5      eU R                  S:  a  UR                  U R                  5        UR                  [
        R                  " U R                  U R                  -  5      5        UR                  S5        U R                   S:X  a!  U R                  S:  a  UR                  S5        [        U5      $ )1Number of tiles or strips per dimension in image.rT  rY   zself.rowsperstrip= < 1)r   r  r   r^  rQ  ro  rp  rT  rP  rS  rO  rR  r   r   r~   )rk  r   r   s      rv   r6  TiffPage.chunked  s\    !d&:&:Q&>LL--.=="TYYt'GHILL4#3#3doo#EFGLL4??T^^#CDE  1$+**,D1#C(("T__-LL4#3#3d6G6G#GHILLO!d&:&:Q&>LLOU|ru   c                f   [        / U R                  QU R                  R                  PU R                  PU R
                  PU R                  PU R                  PU R                  PU R                  PU R                  PU R                  PU R                  PU R                  PU R                  P75      $ )a?  Checksum to identify pages in same series.

Pages with the same hash can use the same decode function.
The hash is calculated from the following properties:
:py:attr:`TiffFile.tiff`,
:py:attr:`TiffPage.shaped`,
:py:attr:`TiffPage.rowsperstrip`,
:py:attr:`TiffPage.tilewidth`,
:py:attr:`TiffPage.tilelength`,
:py:attr:`TiffPage.tiledepth`,
:py:attr:`TiffPage.sampleformat`,
:py:attr:`TiffPage.bitspersample`,
:py:attr:`TiffPage.fillorder`,
:py:attr:`TiffPage.predictor`,
:py:attr:`TiffPage.compression`,
:py:attr:`TiffPage.extrasamples`, and
:py:attr:`TiffPage.photometric`.

)r#  r   r  r"  r   rR  rS  rT  r  r   rV  r   r   r   r   r  s    rv   r#  TiffPage.hash  s    *    !! 	
   !! ""      !!   
 	
ru   c                J    SU R                   ;  a  g[        X R                  S9$ )zSequence of sub-pages, SubIFDs.r  Nrd  )r  r    r  r  s    rv   r  TiffPage.pages  s"     diiZZ00ru   c                h   U R                   (       d  U R                  c  gU R                  [        R                  ;   a-  [        [        R                  [        U R                  5      5      $ [        U R                  5      U R                  R                  -  nUS:  a  gU R                  S:X  a  US:  a  g[        U R                  5      S:  a  g[        b]  U R                  S:w  d   U R                  S:w  d  U R                  S:w  a-  [        [        R                  [        U R                  5      5      $ g)zsMaximum number of threads for decoding segments.

A value of 0 disables multi-threading also when stacking pages.

r   r  r  i 8  r  rY   rT  )rE  r   r   r   rQ  r  r  r   r  r@   r  r   r(  rV  r   )rk  r  s     rv   r   TiffPage.maxworkers   s     !3t666tD,<,<(=>>DKK(4::+>+>>	tq Y%6t 1$"!T^^q%8DNNa<OtD,<,<(=>>ru   c                <  ^^ U R                   S:X  d   U R                  S:w  d  U R                  S;  a  gSU R                  ;   a  U R                  U R
                  :w  dF  U R                  U R                  -  (       d(  U R
                  S-  (       d  U R                  S-  (       a  gSU R                  ;   aI  SU R                  ;   a9  U R                  U R                  :w  d  U R                  U R                  -  (       a  gU R                  mU R                  m[        T5      S	:X  a  g[        T5      S:X  a  g
U R                  (       d  U R                  (       a  g
[        T5      U R                   :w  a  g[#        UU4S j[%        [        T5      S-
  5       5       5      $ )zImage data is stored contiguously.

Contiguous image data can be read from
``offset=TiffPage.dataoffsets[0]`` with ``size=TiffPage.nbytes``.
Excludes prediction and fillorder.

r  rY   >   rP  r  r)  r  Fr  r  r  r  r   Tc              3  j   >#    U  H(  nTU   S :g  =(       a    TU   TU   -   TUS-      :H  v   M*     g7f)r   rY   Nrt   )r   r  r  r  s     rv   r   )TiffPage.is_contiguous.<locals>.<genexpr>I   sC      
, qMQO71:
1#=Q#OO,s   03)r  r   r   r  rO  rR  rP  rS  rQ  rT  r  r  r   r:  rg  r  r   rl  r  )rk  r  r  s    @@rv   rE  TiffPage.is_contiguous   s9    "1$!!8$))4>>1##doo5>>B&??R'"TYY&$$77 ""((
w<1w<1;;$++z?dkk) 
3w<!+,
 
 	
ru   c                    U R                   =(       a=    U R                  S:H  =(       a'    U R                  S:H  =(       a    U R                  (       + $ );Image data is stored in final form. Excludes byte-swapping.rY   )rE  rV  r   r#  r  s    rv   is_finalTiffPage.is_finalN   sG      '!#'!#' &&&		
ru   c                    U R                   R                  R                  =(       aQ    U R                  =(       a>    U R                  SL=(       a)    U R
                  S   U R                  R                  -  S:H  $ )7Image data in file can be memory-mapped to NumPy array.Nr   )r  r  rD  r  r   r  r   r  s    rv   r  TiffPage.is_memmappableX   sd     KK""** ?? 

$&	?
   #djj&9&99Q>	
ru   c                    [        U R                  5      S:  a  U R                  OU R                  S   nSU SU R                   S3$ )NrY   r   z<tifffile.TiffPage  @rr   r   r  r   rm  s     rv   r+  TiffPage.__repr__d   s>    "4;;/!3Q$UG2dkk]!<<ru   c                "    U R                  5       $ ry   r  r  s    rv   r  TiffPage.__str__h   r   ru   c                <  ^  T R                   T :w  a  [        R                  T X5      $ SnS H)  n[        T SU-   5      (       d  M  UR	                  5       n  O   S S!U 4S jjjnSR                  S SR                  S	 T R                   5       5      [        T R                  5      R                   T R                   3S
R                  S [        T R                  5      R                  T R                  (       a  SOST R                  (       a  SOST R                  (       a  SOSU" S5      U" S5      U" S5      U" S5      U4	 5       5      SR                  S [!        T R"                  5       5       5      4 5       5      n[%        T R&                  5      S:  a  T R&                  OT R&                  S   nSU ST R(                   SU 3nUS::  a  U$ UT R*                  R                  US-   US9/nUS:  aN  S HH  n[        T US5      n	U	(       d  M  UR-                  UR	                  5        S[/        XUS-  S9 35        MJ     US:  a3   T R1                  5       n
UR-                  SU S[/        XUS-  S9 35        SR                  U5      $ ! [2         a     Nf = f)"z4Return string containing information about TiffPage.r=  )memmappabler`   r   r   rY   c               v   > [        TU 5      nX!:X  a  g[        US5      (       d  g[        UR                  5      $ )Nr=  r   )r  r   rz   r   )r   r  objrk  s      rv   tostrTiffPage._str.<locals>.tostru   s5    $%C{3''sxx= ru   r  c              3  T   #    U  H  nU(       d  M  UR                  5       v   M      g 7fry   r  r  s     rv   r    TiffPage._str.<locals>.<genexpr>}   s*      
( + AGGIIs   ((r  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   r          4AQr   c              3  8   #    U  H  nU(       d  M  Uv   M     g 7fry   rt   r  s     rv   r   r     s"      
  A
   	REDUCEDr^  TILEDr   r   r   rV  rI  c              3  @   #    U  H  oR                  5       v   M     g 7fry   )rN  r  s     rv   r   r     s     ?,>q,>r
  r   rk  r  rX  )	ndpi_tagsr  rP  r  r   z DATA
r  rY   )r  r   r   rz   r6  rz   )r  r   r  r  rN  r   r   r   r  r   r   r   r   
is_reducedis_maskr^  ru  r9  r   r  r   r  r   r?   r   r  )rk  r  rX  r  r   r  r  r  r'  rO  r  s   `          rv   r  TiffPage._strk   st   ==D >>$66:DtUT\**zz| ;
	! 	! yy 
 444 1 127789K9K8LM  $D$4$45::%)__	""&,,B#'==bm,n-k*k*
  ?F4::,>??%
 
0  #4;;/!3Q5'DKK=4&9Q;K499>>&1*E>BC	A:&dB/5$$::<."5fqjIJL ' A:||~  wgt!DEG {{9%%  s   2J 
JJc                   SU R                   ;  a  gU R                  U R                   R                  S5         n[        U R                  5      nUS:  d  US:  a  gU R
                  =S:X  a    S/nOD=S:X  a    S/nO9=S:X  a    / SQnO-=S	:X  a    / S
QnO!S:X  a  U R                  S;   a  / SQnO/ SQnO gUS:  a9  U[        [        U R                  S   5      R                  R                  5       /-  nUS:  a9  U[        [        U R                  S   5      R                  R                  5       /-  n[        U5      U:w  a  gU$ )zReturn names of samples.rS  NrY   rT  r   WhiteIsZeroBlackIsZero)RedGreenBluer  )CyanMagentaYellowBlackr  r  )LumaCbCr)r  r   r  r   r   r   r   r.   r   r   title)rk  r\  r   r  s       rv   r  TiffPage._sample_names   s   dii**TYY^^C014,,-Q;,*&&0>##';;4E0E!gk4+<+<Q+?@EEKKMNNE!gk4+<+<Q+?@EEKKMNNEu: ru   c                    [         R                   Vs1 s H)  n[        U SU-   5      (       d  M  UR                  5       iM+     sn$ s  snf )z+Set of ``is\_\*`` properties that are True.r   )r   r  r  r  r0  s     rv   r9  TiffPage.flags   sC    
 
'tUT\* DJJL'
 	
 
r2  c           	        U R                   (       d  g0 n[        SS5       Hw  nU R                  R                  U5      nUb+  [	        U[
        5      (       a  UR                  S5      (       d  MN   UR                  [        UR                  5       5      5        My     U$ ! [         a.  n[        5       R                  U < SU U<S 35         SnAM  SnAff = f)z0Consolidated metadata from EER tags 65001-65009.Nrj  r  
   <metadata>z! eer_xml_metadata failed for tag r_  )r  r  r  r  r   r{   r  r  eer_xml_metadatar  r  r7   rm  )rk  r  r  rO  r  s        rv   r  TiffPage.eer_tags   s     {{%'DII%%d+E!%//''66.u||~>? (     h?vlTl$ s   0(B
C(#CCc                "   U R                   (       d  g0 n[        5       nU R                   H  nUR                  S:  d   UR                  U;   d  UR                  S:w  a  M5   UR
                  SS S:w  a  MK  UR
                  R                  S5      nUS   n[        US   5      nU R                  R                  U5      X'   UR                  U5        M     U$ ! [         a,  n[        5       R                  U < S	U<S
 35         SnAM  SnAff = f)z%Consolidated metadata from Nuvu tags.Nr  rT  r  zField 'r   r   rY   z <nuvu_tags> raised r_  )r  r!  r  r  r   rO  r  r   r  r7   rm  r  r$  )rk  r  usedr  partsr   r  r  s           rv   r  TiffPage.nuvu_tags   s     ||!#99Cxx%388t#3syyA~99Ra=I-		,Qx58}  99,,T2FLHHTN      D8+?|d|!LMs   !C6.C
D"!D		Dc                   U R                   (       d  gSU R                  S   R                  0nU R                   HJ  nUR                  nSUs=:  a  S:  d  O  M    UR                  R                  S5      nUR                  X'   ML     U$ ! [         a,  n[        5       R                  U < SU<S 35         SnAM  SnAff = f)z&Consolidated metadata from Andor tags.NId   i  Andorz <andor_tags> raised r_  )	is_andorr  rO  r  r   removeprefixr  r7   rm  )rk  r  r  r  r   r  s         rv   r  TiffPage.andor_tags!  s     }}		$--.99C88D$%%Oxx,,W5"yy    O  D8+@t!MNNOs   )B


C !B;;C c                   U R                   (       d  g0 nU R                   H  nUR                  nSUs=::  a  S:  d  O  M   UR                  n U=S:X  a    [	        U5      US'   ME  =S:X  a    [        U5      US'   M\  =S:X  a    [        U5      US'   Ms  S	:X  a  [        U5      US
'   M   UR                  SS5      u  pV[        U5      X'   M     U$ ! [         a,  n[        5       R                  U < SU<S 35         SnAM  SnAff = f)zConsolidated metadata from EPICS areaDetector tags.

Use the :py:func:`epics_datetime` function to get a datetime object
from the epicsTSSec and epicsTSNsec tags.

Nr  r>  	timeStamprj  uniqueIDrk  
epicsTSSeci  epicsTSNsecr  rY   z <epics_tags> raised r_  )is_epicsr  r  rO  rY  r   r  r,   r  r7   rm  )rk  r  r  r  rO  r   r	  r  s           rv   r  TiffPage.epics_tags!  s     }}99C88DD(5(IIEO.3El{+-0Zz*/25z|,03E
}-#(;;sA#6&,Sk# *   O  D8+@t!MNNOs0   C&C=CC)"C
D!DDc                ,   U R                   (       d  gU R                  n0 nS H  n X   R                  X#'   M     [        R                  R                  5        H  u  pSXQ;   d  M  X   R                  X#'   M     SU;   a\  US   nSU;   aM  US   R                  [        R                  5      nUS-  nUR                  [        R                  5      nXg-  nUS	 XbS'   U$ ! [         a,  n[	        5       R                  U < SU<S 35         SnAM  SnAff = f)z/Consolidated metadata from Hamamatsu NDPI tags.N)MakeModelSoftwarez <ndpi_tags> raised r_  	McuStartsMcuStartsHighBytesr)  )rY  r  rO  r  r7   rm  r   	NDPI_TAGSr`  r,   r   r  )rk  r  r  r   r  r  r  r  s           rv   r  TiffPage.ndpi_tags;!  s    ||yy1DN#z// 2
 ....0JD|#z// 1 & {+I#v-23::5<<H%,,U\\:	!	/0"+;  N  D8+?|d|!LMMNs   C
D'!DDc           
        U R                   (       d  gU R                  nUR                  S5      nUb  [        U5      S:  d	  US   S:w  a  [	        5       R                  U < S35        gUS   US   US   S.n[        R                  n[        R                  n[        US   5       H  n US	US	-  -   US	-  S
-    u  pxpUS:X  a  U
nO; X   R                  XU	-    nUS:X  a  U	S:  a  US   S:X  a  USS nU	S:  a  UOUS   nXu;   a-  [        R                  " [         5         XW   " U5      nSSS5         U" U5      R"                  nXU'   M     UR                  S5      nUbI  [$        R&                  " U5      nUR(                  S:X  a  UR+                  S5      R-                  5       nXS'   UR                  S5      nUb'  [$        R&                  " U5      R-                  5       US'   UR                  S5      nUbE  [$        R&                  " U5      R+                  S5      R/                  5       R-                  5       nXS'   UR                  S5      nUb7  [$        R&                  " U5      R+                  S5      R-                  5       nXS'   UR                  S5      nUbe  0 S US   _S!US   _S"US   _S#US   _S$US	   _S%US&   _S'US(   _S)US*   _S+US
   _S,US-   _S.US/   _S0US1   _S2US3S4 _S5US4S6 _S7US6S8 _S9US8S _US:'   U$ ! [         a-  n[	        5       R                  U < SU<S 35         SnAGM  SnAff = f! [         a0  n[	        5       R                  U < SU SU<S 35         SnAGM  SnAf[         a0  n[	        5       R                  U < SU SU<S 35         SnAGM  SnAff = f! , (       d  f       GN= f! [          a    Un GNf = f);z(Consolidated metadata from GeoTIFF tags.N鯇  rT  r   rY   z invalid GeoKeyDirectoryTag)KeyDirectoryVersionKeyRevisionKeyRevisionMinorr   r  rP  z% corrupted GeoKeyDirectoryTag raised r_  z corrupted GeoKeyDirectoryTag r  z GeoKeyDirectoryTag z not found, raised 鱇  rK  rI  逄  r  r  r  IntergraphMatrix  ModelPixelScale還  )rK  r  ModelTiepoint؅  ModelTransformation  ERR_BIASERR_RANDLINE_OFFSAMP_OFFLAT_OFFLONG_OFFr  
HEIGHT_OFFr  
LINE_SCALEr  
SAMP_SCALE	LAT_SCALE	   
LONG_SCALEr  HEIGHT_SCALE   LINE_NUM_COEFFr  !   LINE_DEN_COEFF5   SAMP_NUM_COEFFI   SAMP_DEN_COEFFRPCCoefficient)r  r  r  r   r7   rm  r   GEO_KEYS	GEO_CODESr  r  rO  r   r  r  r  r   r   r   r  r   rt  r  r   )rk  r  gkdr  geokeysgeocodesr  keyidtagidr  r   r  rO  r   rpccs                  rv   r  TiffPage.geotiff_tagsW!  s    yyll5!;#c(Q,#a&A+Hx'BCD $'q6q6 #A
 -->>3q6]E	.1	MEAIM/+e z K--f~FE E>eaiE"I4D!#2JE!&a ((4$OE2E 5en))  3KM #P U#KK&EzzRf-446).%&U#(-E(:(A(A(CF$%U#KK&..w7??AHHJE&+?#U#KK&..v6==?E,1()( ||E"(DG(DG( DG( DG	(
 47( DG( d1g( d1g( d1g( T!W( d2h( R( !$r"+( !$r"+( !$r"+(  !$rs)!(F#$$ }    h !\D\+  % H$$("@ H""%/  H$$("6ug >""%/  54  sZ   *LM !N55O
L=!L88L= 
N2
$M55N2$N--N25
O	OOc                    U R                   U R                  4 H2  nU(       a  SU;   a  M  USS S:X  a
  SU;   a  Us  $ USS S:X  d  M0  Us  $    g)z3Shaped array description string, or None if absent.z"mibi.NrY   {z"shape":r  shape=r   rX  rk  r   s     rv   rf  TiffPage.shaped_description!  sa     !,,d.?.?@K(k"92A#%**C""2A(*"" A ru   c                    U R                   U R                  4 H"  nU(       d  M  USS S:X  d  USS S:X  d  M   Us  $    g)z-ImageJ description string, or None if absent.Nr  ImageJ=zSCIFIO=rS  rT  s     rv   r2   TiffPage.imagej_description!  sL     !,,d.?.?@K2A)+{2A)/K""	 A
 ru   c                p   U R                   S;  dH  U R                  (       a7  U R                  S   S:X  d$  U R                  (       a  U R                  S   S:  a  g U R                  R                  nUR                  U R                  S   S-   5        UR                  S5      nUS:H  $ ! [         a     gf = f)z/JPEG compressed segments contain JFIF metadata.r  r   r>  Fr  r  s   JFIF)r   r  r  r  r  r\  r   r]  )rk  rl  r  s      rv   r&  TiffPage.is_jfif!  s     $88##"a'&&""1%*	''BGGD$$Q'!+,771:D w  		s   AB( (
B54B5c                    g))Object is :py:class:`TiffFrame` instance.Frt   r  s    rv   r,  TiffPage.is_frame!       ru   c                    g)z)Page does not have IFD structure in file.Frt   r  s    rv   
is_virtualTiffPage.is_virtual!  r^  ru   c                2    [        U R                  5      S:  $ )zPage is SubIFD of another page.rY   rl  r  s    rv   	is_subifdTiffPage.is_subifd"       4;;!##ru   c                2    [        U R                  S-  5      $ )z'Page is reduced image of another image.rY   r   r   r  s    rv   r  TiffPage.is_reduced	"  s     D$$s*++ru   c                2    [        U R                  S-  5      $ )z!Page is part of multi-page image.rT  rg  r  s    rv   is_multipageTiffPage.is_multipage"  s     D$$t+,,ru   c                2    [        U R                  S-  5      $ )z,Page is transparency mask for another image.r  rg  r  s    rv   r  TiffPage.is_mask"  s     D$$u,--ru   c                2    [        U R                  S-  5      $ )z%Page is part of Mixed Raster Content.rP  rg  r  s    rv   is_mrcTiffPage.is_mrc"  s     D$$v-..ru   c                     U R                   S:  $ )zPage contains tiled image.r   )rR  r  s    rv   r^  TiffPage.is_tiled"  s     ~~!!ru   c                X    U R                   b  U R                   S:g  $ U R                  S:H  $ )z&Page contains chroma subsampled image.r  r  )r   r   r  s    rv   r#  TiffPage.is_subsampled""  s2     '##v--1$$ru   c                    U R                   SL$ )z*Page contains ImageJ description metadata.N)r2   r  s    rv   r  TiffPage.is_imagej-"       &&d22ru   c                    U R                   SL$ )z%Page contains Tifffile JSON metadata.N)rf  r  s    rv   re  TiffPage.is_shaped2"  rw  ru   c                L    SU R                   ;  =(       a    SU R                   ;   $ )zPage contains MDFileTag.E  r  r  r  s    rv   rS  TiffPage.is_mdgel7"  s&     " #"	
ru   c                L    SU R                   ;   =(       a    SU R                   ;   $ )z(Page contains Agilent Technologies tags.  r{  r|  r  s    rv   
is_agilentTiffPage.is_agilent?"  s!     dii6ETYY$66ru   c                    U R                   R                  S5      n USL=(       a    UR                  SS S:H  $ ! [         a     gf = f)z'Page contains Media Cybernetics Id tag.p  Nr  s   MC TIFFF)r  rS  rO  r  )rk  r  s     rv   
is_mediacyTiffPage.is_mediacyE"  sK     iimmE"	d?Bsyy!}
'BB 		s   : 
AAc                     SU R                   ;   $ )zPage contains UIC1Tag.r  r|  r  s    rv   r:  TiffPage.is_stkN"       		!!ru   c                     SU R                   ;   $ )zPage contains CZ_LSMINFO tag.r  r|  r  s    rv   rg  TiffPage.is_lsmS"  r  ru   c                     SU R                   ;   $ )z$Page contains FluoView MM_STAMP tag.r  r|  r  s    rv   r;  TiffPage.is_fluoviewX"  r  ru   c                     SU R                   ;   $ )z!Page contains NIHImageHeader tag.r  r|  r  s    rv   r5  TiffPage.is_nih]"  r  ru   c                     U R                   S:  $ )z0Page contains SGI ImageDepth tag with value > 1.rY   )rQ  r  s    rv   is_volumetricTiffPage.is_volumetricb"  s     ""ru   c                     U R                   S:H  $ )zSoftware tag is 'ISS Vista'.z	ISS Vistar   r  s    rv   r  TiffPage.is_vistag"  s     }}++ru   c                    U R                   S:w  d  U R                  S:w  a  gU R                  nUR                  S5      =(       a    UR	                  S5      $ )z>Page contains MDS MetaSeries metadata in ImageDescription tag.r   
MetaSeriesF
<MetaData>z</MetaData>)r  r   r   r  rZ  )rk  r  s     rv   r  TiffPage.is_metaseriesl"  sE     ::?dmm|;||L)Gajj.GGru   c                    U R                   S:w  d  U R                  (       d  gU R                  SS R                  5       R                  S5      $ )z.Page contains OME-XML in ImageDescription tag.r   FNrX  r  r   rc  rZ  r  s    rv   rd  TiffPage.is_omet"  sA     ::?$"2"2%++-66v>>ru   c                    U R                   S:w  d  U R                  (       d  gU R                  SS R                  5       R                  S5      $ )z4Page contains Leica SCN XML in ImageDescription tag.r   Fr  Nz</scn>r  r  s    rv   rm  TiffPage.is_scn{"  sA     ::?$"2"2%++-66x@@ru   c                     SU R                   ;   $ )z'Page contains MicroManagerMetadata tag.  r|  r  s    rv   r<  TiffPage.is_micromanager"  r  ru   c                     SU R                   ;   $ )z.Page contains Andor Technology tags 4864-5030.r  r|  r  s    rv   r  TiffPage.is_andor"  s     tyy  ru   c                    SU R                   ;   =(       aa    SU R                   ;   =(       aK    U R                   S   R                  S:H  =(       a(    U R                   S   R                  R                  S5      $ )z)Page contains Nuvu cameras tags >= 65000.r  rj  rT  zField '65001' is )r  r   rO  r  r  s    rv   r  TiffPage.is_nuvu"  sj     TYY G"G		% &&!+G 		% &&112EF		
ru   c                X    U R                   SS S:H  =(       a    U R                  SS S:H  $ )zPage contains Pilatus tags.NrP  zTVX TIFFrT  # r   r   r  s    rv   r  TiffPage.is_pilatus"  s1     }}Ra J.O43C3CBQ3G43OOru   c                L    U R                   S:H  =(       d    U R                  S:H  $ )z&Page contains EPICS areaDetector tags.zEPICS areaDetector)r   r   r  s    rv   r  TiffPage.is_epics"  s*      44 5}} 44	
ru   c                     SU R                   ;   $ )zPage contains TVIPS metadata.r  r|  r  s    rv   r  TiffPage.is_tvips"  r  ru   c                L    SU R                   ;   =(       d    SU R                   ;   $ )z*Page contains FEI_SFEG or FEI_HELIOS tags.r  r  r|  r  s    rv   r  TiffPage.is_fei"  !     		!7Udii%77ru   c                     SU R                   ;   $ )zPage contains CZ_SEM tag.r  r|  r  s    rv   r  TiffPage.is_sem"  r  ru   c                &    U R                   SS S:H  $ )zPage contains Aperio metadata.Nr  Aperio r   r  s    rv   r_  TiffPage.is_svs"  s     #y00ru   c                     SU R                   ;   =(       a>    SU R                  ;   =(       d(    U R                  SS S:H  =(       d    U R                  S;   $ ! [         a     gf = f)zPage contains Ventana metadata.r~  VentanaN   ScanOutputManager>   Label_ImageProbability_ImageLabel ImageF)r  r   r   r  r  s    rv   r  TiffPage.is_bif"  sq    
	$))#  T]]* G=="%)<<G##FG  		s   AA 
A#"A#c                    U R                   SS S:H  =(       d+    U R                  SS S:H  =(       d    SU R                  SS ;   $ )z!Page contains ScanImage metadata.Nr   zSI.r  zstate.zscanimage.SIi r  r  s    rv   ri  TiffPage.is_scanimage"  sP     MM"1& 9#x/9!1!1$%!88	
ru   c                &    U R                   SS S:H  $ )z"Page contains IndicaLabs metadata.N   IndicaLabsImageWriterr  r  s    rv   rv  TiffPage.is_indica"  s     }}Sb!%<<<ru   c                     SU R                   ;   =(       a!    U R                   R                  S5      SS S:H  $ ! [         a     gf = f)z%Page contains Argos AVS XML metadata.r  Nr  z<ArgosF)r  r  r  r  s    rv   r  TiffPage.is_avs"  sL    	"Otyy'8'8'?'Cx'O  		s   69 
AAc                &    U R                   SS S:H  $ )z1Page contains PerkinElmer tissue images metadata.N   zPerkinElmer-QPIr  r  s    rv   rz  TiffPage.is_qpi"  s    
 }}Sb!%666ru   c                     SU R                   ;   $ )zPage contains GeoTIFF metadata.r"  r|  r  s    rv   r  TiffPage.is_geotiff"  r  ru   c                     SU R                   ;   $ )zPage contains GDAL metadata.r  r|  r  s    rv   r  TiffPage.is_gdal"  s     		!!ru   c                X    U R                   SS S:H  =(       a    U R                   SS S:H  $ )z&Page contains AstroTIFF FITS metadata.Nr  zSIMPLE r  ENDr  r  s    rv   r  TiffPage.is_astrotiff"  s8     Ra I- /  %.	
ru   c                X    U R                   SS S:H  =(       a    SU R                   SS ;   $ )z(Page contains Hamamatsu streak metadata.NrY   [z],r)  r  r  s    rv   r  TiffPage.is_streak"  s8     Ra C' /((2..	
ru   c                     SU R                   ;   $ )zPage contains DNG metadata.  r|  r  s    rv   is_dngTiffPage.is_dng#  r  ru   c                     SU R                   ;   $ )zPage contains TIFF/EP metadata.  r|  r  s    rv   	is_tiffepTiffPage.is_tiffep#  r  ru   c                L    SU R                   ;   =(       d    SU R                   ;   $ )z#Page contains Olympus SIS metadata.r  r  r|  r  s    rv   rY  TiffPage.is_sis#  r  ru   c                L    SU R                   ;   =(       a    SU R                   ;   $ )zPage contains NDPI metadata.    r|  r  s    rv   rY  TiffPage.is_ndpi#  s!     		!6cTYY&66ru   c                    U R                   SS S:H  =(       a,    U R                  SS R                  5       R                  S5      $ )z"Page contains Philips DP metadata.Nr  z
Philips DPiz</DataObject>)r   r   rc  rZ  r  s    rv   rr  TiffPage.is_philips#  sC     }}Sb!\1 ,d6F6FD7

%'((?+	,ru   c                    U R                   R                  =(       aX    SU R                  ;   =(       aB    U R                  S   R                  S:H  =(       a    U R                  S   R                  SS S:H  $ )z'Page contains EER acquisition metadata.rj  r  Nr  r  )r  rZ  r  r   rO  r  s    rv   r  TiffPage.is_eer#  sj     KK"" ="= 		% &&!+= 		% &&s+}<	
ru   c                ^    [        U R                  5      S:H  =(       a    SU R                  ;   $ )z%Page contains embedded C2PA manifest.rY   r  )r   r  r  s    rv   rb  TiffPage.is_c2pa'#  s%     499~"9u		'99ru   )r  r  r  r   r   r  r  rX  r   rQ  rP  rO  rW  rZ  r   r  r   r   r   r  r  r   r   r   r  rT  rS  rR  )r  int | Sequence[int]r  r   r  TiffPage | Noner6  r   rB  r6  zCallable[..., DecodeResult])r*  $threading.RLock | NullContext | Noner   r3  r  r   r   r   r   r3  r  r%  r6  zIterator[DecodeResult])r*  r  r   r3  r  zCallable[[DecodeResult], Any]r   r   r   r3  r  r%  r6  Iterator[Any])r*  r  r   r3  r  z$Callable[[DecodeResult], Any] | Noner   r   r   r3  r  r%  r6  &Iterator[DecodeResult] | Iterator[Any])r   rw   r   r   r*  r  r   r3  r   r3  r6  r  r   rg   r6  rn   r   rg   r6  r  )rP  r   rQ  zContainer[int] | Noner   rg   r6  r  rK  r6  r   r6  rM  )r  r   r6  r   rK  r6  tuple[str, ...]r6  zdict[str, int]r6  dict[str, NDArray[Any]]r6  r   )r6  r,  r!  NNr  r>  r  float | Noner6  tuple[float, float]r6  r  r6  zDateTime | Noner6  r/  )r6  TiffPages | Noner  r  r  )r6  list[str] | Noner  r   r  )r  r  r  r  r  rL  r   rO  rP  rQ  rR  rS  rT  r  r   r  r   r   r   rV  r   r   r   r   rp  r   rW  r   r   rX  rZ  rn  r  rX   r  ra   r-  r   r   r   rW  r  r6  rM  r  rc  r  setterr   r  r  r  r  r  r   r   r   r   r  r  r   r   rU   r   r  r6  r#  r  r   rE  r  r  r+  r  r  r  r9  r  r  r  r  r  r  rf  r2   r&  r,  r`  rc  r  rj  r  ro  r^  r#  r  re  rS  r  r  r:  rg  r;  r5  r  r  r  rd  rm  r<  r  r  r  r  r  r  r  r_  r  ri  rv  r  rz  r  r  r  r  r  r  rY  rY  rr  r  rb  r   rt   ru   rv   r   r     s
   ( N!,K#'""+** I ! /##1## K-J6K"J&Is)J&Is*OS)M3-L#<!L#!#K<L#JIs:K7IsI$&L/&N*.K'.>&*G#*'#J#/#J#6Hc(K(L#/FEK %)G= #	G=G= "G= 
G=R	 N#	$N# N#`  69!$!$!$	% 3	% 		%
 	% 	% 	% 	% 
 	% 	%  69!$!$!$	 3	 		
 ,	 	 	 	 
	 	 6:!%59!%!%_; 3_; 	_;
 3_; _; _; _; 
0_;H 59!%!%_ _ 	_
 3_ _ _ 
_B
*	- '+	< < %	<
 < 
<|
"       __  # #
   0 0 = = # #J  8 # # / / & & ( ( & & ,0"H:(H: H: 
	H:T % % 1 1 	 	 1 1    , &
 &
P 1 1  2 ,
 ,
\ 
 
 	
 	
=@&DB 
 
  ,  ,  " ! !F  6 w wr 	 	    $     $ $ , , - - . . / / " " % % 3 3 3 3 
 
 7 7
   " " " " " " " " # # , , H H ? ? A A " " ! ! 
 
 P P 
 
 " " 8 8 " " 1 1   
 
 = =   7 7 " " " "
 
 
 
 
 " " " " 8 8 7 7 , , 
 
 : :ru   r   c                     \ rS rSr% SrSrSrS\S'   SrS\S	'   S
\S'    S\S'    S\S'    S\S'    S\S'    S\S'    S\S'   S\S'   SSSSS.             SDS jjr	SES jr
SFS jrSGS jrSHS jrSIS jrSJS jr      SKS  jr\SES! j5       r\SLS" j5       r\SMS# j5       r\R*                  SNS$ j5       r\SOS% j5       r\SOS& j5       r\SOS' j5       r\SOS( j5       r\SOS) j5       r\SOS* j5       r\SES+ j5       r\SLS, j5       r\SPS- j5       r\SLS. j5       r\SLS/ j5       r \SQS0 j5       r!\SRS1 j5       r"\SES2 j5       r#\SSS3 j5       r$\STS4 j5       r%\SUS5 j5       r&\SES6 j5       r'\SES7 j5       r(\SVS8 j5       r)\SRS9 j5       r*  SW     SXS: jjr+\SYS; j5       r,\SES< j5       r-\SZS= j5       r.\SES> j5       r/\  S[S? j5       r0SRS@ jr1SRSA jr2S\S]SB jjr3SCr4g)^r   i-#  aK  Lightweight TIFF image file directory (IFD).

The purpose of TiffFrame is to reduce resource usage and speed up reading
image data from file compared to TiffPage.
Properties other than ``offset``, ``index``, ``dataoffsets``,
``databytecounts``, ``subifds``, and ``jpegtables`` are assumed to be
identical with a specified
TiffPage instance, the keyframe.
TiffFrame instances have no ``tags`` property.
Virtual frames just reference the image data in the file. They may not
have an IFD structure in the file.

TiffFrame instances are not thread-safe. All attributes are read-only.

Parameters:
    parent:
        TiffFile instance to read frame from.
        The file handle position must be at an offset to an IFD structure.
        Only a limited number of tag values are read from file.
    index:
        Index of frame in IFD tree.
    offset:
        Position of frame in file, or zero for virtual frame.
    keyframe:
        TiffPage instance with same hash as frame.
    dataoffsets:
        Data offsets of "virtual frame".
    databytecounts:
        Data bytecounts of "virtual frame".

)r  r"  r  r  r   r   r  rp  Fr   rS  Nr  r  r   r  r   r   rM  r  r  r/  rp  r9  r   r  r"  r  r   r  r  r  c         	         Xl         S U l        S U l        [        U[        5      (       a	  U4U l        O[        U5      U l        Ub+  Ub(  Uc  SO
[	        U5      U l        XPl        X`l	        X@l
        g S U l
        SU l        SU l	        UR                  nUc  UR                  5       U l        O![	        U5      U l        UR                  U5        Uc  1 SknO+UR                  (       a  1 SknUR                  U l	        O1 SknUR                  n	[         R"                  n
 U
" U	R$                  UR'                  U	R(                  5      5      S   nUS:  a  SU 3n[1        U5      eU R                  U	R(                  -   nU	R2                  nU* nU	R4                  S S	 nUR'                  X-  5      n[7        U5       H  nUU-  nU
" UUUUS	-    5      S   nUU;  a  M"   [8        R;                  UUU-   UUUU-    S
9nUS;   a  UR>                  U l        MZ  US;   a  UR>                  U l	        Ms  US:X  a  UR>                  U l        M  US:X  a  UR>                  U l        M  Ub1  US:X  d  M  UR@                  S   R>                  UR>                  :w  d  M  Sn[C        U5      e   U R                  (       d  [=        5       RE                  U < S35        O<Ub9  [G        U R                  5      [G        UR                  5      :w  a  Sn[C        U5      eUb  X@l$        g g ! [         R*                  [,        [.        4 a   nSU R                   3n[1        U5      UeS nAff = f! [0         a-  n[=        5       R+                  U < SU<S 35         S nAGM  S nAff = f)Nr   rt   >   r  r  r  r  r  r  >   r  r  r  r  >   r  r  r  r  r  r  r  r]  r^  r_  rT  rc  z <TiffTag.fromfile> raised r_  >   r  r  >   r  r  r  r  r  incompatible keyframez is missing required tags)%r  rp  r   r   r   r  r~   r   r  r  r"  r  rX  r\  rE  r"  re  re  rC  r   r'  r  r]  r   r   rE  r$  r  r$   r  r7   rO  r  ra  rm  r   r  )rk  r  r  r   r  r  r  rl  codesr"  re  r  r  r   r  rE  r  
codeformattagbytesr   r  r  s                         rv   rn  TiffFrame.__init__s#  sS    eS!! (DK,DK"~'A%~!3v;DK*"0%N >'')DKf+DKGGFO$BE##(E"*"9"9D7E{{	.4++RWWT^^-DEaHE
 4<.ug6C$$KK$..0	,,8__Ra(
777?+uAH*hx(Q,&GHKD5 
&&$x/#Hx'/AB '  z!#&99 #&)ii#"yy"%))!c 2 8 8CII E-"3''9 < Hx'@AB!c$*:*:&;s  @
 '
 *Cs##$M  i gz2 	.(6C$#-	.2 ! h9#F 	s0   /L MM3MM
N !NNc                ,    [         R                  U 5      $ )rZ  )r   r  r  s    rv   r  TiffFrame._nextifd#  s      &&ru   c                   U R                   (       a  Sn[        U5      eU R                  R                  nUR                  nU(       a.  [
        R                  " U < S3[        SS9  UR                  5          UR                  U R                  5        [        U R                  U R                  S9nU(       a  UR                  5         U$ ! U(       a  UR                  5         f f = f)zCReturn TiffPage from file.

Raise ValueError if frame is virtual.

z#cannot return virtual frame as pagez" reading TiffPage from closed filerT  rU  rd  )r`  r   r  r  r  rh  ri  rj  rD  r\  r   r   r  r  )rk  r   rl  r  r  s        rv   r6  TiffFrame.aspage#  s     ??7CS/![[## MM(<=
 GGI	GGDKK DKKtzz:D
 
 s   79C	 	C#c                0    [         R                  " U 40 UD6$ )zuReturn image from frame as NumPy array.

Parameters:
    **kwargs: Arguments passed to :py:meth:`TiffPage.asarray`.

)r   r   rk  r   s     rv   r   TiffFrame.asarray#  s     ///ru   c                0    [         R                  " U 40 UD6$ )zReturn image data from frame as xarray DataArray.

Parameters:
    **kwargs: Arguments passed to :py:meth:`TiffPage.asarray`.

)r   r   r  s     rv   r   TiffFrame.asxarray$  s       000ru   c                     SSK Jn  U" U 40 UD6$ )zrReturn image from frame as Zarr store.

Parameters:
    **kwargs: Arguments passed to :py:class:`ZarrTiffStore`.

rY   rK  rL  rM  s      rv   r   TiffFrame.aszarr$  rO  ru   c                6    [         R                  " U /UQ70 UD6$ )zRReturn image from frame as RGB(A). Work in progress. Do not use.

:meta private:

)r   rW  rk  r  r   s      rv   rW  TiffFrame.asrgb$  s     ~~d4T4V44ru   c                6    [         R                  " U /UQ70 UD6$ )zReturn iterator over decoded tiles or strips.

Parameters:
    **kwargs: Arguments passed to :py:meth:`TiffPage.segments`.

:meta private:

)r   r-  r  s      rv   r-  TiffFrame.segments"$  s       7777ru   c                     U R                   S   $ )zIndex of frame in IFD chain.rK  r_  r  s    rv   r  TiffFrame.index/$  ra  ru   c                    U R                   $ )zIndex of frame in IFD tree.r_  r  s    rv   rc  TiffFrame.treeindex4$  re  ru   c                    U R                   $ )z&TiffPage with same hash as this frame.r"  r  s    rv   r  TiffFrame.keyframe9$       ~~ru   c                  U R                   UL a  g U R                   b  Sn[        U5      e[        U R                  5      [        UR                  5      :w  a  Sn[        U5      eUR                  (       a  UR
                  U l        Xl         g )Nzcannot reset keyframer  )r"  ra  r   r  rE  r  )rk  r  r   s      rv   r  r   >$  su    >>X%>>%)Cs##t C(<(<$==)Cs##!!"*"9"9D!ru   c                    g)r\  Trt   r  s    rv   r,  TiffFrame.is_frameL$  s     ru   c                     U R                   S:*  $ )z*Frame does not have IFD structure in file.r   r=  r  s    rv   r`  TiffFrame.is_virtualQ$  s     {{aru   c                2    [        U R                  5      S:  $ )z Frame is SubIFD of another page.rY   rl  r  s    rv   rc  TiffFrame.is_subifdV$  re  ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  r  r  s    rv   r  TiffFrame.is_final[$  s$     ~~)))~~&&&ru   c                L    U R                   c   eU R                   R                  $ )zLImage data is stored contiguously.

See :py:attr:`TiffPage.is_contiguous`.

)r"  rE  r  s    rv   rE  TiffFrame.is_contiguousa$  s$     ~~)))~~+++ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  r  r  s    rv   r  TiffFrame.is_memmappablek$  $     ~~)))~~,,,ru   c                L    U R                   c   eU R                   R                  $ )zKChecksum to identify pages in same series.

See :py:attr:`TiffPage.hash`.

)r"  r#  r  s    rv   r#  TiffFrame.hashq$  $     ~~)))~~"""ru   c                L    U R                   c   eU R                   R                  $ )zShape of image array in page.)r"  r   r  s    rv   r   TiffFrame.shape{$  $     ~~)))~~###ru   c                L    U R                   c   eU R                   R                  $ )zYNormalized 5-dimensional shape of image array in page.

See :py:attr:`TiffPage.shaped`.

)r"  r   r  s    rv   r   TiffFrame.shaped$  s$     ~~)))~~$$$ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  r  r  s    rv   r  TiffFrame.chunks$  $     ~~)))~~$$$ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  r6  r  s    rv   r6  TiffFrame.chunked$  s$     ~~)))~~%%%ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  r   r  s    rv   r   TiffFrame.tile$  $     ~~)))~~"""ru   c                t    [        U R                  5      S:  a  U R                  OU R                  S   nSU 3$ )rj  rY   r   
TiffFrame rl  rm  s     rv   r   TiffFrame.name$  s4      #4;;/!3QE7##ru   c                L    U R                   c   eU R                   R                  $ rp  )r"  r  r  s    rv   r  TiffFrame.ndim$  r?  ru   c                L    U R                   c   eU R                   R                  $ )z#Names of dimensions in image array.)r"  r  r  s    rv   r  TiffFrame.dims$  r?  ru   c                L    U R                   c   eU R                   R                  $ )z*Ordered map of dimension names to lengths.)r"  r  r  s    rv   r  TiffFrame.sizes$  r5  ru   c                L    U R                   c   eU R                   R                  $ )z4Ordered map of dimension names to coordinate arrays.)r"  r  r  s    rv   r  TiffFrame.coords$  r:  ru   c                L    U R                   c   eU R                   R                  $ r  )r"  r   r  s    rv   r   TiffFrame.size$  r?  ru   c                L    U R                   c   eU R                   R                  $ r  )r"  r   r  s    rv   r   TiffFrame.nbytes$  r:  ru   c                L    U R                   c   eU R                   R                  $ )z!Data type of image array in page.)r"  r   r  s    rv   r   TiffFrame.dtype$  r5  ru   c                L    U R                   c   eU R                   R                  $ )zOCharacter codes for dimensions in image array.

See :py:attr:`TiffPage.axes`.

)r"  r  r  s    rv   r  TiffFrame.axes$  r2  ru   c                V    U R                   c   eU R                   R                  X5      $ )zbReturn number of pixels per unit in X and Y dimensions.

See :py:attr:`TiffPage.get_resolution`.

)r"  r  )rk  r  r  s      rv   r  TiffFrame.get_resolution$  s)     ~~)))~~,,T99ru   c                L    U R                   c   eU R                   R                  $ r  )r"  r   r  s    rv   r   TiffFrame.resolution$  s$     ~~)))~~(((ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  r   r  s    rv   r   TiffFrame.resolutionunit$  r/  ru   c                L    U R                   c   eU R                   R                  $ )r  )r"  rU   r  s    rv   rU   TiffFrame.datetime$  s$     ~~)))~~&&&ru   c                L    U R                   c   eU R                   R                  $ )z2:py:class:`COMPRESSION` scheme used on image data.)r"  r   r  s    rv   r   TiffFrame.compression$  s$     ~~)))~~)))ru   c                L    U R                   c   eU R                   R                  $ )z[Return decoded segment, its shape, and indices in image.

See :py:attr:`TiffPage.decode`.

)r"  r  r  s    rv   r  TiffFrame.decode$  s$     ~~)))~~$$$ru   c                    [        U R                  5      S:  a  U R                  OU R                  S   nSU SU R                   S3$ )NrY   r   z<tifffile.TiffFrame r  rr   r  rm  s     rv   r+  TiffFrame.__repr__	%  s>    "4;;/!3Q%eWBt{{m1==ru   c                "    U R                  5       $ ry   r  r  s    rv   r  TiffFrame.__str__%  r   ru   c                   [        U R                  5      S:  a  U R                  OU R                  S   nUS:  a  U R                  b  U R                  R                  US-
  S9OSn[	        U R
                  US-
  US-
  S9n[	        U R                  US	-
  US-
  S9n/ nUb  UR                  S
U 35        USU 3SU 3/-  nSSR                  U5      -   nOVU R                  bG  SR                  SR                  S U R                   5       5      [        U R                  5      45      nOSnSU SU R                   SU 3$ )z5Return string containing information about TiffFrame.rY   r   r   Nr>  r  r;  r  r  z
 Keyframe z	 Offsets z Bytecounts r  r  r  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   !TiffFrame._str.<locals>.<genexpr>%%  s     8ZSVVZr  r=  rA  r  )r   r  r"  r  r?   r  r  r   r   r   rz   r   r   )	rk  r  rX  r  kfofbc
info_partsr  s	            rv   r  TiffFrame._str%  sK   "4;;/!3QA: >>- ##%"*#5 
 ))6A:NB##52:fqjB J~!!Jrd"34Yrd+|B4-@AAJ$))J//D^^'99HH8TZZ88

OD DE7"T[[MD6::ru   )	r  r"  r  r  r   r  r   r  rp  )r  r  r  r   r   r3  r  r  r  r/  r  r/  r6  r   rK  r  )r   rg   r6  r  r  r  )r  rg   r   rg   r6  r  )r  rg   r   rg   r6  r  r  r6  r  )r  r   r6  r   r  r6  rN  r  rK  r  r  r  )r6  r1  r  r  r  r  r  r  r  )5r  r  r  r  r  rG  rS  rL  r  rn  r  r6  r   r   r   rW  r-  rM  r  rc  r  r  r,  r`  rc  r  rE  r  r#  r   r   r  r6  r   r   r  r  r  r  r   r   r   r  r  r   r   rU   r   r  r+  r  r  r   rt   ru   rv   r   r   -#  s   @	I Hd"E" -K$  /##1##'/ "$(.215h% #	h%h% h% "h% ,h% /h% 
h%T'801	-588$'8	/8       __" "       $ $ ' '
 , , - -
 # # $ $
 % % % %
 & &
 # #
 $ $
 # #
 # #
 $ $
 % %
 # #
 % %
 $ $
 # # ,0":(: : 
	: ) )
 - -
 ' ' * *
 	%	$	% 	%>; ;ru   r   c                  4   \ rS rSr% SrSrS\S'    S\S'   S\S	'   S
\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   SS.     S;S jjr\S<S j5       r	\S=S j5       r
\S=S j5       r\R                  S>S j5       r\S=S j5       r\R                  S>S j5       r\S?S  j5       rS@S! jr\SAS" j5       r\ SBS#S#S#S$.           SCS% jjj5       r\S#S#S#S$.           SDS& jj5       r SES'S(S)S$.           SFS* jjjr SG   SHS+ jjrSIS, jrS)S-.SJS. jjrSKS/ jr SES)S)S0.       SLS1 jjjrS'S(S(S$.         SMS2 jjr\SNS3 j5       r\    SOS4 j5       r\    SPS5 j5       r\SQS6 j5       rS=S7 jr\SRS8 j5       rSSS9 jrS:rg)Tr    i.%  a  Sequence of TIFF image file directories (IFD chain).

TiffPages instances have a state, such as a cache and keyframe, and are not
thread-safe. All attributes are read-only.

Parameters:
    arg:
        If a *TiffFile*, the file position must be at offset to offset to
        TiffPage.
        If a *TiffPage* or *TiffFrame*, page offsets are read from the
        SubIFDs tag.
        Only the first page is initially read from the file.
    index:
        Position of IFD chain in IFD tree.

Nr  r  r>  _offsetszdict[int, TiffPage | TiffFrame]_loadedr  r"  ztype[TiffPage | TiffFrame]	_tiffpager   _indexed_cached_cacher   _offsetr3  _nextpageoffsetr/  r  rd  c                 S U l         / U l        0 U l        SU l        SU l        [
        U l        S U l        SU l        SU l	        S U l
        Uc  S U l        OG[        U[        [        R                  45      (       a  [        U5      4U l        O[!        U5      U l        [        U["        5      (       a  Xl         U R                   R$                  nUR'                  5       U l
        [(        R*                  " U R                   R,                  R.                  UR1                  U R                   R,                  R2                  5      5      S   nUS:X  a%  [5        5       R7                  U< S35        SU l        g OUR8                  bv  UR8                  nUR                   U l         U R                   R$                  n[;        U5      S:X  d	  US   S:X  a%  [5        5       R7                  U< S35        SU l        g US   nOSU l        g X@l	        XCR<                  :  a(  [5        5       R7                  U < SU< 35        SU l        g U R                  c  SO/ U R                  QSP7nUR?                  U5        [        U R                   US9nU R                  RA                  U5        XpR                  S'   Xpl        U R                  c-  U R                  RC                  WSS  5        SU l        SU l        g g )	NFr   z contains no pagesTz contains invalid SubIFDsz invalid offset to first page rd  rY   )"r  ro  rp  rr  rs  r   rq  r"  rt  ru  rv  r  r   r   r   r  r~   r   r  rX  re  re  r"  rg  r   rD  r7   rm  rp  r   r   r\  r   r  )rk  argr  rl  r   r  r  r  s           rv   rn  TiffPages.__init__O%  sy    !#=DKU]]344u:-DK,DKc8$$K''B#%779D ]]  --((334 F {  C7*<!=> $  [[$kkG**DK''B7|q GAJ!O  C7*C!DE $QZF DMWWH(8
C !DM $A*;DKK*;*; 	
 	95V$Q'MM  - DMDL	 (ru   c                r     [        [        U R                  S   5      $ ! [         a    [	        S5      Sef = f)z6First page as TiffPage, or raise IndexError if absent.r   N)r_   r   rp  r  r4  r  s    rv   r   TiffPages.first%  s7    	*$,,q/22 	*Q-T)	*s    6c                H     U R                  S5        g! [         a     gf = f)z&IFD chain contains more than one page.rY   FT)_seekr4  r  s    rv   rj  TiffPages.is_multipage%  s+    	JJqM   		s    
!!c                    U R                   $ )zRPages and frames are being cached.

When set to ``False``, the cache is cleared.

)rt  r  s    rv   r  TiffPages.cache%  s     {{ru   c               v    [        U5      nU R                  (       a  U(       d  U R                  5         Xl        g ry   )r   rt  r  r  s     rv   r  r  %  s"    U;;uKKMru   c                (    U R                   [        :H  $ )z)Use TiffFrame (True) or TiffPage (False).)rq  r   r  s    rv   rl  TiffPages.useframes%  s     ~~**ru   c               @    U(       a  [         U l        g [        U l        g ry   )r   r   rq  r  s     rv   rl  r  %  s    &+ru   c                    U R                   $ )z-TiffPage used as keyframe for new TiffFrames.r  r  s    rv   r  TiffPages.keyframe%  r!  ru   c                  [        U[        [        R                  45      (       d  S[	        U5       3n[        U5      e[        U5      nUS:  a  U[        U 5      -  nU R                  b  U R                  R                  U:X  a  gUS:X  a#  [        [        U R                  S   5      U l        gU R                  (       d  U[        U R                  5      :  aG  XR                  ;   a8  U R                  U   n[        U[        5      (       a  X0l        gU R                  U	 U R                  n[        U l         [        [        U R                  U5      5      U l        X@l        U R                  U R                  U'   g! X@l        f = f)zSet keyframe to TiffPage specified by ``index``.

If not found in the cache, the TiffPage at ``index`` is loaded from
file and added to the cache.

zindices must be integers, not r   N)r   r   r   r  rw  r   r   r"  r  r_   r   rp  rr  ro  rq  _getitem)rk  r  r   r  r  s        rv   r  TiffPages.set_keyframe%  s,    %#u}}!56624;-@CC. E
19SYE>>%$..*>*>%*GA:!(DLLO<DNMMUS%77||#<<&D$))!%U#>>!	&!(DMM%,@ADN%N"nnU &Ns   8$E< <Fc                ^    U R                   (       d  U R                  S5        U R                  $ )z2File position where next IFD offset can be stored.rK  )rr  r}  rv  r  s    rv   r[  TiffPages.next_page_offset%  s"     }}JJrN###ru   .validater  r6  c                  g ry   rt   rk  r   r  r  r  r6  s         rv   rS  TiffPages.get%        #ru   c                  g ry   rt   r  s         rv   rS  r  &  r  ru   r   FTc              N     U R                  XXES9$ ! [         a    Uc  e  U$ f = f)a5  Return specified page from cache or file.

The specified TiffPage or TiffFrame is read from file if it is not
found in the cache.

Parameters:
    key:
        Index of requested page in IFD chain.
    default:
        Page or frame to return if key is out of bounds.
        By default, an IndexError is raised if key is out of bounds.
    validate:
        If non-zero, raise RuntimeError if value does not match hash
        of TiffPage or TiffFrame.
    cache:
        Store returned page in cache for future use.
    aspage:
        Return TiffPage instance.

r  )r  r4  r  s         rv   rS  r  &  sE    <	==e !    	 	s    $$c               L   U R                   c   eU R                  (       a  gU R                  (       d  gU R                  (       d  U R	                  S5        U R
                  (       d  gU R                   R                  nUSL a  U R                  nOUSL a  Sn[        U R                  5       Hn  u  p4X0R                  ;  d  M  U R                  c  UO/ U R                  QUP7nUR                  U5        U R                  U R                   XQS9U R                  U'   Mp     SU l        g)z#Read all remaining pages from file.NrK  TFr  r  )r  rs  ro  rr  r}  rt  r  r"  r  rp  r  r\  rq  )rk  r  rl  r  r   r  s         rv   r  TiffPages._load6&  s     {{&&&<<}}}}JJrN{{[[##t~~HH"4==1IA$,A2CDKK2C2C  "&..KKy #1 #Q 2 ru   c           
     r  ^ U R                   c   e [        U R                  5      S:  a  Sn[        U5      e[	        [
        U R                  S   5      nUR                  (       d  Sn[        U5      eU R                  S5        U R                  S   U R                  S   -
  nU R                  S   U R                  S   -
  U:w  d#  U R                  S   U R                  S   -
  U:w  a  S	n[        U5      eU R                  SUR                  S
9nUR                  S   UR                  -
  nUS:  d  XS:  a  S	n[        U5      eUR                  UR                  /nX$S.nU R                   R                  R                  U-
  n[        [!        UR                  U-   X5      SS9 H  u  pX-  m[#        U4S jUR                   5       5      nU
S:  a  U
OSnUR%                  U=(       d    S5        ['        UR                   U R(                  c  U	O/ U R(                  QU	P7UUUR*                  US9Xy'   M     X`l        Xpl        SU l        SU l        SU l        g! [2         aT  nU R                   R                  R                  S:  a&  [5        5       R7                  U < SU<S 35         SnAg SnAgSnAff = f)zCalculate virtual TiffFrames.NrY   zpages already loadedr   zdata not contiguousr  rT  r   zpage offsets not equidistantr  r  )startc              3  ,   >#    U  H	  oT-   v   M     g 7fry   rt   )r   r  r  s     rv   r   1TiffPages._load_virtual_frames.<locals>.<genexpr>v&  s     #D3CaE3C   r  r   r  r  r  T        z <_load_virtual_frames> raised r_  )r  r   ro  r   r_   r   rp  rE  r}  r  r#  r  r   r  r   r  r  r~   r   r   r  r  rt  rs  rr  r  r7   rm  )rk  r   r  deltapage1offsetoffsetnew_offsets
new_loadedfilesizer  r   r  offset_or_noner  r  s                 @rv   rj  TiffPages._load_virtual_framesU&  sv   {{&&&4	4==!A%, o%$,,q/2D%%+ o%JJqMMM!$t}}Q'77Ea 4==#33u<==#dmmA&66%?4 o%MM!diiM8E ,,Q/%,,>La<#74 o%&*kk5<<%@K>B:MJ{{--22U:H!*ellU*H<A" M##D43C3C#DD+1I+=4"">#6Q7$-KK!%!4:ODKK:O:O) +#'#6#6!	%
!"" (M%LDKDL DM 	{{%%**j8  h=c\D\J  9	s   II 
J6"AJ11J6fullyc              X   U R                   (       d  g[        [        U R                  S   5      U l        U(       a  SU R                  S   0U l        OKU R                  R                  5        VVs0 s H  u  p#[        U[        5      (       a  M  X#_M      snnU l        SU l        gs  snnf )zADelete all but first page from cache. Set keyframe to first page.Nr   F)	ro  r_   r   rp  r"  r`  r   r   rs  )rk  r  r   r  s       rv   r  TiffPages._clear&  s    }}hQ8t||A/DL
 !LL..00DA!!Y/ 0DL
 s   0B&B&c                  U R                   c   eU R                  n[        U5      nUS:X  a  Sn[        U5      eU R                   R                  nUR
                  (       a  Sn[        U5      eU R                  (       d  SUs=::  a  U:  a  O  OUS:  a  gUR                  X!   5      $ U R                   R                  nUR                  nUR                  nUR                  n	UR                  n
UR                  n[        R                   nUS   nUS:  Ga  UR                  U5        SnSn U" XR#                  U
5      5      S   nUS:  a  S	U S
3nU(       aS  [+        5       R%                  U < SU SU SUS 35        US	 US-  nU R,                  R/                  US5        SU l        GOQX-   X-  -   U l         UR#                  X-  U-   5      n[3        U" UUU* S 5      S   5      nUS:X  a	  SU l        GOXR4                  :  a(  [+        5       R%                  U < SU< 35        SU l        OUR7                  U5        US-  nSUs=::  a  U:  a  O  OOUS:X  a  [9        USS 5       H  u  nnUU:X  d  M  UnUSUS-    U l        U R,                  R;                  5        VVs0 s H  u  nnUU::  d  M  UU_M     snnU l        SU l        [+        5       R%                  U < SU SU< 35          O   US:  a  GM  US:  a  gX:  a  Sn[        U5      eUR                  X!   5      $ ! [        R$                  [&        4 a  n[)        U5      n SnAGNSnAff = f! [        R$                  [&        4 aF  n[+        5       R%                  U < SUS-    SU R0                   SU<S 35        SU l         SnAM  SnAff = fs  snnf )zASeek file to offset of page specified by index and return offset.Nr   zindex out of rangezseek of closed filerK  rv  r=  r^  r_  z > 4096z corrupted tag list of page r  r  r_  rY   Tz invalid offset to page z invalid page offset r  z# invalid circular reference to IFD z at offset=)r  ro  r   r4  r  r  r   rr  r\  r"  rg  rD  rC  r'  rE  re  re  r   r  r]  rF  r7   rp  r  rv  r   r   r   r  r`  )rk  r  r  
lenoffsetsr   rl  r"  rg  rD  rC  r'  rE  re  r   r  e	next_datar  r  or   r  s                         rv   r}  TiffPages._seek&  s   {{&&&--\
?&CS/![[##99'CS/!==A33qy777>**{{((__
&&NN	,,5 GGFOEC{GGI,>?B t|25'Ah:!l"VHHSJ@ BKa
  T2 $#)#5#GD 
GGEOj$@A	VL)ZKL2IJ1MN { $ $)>vjIJ $NN6"!OJE&J& S %gcrl3DAq{ !(/!a%(8-1\\-?-?-A(-ATQQ!VDAqD-A( )-#h&I cfY0  4g 5 B 19&CS/!www~&& LL'* 1g( LL'* h6!A~&b)=)=(> ?!\D\+
 !%6(s<   -L* </M &O 7O *MMMN=7;N88N=)rl  r  c         	        U R                   nU R                  nU=c     [        [        [	        U 5      5      5      nGO0==[
        S` =b  u   O  =[        R                  S` =b  u   O    O7    [        U5      nSU l        US:X  a  U R                  /$  U" U5      /XPl        $ =[        S` =b  u     UR                  S5      u  pgnU R                  (       d3  [        Xv5      [	        U R                  5      :  a  U R                  S5        [        [        UR                  [	        U R                  5      5      6 5      nO4  [        S` =b  u   [        U5      nO   S[!        U5       3n	[#        U	5      eU R$                  c   eU R$                  n
 ['        U5      nU R+                  U5        U(       a  U R$                  R,                  OSnU(       a  SU l         U Vs/ s H  o" XS9PM
     nnUR/                  SU R$                  5        Xl        U(       a  XPl        U$ ! XPl        f = f! [(         a    / s $ f = fs  snf ! Xl        U(       a  XPl        f f = f)	zReturn specified pages as list of TiffPages or TiffFrames.

The first item is a TiffPage, and is used as a keyframe for
following TiffFrames.

rt   Fr   r  rK  z-key must be integer, slice, or iterable, not Tr  )r  rl  r  r  r   r   r   r  r   r  r  rr  rk  ro  r}  rQ   rw  r   r"  r  r  r  r#  insert)rk  r   rl  r  getitemr   r  stopr   r   r  r   	validhashr  r  s                  rv   r  TiffPages._getlist'  s    --^^
5T+,((#h!&!8 JJ<'0#CL>%/N!$Y!7Q}}T)9C<N)NJJrN5#++c$--.@"ABC	 
 3i CDI;O   n$ ~~)))>>	IE 	% +3DNN''	!DN	,=@ASWQ3SEALLDNN+ &N!+C &0N&  	I	 B &N!+ s<   H 	H$ H; H6&H; H!$H32H36H; ;Ic                 U R                   c   e[        U5      nU R                  nUS:  a  U[        U 5      -  nO=U R                  (       a,  U[        U5      :  a  SU S[        U5       S3n[        U5      eU(       a  [        OU R                  nXR                  ;   a  U R                  U   nU R                  (       a,  U(       d%  U(       a  X(R                  :w  a  Sn[        U5      eU$ [        U[        U45      (       a%  U(       a  X(R                  :w  a  Sn[        U5      eU$ U R                  c  UO/ U R                  QUP7n	U R                  U5        U" U R                   XR                  S9n[        U[        [         45      (       d   eU(       a  X(R                  :w  a  Sn[        U5      eU R                  (       d  U(       a  XR                  U'   U$ )z)Return specified page from cache or file.r   zindex z out of range(rz  zpage hash mismatchr  )r  r   ro  r   rr  r4  r   rq  rp  rt  r#  ra  r   r  r}  r"  r   )
rk  r   r  r  r6  r  r   r  r  r  s
             rv   r  TiffPages._getitemF'  s    {{&&&#h--73t9C]]sc'l23%~c'l^1=CS/!%84>>,,<<$D{{6II 5.C&s++$8 455II 5.C&s++ ;;&C,?dkk,?3,? 	 	

39~~N$9 56666II-&Cs##;;% $LLru   c                   g ry   rt   rk  r   s     rv   __getitem__TiffPages.__getitem__v'  s    @Cru   c                   g ry   rt   r  s     rv   r  r  y'  s     &)ru   c                  U R                   nU R                  n[        U[        [        R
                  45      (       a  U" [        U5      5      $ [        U[        5      (       a  UR                  S5      u  pEnU R                  (       d)  [        XT5      [        U5      :  a  U R                  S5        [        UR                  [        U5      5      6  Vs/ s H
  os" U5      PM     sn$ [        U[        5      (       a-  [        U[        5      (       d  U Vs/ s H
  o" U5      PM     sn$ Sn	[        U	5      es  snf s  snf )Nr  rK  *key must be an integer, slice, or sequence)ro  r  r   r   r   r  r  r  rr  rk  r   r}  r  rS   rz   r   )
rk  r   r  r  r  r  r   r  r   r   s
             rv   r  r  ~'  s     ----cC/003s8$$c5!! [[3NE==S%5G%D

2(-s{{3w</H(IJ(I1GAJ(IJJc8$$ZS-A-A(+,1GAJ,,:n K -s   D7D<c              #     #    [         R                  " 5        H  n U R                  U5      nUv   M     U R                  (       a  SU l        g g ! [         a       M(  f = f7f)NT)	itertoolsr  r  r4  rt  rs  )rk  r  r  s      rv   r  TiffPages.__iter__'  sX     "A}}Q' J # ;;DL   s'   A!A"A!
AA!AA!c                2    [        U R                  5      S:  $ )z'Return True if file contains any pages.r   )r   ro  r  s    rv   __bool__TiffPages.__bool__'  s    4==!A%%ru   c                p    U R                   (       d  U R                  S5        [        U R                  5      $ )zReturn number of pages in file.rK  )rr  r}  r   ro  r  s    rv   r  TiffPages.__len__'  s%     }}JJrN4==!!ru   c                "    SU R                    S3$ )Nz<tifffile.TiffPages @rr   )ru  r  s    rv   r+  TiffPages.__repr__'  s    &t||nA66ru   )rt  rs  r  rr  r"  rp  rv  ru  ro  rq  r  rl  )rx  zTiffFile | TiffPage | TiffFramer  zSequence[int] | int | Noner6  r   r  r  rO  r   r6  r   rl  )r  r   r6  r   r6  r3  ).)r  r   r   r   r  r   r  r   r6  r   r6  TiffPage | TiffFrame)r  r  r   r   r  r   r  r   r6  r   r6  r  ry   )r  TiffPage | TiffFrame | Noner   r   r  r   r  r   r6  r   r6  r  )T)r  zTiffPage | bool | Noner6  r   rB  )r  r   r6  r   )r  r   r6  r   )r   z"int | slice | Iterable[int] | Nonerl  r   r  r   r6  list[TiffPage | TiffFrame])
r   r   r  r   r  r   r6  r   r6  r  )r   r   r6  r  )r   slice | Sequence[int]r6  r  )r   zint | slice | Sequence[int]r6  z1TiffPage | TiffFrame | list[TiffPage | TiffFrame])r6  zIterator[TiffPage | TiffFrame]rK  rK  ) r  r  r  r  r  r  rL  rn  rM  r   rj  r  r  rl  r  r  r[  ra   rS  r  rj  r  r}  r  r  r  rb   r  r  r  r+  r   rt   ru   rv   r    r    .%  st   " #FO",,,))NMLL"" -1K ,K 
 *K  
K Z * *     \\  + + : :  #-J $ $ 
 		# 	# 		#	# 	# 	# 	# 
	# 	#  	# &		#	# 	# 	# 	# 
	# 	# 04	% % -	%% % % % 
%R ,0( 
	>7r *. "e'R 37>
 >/>
 > > 
$>J ..
 . . . 
.` C C)()	#) ) .	: *    & " "7ru   r    c                     \ rS rSr% SrSrS\S'    S\S'    S\S'    S\S	'    S\S
'    S\S'    S\S'                   S#S jr\SSSS.         S$S jj5       r	\
              S%S j5       r\
          S&S j5       r\S'S j5       r\R                  S(S j5       r\S)S j5       r\S)S j5       r\S)S j5       r\S*S j5       rS+S jrSSS.       S,S jjrS-S jrS)S jrS)S  jrS.S/S! jjrS"rg)0r$   i'  a  TIFF tag structure.

TiffTag instances are not thread-safe. All attributes are read-only.

Parameters:
    parent:
        TIFF file tag belongs to.
    offset:
        Position of tag structure in file.
    code:
        Decimal code of tag.
    dtype:
        Data type of tag value item.
    count:
        Number of items in tag value.
    valueoffset:
        Position of tag value in file.

)_valuer  r  r   r   r  r  TiffFile | TiffWriterr  r   r   r  r   r  r  rg   r  c                   Xl         [        U5      U l        [        U5      U l        [        U5      U l        X`l        Xpl         [        U5      U l        g ! [         a    [        U5      U l         g f = fry   )
r  r   r   r  r  r  r  r   r   r   )rk  r  r   r  r   r  rO  r  s           rv   rn  TiffTag.__init__'  s_     &kI	Z
&	$!%DJ 	$UDJ	$s   A A21A2NT)r   rm  r  c         
     N   UR                   nUR                  nUcA  Uc  UR                  5       nOUR                  U5        UR	                  UR
                  5      nOUc  UR                  5       nX%R
                  -   UR                  -
  n[        R                  " UR                  U5      u  pp [        R                  U	   nU
[        R                   " U5      -  nXR                  :  d  U[        R"                  ;   a  [        R                  " UR$                  U5      S   nUS:  d  X-   UR&                  :  a9  SU SU SU 3nU(       a  [        U5      e[        5       R)                  U5        SnOU[        R*                  ;   a  [,        R/                  XXX5      nOSnOU	S;   a  USU nO|UR0                  (       a-  U
S	:X  a'  U	S
;   a!  USS S:w  a  [        R                  " SU5      nO>UR2                   U
[5        US   5      -   US	    3n[        R                  " UUSU 5      n[,        R7                  XX5      nU " XXXU5      $ ! [         aN  nSU SU SU	< 3nU(       a  [        U5      Ue[        5       R                  U5        U " XXU
SS5      s SnA$ SnAff = f)a  Return TiffTag instance from file.

Parameters:
    parent:
        TiffFile instance tag is read from.
    offset:
        Position of tag structure in file.
        The default is the position of the file handle.
    header:
        Tag structure as bytes.
        The default is read from the file.
    validate:
        Raise TiffFileError if data type or value offset are invalid.

Raises:
    TiffFileError:
        Data type or value offset are invalid and ``validate`` is
        ``True``.

N<tifffile.TiffTag r  z> invalid data type r   rP  z> invalid value offset    rY   rT  r  rY   >   r  r;  r  r  s       <Q)r"  r  rX  r\  r   rE  r(  re  re  r&  r   r  r  r   r7   r  r  TAG_READERSrg  r   rm  TAG_LOADr$   _read_valuerY  r   r   _process_value)clsr  r   rm  r  r"  rl  r  r  r   r  rO  r  r  r   	valuesizer  s                    rv   r  TiffTag.fromfile'  s   < {{>~WWT\\*F^WWYF||+d.E.EE$*MM$2F2F$O!U
	D++E2K FOOK88	///t''' --(9(95A!DKQ+"9BGG"C(b 9,,7=:  ',,  %&++D i*9%ELL
#ab	00 MM$.E >>"3{1~../q>"$ 
 MM#uZi'89E&&uEB64kJJi  	D$TF"VH 5%%*I/  #C(c1HNN3vtE4CC	Ds   0I 
J$AJJ$J$c          
         [         R                  U   nU R                  n	U R
                  R                  n
U R
                  R                  nU[        R                  " U5      -  nUS:  d  X\-   U	R                  :  a  SU SU SU< 3n[        U5      eU	R                  U5        U[         R                  ;   a   [         R                  U   n U" XX4U5      nU$ US
;   aB  U	R!                  U5      n[#        U5      U:w  a   [        5       R                  SU SU S35        U$ U[         R$                  ;  a  US:  a  ['        XX4U5      nU$ [        R(                  " U
 U[+        US   5      -   US    3U	R!                  U5      5      nU$ ! [         a  nSU SU SU< 3n[        U5      UeSnAff = f! [         a@  n[        5       R                  SU SU SU<S	 35        U	R                  U5         SnAGN SnAff = f)zRead tag value from file.z	<TiffTag r  z> invalid dtype=NrP  z> invalid valueoffset=r  	> raised r_  r  z> could not read all valuesr  r   rY   )r   r  r  r   r  r"  r   rD  re  r  r   r\  r  r  r7   rm  r   r   	TAG_TUPLE
read_numpyre  r   )r  r   r  r   r  r  r  r  r   rl  r   rD  r  readfuncrO  s                  rv   r  TiffTag._read_value](  s   	.++E2K
 KK))	[[++
FOOK88	?k5?dV2fX-D~FC$$ 	4###''-H jI IGGI&E5zY&  (b 90 0  'EDLreJGE 	 MM+ec+a.&99:;q>:JK	"E ]  	.dV2fX->zBC$#-	..  %  (b	#N $$	%s/   F 
F5 
F2F--F25
G??5G::G?c                 ^ U b5  US;   d/  U[         R                  ;   d  [        U [        [        45      (       d  U $ US:X  a3  U R                  S5      n  U R                  S5      R                  5       n U $ U[         R                  ;   a)  [         R                  U   m [	        U4S jU  5       5      n [        U 5      S:X  a  U[         R                  ;  a  U S   n U $ ! [         aa     U R                  S5      R                  5       n  U $ ! [         a0  n[        5       R                  SU SU S	U<S
 35         SnA U $ SnAff = ff = f! [         a4  nUS;  a$  [        5       R                  SU SU SU<S
 35         SnANSnAff = f)zProcess tag value.N>   rY   r  rT  r+  utf-8cp1252r  r  z*> coercing invalid ASCII to bytes, due to r_  c              3  4   >#    U  H  nT" U5      v   M     g 7fry   rt   r   r  r.  s     rv   r   )TiffTag._process_value.<locals>.<genexpr>(  s     2EqaddE      r  r  r  rY   r   )r   r  r   r{   r~   r  r  rc  UnicodeDecodeErrorr7   rm  TAG_ENUMr   r   r  )rO  r  r   r   r  r.  s        @rv   r  TiffTag._process_value(  s    Mt'''eeU^44LA: LL)E	W-335 L4== d#A	2E22 u:?t4>>9!HE5 & !LL288:E L * H$$,TF"VH =CCF,,P  L  z) H$$,TF"VH =""%/	sH   C E
 
E'D		
E$D>7E>EE

F*FFc           	        U R                   Gc  U R                  R                  nUR                     UR                  nU(       a.  [
        R                  " U < S3[        SS9  UR                  5          [        R                  U R                  U R                  U R                  U R                  U R                  U R                  5      nU(       a  UR!                  5         SSS5        [        R#                  WU R                  U R                  U R                  5      U l         U R                   $ ! U(       a  UR!                  5         f f = f! , (       d  f       Nr= f)z2Value of tag, delay-loaded from file if necessary.Nz reading value from closed filerT  rU  )r  r  r  r*  r  rh  ri  rj  rD  r$   r  r   r  r   r  r  r  r  )rk  rl  r  rO  s       rv   rO  TiffTag.value(  s    ;;
 ''B MM("AB##$
 GGI##//		



((E 
- . "00		

	DK {{ 
 + s%   AE4AD0
E0E

E
Ec                   Xl         g ry   )r  r  s     rv   rO  r  (  s    ru   c                n     U R                   R                  $ ! [         a    SU R                    3s $ f = f)zName of data type of tag value.TYPE)r   r   r   r  s    rv   
dtype_nameTiffTag.dtype_name(  s5    	'::??" 	'$**&&	's    44c                |    [         R                  R                  U R                  [	        U R                  5      5      $ )z0Name of tag from :py:attr:`_TIFF.TAGS` registry.)r   r  rS  r  rz   r  s    rv   r   TiffTag.name(  s%     yy}}TYYDII77ru   c                <    [         R                  U R                     $ )z$Data type as ``struct.pack`` format.)r   r  r   r  s    rv   r  TiffTag.dataformat)  s       ,,ru   c                ~    U R                   [        R                  " [        R                  U R
                     5      -  $ )z%Number of bytes of tag value in file.)r  re  r  r   r  r   r  s    rv   valuebytecountTiffTag.valuebytecount)  s+     zzFOOD,=,=djj,IJJJru   c                h   [        U R                  [        5      (       a  U R                  nGOU R                  R                  n[
        R                  U R                     nU R                  [        US   5      -  nUR                   U US    3nSn U R                  S:X  a>  [        R                  " XPR                  R                  S5      5      n[        U5      U:g  nOhUS:X  a@  [        U R                  [        5      (       d!  [        R                  " XPR                  5      nO"[        R                  " U/U R                  Q76 n U(       aw  U R                  R&                  n	U	R)                  5       n
U	R+                  U R,                  5        U	R/                  [        R0                  " U5      5      nU	R+                  U
5        U R2                  [        U R                  5      U R                  WS4$ ! [          a1  nUR"                  (       a  US:X  a  Sn[%        U5      UeSn SnANSnAff = f)	zfReturn tag code, dtype, count, and encoded value.

The encoded value is read from file if necessary.

r   rY   FrT  r  z-cannot pack 64-bit NDPI value to 32-bit dtypeTN)r   rO  r{   r  r"  r   r  r   r  r   r   re  rf  rg  r   r~   r  rY  r   r  rX  r\  r  r   r  r  )rk  rO  r"  r  r  r  use_fallbackr  r   rl  rm  s              rv   astupleTiffTag.astuple)  s    djj%((JJE;;##D**4::6JJJZ]!33E^^$UGJqM?;C L$::?"KKZZ->->w-GHE#&u:#6LaZ
4::u(E(E"KKZZ8E"KK9djj9E [[++ggi(() 45yy#djj/4::udBB  $<<EQJIC$S/s2#	$s&   AG6 "AG6 (!G6 6
H1 'H,,H1)r   r  c         
        U R                   S:  d  U R                  S:  a  SU R                    S3n[        U5      e[        US5      (       a  Sn[	        U5      eU R
                  R                  nU R
                  R                  nUR                  (       a~  U R                  S:X  a^  U R                  S;   aN  [        U R                  [        5      (       a  U R                  S   nOU R                  nUS	:  a  S
n[        U5      e[        R                  nUc  SnUc  U R                  nOW[        U[         5      (       a2  [#        U5      S:  a  US   S;   a  USS n [        R$                  U   nO[)        [*        U5      nSn [        R,                  U   n	US:X  av  [        U[         5      (       a   UR/                  S5      nO"[        U[2        5      (       d  Sn[        U5      e[#        U5      S:X  d	  USS S:w  a  US-  n[#        U5      nU4nO[        U[2        5      (       aJ  [4        R6                  " U	5      n[#        U5      U-  (       a  Sn[        U5      e[#        U5      U-  nUnU4nO4 [#        U5      nUS;   a"  US:  d
  US-  (       a  Sn[        U5      eUS-  nUc9  [4        R8                  " UR:                   U[=        U	S   5      -   U	S    3/UQ76 n[#        U5      nU R                  [4        R6                  " [        R,                  U R                     5      -  nU R                  nUR?                  5       n X R                  :w  aQ  URA                  U R                   S-   5        URC                  [4        R8                  " UR:                  S-   U5      5        XRD                  ::  GaA  XRD                  ::  aP  URA                  U R                   S-   5        URC                  [4        R8                  " URF                  X5      5        GOURA                  S[H        RJ                  5        UR?                  5       nUS-  (       a  URC                  S5        US-  nURA                  U R                   S-   5        URC                  [4        R8                  " URF                  U[4        R8                  " URL                  U5      5      5        URA                  U5        URC                  U5        GOXRD                  ::  a  U R                   S-   [4        R6                  " URF                  SS 5      -   nURA                  U R                   S-   5        URC                  [4        R8                  " URF                  X5      5        U(       a/  URA                  U R                  5        URC                  SU-  5        GOX::  d  U R                  U-   URN                  :X  a  URA                  U R                   S-   5        URC                  [4        R8                  " URF                  SS U5      5        URA                  U R                  5        URC                  U5        U(       a  X-
  S:  a  URC                  SX-
  -  5        GOURA                  S[H        RJ                  5        UR?                  5       nUS-  (       a  URC                  S5        US-  nURA                  U R                   S-   5        URC                  [4        R8                  " URF                  U[4        R8                  " URL                  U5      5      5        URA                  U5        URC                  U5        U(       a/  URA                  U R                  5        URC                  SU-  5        URA                  U5        [Q        U R
                  U R                   U RR                  UUSU5      $ ! [&         a    SU< 3n[        U5      Sef = f! [&         a    SU< 3n[        U5      Sef = f! [0         a  n
Sn[        U5      U
eSn
A
ff = f! [         a	    U4nSn GNf = f! URA                  U5        f = f)a  Write new tag value to file and return new TiffTag instance.

Warning: changing tag values in TIFF files might result in corrupted
files or have unexpected side effects.

The packed value is appended to the file if it is longer than the
old value. The file position is left where it was.

Overwriting tag values in NDPI files > 4 GB is only supported if
single integer values and new offsets do not exceed the 32-bit range.

Parameters:
    value:
        New tag value to write.
        Must be compatible with the ``struct.pack`` formats
        corresponding to the tag's data type.
    dtype:
        New tag data type. By default, the data type is not changed.
    erase:
        Overwrite previous tag value in file with zeros.

Raises:
    struct.error:
        Value is not compatible with dtype or new offset exceeds
        TIFF size limit.
    ValueError:
        Invalid value or dtype, or old integer value in NDPI files
        exceeds 32-bit range.

rP  zcannot rewrite tag at offset z < 8r  zGTiffTag.overwrite got an unexpected TiffFile instance as first argumentrY   >   r  r  r   rU  zcannot patch NDPI > 4 GB filesNru   z<>|=zunknown data type rT  r  r  rK  r+  r  r  zinvalid RATIONAL valuerQ  r  )*r   r  r   r   r   r  r  r"  rY  r  r   r   rO  r~   r   ra  rz   r   r  r  r.   r   r  rg  r  r{   re  r  rf  r   r   rX  r\  r   r(  r%  r  rd  rg  r   r$   r  )rk  rO  r   r  r   rl  r"  r  packedvaluer  r  r  dtsizenewsizeoldsizer  rm  s                    rv   r  TiffTag.overwrite0)  s   L ;;?d..21$++dCCS/!5,''$  C. [[##{{<<zzQ4::#8djj%00

1A

Az>:C$S/)??D=E=JJEs##5zA~%(f"4ab	0((/
 He,E$(	,**51J
 A:%%%3!LL1E  u--8 o%5zQ%*"7 JEHEu%%__Z0F5zF"2 o%J&(EKHEE
 19	2C$S/)! ++>>"53z!}+=#=">z!}oNK k"**vt/@/@/LMM&&ggiK	

"a(T^^c%95AB111555GGDKK!O,HHV[[%MN GGAr{{+"$'')K"Q)#q(GGDKK!O,HH OO!"KK(9(9;G GGK(HH[)333 KK!Ofoodoobq6I&JJ  a(T__eIJGGD,,-HHWw./#t'7'7''ARWW'La(T__Ra%8%@A(()%W.2HHW(9:; 2;;' ggi?HHW%1$Ka(KKD$5$5{C $%GGD,,-HHWw./ GGCLKKKKII
 	
Y  0*5)4 o4/0  	,&ui0CS/t+	, * 3<C$S/s230  | GGCLsO   _ _= 3` 3`= Qa _:=`
`:'`55`:=aaa&c                   U R                   S:w  d  U R                  S:w  a  g[        5       R                  U < S35        [        R
                  " S/U R                  Q76 n[        R                  " SU5      S   U l        U R                  R                  nUR                     UR                  U R                  5        [        R                  " SUR                  S5      5      U l        SSS5        g! , (       d  f       g= f)	zCorrect 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.

r  rT  Nz! correcting LSM bitspersample tag<HH<Ir   r  )r  r  r7   rm  re  rf  rO  re  r  r  r  r*  r\  r   )rk  rO  rl  s      rv   r  TiffTag._fix_lsm_bitspersample*  s     99tzzQD8#DEFE/DJJ/!==u5a8[[##WWGGD$$%ubggaj9DJ WWs   !AC11
C?c                    SR                  [        R                  R                  U R                  / 5      5      nU(       a  SU-   nSU R                   U SU R
                   S3$ )NrI  r  r  r  rr   )r   r   r  getallr  r   r0  s     rv   r+  TiffTag.__repr__"*  sR    xx		((B78:D#DII;tfBt{{m1EEru   c                "    U R                  5       $ ry   r  r  s    rv   r  TiffTag.__str__(*  r   ru   c                   U R                   S;   nUS::  a  SnOU(       a  US-  nOUS-  nU R                  nU R                  S:  a  USU R                   S3-  nSR                  [        R
                  R                  U R                   / 5      5      nU(       a  U R                    S	U S
U R                   3nOU R                    S
U R                   3nSU S	U S
U R                   S	3n U R                  n U R                  S:X  a  [        U5      nO[        [        S U 5       5      5      n US::  a  USU-   -  nUSU nU$ USU-   -  nU$ ! [         a|    [        U[        [        45      (       aT  US::  a  USS nOHU(       a'  US:X  a  USS nO5[!        U5      S:  a  USS USS -   nO[!        U5      S:  a  USS USS -   n[        XUS9n Nf = f! ["         a    Sn Nf = f)z3Return string containing information about TiffTag.>   r  r  r  r  r   rY   r   rP  r  ]rI  r  r  zTiffTag c              3  8   #    U  H  n[        U5      v   M     g 7fry   )r/   r   r  s     rv   r   TiffTag._str.<locals>.<genexpr>F*  s     )De'!**er  Nr  r     i r  i r  	CORRUPTEDz= r  )r  r  r  r   r   r  r	  r   r  rO  r/   r?   r~   r  r   rM  r   r   )	rk  r  rX  is_strip_tiler  r   r   linerO  s	            rv   r  TiffTag._str+*  s   		%99Q;FaZFaZF::>qA&&Exx		((B78ii[$r$++7Dii[4;;-0D$qr$*:*:);1=	CJJEC::?#ENE#E)De)D$DEE Q;D5L D<D  D5L D#  CeeT]33{ %ds&!Q;$)$3KE Z$.$)$3K%,$>EUd* %etuUV} <6BC  	 E	 s+   +G 8E E BGGG'&G')r  r  r  r   r   r  rO  r  )r  r  r   r   r  r   r   zDATATYPE | intr  r   rO  rg   r  r   r6  r   )
r  r   r   r3  rm  r9  r  r   r6  r$   )r  r  r   r   r  r   r   r   r  r   r  r   r6  rg   )
rO  rg   r  r   r   r   r   r   r6  rg   r  )rO  rg   r6  r   rK  rK  )r6  r|   )rO  rg   r   zDATATYPE | int | str | Noner  r   r6  r$   rB  r  r  )r  r  r  r  r  rG  rL  rn  classmethodr  rN  r  r  rM  rO  r  r  r   r  r  r	  r  r  r+  r  r  r   rt   ru   rv   r$   r$   '  se   (I "!#K,
IJ1J'(K$%$ $ 	$
 $ $ $ $ 
$,  "#bKbK
 bK bK bK 
bK bKH :%:: : 	:
 : : 
: :x ,,,&),36,	, ,\ % %N \\  ' ' 8 8 - - K K"CR .2^
^

 +^
 ^
 
^
@:$F- -ru   r$   c                  0   \ rS rSr% SrSrS\S'   S\S'   S\S	'   S
\S'   SS jrSS jrS S jr	S!S jr
S"S jr  S#       S$S jjr  S#       S%S jjr S&     S'S jjrS(S jrS)S jrS*S jrS+S jrS,S jrS-S jrS.S jrS.S jrS/S0S jjrSrg)1r&   i[*  a8  Multidict-like interface to TiffTag instances in TiffPage.

Differences to a regular dict:

- values are instances of :py:class:`TiffTag`.
- keys are :py:attr:`TiffTag.code` (int).
- multiple values can be stored per key.
- can be indexed by :py:attr:`TiffTag.name`` (``str``), slower than by key.
- ``iter()`` returns values instead of keys.
- ``values()`` and ``items()`` contain all values sorted by offset.
- ``len()`` returns number of all values.
- ``get()`` takes optional index argument.
- some functions are not implemented, such as, ``update`` and ``pop``.

)_count_dict_list_sortedr   r	  zdict[int, TiffTag]r 	  zlist[dict[int, TiffTag]]r!	  list[TiffTag] | Noner"	  c                R    0 U l         U R                   /U l        SU l        S U l        g r  )r 	  r!	  r	  r"	  r  s    rv   rn  TiffTags.__init__x*  s$    
jj\
-1ru   c                   UR                   nU R                   H  nX#;  d  M
  XU'     O   U R                  R                  X!05        U =R                  S-  sl        SU l        g)Add tag.rY   N)r  r!	  r   r	  r"	  )rk  r  r  r  s       rv   r$  TiffTags.add~*  sS    xxA}$ 
 JJtk*qru   c                H    [        U R                  R                  5       5      $ )zReturn codes of all tags.)rM  r 	  keysr  s    rv   r*	  TiffTags.keys*  s    DJJOO%&&ru   c                    U R                   cC  [        U R                   VVs/ s H  oR                  5         H  o"PM     M     snnS S9U l         U R                   $ s  snnf )z1Return all tags in order they are stored in file.c                    U R                   $ ry   r=  )r.  s    rv   r  !TiffTags.values.<locals>.<lambda>*  s    ahhru   r
  )r"	  ru  r!	  r  )rk  r  r.  s      rv   r  TiffTags.values*  sN    <<! JJ;Jq
1
J;&DL || <s   "A
c                d    U R                  5        Vs/ s H  oR                  U4PM     sn$ s  snf )z>Return all (code, tag) pairs in order tags are stored in file.)r  r  )rk  r.  s     rv   r`  TiffTags.items*  s&    %)[[]3]]333s   -Nc               l    U R                  USUS9nUc  U$  UR                  $ ! [         a    Us $ f = f)aQ  Return value of tag by code or name if exists, else default.

Parameters:
    key:
        Code or name of tag to return.
    default:
        Another value to return if specified tag is corrupted or
        not found.
    index:
        Specifies tag in case of multiple tags with identical code.
        The default is the first tag.

N)r  r  )rS  rO  r   )rk  r   r  r  r  s        rv   r  TiffTags.valueof*  sE    ( hhsDh6;N	99 	N	s   $ 33c               T   Uc7  XR                   ;   a  U R                   U   $ [        U[        5      (       d  U$ Sn U R                  U   nX;   a  XA   $ [        U[        5      (       d  U$ UR                  5        H  nUR                  U:X  d  M  Us  $    U$ ! [         a    Us $ f = f)aF  Return tag by code or name if exists, else default.

Parameters:
    key:
        Code or name of tag to return.
    default:
        Another tag to return if specified tag is corrupted or
        not found.
    index:
        Specifies tag in case of multiple tags with identical code.
        The default is the first tag.

r   )r 	  r   rz   r!	  r4  r  r   )rk  r   r  r  r  r  s         rv   rS  TiffTags.get*  s    ( =jj zz#&c3''E	::e$D ;9#s##N;;=Cxx3
 !   	N	s   B B'&B'c               b   / nU R                    H  nX;   a  UR                  XA   5        M    O   U(       a  U$ [        U[        5      (       d  U$ U R                    HF  nUR	                  5        H&  nUR
                  U:X  d  M  UR                  U5          O   U(       a  MF    O   U=(       d    U$ )zReturn list of all tags by code or name if exists, else default.

Parameters:
    key:
        Code or name of tags to return.
    default:
        Value to return if no tags are found.

)r!	  r   r   rz   r  r   )rk  r   r  r  r  r  s         rv   r	  TiffTags.getall*  s     !#JJD{di(	 
 M#s##NJJD{{}88s?MM#& % 6    ru   c                   XR                   ;   a  U R                   U   $ [        U[        5      (       d  [        U5      eU R                   R	                  5        H  nUR
                  U:X  d  M  Us  $    [        U5      e)z>Return first tag by code or name. Raise KeyError if not found.)r 	  r   rz   r  r  r   )rk  r   r  s      rv   r  TiffTags.__getitem__ +  sd    **::c?"#s##3-::$$&Cxx3
 ' smru   c               J    UR                   U:X  d   eU R                  U5        g)r'	  N)r  r$  )rk  r  r  s      rv   __setitem__TiffTags.__setitem__+  s    xx4ru   c                  SnU R                    H#  nX;   a  SnX1	 U =R                  S-  sl        M#    O   U(       a  SU l        g[        U[        5      (       d  [        U5      eU R                    HP  nUR                  5        H9  nUR                  U:X  d  M  X4R                  	 U =R                  S-  sl        Sn  MN       O   U(       d  [        U5      eSU l        g)z Delete all tags by code or name.FTrY   N)	r!	  r	  r"	  r   rz   r  r  r   r  )rk  r   foundr  r  s        rv   __delitem__TiffTags.__delitem__+  s    JJD{Iq   DL#s##3-JJD{{}88s?XXKK1$K E %   3-ru   c                  ^ TU R                   ;   a  g[        T[        5      (       d  g[        U4S jU R                   R	                  5        5       5      $ )zReturn if tag is in map.TFc              3  @   >#    U  H  oR                   T:H  v   M     g 7fry   )r   )r   r  r  s     rv   r   (TiffTags.__contains__.<locals>.<genexpr>3+  s     C/B88t#/B   )r 	  r   rz   r;  r  rk  r  s    `rv   __contains__TiffTags.__contains__-+  s@    4::$$$Ctzz/@/@/BCCCru   c                4    [        U R                  5       5      $ )zReturn iterator over all tags.)r  r  r  s    rv   r  TiffTags.__iter__5+  s    DKKM""ru   c                    U R                   $ )zReturn number of tags.)r	  r  s    rv   r  TiffTags.__len__9+  s    {{ru   c                "    S[        U 5      S S3$ )Nz<tifffile.TiffTags @0x016Xrr   idr  s    rv   r+  TiffTags.__repr__=+  s    '4a88ru   c                "    U R                  5       $ ry   r  r  s    rv   r  TiffTags.__str__@+  r   ru   c                `   / n/ nU  Hn  nUR                  US-   S9nUR                  USU R                  5       5        US:  d  M?  [        U5      U:  d  MP  UR                  UR                  XS95        Mp     SR	                  U5      nUS:  a  U(       a  USSR	                  U5      -   -  nU$ )z.Return string with information about TiffTags.rY   r  Nr   r  r  r  )r  r   rc  r   r   )rk  r  rX  tlinesvlinesr  tagstrr  s           rv   r  TiffTags._strC+  s    CXXEAIX.FMM&%...01zc&kE1chhfhBC  6"A:&fv{{6222Fru   rB  )r  r$   r6  r   )r6  r>  )r6  zlist[TiffTag])r6  zlist[tuple[int, TiffTag]]r  )r  rg   r  r3  r   rD  r6  rg   )r  r8  r  r3  r   rD  r6  r8  ry   )r  rg   r   rD  r6  r#	  )r   rD  r6  r$   )r  r   r  r$   r6  r   r   rD  r6  r   )r  rJ  r6  r   )r6  zIterator[TiffTag]rK  rK  r  r  )r  r  r  r  r  rG  rL  rn  r$  r*	  r  r`  r  rS  r	  r  r;	  r?	  rF	  r  r  r+  r  r  r   rt   ru   rv   r&   r&   [*  s     8I K##!!2
'4   	
  
@ #' %  	%
 %% 
%V 	 ! 	 ! !
 
 !D	
:D#9 ru   r&   c                     \ rS rSr% SrSrS\S'   S\S'       S S jr    S S	 jrS!S
 jr	S"S jr
\S#S j5       r\S$S j5       r\S%S j5       r\S&S j5       r S'     S(S jjr\S)S j5       r\S*S j5       r\S+S j5       r\S,S j5       r S'     S-S jjr\S.S j5       r\S/S j5       rS0S jrS1S jrS2S jrS3S jrS4S jrS5S jrS5S jrSrg)6r%   iS+  a  Registry of TIFF tag codes and names.

Map tag codes and names to names and codes respectively.
One tag code may be registered with several names, for example, 34853 is
used for GPSTag or OlympusSIS2.
Different tag codes may be registered with the same name, for example,
37387 and 41483 are both named FlashEnergy.

Parameters:
    arg: Mapping of codes to names.

Examples:
    >>> tags = TiffTagRegistry([(34853, 'GPSTag'), (34853, 'OlympusSIS2')])
    >>> tags.add(37387, 'FlashEnergy')
    >>> tags.add(41483, 'FlashEnergy')
    >>> tags['GPSTag']
    34853
    >>> tags[34853]
    'GPSTag'
    >>> tags.getall(34853)
    ['GPSTag', 'OlympusSIS2']
    >>> tags.getall('FlashEnergy')
    [37387, 41483]
    >>> len(tags)
    4

)r 	  r!	  zdict[int | str, str | int]r 	  z list[dict[int | str, str | int]]r!	  c               X    0 U l         U R                   /U l        U R                  U5        g ry   )r 	  r!	  r  )rk  rx  s     rv   rn  TiffTagRegistry.__init__v+  s$    
 
jj\
Cru   c                  [        U[        5      (       a+  UR                  5        H  u  p#U R                  X#5        M     g[        U[        5      (       a  [        UR                  5       5      nU H  u  p#U R                  X#5        M     g)z]Add mapping of codes to names to registry.

Parameters:
    arg: Mapping of codes to names.

N)r   r%   r`  r$  r  rM  )rk  rx  r  r   s       rv   r  TiffTagRegistry.update+  sg     c?++!iik
$ *c4  syy{#CJDHHT  ru   c                   U R                    H(  nX;   a
  X1   U:X  a    gX;  d  M  X#;  d  M   X#U'   XU'     g   U R                   R                  XX!05        g)zAdd code and name to registry.N)r!	  r   )rk  r  r   r  s       rv   r$  TiffTagRegistry.add+  sS    AyQW_}$$  JJt467ru   c                >    S U R                    5       n[        US S9$ )z*Return all registry items as (code, name).c              3     #    U  H8  oR                  5         H!  n[        US    [        5      (       d  M  Uv   M#     M:     g7fr0  )r`  r   r   )r   r  r  s      rv   r   (TiffTagRegistry.items.<locals>.<genexpr>+  s.      
!!779a
1Q48MAA9Azs
   /AAc                    U S   $ r  rt   )r  s    rv   r  'TiffTagRegistry.items.<locals>.<lambda>+  s    1Q4ru   r
  )r!	  ru  )rk  r`  s     rv   r`  TiffTagRegistry.items+  s$    
zz
 e00ru   c                   g ry   rt   rk  r   r  s      rv   rS  TiffTagRegistry.get+      =@ru   c                   g ry   rt   rg	  s      rv   rS  rh	  +  ri	  ru   c                   g ry   rt   rg	  s      rv   rS  rh	  +      58ru   c                   g ry   rt   rg	  s      rv   rS  rh	  +  rl	  ru   Nc               B    U R                    H  nX;   d  M
  X1   s  $    U$ )zReturn first code or name if exists, else default.

Parameters:
    key: tag code or name to lookup.
    default: value to return if key is not found.

r!	  )rk  r   r  r  s       rv   rS  rh	  +  s%     Axv  ru   c                   g ry   rt   rg	  s      rv   r	  TiffTagRegistry.getall+      FIru   c                   g ry   rt   rg	  s      rv   r	  rq	  +  rr	  ru   c                   g ry   rt   rg	  s      rv   r	  rq	  +      DGru   c                   g ry   rt   rg	  s      rv   r	  rq	  +  ru	  ru   c               l    U R                    Vs/ s H  o1U;   d  M
  X1   PM     nnU=(       d    U$ s  snf )zReturn list of all codes or names if exists, else default.

Parameters:
    key: tag code or name to lookup.
    default: value to return if key is not found.

ro	  )rk  r   r  r  r  s        rv   r	  rq	  +  s4     #'**9*Qq&!&*9   :s   	11c                   g ry   rt   r  s     rv   r  TiffTagRegistry.__getitem__+      /2ru   c                   g ry   rt   r  s     rv   r  ry	  +  rz	  ru   c               T    U R                    H  nX;   d  M
  X!   s  $    [        U5      e)z7Return first code or name. Raise KeyError if not found.)r!	  r  )rk  r   r  s      rv   r  ry	  +  s(    Axv  smru   c                   SnU R                    H  nX;   d  M
  SnX1   nX1	 X4	 M     U(       d  [        U5      eU R                  /U R                   SS  Vs/ s H  o3(       d  M  UPM     sn-   U l         gs  snf )z Delete all tags of code or name.FTrY   N)r!	  r  r 	  )rk  r   r>	  r  rO  s        rv   r?	  TiffTagRegistry.__delitem__+  so    AxFH  3-jj\

12$D1!Q$DD
$Ds   
A5$A5c               B   ^ [        U4S jU R                   5       5      $ )z&Return if code or name is in registry.c              3  .   >#    U  H
  nTU;   v   M     g 7fry   rt   )r   r  r  s     rv   r   /TiffTagRegistry.__contains__.<locals>.<genexpr>+  s     1j419j   )r;  r!	  rE	  s    `rv   rF	  TiffTagRegistry.__contains__+  s    1djj111ru   c                4    [        U R                  5       5      $ )z+Return iterator over all items in registry.)r  r`  r  s    rv   r  TiffTagRegistry.__iter__+  s    DJJL!!ru   c                R    SnU R                    H  nU[        U5      -  nM     US-  $ )z!Return number of registered tags.r   rT  )r!	  r   )rk  r   r  s      rv   r  TiffTagRegistry.__len__,  s,    ACFND qyru   c                "    S[        U 5      S S3$ )Nz<tifffile.TiffTagRegistry @0xrM	  rr   rN	  r  s    rv   r+  TiffTagRegistry.__repr__	,  s    .r$xoQ??ru   c                l    SR                  SR                  S U R                  5        5       5      5      $ )NzTiffTagRegistry((
  {}
))z,
  c              3  :   #    U  H  u  pS U SU< S3v   M     g7f)(r   rz  Nrt   )r   r  r   s      rv   r   *TiffTagRegistry.__str__.<locals>.<genexpr>,  s!     N:41TF"THA.s   )r   r   r`  r  s    rv   r  TiffTagRegistry.__str__,  s-    ,33LLNNN
 	
ru   )rx  z<TiffTagRegistry | dict[int, str] | Sequence[tuple[int, str]]r6  r   )r  r   r   rz   r6  r   )r6  zlist[tuple[int, str]])r  r   r   r   r6  rQ  )r  r   r   rz   r6  r3  )r  rz   r   r   r6  rz   )r  r   r   rz   r6  r   ry   )r  str | int | Noner   rD  r6  r	  )r  r   r   r   r6  r   )r  r   r   rz   r6  r5  )r  	list[str]r   r   r6  r	  )r  r>  r   rz   r6  r>  )r  list[str] | list[int] | Noner   rD  r6  r	  r   r   r6  rz   )r   rz   r6  r   )r   rD  r6  rD  rX	  )r  rD  r6  r   )r6  zIterator[tuple[int, str]]rK  rK  )r  r  r  r  r  rG  rL  rn  r  r$  r`  ra   rS  r	  r  r?	  rF	  r  r  r+  r  r   rt   ru   rv   r%   r%   S+  sP   8 #I%%++I 
	!I! 
	!*8 1 @ @@ @8 88 8 >B*:	 I II IG GG G JN!*F!!	%! 2 22 2E2"@
ru   r%   c                     \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'    S\S'    S\S'    S\S'    S\S'    S\S'    S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S \S!'      SDS"S"S"S"S"S"S"S#S#S"S$.
                             SES% jjjr\SFS& j5       r\	SGS' j5       r
\SHS( j5       r\SIS) j5       r\SJS* j5       r\	SKS+ j5       r\	SLS, j5       r\	SJS- j5       r\	SJS. j5       r\	SMS/ j5       r\	SNS0 j5       r\	SOS1 j5       r\	SOS2 j5       r\	SPS3 j5       r\	SQS4 j5       rS"S5.     SRS6 jjrS"S"S7.       SSS8 jjrS"S"S7.       STS9 jjr\SUS: j5       rSVS; jr\    SWS< j5       r\    SXS= j5       r\    SYS> j5       r\SZS? j5       r \SJS@ j5       r!SHSA jr"SHSB jr#SCr$g")[r   i,  a  Sequence of TIFF pages making up multi-dimensional image.

Many TIFF based formats, such as OME-TIFF, use series of TIFF pages to
store chunks of larger, multi-dimensional images.
The image shape and position of chunks in the multi-dimensional image is
defined in format-specific metadata.
All pages in a series must have the same :py:meth:`TiffPage.hash`,
that is, the same shape, data type, and storage properties.
Items of a series may be ``None`` (missing) or instances of
:py:class:`TiffPage` or :py:class:`TiffFrame`, possibly belonging to
different files.

Parameters:
    pages:
        List of TiffPage, TiffFrame, or ``None``.
        The file handles of TiffPages or TiffFrames may not be open.
    shape:
        Shape of image array in series.
    dtype:
        Data type of image array in series.
    axes:
        Character codes for dimensions in shape.
        Length must match shape.
    attrs:
        Arbitrary metadata associated with series.
    coords:
        Ordered map of dimension character codes to coordinate arrays.
    units:
        Map of dimension character codes to unit strings.
    index:
        Index of series in multi-series files.
    parent:
        TiffFile instance series belongs to.
    name:
        Name of series.
    kind:
        Nature of series, such as, 'ome' or 'imagej'.
    truncated:
        Series is truncated, for example, ImageJ hyperstack > 4 GB.
    multifile:
        Series contains pages from multiple files.
    transform:
        Function to transform image data after decoding.

r  r  r  r  r   r  numpy.dtype[Any]r   rz   r   r   -Callable[[NDArray[Any]], NDArray[Any]] | None	transformr   is_multifileis_truncated!list[TiffPage | TiffFrame | None]_pagesr   r  _lenr  rM  r  r   r&  dict[str, str]_unitsr  r  _explicit_coordsNF)
r  r  unitsr  r  r   r   r  	multifiler	  c      
           SU l         SU l        Uc  0 O
[        U5      U l        Uc  0 O
[        U5      U l        Uc  0 O
[        U5      U l        [        U R
                  5      U l        Uc  SO
[        U5      U l	        [        U5      U l        U /U l        [        U R                  5      n [        S U R                   5       5      nUc  UR"                  nUc  UR$                  nUc  UR&                  n[(        R&                  " U5      U l        U=(       d    SU l        U
=(       d    SU l        Xl        UU l        [3        U5      U l        [3        U5      U l        U	b  Xl        O4U R                  (       a  U R0                  R8                  U l        OS U l        [;        U5      U l        X@l         U(       dO  US:X  aI  [=        UR"                  5      nUS:  a'  [        [=        U R                  5      U-  5      U l        g Xl        g Xl        g ! [         a=     [        S U R                   5       5      n GNp! [         a    Sn[!        U5      S ef = ff = f)Nr=  rt   r   c              3     #    U  HV  nUc  M  UR                   c  M  UR                   R                  R                  R                  (       a  MH  UR                   v   MX     g 7fry   )r  r  r  r  r  s     rv   r   *TiffPageSeries.__init__.<locals>.<genexpr>,  sN      $A  JJ  

))44;;	 

$s   A A -A A c              3  b   #    U  H%  nUc  M  UR                   c  M  UR                   v   M'     g 7fry   r[  r  s     rv   r   r	  ,  s,       ( )* AJJ(s   ///z no valid keyframe found in pagesrY   ) r  r  r  r&  r	  r  r!  r	  r   r  rM  r	  r  r   r  r  r   r   r  r   r   r   r   r	  r  r   r	  r	  r  r~   r@   r	  )rk  r  r   r   r  r  r  r	  r  r  r   r   r  r	  r	  r  r  r   r  s                      rv   rn  TiffPageSeries.__init__i,  s   & 
!MbtE{!MbtE{#^rf #DLL 1 =ac%j5kfT[[!	0  H$ =NNE<==D=NNE[['
JB	JB	"  O O K[[--..DKDKEl
Vq['A1u 4 9:	"	IW  		00  ![[  
 ! 08 o4/0		0s   +H 
IH77IIc                2    [        U R                  5      S:  $ )z%Series contains multiple resolutions.rY   )r   r  r  s    rv   is_pyramidalTiffPageSeries.is_pyramidal,  re  ru   c                   U R                   (       d  gSnU R                    H{  nUb  [        UR                  5      S:X  a    gUR                  (       d    gU(       d  UR                  S   UR                  -   nMY  XR                  S   :w  a    gXR                  -  nM}     U R                   S   nUb  [        UR                  5      S:X  a  gUR                  S   n[        U R                   5      S:X  aJ  [        U[        5      (       a5  UR                  (       d"  UR                  (       d  UR                  (       a  U$ X[        U R                  5      U R                  R                  -  -   :X  a  U$ g)z(Offset to contiguous image data in file.Nr   rY   )r	  r   r  r  r   r   r   r  re  r:  r@   r  r   r   )rk  rm  r  r   s       rv   r  TiffPageSeries.dataoffset,  s     {{KKD|s4#3#349==&&q)DKK7&&q));;C   {{1~<3t//0A5!!!$!4**4>>T[[ M74;;/$**2E2EEEEMru   c                    U R                   $ )z.Character codes for dimensions in image array.)r  r  s    rv   r  TiffPageSeries.axes,       zzru   c                    U R                   $ )zShape of image array in series.r  r  s    rv   r   TiffPageSeries.shape,  re  ru   c                ,    [        U R                  5      $ rp  rq  r  s    rv   r  TiffPageSeries.ndim,  rs  ru   c                >    [        [        U R                  5      5      $ ru  rv  r  s    rv   r  TiffPageSeries.dims,  ry  ru   c                R    [        [        U R                  U R                  SS95      $ r{  r|  r  s    rv   r  TiffPageSeries.sizes,  r~  ru   c                ,    [        U R                  5      $ r  r  r  s    rv   r   TiffPageSeries.size,  r  ru   c                H    U R                   U R                  R                  -  $ rN  )r   r   r   r  s    rv   r   TiffPageSeries.nbytes-  s     yy4::....ru   c                    U R                   nU R                  nUR                  S5      S:X  a+  UR                  S5      S:X  a  SU;   a  SU;   a
  US   US   4$ g)z>Pixel spacing in micrometer as (x, y), or None if unavailable.r  
micrometerr  N)r  r  rS  )rk  r  r	  s      rv   r  TiffPageSeries.mpp-  s^     ""  IIcNl*		#,.vv3K--ru   c                *  ^
 0 m
U R                   R                  5        Hf  u  p[        U[        5      (       aG  Uu  p4U R                  U R
                  R                  U5         n[        R                  " X4USS9T
U'   Ma  UT
U'   Mh     [        U
4S jU R
                   5       5      (       dg  U R                  R                  n[        U R
                  U R                  SS9 H.  u  pxUT
;  d  M  Xv;   d  M  Xg   n	[        U	5      U:X  d  M)  U	T
U'   M0     T
$ )z>Ordered map of dimension character codes to coordinate arrays.Fr  c              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   r   r  r  s     rv   r   (TiffPageSeries.coords.<locals>.<genexpr>!-       5*B<*r  Tr4  )r  r`  r   r~   r  r  r  r   r  rl  r  r  r  r   )rk  r   rO  r  r  num	kf_coordsr  r   kcr  s             @rv   r  TiffPageSeries.coords-  s     +-,,,,.JC%''#kk$**"2"23"78#nnU#Ns#s / 5$**555,,I

DKKEV#"B2w$%'r
	 F
 ru   c                B  ^ 0 mU R                   R                  5        GH  u  p[        U[        5      (       aO  [	        U5      S:X  a@  Uu  p4U R
                  U R                  R                  U5         nUS:  a  XC-
  U-  TU'   Mh  Mj  [        U[        R                  5      (       d  M  UR                  R                  S:X  d  M  [	        U5      S:  d  M  US   US   -
  [	        U5      S-
  -  n[        R                  " U5      n[        R                  " XvSSS9(       d  GM  [        U5      TU'   GM     [        U4S jU R                   5       5      (       d  U R                   R"                  nU R                   H  n	U	T;  d  M  X;   d  M  X   n
U
R                  R                  S:X  d  M2  [	        U
5      S:  d  MC  U
S   U
S   -
  [	        U
5      S-
  -  n[        R                  " U
5      n[        R                  " XvS	SS9(       d  M  [        U5      TU	'   M     T$ )
aE  Coordinate step sizes per axis.

Map dimension character codes to the spacing between consecutive
coordinate values. Only axes with numeric, approximately uniformly
spaced coordinates are included. The scale is the average step size
``(last - first) / (n - 1)``, provided all individual steps are
within 5% of that average.

rT  r   r  rY   rK  皙?)rtolatolc              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   r	  s     rv   r   .TiffPageSeries.coord_scales.<locals>.<genexpr>H-  r	  r  皙?)r  r`  r   r~   r   r  r  r  r   r8  r   r   r  allcloserY  rl  r  r  )rk  r   rO  r  r  r	  avgdiffsr	  r  r	  r  s              @rv   r  TiffPageSeries.coord_scales*-  s    $&,,,,.JC%''CJ!O $kk$**"2"23"787#'<3"6F3K E5==11ekk6F6F#6M u:> 9uQx/CJNCC!JJu-E~~et!DD&+Cjs! /$ 5$**555,,IjjV#"Bxx}}+B!!"v1~#b'A+> %

2 >>%3QGG).sF2J ! ru   c                  ^ 0 mU R                   R                  5        H  u  p[        U[        5      (       a  [	        U5      S:X  dN  [        U[
        R                  5      (       d  MJ  UR                  R                  S:X  d  Mf  [	        U5      S:  d  Mw  [        US   5      TU'   M     [        U4S jU R                   5       5      (       dz  U R                  R                  nU R                   HT  nUT;  d  M  XC;   d  M  X4   nUR                  R                  S:X  d  M2  [	        U5      S:  d  MC  [        US   5      TU'   MV     T$ )zCoordinate offsets (first pixel position) per axis.

Map dimension character codes to the coordinate value of the
first pixel. Only axes with numeric coordinates are included.

rT  r  r   c              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   r	  s     rv   r   /TiffPageSeries.coord_offsets.<locals>.<genexpr>h-  r	  r  )r  r`  r   r~   r   r   r8  r   r   rY  rl  r  r  r  )rk  r   rO  r	  r  r	  r  s         @rv   r  TiffPageSeries.coord_offsetsT-  s     $&,,,,.JC5%((SZ1_5%--00KK$$+JN#E!Hos / 5$**555,,IjjV#"Bxx}}+B!%*2a5\r
	 !
 ru   c                  ^ [        U R                  5      m[        U4S jU R                   5       5      (       d  U R                  R
                  R                  S5      n[        U[        5      (       a[  US;  aU  U R                  R                  nS H9  nX0R                  ;   d  M  UT;  d  M  X0R                  ;  d  M-  X2;   d  M4  UTU'   M;     T$ )zXCoordinate unit strings per axis.

Map dimension character codes to their unit string.

c              3  <   >#    U  H  oS ;   d  M
  UT;   v   M     g7f)XYZNrt   r	  s     rv   r   -TiffPageSeries.coord_units.<locals>.<genexpr>{-  s     D*Be<2<*s   	r   >   r   	undefinedr  r  Z)r  r	  rl  r  r  r  rS  r   rz   r  r	  )rk  r  r	  r  r  s       @rv   r  TiffPageSeries.coord_unitsq-  s     dkk" D$**DDDmm))--.>?G'3''G < - !MM00	)Bjj(f,&;&;;O%,r
 * ru   c                \   U R                   R                  R                  5        VVs0 s H  u  pUS:w  d  M  X_M     nnnUR                  U R                  5        SU;  a  U R
                  nUb  XCS'   S H+  nX;  d  M
  [        X5      nU(       d  M  [        U5      X1'   M-     U$ s  snnf )zMetadata dictionary for series.r   r  )r  r  r  )r  r  r`  r  r&  r  r  r  )rk  r   rO  r  r  s        rv   r  TiffPageSeries.attrs-  s    
 #mm11779"
9
&& CJ9 	 "

 	dkk"((C #uCC *5"&u+FK	 D
 "
s
   B(B()r   c                   U R                   c  Sn[        U5      eUb  U R                  U   R                  " S0 UD6$ U R                   R                  " SSU 0UD6nU R                  b  U R	                  U5      nU$ )zReturn images from series of pages as NumPy array.

Parameters:
    level:
        Pyramid level to return.
        By default, the base level is returned.
    **kwargs:
        Additional arguments passed to :py:meth:`TiffFile.asarray`.

	no parentr   rt   )r  r   r  r   r	  )rk  r   r   r   r  s        rv   r   TiffPageSeries.asarray-  sy     ;;CS/!;;u%--777$$;D;F;>>%^^F+Fru   )r   r   c                  SSK Jn  U R                  c  Sn[        U5      eU nU(       d  UcP  U R                  S:w  a@  U R                  R                  SS9nU R                  [        U5      :  a  XpR                     nUb  UR                  U   nUSL a  UR                  " S
SS0UD6nOUR                  " S
0 UD6nU" UUR                  UR                  UR                  UR                  S	9$ )a!  Return image data from series of pages as xarray DataArray.

Parameters:
    level:
        Pyramid level to return.
        By default, the base level is returned.
    squeeze:
        Remove length-1 dimensions from image array, except X and Y.
        If ``False``, preserve all dimensions.
        If ``None`` (default), remove length-1 dimensions except
        for ``'shaped'`` series.
    **kwargs: Passed to :py:meth:`asarray`.

Returns:
    :py:class:`xarray.DataArray`
        Image data with coordinates, dimensions, and attributes.

r   rm   r	  r   Tr  Fr   rH  rt   )r   rn   r  r   r   r  r  r   r  r   r  r  r   r  )	rk  r   r   r   rn   r   r   r  r  s	            rv   r   TiffPageSeries.asxarray-  s    2 	%;;CS/!!%w499+@{{..t.<H{{S]*!++.]]5)F e>>:%:6:D>>+F+D==,,
 	
ru   c                   U R                   c  Sn[        U5      eSSKJn  U nU(       a@  U R                   R	                  SS9nU R
                  [        U5      :  a  XpR
                     nU" U4SU0UD6$ )a  Return images from series of pages as Zarr store.

Parameters:
    level:
        Pyramid level to return.
        By default, a multi-resolution store is returned.
    squeeze:
        Remove length-1 dimensions from image array, except X and Y.
        If ``False``, preserve all dimensions.
        If ``None`` (default), remove length-1 dimensions except
        for ``'shaped'`` series.
    **kwargs:
        Additional arguments passed to :py:class:`ZarrTiffStore`.

r	  rY   rK  Tr  r   )r  r   r   r  r  r  r   )rk  r   r   r   r   r  r   r  s           rv   r   TiffPageSeries.aszarr-  sp    , ;;CS/!'!%{{..t.<H{{S]*!++.V;5;F;;ru   c                    U $ )z{Return self for backwards compatibility.

.. deprecated::
    Access the series directly instead of via ``series.pages``.

rt   r  s    rv   r  TiffPageSeries.pages.  s	     ru   c                  [        U5      nUS:  a  XR                  -  n[        U R                  5      S:X  ax  SUs=:  a  U R                  :  aa  O  O^U R                  S   nUb  U R                  c  Sn[        U5      eU R                  R                  R                  UR                  U-   5      $ U R                  U   $ )z3Return specified page of series from cache or file.r   rY   "series has no valid page or parent)	r   r	  r   r	  r  r   r  r  r  )rk  r   r  r   s       rv   r  TiffPageSeries._getitem".  s    #h799Ct{{q Q%8tyy%8;;q>D|t{{2: o%;;$$--djj3.>??{{3ru   c                   g ry   rt   r  s     rv   r  TiffPageSeries.__getitem__/.  s     '*ru   c                   g ry   rt   r  s     rv   r  r	  4.  s     -0ru   c                  [        U[        [        R                  45      (       a  U R	                  [        U5      5      $ [        U[
        5      (       a@  [        UR                  U R                  5      6  Vs/ s H  o R	                  U5      PM     sn$ [        U[        5      (       a6  [        U[        5      (       d!  U Vs/ s H  o0R	                  U5      PM     sn$ Sn[        U5      es  snf s  snf )zReturn specified page(s).r  )r   r   r   r  r  r  r  r  r	  rS   rz   r   )rk  r   r  r   r   s        rv   r  r	  9.  s    
 cC/00==S**c5!!.3S[[5K.LM.LMM!$.LMMc8$$ZS-A-A.12cMM!$c22:n	 N2s   8C-C2c              #  |  #    [        U R                  5      U R                  :X  a  U R                   Sh  vN   gU R                  b  U R                  S   c  Sn[	        U5      eU R                  R
                  nU R                  S   R                  n[        U R                  5       H  nX#U-      v   M     g N7f)z%Return iterator over pages in series.Nr   r	  )r   r	  r	  r  r   r  r  r  )rk  r   r  r  r  s        rv   r  TiffPageSeries.__iter__G.  s      t{{tyy({{""{{"dkk!n&<: o%KK%%EKKN((E499%AI&& & #s   3B<B:BB<c                    U R                   $ )z!Return number of pages in series.)r	  r  s    rv   r  TiffPageSeries.__len__U.       yyru   c                <    SU R                    SU R                   S3$ )Nz<tifffile.TiffPageSeries r  rr   )r  r   r  s    rv   r+  TiffPageSeries.__repr__Z.  s    *4;;-q1EEru   c                   SR                  S U R                  (       a  [        U R                  < S5      OSSR                  S U R                   5       5      [	        U R
                  5      U R                  U R                  U R                  (       a  [        U R                  5       S3OS[        U 5       S3U R                  (       a  S	U R                   3OS4 5       5      nS
U R                   SU 3$ )Nr  c              3  8   #    U  H  nU(       d  M  Uv   M     g 7fry   rt   r  s     rv   r   )TiffPageSeries.__str__.<locals>.<genexpr>^.  s"      

  A
r     r=  r  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   r	  b.  r  r  z Levelsr  @zTiffPageSeries )r   r   r*  r   rz   r   r  r   r	  r   r  r  r  )rk  r  s     rv   r  TiffPageSeries.__str__].  s    II 
 26499-"-444DJJ				262C2CC$%W-t9+V$+/??1T__%&

 
 !Rs33ru   )r&  r  r  r	  r  r	  r	  r  r	  r   r	  r	  r  r   r  r   r  r	  NNN)r   r2  r   r3  r  rQ  r  %Sequence[TiffPage | TiffFrame | None]r  zMapping[str, Any] | Noner  z7Mapping[str, NDArray[Any] | tuple[float, float]] | Noner	  zMapping[str, str] | Noner  r3  r  r  r   rQ  r   rQ  r  r   r	  r   r	  r	  r6  r   r  r  rK  r  rK  r  r  )r6  ztuple[float, float] | Noner  )r6  dict[str, float]r6  r	  r  )r   r3  r   rg   r6  r  )r   r3  r   r%  r   rg   r6  rn   )r   r3  r   r%  r   rg   r6  r  )r6  r   )r   r   r6  r  )r   int | numpy.integer[Any]r6  r  )r   r  r6  r	  )r   0int | numpy.integer[Any] | slice | Sequence[int]r6  z?TiffPage | TiffFrame | list[TiffPage | TiffFrame | None] | None)r6  z%Iterator[TiffPage | TiffFrame | None])%r  r  r  r  r  rL  rn  rM  r	  rX   r  r  r   r  r  r  r   r   r  r  r  r  r  r  r   r   r   r  r  ra   r  rb   r  r  r+  r  r   rt   ru   rv   r   r   ,  s   ,\ ! D.,A
I
I-<<:4I .-K
IJ '+"&R +/JN*. "&CG#R $	R
  R R4R (R HR (R R  R R R R  !R" A#R$ 
%Rh $ $  B       0 0 = = # # / /    & ' 'R  8  4  ( &*"58	4 !#	4
 4
 	4

 4
 
4
r !#	"< "< 	"<
 "< 
"<J    *+*	$* * 0(0	*0 0 C	H  ' '  F4ru   r   c                  &   \ rS rSr% SrS\S'   S\S'   S\S'   S	S
S.       SS jjrS	S
S.     SS jjr\SS j5       r	\
    SS j5       r\
    SS j5       r\    SS j5       r\SS j5       r\SS j5       rS S jrS!S jrS!S jrSrg	)"r#   ip.  aU  Sequence of TiffPageSeries in TIFF file.

Returned by :py:attr:`TiffFile.series`.

Items can be accessed by index or iterated over.
A new ``TiffSeries`` with different kind and squeeze settings is returned
by calling the instance.

Parameters:
    parent:
        TiffFile instance series belongs to.
    kind:
        Filter series by kind, such as 'ome' or 'imagej'.
        If ``None``, the default series are returned.
    squeeze:
        Remove length-1 dimensions from series shapes, except X and Y.
        If ``False``, series shapes include all dimensions.

Examples:
    >>> with TiffFile('temp.ome.tif') as tif:
    ...     series = tif.series
    ...     series[0].shape
    ...     series(squeeze=False)[0].shape
    ...     series(kind='generic')[0].shape
    ...
    (8, 2, 512, 512, 3)
    (8, 2, 1, 512, 512, 3)
    (16, 512, 512, 3)

r   _parentr   _squeezerQ  _kindNT)r   r   c              (    Xl         X l        X0l        g ry   )r
  r
  r
  )rk  r  r   r   s       rv   rn  TiffSeries.__init__.  s     
ru   c               *    [        U R                  X!S9$ )aX  Return new TiffSeries with specified kind and squeeze settings.

Parameters:
    kind:
        Filter series by kind, such as 'ome' or 'imagej'.
        If ``None``, the default series are returned.
    squeeze:
        Remove length-1 dimensions from series shapes, except X and Y.
        If ``False``, series shapes include all dimensions.

)r   r   )r#   r
  )rk  r   r   s      rv   __call__TiffSeries.__call__.  s    " $,,CCru   c                ^    U R                   R                  U R                  U R                  S9$ )z6Return list of TiffPageSeries, computing if necessary.r  )r
  r  r
  r
  r  s    rv   rT  TiffSeries._series.  s&     ||''

DMM'JJru   c                   g ry   rt   r  s     rv   r  TiffSeries.__getitem__.  s     ru   c                   g ry   rt   r  s     rv   r  r
  .  s      #ru   c               T   U R                   n[        U[        [        R                  45      (       a  U[        U5         $ [        U[
        5      (       a  X!   $ [        U[        5      (       a*  [        U[        5      (       d  U Vs/ s H  o2U   PM	     sn$ Sn[        U5      es  snf )zReturn specified series.r  )	rT  r   r   r   r  r  rS   rz   r   )rk  r   r   r   r   s        rv   r  r
  .  s    
 cC/00#c(##c5!!;c8$$ZS-A-A'*+s!1Is++:n ,s   B%c                ,    [        U R                  5      $ )zReturn number of series.r   rT  r  s    rv   r  TiffSeries.__len__.  s     4<<  ru   c                ,    [        U R                  5      $ )zReturn iterator over series.)r  rT  r  s    rv   r  TiffSeries.__iter__.  s     DLL!!ru   c                2    [        U R                  5      S:  $ )z Return True if any series exist.r   r
  r  s    rv   r  TiffSeries.__bool__.  s    4<< 1$$ru   c                     S[        U 5       S3$ )Nz<tifffile.TiffSeries [z]>r   r  s    rv   r+  TiffSeries.__repr__.  s    'D	{"55ru   c                2    SR                  S U  5       5      $ )Nr  c              3  ,   #    U  H
  nS U 3v   M     g7fr  Nrt   r  s     rv   r   %TiffSeries.__str__.<locals>.<genexpr>.  s     04a2aS4   r   r  s    rv   r  TiffSeries.__str__.  s    yy04000ru   )r
  r
  r
  )r  r   r   rQ  r   r   r6  r   )r   rQ  r   r   r6  r#   )r6  r  )r   r
  r6  r   )r   r  r6  r  )r   r
  r6  z%TiffPageSeries | list[TiffPageSeries]rK  )r6  zIterator[TiffPageSeries]r  rK  )r  r  r  r  r  rL  rn  r
  rM  rT  ra   r  rb   r  r  r  r+  r  r   rt   ru   rv   r#   r#   p.  s5   > N  
 
 
 
  
  

   	D D 	D
 
D& K K +	  #(#	# # C	.  ! ! " "%61ru   r#   c                     \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'    S\S'    S\S'   S\S'   SSSS.             S%S jjrSSSSSSSS.                 S&S jjrS'S jrS(S jr	S)S jr
\S*S j5       r\S+S j5       r\S*S j5       r\S,S j5       r\S-S j5       r\S.S j5       rS/S  jr        S0S! jrS)S" jrS)S# jrS$rg)1r   i.  ad  Sequence of files containing compatible array data.

Parameters:
    imread:
        Function to read image array from single file.
    files:
        Glob file name pattern or sequence of file names.
        If ``None``, use '\*'.
        All files must contain array data of same shape and dtype.
        Binary streams are not supported.
    container:
        Name or open instance of ZIP file in which files are stored.
    sort:
        Function to sort file names if ``files`` is a pattern.
        The default is :py:func:`natural_sorted`.
        If ``False``, disable sorting.
    parse:
        Function to parse sequence of sorted file names to dims, shape,
        chunk indices, and filtered file names.
        The default is :py:func:`parse_filenames`` if ``kwargs`
        contains ``'pattern'``.
    **kwargs:
        Additional arguments passed to ``parse`` function.

Examples:
    >>> filenames = ['temp_C001T002.tif', 'temp_C001T001.tif']
    >>> ims = TiffSequence(filenames, pattern=r'_(C)(\d+)(T)(\d+)')
    >>> ims[0]
    'temp_C001T002.tif'
    >>> ims.shape
    (1, 2)
    >>> ims.axes
    'CT'

Callable[..., NDArray[Any]]r4   rM  r   rz   r  r  r  ztuple[tuple[int, ...]]r  r	  rS  rg   
_containerN)r   r   parsec                 ^ ^ S nUc  SnUc  [         nO [        U5      (       a  UnOU(       a  [         nUT l        Ub  SS Kn[	        U[
        [        R                  45      (       a  SS Kn	U	R                  U5      T l        O([        T R                  S5      (       d  Sn
[        U
5      e[	        U[
        5      (       a5  UR                  T R                  R                  5       U5      nUb  U" U5      nO[	        U[        R                  5      (       a  [        R                  " U5      /nOL[	        U[
        5      (       a"  [        R                  " U5      nUb  U" U5      nOUb  Ub  U" S U 5       5      nU Vs/ s H  n[        R                  " U5      PM     nnU(       d  Sn
[        U
5      e[        U5      (       d  Sn
[!        U
5      eU(       a  U4       SU 4S jjjnUnUc  UR#                  S	5      (       a  [$        nU(       a   U" U40 UD6u  ppO2Sn['        U5      4n[)        S [+        ['        U5      5       5       5      n[	        U[,        5      (       d   e[	        US   [
        5      (       d   e[.        R0                  mSR3                  U4S jU 5       5      nUT l        UT l        UT l        [)        U5      T l        [)        U5      T l        UT l        g s  snf ! [         a  nS
n
[        U
5      UeS nAff = f)Nr   r   rD  zinvalid containerc              3  $   #    U  H  ov   M     g 7fry   rt   r  s     rv   r   (FileSequence.__init__.<locals>.<genexpr>N/  s     /Aa   r   zinvalid imread functionc                  > TR                   R                  U 5       n[        R                  " UR	                  5       5       nU" U40 UD6sS S S 5        sS S S 5        $ ! , (       d  f       O= f S S S 5        g ! , (       d  f       g = fry   )r'
  rD  r}  r~  r   )r  _imreadr   handle1handle2rk  s        rv   imread_&FileSequence.__init__.<locals>.imread_[/  s`     OO((2gJJw||~.'"75f5 /. 32... 322s#   %A9	A	A9
A,	(A99
Br   zfailed to parse file names)sequencec              3  &   #    U  H  o4v   M	     g 7fry   rt   r  s     rv   r   r+
  r/  s     <*;QD*;s   r=  c              3     >#    U  H6  nTR                  UR                  5       US    R                  5       5      v   M8     g7fr0  )rS  r  rN  )r   dimr  s     rv   r   r+
  w/  s/     N#uyyc!flln==s   >A)r  rz   r.
  rg   r   rg   r6  r  ) r;   callabler'
  fnmatchr   rz   r  PathLikezipfileZipFiler   r   filternamelistr	  r   r   rS  r=   r   r~   r  rM  r   
AXES_CODESr   rS  r4   r  r  r   r  )rk  r4   r   r   r   r(
  r   	sort_funcr8
  r:
  r   r  r1
  r  r   r  r  r  r  s   `                 @rv   rn  FileSequence.__init__/  s    6:	=E<&Id^^I&I $ )c2;;%788")//)"<T__f55) o%%%%t'?'?'A5I(%e,Er{{++YYu%&Es##IIe$E$!%()"7///E',-u!1u-"CS/!+CC.  /566(+6@C66 6 F=VZZ	22#E/.3E.DV.D+We
 !DZME<%E
*;<<G%&&&&%(C((((wwNNN	$K	5\
] .8  /2 o3./s   < K)K. .
L8LLrY   )r   r   r   r   r   r   r   c                 ^ ^^^ Ub  TU-  mT R                   n	Ub  US:  a  [        R                  n[        [	        U	5      U5      n[        U[        5      (       d   eTc  T R                  [        :X  a  SmO[        T5      mUb  Uc/  T R                  " U	S   40 TD6n
U
R                  nU
R                  nA
[        R                  " U5      nUc   eU(       a  [        T R                  X$S9n[        X{R                  U5      mSUUUU 4S jjnUS:  a7  [        UR                  T R                   5      U	SS9 H  u  pU" X5        M     T$ [#        U5       nUR%                  XR                  T R                   5      U	5       H  nM     SSS5        T$ T R                  U-   n[        UUU5      mTR'                  S	/UQ75      mSUUUU 4S
 jjnUS:  a'  [        T R                   U	SS9 H  u  pU" X5        M     O8[#        U5       nUR%                  UT R                   U	5       H  nM     SSS5        TR'                  USS9mT$ ! , (       d  f       T$ = f! , (       d  f       N2= f)a  Return images from files as NumPy array.

Parameters:
    imreadargs:
        Arguments passed to :py:attr:`FileSequence.imread`.
    chunkshape:
        Shape of chunk in each file.
        Must match ``FileSequence.imread(file, **imreadargs).shape``.
        By default, this is determined by reading the first file.
    chunkdtype:
        Data type of chunk in each file.
        Must match ``FileSequence.imread(file, **imreadargs).dtype``.
        By default, this is determined by reading the first file.
    axestiled:
        Axes to be tiled.
        Map stacked sequence axis to chunk axis.
    ioworkers:
        Maximum number of threads to execute
        :py:attr:`FileSequence.imread` asynchronously.
        If *0*, use up to :py:attr:`_TIFF.MAXIOWORKERS` threads.
        Using threads can significantly improve runtime when reading
        many small files from a network share.
        If enabled, internal threading for the ``imread`` function
        should be disabled.
    out_inplace:
        Decode directly into output array without intermediate copy.
        Not all :py:attr:`FileSequence.imread` functions support this,
        especially in non-contiguous cases.
    out:
        Output array, *'memmap'*, or file for image data.
        By default, create a new array.
        If a *numpy.ndarray*, a writable array to which the images
        are copied.
        If *'memmap'*, create a memory-mapped array in a temporary
        file.
        If a *string* or *open file*, the file used to create a
        memory-mapped array.
    **kwargs:
        Deprecated: Arguments passed to :py:attr:`FileSequence.imread`
        in addition to ``imreadargs``.

Raises:
    IndexError, ValueError: Array shapes do not match.

NrY   Tr   )r   c               x   > T(       a  TR                   " U4STU    0TD6  g TR                   " U40 TD6nUTU '   Ag Nr   r   )r  r  imr   r   r  rk  s      rv   r  "FileSequence.asarray.<locals>.func/  sA     KKFfUmFvFX88B$&F5Mru   rT  r4  rK  c                  > [        [        R                  " U TR                  5      5      nT(       a  TR                  " U4STU   0TD6  g TR                  " U40 TD6nUTU'   Ag rC
  )r   r   ravel_multi_indexr   r4   )r  r  index_rD
  r   r   r  rk  s       rv   r  rE
  /  sa     ++E4::> KKGfVnGGX88B%'F6Nru   Fr  )r  ztuple[int | slice, ...]r  rz   r6  r   )rS  r   MAXIOWORKERSr  r   r   r   r4   r   r   r   r   r(   r-   r  slicesr  rT   r8  rt  )rk  r   r   r   r   r   r   r   r   r   rD
  tiledr  r  r  r;  r   r   r  s   `     ` `         @rv   r   FileSequence.asarray/  sH   @ !j F	A))IE
I.	)S))))4;;&#8K{+K!3U1X00BJJ[[,
%%%!$**jNE"3Z@F	 	 1}'*LL.d(OE )(N E (	2h%\\ll4<<8%  3D 9 JJ+E"3z:F^^R$5*$56F  1}'*4<<t'LOE) (M (	2h%\\$eD E 3 ^^E^6FE 32D  32s   3I%I
I
I'c                     SSK Jn  U" U 40 UD6$ )z{Return images from files as Zarr store.

Parameters:
    **kwargs: Arguments passed to :py:class:`ZarrFileSequenceStore`.

rY   )ZarrFileSequenceStore)r   rN
  )rk  r   rN
  s      rv   r   FileSequence.aszarr0  s     	0$T4V44ru   c                `    U R                   b  U R                   R                  5         SU l         g)zClose open files.N)r'
  r  r  s    rv   r  FileSequence.close0  s#    ??&OO!!#ru   c                    [        U R                  5      S:X  a.  [        R                  R	                  U R                  S   5      nU$ [        R                  R                  U R                  5      nU$ )z8Return longest common sub-path of each file in sequence.rY   r   )r   rS  r  rE  rG  
commonpath)rk  rS
  s     rv   rS
  FileSequence.commonpath 0  sU    t{{q Q8J  ++DKK8Jru   c                X    [        U R                  5      [        U R                  5      -
  $ )z$Number of missing files in sequence.)r@   r   r   rS  r  s    rv   files_missingFileSequence.files_missing(0  s!     tzz"S%555ru   c                ,    [        U R                  5      $ )z$Return iterator over all file names.)r  rS  r  s    rv   r  FileSequence.__iter__-0  s     DKK  ru   c                ,    [        U R                  5      $ ry   )r   rS  r  s    rv   r  FileSequence.__len__20  s    4;;ru   c                   g ry   rt   r  s     rv   r  FileSequence.__getitem__60  rz	  ru   c                   g ry   rt   r  s     rv   r  r]
  90  s    7:ru   c                    U R                   U   $ ry   )rS  r  s     rv   r  r]
  <0  s    {{3ru   c                    U $ ry   rt   r  s    rv   r  FileSequence.__enter__@0  r  ru   c                $    U R                  5         g ry   r   r!  s       rv   r%  FileSequence.__exit__C0  r'  ru   c                "    S[        U 5      S S3$ )Nz<tifffile.FileSequence @0xrM	  rr   rN	  r  s    rv   r+  FileSequence.__repr__K0  s    +BtHT?!<<ru   c                   U R                   (       a  [        U R                   5      OU R                  S   n[        R                  R                  U5      S   nSR                  U R                  R                  US[        U R                  5       SU R                   S3SR                  SR                  S	 U R                   5       5      5      S
R                  SR                  S U R                   5       5      5      45      $ )Nr   rK  
 zfiles: z (z	 missing)z	shape: {}r   c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   'FileSequence.__str__.<locals>.<genexpr>V0  s     ,HZSVVZr  zdims: {}c              3  $   #    U  H  ov   M     g 7fry   rt   r  s     rv   r   ri
  W0  s     +Ay!Ayr,
  )r'
  rz   rS  r  rE  r  r   r  r  r   rV
  r   r   r  )rk  r   s     rv   r  FileSequence.__str__N0  s    '+s4??#DKKNww}}T"2&zz''#dkk*+2d.@.@-AK""499,HTZZ,H#HI!!$))+Atyy+A"AB	
 		
ru   )r'
  rS  r  r  r4   r  r   )r4   r&
  r   @str | os.PathLike[Any] | Sequence[str | os.PathLike[Any]] | Noner   str | os.PathLike[Any] | Noner    Callable[..., Any] | bool | Noner(
  zCallable[..., Any] | Noner   rg   r6  r   )r   r*  r   r/  r   r3  r   1dict[int, int] | Sequence[tuple[int, int]] | Noner   r3  r   r%  r   rw   r   rg   r6  r  )r   rg   r6  rN
  rB  rK  rK  )r6  Iterator[str]r	  )r   r  r6  r	  )r   int | slicer6  zstr | list[str]rF  rG  )r  r  r  r  r  rL  rn  r   r   r  rS
  rM  rV
  rb   r  r  ra   r  r  r%  r+  r  r   rt   ru   rv   r   r   .  s   "H ('8B
I2
'##$O 4815+/`+` M	` 1` /` )` ` 
`J -1-1'+GK !#'M *M +	M
 %M EM M !M M M 
M^	5 6 6 ! !     2 2: :   , ( (	
 
=
ru   r   c                  j   ^  \ rS rSrSr\ S\S.       SU 4S jjjj5       r\S	S j5       rSr	U =r
$ )
r"   i]0  zSequence of TIFF files containing compatible array data.

Same as :py:class:`FileSequence` with the :py:func:`imread` function,
``'\*.tif'`` glob pattern, and ``out_inplace`` enabled by default.

r   c               2   > [         TU ]  " X!c  SOU40 UD6  g )Nz*.tif)superrn  )rk  r   r4   r   r  s       rv   rn  TiffSequence.__init__f0  s     	MuOOru   c                "    S[        U 5      S S3$ )Nz<tifffile.TiffSequence @0xrM	  rr   rN	  r  s    rv   r+  TiffSequence.__repr__r0  s    +BtHT?!<<ru   rt   ry   )r   rl
  r4   r&
  r   rg   r6  r   rK  )r  r  r  r  r  rb   r4   rn  r+  r   __classcell__)r  s   @rv   r"   r"   ]0  su     
 		P /5	P M	P ,	P 	P 
	P 	P 	P = =ru   r"   c                  
   \ rS rSr% SrSrS\S'    S\S'    S\S'    S\S	'    S\S
'    S\S'    S\S'    S\S'    S\S'    SSS.         SS jjr    SS jr S   SS jjr	\
SS j5       r\
SS j5       rSS jrSrg) r(   iw0  aL  Tiled sequence of chunks.

Transform a sequence of stacked chunks to tiled chunks.

Parameters:
    stackshape:
        Shape of stacked sequence excluding chunks.
    chunkshape:
        Shape of chunks.
    axestiled:
        Axes to be tiled. Map stacked sequence axis
        to chunk axis. By default, the sequence is not tiled.
    axes:
        Character codes for dimensions in stackshape and chunkshape.

Examples:
    >>> ts = TiledSequence((1, 2), (3, 4), axestiled={1: 0}, axes='ABYX')
    >>> ts.shape
    (1, 6, 4)
    >>> ts.chunks
    (1, 3, 4)
    >>> ts.axes
    'AYX'

)	
_axestiled
_chunkdims_shape_untiled
_stackdimsr  axes_squeezedr  r   shape_squeezedrM  r  r   zstr | tuple[str, ...] | Noner  r
  r~
  r   r}
  r{
  r|
  ztuple[tuple[int, int], ...]rz
  N)r   r  c         	     .  ^ ^ [        U5      T l        [        U5      T l        [        U5      [        U5      -   T l        Ub/  [        U5      [        T R                  5      :w  a  Sn[        U5      eU(       Gal  [        [        U 4S j[        U5      R                  5        5       SS95      T l	        Uc  / O
[        U5      n[        T R                  5      nS/T R                  -  [        U5      -   n[        5       n	T R                   HL  u  pX;   d  X;   a  Sn[        U5      eU	R                  U
5        U	R                  U5        X{==   X   -  ss'   MN     T R                   H  u  pXz	 X	 U(       d  M  Xj	 M     [        U5      T l        [        U5      T l        Uc  S T l        O[!        U["        5      (       a  SR%                  U5      T l        O[        U5      T l        OpST l	        T R                  T l        S	T R                  -  [        U5      -   T l        Uc  S T l        O-[!        U["        5      (       a  UT l        O[        U5      T l        [        T R                  5      [        T R                  5      :X  d   eT R                  b.  [        T R                  5      [        T R                  5      :X  d   eT R                  c)  [        S
 T R                   5       5      T l        S T l        g Sm[        U4S j[+        T R                  T R                  SS9 5       5      T l        [        U4S j[+        T R                  T R                  SS9 5       5      n[!        T R                  ["        5      (       a  SR%                  U5      OUT l        g )Nz2axes length does not match stackshape + chunkshapec              3  H   >#    U  H  u  pXTR                   -   4v   M     g 7fry   )r}
  )r   ax0ax1rk  s      rv   r   )TiledSequence.__init__.<locals>.<genexpr>0  s&      (?HC DOO34(?s   "T)reverserY   zduplicate axisr=  rt   r  c              3  4   #    U  H  oS :  d  M
  Uv   M     g7fr  rt   r  s     rv   r   r
  1  s     'G:aQ:s   		)r  r  rX  rY  r  c              3  H   >#    U  H  u  pUS :  d  UT;   d  M  Uv   M     g7fr  rt   r   r  r  keeps      rv   r   r
  1  s)      (DEAq5B$J D   "	"r4  c              3  H   >#    U  H  u  pUS :  d  UT;   d  M  Uv   M     g7fr  rt   r
  s      rv   r   r
  1  s)      DEAq5B$J Dr
  )r   r}
  r{
  r~   r|
  r   ru  r  r`  rz
  rM  r!  r$  r   r  r  r   rz   r   r
  r~
  r  )rk  
stackshaper   r   r  r   	axes_listr   r  r  r
  r
  _ax1r  r
  s   `             @rv   rn  TiledSequence.__init__0  s    j/j/#J/%
2CCD	S1D1D-E EFCS/! $(,Y(=(=(? !DO #lT
I,,-ES4??*T*-==F5D OO;#+*C$S/)
jo-
 , "__	JK9!	 -
 uDJ-DK| 	D#&&GGI.	!),	 DO,,DJ053DDDK| 	D#&& 	!$K	4::#dkk"222299 tzz?c$))n44499"''G4::'G"GD!%D:D"' ( TYYtD( #D
   TYYtD H &0		3%?%?!X ru   c             #  H  #    S/U R                   -  nU H  n[        U5      U R                  :w  a'  S[        U5      < SU R                   3n[        U5      e/ UQUQnU R                   H  u  pgXV   XW'   M     U R                   H  u  phXV	 M	     [        U5      v   M     g7f)zxReturn iterator over chunk indices of tiled sequence.

Parameters:
    indices: Indices of chunks in stacked sequence.

r   len(index)=r  N)r{
  r   r}
  r   rz
  r~   )	rk  r  r  r  r   
index_listr
  r
  r
  s	            rv   r  TiledSequence.indices1  s      S4??*
E 5zT__,$UT$//):; o%.5.:.J OO",/
 ,!__	O -
## s   B B"c             #    #    [        S5      /U R                  -  nUc-  [        R                  " U R                  SU R
                   5      nU H  n[        U5      U R
                  :w  a'  S[        U5      < SU R
                   3n[        U5      e/ UQUQnU R                   H9  u  pgU R                  U   n[        [        XV   5      U-  n	[        XU-   5      XW'   M;     U R                   H  u  pjXV	 M	     [        U5      v   M     g7f)zReturn iterator over slices of chunks in tiled sequence.

Parameters:
    indices:
        Indices of chunks in stacked sequence.
        By default, iterate over all chunks in stacked sequence.

Nr
  r  )r  r{
  r   ndindexr|
  r}
  r   r   rz
  r_   r   r~   )rk  r  
chunkslicer  r   
wholeslicer
  r
  r2  r  r
  s              rv   rJ
  TiledSequence.slices,1  s      */t(G
?mmD$7$78I$//$JKGE 5zT__,$UT$//):; o%.5.:.J OO'',jo.2"'q5/
 , "__	O -
## s   DD	c                ,    [        U R                  5      $ )z'Number of dimensions in tiled sequence.rq  r  s    rv   r  TiledSequence.ndimM1  rs  ru   c                ,    [        U R                  5      $ )zSequence is tiled.)r   rz
  r  s    rv   r^  TiledSequence.is_tiledR1  s     DOO$$ru   c                <    SU R                    SU R                   S3$ )Nz<tifffile.TiledSequence shape=z chunks=rr   )r   r  r  s    rv   r+  TiledSequence.__repr__W1  s!    ,TZZLQO	
ru   )
r
  rE  r   rE  r   ro
  r  str | Sequence[str] | Noner6  r   )r  zIterable[Sequence[int]]r6  zIterator[tuple[int, ...]]ry   )r  zIterable[Sequence[int]] | Noner6  z!Iterator[tuple[int | slice, ...]]rK  r  rK  )r  r  r  r  r  rG  rL  rn  r  rJ
  rM  r  r^  r+  r   rt   ru   rv   r(   r(   w0  s   4
I , 3
&&,##C//MO9O)##>++0 HL+/W!W "W EW )W 
Wr$.$	"$2 9=$5$	*$B   % %
ru   r(   c                  &   \ rS rSr% SrSrS\S'   S\S'   S\S	'   S\S
'   S\S'   S\S'   S\S'   S\S'   S\S'    S=SSSS.           S>S jjjrS?S jrS?S jr	S@S jr
SAS jrSAS jrS@S jrSBSCS jjrSDSES jjrSFS jrSGS jrS?S  jr SBS!S"S#.           SHS$ jjjr  SISS%.         SJS& jjjr SKSS'.       SLS( jjjrSMS) jr S=     SNS* jjr  SOS+SSS+S,.                 SPS- jjjrSQS. jr        SRS/ jrSSS0 jrSSS1 jr\SSS2 j5       r\SSS3 j5       r\SSS4 j5       r \SSS5 j5       r!\S@S6 j5       r"\SAS7 j5       r#\STS8 j5       r$\$RJ                  SUS9 j5       r$SVS: jr&\SAS; j5       r'\SAS< j5       r(Sr)g)Wr   i]1  a  Binary file handle.

A limited, special purpose binary file handle that can:

- handle embedded files (for example, LSM within LSM files).
- re-open closed files (for multi-file formats, such as OME-TIFF).
- read and write NumPy arrays and records from file-like objects.

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

FileHandle instances are not thread-safe.

Parameters:
    file:
        File name or seekable binary stream, such as open file,
        BytesIO, or fsspec OpenFile.
    mode:
        File open mode if ``file`` is file name.
        The default is 'rb'. Files are always opened in binary mode.
    name:
        Name of file if ``file`` is binary stream.
    offset:
        Start position of embedded file.
        The default is the current file position.
    size:
        Size of embedded file.
        The default is the number of bytes from ``offset`` to
        the end of the file.

)	_close_dirr#  _file_lockrW  _nameru  _sizez6str | os.PathLike[Any] | FileHandle | IO[bytes] | Noner
  zIO[bytes] | Noner#  rz   rW  r
  r
  r   ru  r
  r   r
  threading.RLock | NullContextr
  N)r   r   r   c                  Uc  SOUU l         S U l        Xl        U=(       d    SU l        SU l        Uc  SOUU l        Uc  SOUU l        SU l        [        5       U l	        U R                  5         U R                  c   eg )NrE  r=  rK  T)rW  r#  r
  r
  r
  ru  r
  r
  r   r
  rD  )rk  r   r   r   r   r   s         rv   rn  FileHandle.__init__1  sr     "\Tt

ZR
	#^r<RT
 ]
		xx###ru   c                   U R                   b  g[        U R                  [        R                  5      (       a%  [        R
                  " U R                  5      U l        [        U R                  [        5      (       a  U R                  SS S:w  a  U =R                  S-  sl        U R                  S;  a  SU R                   3n[        U5      e[        R                  R                  U R                  5      U l        [        R                  R                  U R                  5      u  U l        U l        [        U R                  U R                  SS9U l         SU l        [!        SU R"                  5      U l        GO[        U R                  [$        5      (       Ga)  U R                  R                   U l         [!        SU R"                  5      U l        U =R"                  U R                  R"                  -  sl        S	U l        U R                  (       dz  U R"                  (       aN  [        R                  R'                  U R                  R                  5      u  p#U S
U R"                   U 3U l        OU R                  R                  U l        U R                  R                  U l        U R                  R                  U l        GO[)        U R                  S5      (       GaM  [        U R                  [*        R,                  5      (       a  U R                  < S3n[/        U5      e[1        [2        [4           U R                  5      U l          U R                   R7                  5         U R"                  S:  a  U R                   R7                  5       U l        S	U l        U R                  (       dA   [        R                  R                  U R                   R:                  5      u  U l        U l        [>        R@                  " [<        5         U R                   RB                  U l        SSS5        GOD[)        U R                  S5      (       Ga  U R                  n[1        [2        [4           UR                  5       5      U l          U R                   R7                  5         U R"                  S:  a  U R                   R7                  5       U l        SU l        U R                  (       d7   [        R                  R                  UR                  5      u  U l        U l        [>        R@                  " [<        5         URB                  U l        SSS5        O$S[G        U R                  5      < 3n[        U5      eU R                   c   eU R"                  (       a%  U R                   RI                  U R"                  5        U RJ                  S:  a  U R                   R7                  5       nU R                   RI                  U R"                  [        RL                  5        U R                   R7                  5       U l%        U R                   RI                  U5        gg! [8         a    Sn[        U5      Sef = f! [<         a^     [        R                  R                  U R                   R                  5      u  U l        U l         GN! [<         a    SU l          GNf = ff = f! , (       d  f       GNu= f! [8         a^    [>        R@                  " [8        5         U R                   RE                  5         SSS5        O! , (       d  f       O= fSn[        U5      Sef = f! [<         a    SU l         GNPf = f! , (       d  f       GN
= f)zOpen or re-open file.NrK  b>   rE  wbxbrD  zinvalid mode )encodingTr   Fr	  r\  z is not open in binary modezbinary stream is not seekablezUnnamed binary streamrD  zOpenFile is not seekablezLthe first parameter must be a file name or seekable binary file object, not )'r#  r   r
  r  r9
  r	  rz   rW  r   rE  realpathr  r
  r
  rD  r
  rk  ru  r   splitextr   r}  
TextIOBaser   r_   r\   r{   rX  r  r   r   r  r  r   r  rw  r\  r
  rd  )rk  r   r   ra  r
  rm  s         rv   rD  FileHandle.open1  s   88djj"++..4::.DJdjj#&&zz"##%

c!
zz!::%djj\2 o%))$**5DJ$&GGMM$**$=!DItz

DJJDH DKq$,,/DL

J//zz~~DHq$,,/DLLLDJJ...LDK::<< " 0 01A1A BID$(64<<.!>DJ!%!1!1DJ))DJ

DITZZ(( $**bmm44&ABn$BuItzz2DH0
 ||a#xx}}DK::=,.GGMM$((--,H)DItz $$^4!XX]]
 54TZZ((EBuIuzz|4DH0 ||a#xx}}DK::9,.GGMM%**,E)DItz $$^4"ZZ
 54
DJJ'*, 
 S/!xx###<<HHMM$,,'::>((--/CHHMM$,,4DJHHMM#	 k  05 o4/0 & ==02dhhmm0L-	4:) =%<

==
 54  0((3HHNN$ 4330 o4/	0 & 9!8DJ944s   
Y ,A Y+ [?[( !6] 1]+Y(+
[6A Z99[
[[[
[%($]\0'	]0
\>	:]]('](+
]:c                    U R                   (       aS  U R                  bE  [        R                  " [        5         U R                  R                  5         SSS5        SU l        ggg! , (       d  f       N= f)zClose file handle.N)r
  r#  r  r  r  r  r  s    rv   r  FileHandle.close2  sH    ;;488/$$Y/  0DH 0;//s   A&&
A4c                    U R                   c   e U R                   R                  5       $ ! [        [        4 a)  n[	        U R                   5       S3n[        U5      UeSnAff = f)z@Return underlying file descriptor if exists, else raise OSError.Nz  does not have a file descriptor)r#  r}  r]  r   rw  )rk  r  r   s      rv   r}  FileHandle.fileno2  s_    xx###	(88??$$( 	($((^$$DEC#,C'	(s   + A$$AA$c                    U R                   c   e[        U R                   S5      (       a  U R                   R                  5       $ g)z'Return True if stream supports writing.writableF)r#  r   r
  r  s    rv   r
  FileHandle.writable'2  s9    xx###488Z((88$$&&ru   c                    g)z-Return True if stream supports random access.Trt   r  s    rv   seekableFileHandle.seekable.2  s    ru   c                n    U R                   c   eU R                   R                  5       U R                  -
  $ )zReturn file's current position.)r#  rX  ru  r  s    rv   rX  FileHandle.tell22  s+    xx###xx}}--ru   c                  U R                   c   eU R                  (       a  US:X  a6  U R                   R                  U R                  U-   U5      U R                  -
  $ US:X  aS  U R                  S:  aC  U R                   R                  U R                  U R                  -   U-   S5      U R                  -
  $ U R                   R                  X5      $ )aR  Set file's current position.

Parameters:
    offset:
        Position of file handle relative to position indicated
        by ``whence``.
    whence:
        Relative position of ``offset``.
        0 (``os.SEEK_SET``) beginning of file (default).
        1 (``os.SEEK_CUR``) current position.
        2 (``os.SEEK_END``) end of file.

r   rT  )r#  ru  r\  r
  )rk  r   whences      rv   r\  FileHandle.seek72  s     xx###<<{HHMM$,,"7@4<<O {tzzA~HHMM$,,";f"DaHll# xx}}V,,ru   c                   US:  a  U R                   (       a  U R                  nU R                  c   eU R                  R                  U5      $ )zReturn bytes read from file.

Parameters:
    size:
        Number of bytes to read from file.
        By default, read until the end of the file.

r   )ru  r
  r#  r   rk  r   s     rv   r   FileHandle.readR2  s=     !8::Dxx###xx}}T""ru   c               V    U R                   c   eU R                   R                  U5      $ )zqRead bytes from file into buffer and return number of bytes read.

Parameters:
    buffer: Buffer to read into.

)r#  readintork  buffers     rv   r
  FileHandle.readinto`2  s)     xx###xx  ((ru   c               V    U R                   c   eU R                   R                  U5      $ )zjWrite bytes to file and return number of bytes written.

Parameters:
    buffer: Bytes to write to file.

)r#  r   r
  s     rv   r   FileHandle.writej2  s'     xx###xx~~f%%ru   c                    U R                   c   e[        U R                   S5      (       a  U R                   R                  5         gg)z,Flush write buffers of stream if applicable.Nr  )r#  r   r  r  s    rv   r  FileHandle.flusht2  s6    xx###488W%%HHNN &ru   rW  r  )r   orderc          	         U R                   (       d  Sn[        U5      eU R                  c   e[        R                  " U R                  UUU R
                  U-   UUS9$ )ah  Return ``numpy.memmap`` of array data stored in file.

Parameters:
    dtype:
        Data type of array in file.
    shape:
        Shape of array in file.
    offset:
        Start position of array-data in file.
    mode:
        File is opened in this mode. The default is read-only.
    order:
        Order of ndarray memory layout. The default is 'C'.

z%cannot memory-map file without fileno)r   r   r   r   r
  )rD  r   r#  r   r:   ru  )rk  r   r   r   r   r
  r   s          rv   r  FileHandle.memmap_arrayz2  sZ    0 ||9CS/!xx###||HH<<&(
 	
ru   r   c               @   [         R                  " U5      nUS:  a*  Uc  U R                  OUR                  nXQR                  -  nOX!R                  -  nUc  [         R
                  " X!5      OUnUR                  U:w  a  Sn[        U5      eU R                  c   eU(       a(  U R                  R                  U R                  U-   5         U R                  R                  U5      nX:w  a  SU SU 3n[        U5      eUR                  R                   (       dL  UR                   (       d  UR#                  S5        UR%                  UR                  R'                  5       5      nO5UR                  R                   UR                   :w  a  UR#                  S5        Ub!  [)        US5      (       a  UR+                  5         U$ ! [         aR    [         R                  " U R                  R                  U5      U5      R                  UR                  5      USS& Un GN5f = f)aE  Return NumPy array from file in native byte order.

Parameters:
    dtype:
        Data type of array to read.
    count:
        Number of items to read. By default, all items are read.
    offset:
        Start position of array-data in file.
    out:
        NumPy array to read into. By default, a new array is created.

r   Nzsize mismatchzfailed to read  bytes, got Tr  )r   r   r
  r   r   rB  r   r#  r\  ru  r
  r   r  r   rt  r   isnativebyteswapr  r
  r   r  )	rk  r   r  r   r   r   r  r   r  s	            rv   r  FileHandle.read_array2  s   * E"19#&;TZZCJJFnn,E^^+F.1kU*s==F"!CS/!xx###HHMM$,,/0	!!&)A ;#F8<s;CS/!||$$>>%[[!:!:!<=F\\""enn4OOD!?wsG44IIK)  	((v)>FNNF1I A		s   G AHHr  c               X   U R                   c   e[        R                  " U5      nUb  UR                  U5      n [        R                  R                  U R                   X5      nUS:X  a  US   $ U$ ! [        [        R                  4 a    Uc  U R                  UR                  -  n[        U[        [        45      (       a  [        U5      UR                  -  nOX!R                  -  nU R                   R                  U5      n[        R                  R!                  UUU5      n Nf = f)zReturn NumPy record from file.

Parameters:
    dtype:
        Data type of record array to read.
    shape:
        Shape of record array to read.
    byteorder:
        Byte order of record array to read.

rY   r   )r#  r   r   r
  recr  r]  r}  UnsupportedOperationr
  r   r   r~   rM  r@   r   
fromstring)rk  r   r   r   recordr   r  s          rv   read_recordFileHandle.read_record2  s   $ xx###E" &&y1E	YY''%?F( "QJvay2F2' 001 	 }

enn4%%//u~6~~-
 88==&DYY))F	s   *A2 2B4D)(D)c                   US:  a  gU R                   c   eU R                   R                  US-
  [        R                  5        U R                   R	                  S5        U$ )zAppend null-bytes to file.

The file position must be at the end of the file.

Parameters:
    size: Number of null-bytes to write to file.

rY   r   r+  )r#  r\  r  r  r   r
  s     rv   r@  FileHandle.write_empty3  sM     !8xx###dQh,wru   c               x   U R                   c   eU R                   R                  5       n[        R                  " X5      n UR	                  U R                   5        U R                   R                  5       U-
  $ ! [
        R                   a,    U R                   R                  UR                  5       5         N\f = f)zaWrite NumPy array to file in C contiguous order.

Parameters:
    data: Array to write to file.

)	r#  rX  r   r  tofiler}  r
  r   r  )rk  r  r   rm  s       rv   rA  FileHandle.write_array3  s     xx###hhmmo&&t3	+KK! xx}}$$ && 	+HHNN4<<>*	+s   A9 9=B98B9T)r   r*  r   r  c         	   #    ^#    U R                   c   eUc  [        U5      nUS:  a  gUS:X  a~  US   S:  aV  US   S:  aM  Uc  U R                  nU   U R                  US   5        U R                   R	                  US   5      n	SSS5        OSn	Tc  SOTS   n
U(       a  W	U
4OW	U
4/v   gUc  U R                  nUc  [
        R                  nTc  [        [        U5      5      m[        [        U[        U5      [        U5      5      5       Vs/ s H  nTU   X   X+   4PM     nn[        U5      U:  aV  [        5       R                  SU S[        U5       35        UR                  U4S j[        [        U5      U5       5       5        U(       a  [        US S9nS	n[        US-
  5       H5  nX   u  pnXS-      S   nUS:X  d  US:X  d  US:X  a  M(  UU-   U:w  d  M3  S
n  O   U R                  nU R                   R                  nU(       a  SnX:  a  UnSnSnUU::  a8  X:  a3  X   u  nnnUS:  a  US:  a  US:  a  UnUU-  nUS-  nUU::  a  X:  a  M3  US:  a  Sn	OU   U" U5        U" U5      n	SSS5        SnSn/ nUU:  aR  UU   u  pnUS:  a$  US:  a  UU-  nUR                  W	UU U
45        UnOUR                  SU
45        US-  nUU:  a  MR  U(       a  U Sh  vN   OUv   X:  a  M  gSnX:  a  / nSnU   UU::  ad  X:  a_  X   u  pnUS:  a-  US:  a'  U" U5        UR                  U" U5      U
45        UU-  nOUR                  SU
45        US-  nUU::  a  X:  a  M_  SSS5        U(       a  U Sh  vN   OUv   X:  a  M  gg! , (       d  f       GN= fs  snf ! , (       d  f       GNA= f N! , (       d  f       NX= f NN7f)a  Return iterator over segments read from file and their indices.

The purpose of this function is to

- reduce small or random reads.
- reduce acquiring reentrant locks.
- synchronize seeks and reads.
- limit size of segments read into memory at once.
  (ThreadPoolExecutor.map is not collecting iterables lazily).

Parameters:
    offsets:
        Offsets of segments to read from file.
    bytecounts:
        Byte counts of segments to read from file.
    indices:
        Indices of segments in image.
        The default is ``range(length)``.
    length:
        Number of segments to read from file.
        By default, ``len(offsets)``.
    sort:
        Read segments from file in order of their offsets.
    lock:
        Reentrant lock to synchronize seeks and reads.
    buffersize:
        Approximate number of bytes to read from file in one pass.
        The default is :py:attr:`_TIFF.BUFFERSIZE`.
    flat:
        Return iterator over individual (segment, index) tuples.
        If ``False``, return an iterator over a list of
        (segment, index) tuples that are acquired in one pass.

Yields:
    Individual or lists of ``(segment, index)`` tuples.

NrY   r   z!tifffile.read_segments: expected z segments, got c              3  4   >#    U  H  nTU   S S 4v   M     g7fr0  rt   )r   r  r  s     rv   r   +FileHandle.read_segments.<locals>.<genexpr>3  s       ,HqQ",Hr  c                    U S   $ r*  rt   r  s    rv   r  *FileHandle.read_segments.<locals>.<lambda>3  s    adru   r
  TFrK  )r#  r   r
  r\  r   r   
BUFFERSIZEr~   r  r  r7   rm  r  ru  r   )rk  r  r  r  rY  r   r*  r   r  r  r  r  r-  iscontigr   r   r  
nextoffsetr\  r   r2  r  r
  r  r  r  r   s      `                       rv   r7  FileHandle.read_segments53  s    l xx###>\FA:Q;!}q WQZ!^<::DIIgaj)88==A7D T  AgajE#'4-tUm_<<::DJ?E&M*G
 3vs7|S_EF
F QZZ]3F 	 
 x=6!H"8?3x=/C OO ,1#h-,H  hN;Hvz"A#+; Ay!a%+J{i1n
a	!Z/  # yyxx}} A*	:-!*&kGAq!1uQ!A:%&F!Q	FA  :-!* A:DV#I  !e/7{,E9zi!m	)tE$'7&?@ $tUm4FA !e %%% LC *D jFDj(QZ/7{,E9zi!mVtI&>? 	)tUm4FA j(QZ  !!!' jq T$
`   &  "s   AO3NBON,%B8O!A8OO&N17A$OO)O*O:OA)O3OOOO
N)$O1
O ;	O
OOc                    U $ ry   rt   r  s    rv   r  FileHandle.__enter__3  r  ru   c                $    U R                  5         g ry   r   r!  s       rv   r%  FileHandle.__exit__3  r'  ru   c                8    S[        U R                  S5      < S3$ )Nz<tifffile.FileHandle r)  rr   )r*  r
  r  s    rv   r+  FileHandle.__repr__3  s    &wtzz2'>&ACCru   c                    SR                  SU R                  U R                  U R                   S3U R                  c  S45      $ S45      $ )Nrg
  r   z bytesr  rD  )r   r
  r
  r
  r#  r  s    rv   r  FileHandle.__str__3  sW    zz

		::,f% HH,
 	
 39
 	
ru   c                    U R                   $ )zName of file or stream.)r
  r  s    rv   r   FileHandle.name4  r	  ru   c                    U R                   $ )z"Directory in which file is stored.)r
  r  s    rv   rG  FileHandle.dirname4  r	  ru   c                j    [         R                  R                  U R                  U R                  5      $ )zAbsolute path of file.)r  rE  r   r
  r
  r  s    rv   rE  FileHandle.path4  s!     ww||DIItzz22ru   c                    [         R                  R                  U R                  R	                  5       5      u  pU(       a  UR                  S5      (       a  SU-   nU$ )z&File name extension of file or stream.z.ome)r  rE  r
  r
  r  rZ  )rk  r   ra  s      rv   rB  FileHandle.extension4  sF     GG$$TZZ%5%5%78	4==((3,C
ru   c                    U R                   $ )zSize of file in bytes.)r
  r  s    rv   r   FileHandle.size4  r	  ru   c                    U R                   SL $ )zFile is closed.Nr  r  s    rv   r  FileHandle.closed"4  s     xx4ru   c                    U R                   $ )z/Reentrant lock to synchronize reads and writes.)r
  r  s    rv   r*  FileHandle.lock'4  r	  ru   c               &    U R                  U5        g ry   )set_lockr  s     rv   r*  r   ,4  s    eru   c                    [        U5      [        U R                  [        5      :X  a,  U(       a  [        R
                  " 5       O	[        5       U l        gg)z3Set reentrant lock to synchronize reads and writes.N)r   r   r
  r   	threadingRLock)rk  r*  s     rv   r  FileHandle.set_lock04  s2    :DJJ<<.2*DJ =ru   c                @    [        U R                  [        5      (       + $ )z9File uses reentrant lock to synchronize reads and writes.)r   r
  r   r  s    rv   has_lockFileHandle.has_lock54  s     djj+666ru   c                f     U R                   R                  5         g! [        [        4 a     gf = f)z)File has fileno and can be memory-mapped.FT)r#  r}  r]  r   r  s    rv   rD  FileHandle.is_file:4  s3    	HHOO  ( 		s    00ry   )r   z<Literal['r', 'r+', 'w', 'x', 'rb', 'r+b', 'wb', 'xb'] | Noner   r-  r   rQ  r   r3  r   r3  r6  r   rB  rK  r  r  )r
  r   r   r   r6  r   )rK  )r   r   r6  r{   )r
  	bytearrayr6  r   )r
  zbytes | memoryview[Any]r6  r   )r   r3  r   rM  r   r   r   rz   r
  rz   r6  r  )rK  r   )
r   r3  r  r   r   r   r   NDArray[Any] | Noner6  r  r  )r   r3  r   ztuple[int, ...] | int | Noner   z'Literal['S', '<', '>', '=', '|'] | Noner6  numpy.recarray[Any, Any])r   r   r6  r   )r  r  r   r3  r6  r   r  )r  r2  rY  r3  r  rE  r  rE  r   r   r*  r  r   r3  r  r   r6  zMIterator[tuple[bytes | None, int]] | Iterator[list[tuple[bytes | None, int]]]rF  rG  rK  )r6  r
  r  )r*  r   r6  r   )*r  r  r  r  r  rG  rL  rn  rD  r  r}  r
  r
  rX  r\  r   r
  r   r  r  r  r
  r@  rA  r7  r  r%  r+  r  rM  r   rG  rE  rB  r   r  r*  r  r  r  rD  r   rt   ru   rv   r   r   ]1  sb   D
I BA	JJ
ILJL(( $  !$
 I$=$ $ $ $ 
$0fP(.
-6#)& 	#
 #
#
 #
 	#
 #
 #
 
#
P 	> $(>> > 	> !> 
>F /0-3
 >B-3-3 ,-3
 ;-3 
"-3^& #'%%  %
 
%8 )-!j 59!%j
 &j jj "j j 3j j j	3jX, ( (	
 
(D	
     3 3           
[[ F
 7 7  ru   r   c                      \ rS rSr% SrSrS\S'    S\S'    S\S	'    S
\S'    S\S'     SSS.     SS jjjrSS jrSS jr	SS jr
 S         SS jjr S         SS jjrSS jrS S jrS!S jrSrg)"r   iD4  zKeep FileHandles open.

Parameters:
    size: Maximum number of files to keep open. The default is 8.
    lock: Reentrant lock to synchronize reads and writes.

)r   r
  r*  pastr   r   r   zdict[FileHandle, int]r   zset[FileHandle]r
  zlist[FileHandle]r  r
  r*  N)r*  c                   / U l         0 U l        [        5       U l        Uc  SO
[	        U5      U l        Uc  [        5       U l        g UU l        g )NrP  )r  r   r!  r
  r   r   r   r*  )rk  r   r*  s      rv   rn  FileCache.__init___4  s?     	
E	A3t9	%)\KM	t	ru   c                  U R                      XR                  ;   a  U R                  U==   S-  ss'   OUR                  (       a;  UR                  5         SU R                  U'   U R                  R                  U5        OESU R                  U'   U R                  R                  U5        U R                  R                  U5        SSS5        g! , (       d  f       g= f)z Open file, re-open if necessary.rY   rT  N)r*  r   r  rD  r  r   r
  r$  rk  rl  s     rv   rD  FileCache.openk4  s    YYZZ

2!#	!"

2		  $!"

2		b!		  $ YYs   B9C
Cc                   U R                      XR                  ;   a  U R                  U==   S-  ss'   U R                  5         SSS5        g! , (       d  f       g= f)z8Decrement reference count of file handle and trim cache.rY   N)r*  r   _trimr  s     rv   r  FileCache.closey4  s8    YYZZ

2!#JJL YYs   7A
Ac                   U R                      U R                   Vs/ s H  oU R                  ;  d  M  UPM     sn H   nUR                  5         U R                  U	 M"     U R                   Vs/ s H  oU R                  ;   d  M  UPM     snU l        U =R                  U R                  R                  5       -  sl        SSS5        gs  snf s  snf ! , (       d  f       g= f)z'Close all file handles opened by cache.N)r*  r   r
  r  r  r*	  r  s     rv   clearFileCache.clear4  s    YY$(JJFJbDII2ErJF
JJrN G '+iiDi3CiDDIII**I YF E	 Ys2   CC	C	5C.CC5C	
C
C!c                  U R                      XR                  ;  nU(       av  UR                  (       a   UR                  5         SU R                  U'   O*SU R                  U'   U R                  R                  U5        U R                  R                  U5        UR                  X$5        UR                  U5      nU(       a  U R                  5         SSS5        U$ ! , (       d  f       W$ = f)a  Return bytes read from binary file.

Parameters:
    fh:
        File handle to read from.
    offset:
        Position in file to start reading from relative to the
        position indicated by ``whence``.
    bytecount:
        Number of bytes to read.
    whence:
        Relative position of offset.
        0 (``os.SEEK_SET``) beginning of file (default).
        1 (``os.SEEK_CUR``) current position.
        2 (``os.SEEK_END``) end of file.

r   rY   N)r*  r   r  rD  r
  r$  r  r   r\  r   r  )rk  rl  r   r  r
  	transientr  s          rv   r   FileCache.read4  s    > YY**,I99GGI%&DJJrN%&DJJrNIIMM"%		  $GGF#779%D

   Y    CC
C+c                  U R                      XR                  ;  nU(       av  UR                  (       a   UR                  5         SU R                  U'   O*SU R                  U'   U R                  R                  U5        U R                  R                  U5        UR                  X$5        UR                  U5      nU(       a  U R                  5         SSS5        U$ ! , (       d  f       W$ = f)a  Write bytes to binary file and return number of bytes written.

Parameters:
    fh:
        File handle to write to.
    offset:
        Position in file to start writing from relative to the
        position indicated by ``whence``.
    data:
        Bytes to write.
    whence:
        Relative position of offset.
        0 (``os.SEEK_SET``) beginning of file (default).
        1 (``os.SEEK_CUR``) current position.
        2 (``os.SEEK_END``) end of file.

r   rY   N)r*  r   r  rD  r
  r$  r  r   r\  r   r  )rk  rl  r   r  r
  r  writtens          rv   r   FileCache.write4  s    2 YY**,I99GGI%&DJJrN%&DJJrNIIMM"%		  $GGF#hhtnG

   Y r  c                f   Sn[        U R                  5      nXs=:  a  U R                  :  a  O  gU R                  U   nX0R                  ;  aC  U R                  U   S::  a0  UR                  5         U R                  U	 U R                  U	 US-  nOUS-  nXs=:  a  U R                  :  a  M~  g  gg)zTrim file cache.r   rY   N)r   r  r   r
  r   r  )rk  r  r   rl  s       rv   r  FileCache._trim4  s    499~&TYY&5!B"tzz"~':
JJrNIIe$	
 &TYY&&ru   c                ,    [        U R                  5      $ )z&Return number of tracked file handles.)r   r   r  s    rv   r  FileCache.__len__4  s    4::ru   c                "    S[        U 5      S S3$ )Nz<tifffile.FileCache @0xrM	  rr   rN	  r  s    rv   r+  FileCache.__repr__4  s    (D$q99ru   ry   )r   r3  r*  r  r6  r   )rl  r   r6  r   rB  r  )
r   r   r  r   r
  r   rl  r   r6  r{   )
r   r   r  r{   r
  r   rl  r   r6  r   rK  rK  )r  r  r  r  r  rG  rL  rn  rD  r  r  r   r   r  r  r+  r   rt   ru   rv   r   r   D4  s     :I
I/  +
$
$
''9  
< 6:	
<
< 3	
<
 

<%+ - 	-
 - -- 
-j ' 	'
 ' '' 
'R:ru   r   c                     \ rS rSr% SrSrS\S'    S\S'    S\S'    S\S'    S\S	'    S\S
'    S\S'           S               S S jjr\S!S j5       r	\S!S j5       r
\S!S j5       r\S"S j5       r\S#S j5       r\S!S j5       r\S$S j5       r\S%S j5       r\S%S j5       r\S&S j5       r\S!S j5       r\S'S j5       r\S(S j5       r\S)S j5       rS!S jrS*S jrS+S jrSrg),r   i4  ay  Normalized shape of image array in TIFF pages.

Parameters:
    frames:
        Number of TIFF pages.
    separate_samples:
        Number of separate samples.
    depth:
        Image depth.
    length:
        Image length (height).
    width:
        Image width.
    contig_samples:
        Number of contiguous samples.
    extrasamples:
        Number of extra samples.

)rW  rZ  r   rr  rY  r[  rX  r   rr  r[  rZ  rY  rX  rW  r   c                   US:w  a  US:w  a  Sn[        U5      e[        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        g )NrY   zinvalid samples)	r   r   rr  r[  rZ  rY  rX  rW  r   )	rk  rr  r[  rZ  rY  rX  rW  r   r   s	            rv   rn  StoredShape.__init__,5  sv     q ^q%8#CS/!&k #$4 5Z
&kZ
!.1-ru   c                    [        U R                  5      U R                  -  U R                  -  U R                  -  U R
                  -  U R                  -  $ )zProduct of all dimensions.)absrr  r[  rZ  rY  rX  rW  r  s    rv   r   StoredShape.sizeB5  s[     ##$jj kk jj	
 !!"	
ru   c                R    U R                   S:  a  U R                   $ U R                  $ )z0Number of samples. Count of SamplesPerPixel tag.rY   r[  rW  r  s    rv   r\  StoredShape.samplesN5  s2    
 $$q( !!	
 $$	
ru   c                4    U R                   U R                  -
  $ )zNumber of photometric samples.)r\  r   r  s    rv   photometric_samplesStoredShape.photometric_samplesW5  s     ||d////ru   c                    U R                   U R                  U R                  U R                  U R                  U R
                  4$ )z0Normalized 6D shape of image array in all pages.)rr  r[  rZ  rY  rX  rW  r  s    rv   r   StoredShape.shape\5  s<     KK!!JJKKJJ
 	
ru   c                t    U R                   U R                  U R                  U R                  U R                  4$ )z2Normalized 5D shape of image array in single page.r[  rZ  rY  rX  rW  r  s    rv   r|  StoredShape.page_shapeh5  s5     !!JJKKJJ
 	
ru   c                    U R                   U R                  -  U R                  -  U R                  -  U R                  -  $ )z%Product of dimensions in single page.r8  r  s    rv   r_  StoredShape.page_sizes5  sH     !!jjkk jj !!	"	
ru   c                   U R                   U R                  /nU R                  S:  a  UR                  SU R                  5        U R                  S:  a  UR                  SU R                  5        O+U R
                  S:  a  UR                  U R
                  5        U R                  S:  a  UR                  SU R                  5        [        U5      $ )z@Shape with length-1 dimensions removed, except length and width.rY   r   )	rY  rX  rZ  r  r[  rW  r   rr  r~   r  s     rv   r  StoredShape.squeezed~5  s     djj)::>LLDJJ'  1$LLD112  1$LL,,-;;?LLDKK(U|ru   c                t   U R                   S:  =(       a    U R                  S:  =(       a    U R                  S:  =(       aw    U R                  S:  =(       aa    U R                  S:H  =(       d    U R
                  S:H  =(       a5    U R
                  S:  a  U R
                  OU R                  U R                  :  $ )zShape is valid.rY   )rr  rZ  rY  rX  r[  rW  r   r  s    rv   r`  StoredShape.is_valid5  s     KK1 
 

a
 q 
  

a
  &&!+Gt/B/Ba/G	
  &&* ##** 	
ru   c                     U R                   S:  $ )zShape contains planar samples.rY   )r[  r  s    rv   	is_planarStoredShape.is_planar5  s     $$q((ru   c                H    U R                   S:  a  gU R                  S:  a  gg)z!Value of PlanarConfiguration tag.rY   rT  Nr0  r  s    rv   r   StoredShape.planarconfig5  s)       1$"ru   c                    g)Nr  rt   r  s    rv   r  StoredShape.__len__5  s    ru   c                   g ry   rt   r  s     rv   r  StoredShape.__getitem__5  rz	  ru   c                   g ry   rt   r  s     rv   r  rH  5  ri	  ru   c                    U R                   U   $ ry   r  r  s     rv   r  rH  5  s    zz#ru   c                ,    [        U R                  5      $ ry   )r#  r   r  s    rv   r7  StoredShape.__hash__5  s    DJJru   c               b    [        U[        5      =(       a    U R                  UR                  :H  $ ry   )r   r   r   r2  s     rv   r4  StoredShape.__eq__5  s!    %-K$**2KKru   c                    SU R                    SU R                   SU R                   SU R                   SU R                   SU R
                   SU R                   S3$ )	Nz<StoredShape(frames=z, separate_samples=z, depth=z	, length=z, width=z, contig_samples=z, extrasamples=z)>)rr  r[  rZ  rY  rX  rW  r   r  s    rv   r+  StoredShape.__repr__5  sz    kk] #  $ 5 56 7ZZL !kk] #ZZL !"112 3 --.
	
ru   N)rY   rY   rY   rY   rY   rY   r   )rr  r   r[  r   rZ  r   rY  r   rX  r   rW  r   r   r   r6  r   rK  )r6  z#tuple[int, int, int, int, int, int]rm  r  r  r  )r   r   r6  r   )r   r  r6  rM  )r   rq
  r6  zint | tuple[int, ...]rI  rK  )r  r  r  r  r  rG  rL  rn  rM  r   r\  r3  r   r|  r_  r  r`  rA  r   rb   r  ra   r  r7  r4  r+  r   rt   ru   rv   r   r   4  s   (I K%J4K:J/'B  !.. . 	.
 . . . . 
., 	
 	
 
 
 0 0 	
 	
 
 
 
 
   
 
  ) )     2 2@ @  L
ru   r   c                  z    \ rS rSrSrSrSS jr        SS jr  S     SS jjrSS jr	SS jr
SS	 jrSrg
)r   i5  zNull context manager and dummy reentrant lock.

Can replace :py:class:`threading.RLock` where no synchronization
is needed. Implements both the context manager and lock interfaces.

>>> with NullContext():
...     pass
...

rt   c                    U $ ry   rt   r  s    rv   r  NullContext.__enter__5  r  ru   c                    g)NFrt   r!  s       rv   r%  NullContext.__exit__5  s     ru   c                    g)z)Acquire lock immediately and return True.Trt   )rk  blockingtimeouts      rv   acquireNullContext.acquire5  s     ru   c                    g)zRelease lock (no-op).Nrt   r  s    rv   releaseNullContext.release5  s    ru   c                    g)z!Return False; lock is never held.Frt   r  s    rv   lockedNullContext.locked5  s    ru   c                    g)NzNullContext()rt   r  s    rv   r+  NullContext.__repr__5  s    ru   NrF  )r"  rH  r#  rI  r$  rJ  r6  zLiteral[False])TrK  )rW  r   rX  rY  r6  r   rB  r  rK  )r  r  r  r  r  rG  r  r%  rY  r\  r_  r+  r   rt   ru   rv   r   r   5  sv    	 I, ( (	
 
   
	$ru   r   c                     \ rS rSr% SrSrS\S'    S\S'    S\S'     SS	SS
.       SS jjjrSS	S.SS jjjrSS	S.SS jjjr	 SSS.     SS jjjr
\SS j5       rSS jrSS jrSS jr        SS jrSrg)r)   i5  aj  Stopwatch for timing execution speed.

Parameters:
    message:
        Message to print.
    end:
        End of print statement.
    started:
        Value of performance counter when started.
        The default is the current performance counter.

Examples:
    >>> import time
    >>> with Timer('sleep:'):
    ...     time.sleep(1.05)
    sleep: 1.0... s

)durationstartedstoppedrY  re  rf  rd  Nr  )endre  c               x    Ub
  [        XSS9  SU l        Uc  [        R                  " 5       nU=U l        U l        g )NTrg  r          printrd  timeperf_counterre  rf  )rk  messagerg  re  s       rv   rn  Timer.__init__6  s<     '$/?'')G&--t|ru   rg  c                   Ub
  [        XSS9  SU l        [        R                  " 5       =U l        U l        U R                  $ )z$Start timer and return current time.Tri  rj  rk  rk  ro  rg  s      rv   r  Timer.start(6  s:    '$/&*&7&7&99t|||ru   c                   [         R                  " 5       U l        Ub
  [        XSS9  U R                  U R                  -
  U l        U R
                  $ )ztReturn duration of timer since start.

Parameters:
    message: Message to print.
    end: End of print statement.

Tri  )rm  rn  rf  rl  re  rd  rs  s      rv   r  
Timer.stop06  sB     ((*'$/t||3}}ru   c               H    [        U 5      nUb
  [        USS9  [        X2SS9  g)zPrint duration from timer start till last stop or now.

Parameters:
    message: Message to print.
    end: End of print statement.

Nr  rq  Tri  )rz   rl  )rk  ro  rg  r   s       rv   rl  Timer.print>6  s'     $i's#c$'ru   c                 ,    [         R                  " 5       $ )z$Return value of performance counter.)rm  rn  rt   ru   rv   clockTimer.clockM6  s       ""ru   c                L   U R                   S::  a#  [        R                  " 5       U R                  -
  nOU R                   n[	        [        US95      nSnU[        U5      :  a,  X#US-    S;   a!  US-  nU[        U5      :  a  X#US-    S;   a  M!  X#US-    S:X  a  US-  nX#S  S	3$ )
z7Return duration from timer start till last stop or now.rj  )secondsr   rT  z0:0010203040506070809rY   r  Nz s)rd  rm  rn  re  rz   	TimeDeltar   )rk  rd  r  r  s       rv   r  Timer.__str__R6  s    ==C((*T\\9H}}H	(+,#a&jQ1q5\-DDFA #a&jQ1q5\-DDQ<3FAB%|ru   c                "    SU R                    S3$ )NzTimer(started=rz  )re  r  s    rv   r+  Timer.__repr__a6  s    ~Q//ru   c                    U $ ry   rt   r  s    rv   r  Timer.__enter__d6  r  ru   c                $    U R                  5         g ry   )rl  r!  s       rv   r%  Timer.__exit__g6  r'  ru   ry   )ro  rQ  rg  rz   re  r  r6  r   )ro  rQ  rg  rz   r6  rY  )ro  rQ  rg  rQ  r6  r   )r6  rY  rK  rF  rG  )r  r  r  r  r  rG  rL  rn  r  r  rl  rN  rz  r  r+  r  r%  r   rt   ru   rv   r)   r)   5  s    & 3IN4N4OB #.  $.. 	.
 . 
.c  S   %)(?C(!(2<(	( # #0, ( (	
 
ru   r)   c                      \ rS rSrSrSrg)r   ip6  z;Exception to indicate invalid OME-XML or unsupported cases.rt   Nr  rt   ru   rv   r   r   p6  s    Eru   r   c                  p   \ rS rSr% SrSrS\S'    S\S'    S\S'    S\S'    S\S	'    S
\S'   S\S'   / rS\S'   S)S jrSS.           S*S jjr	SS.S+S jjr
S,S jrS,S jr\S-S j5       r\ S.       S/S jj5       r\S0S j5       r\  S1         S2S jj5       r\        S3S j5       r\          S4S j5       r          S5S jr\          S6S  j5       r\          S7S! j5       rS8S" jrS9S# jrS)S$ jr      S:S% jr\ S.S&S'.       S;S( jjj5       rSrg)<r   it6  a  Create OME-TIFF XML metadata.

https://www.openmicroscopy.org/Schemas/OME/

Parameters:
    **metadata:
        Additional OME-XML attributes or elements to be stored.

        Creator:
            Name of creating application.
            The default is 'tifffile.py and version'.
        UUID:
            Unique identifier.
        Experimenter:
            Dict of Experimenter attributes (FirstName, LastName, Email,
            Institution, UserName, etc.).
            A list of dicts creates multiple Experimenter elements.
        Project:
            Dict of Project attributes (Name, Description).
            A list of dicts creates multiple Project elements.

Examples:
    >>> omexml = OmeXml()
    >>> omexml.addimage(
    ...     dtype='uint16',
    ...     shape=(32, 256, 256),
    ...     storedshape=(32, 1, 1, 256, 256, 1),
    ...     axes='CYX',
    ...     Name='First Image',
    ...     PhysicalSizeX=2.0,
    ...     MapAnnotation={'key': 'value'},
    ...     Dataset={'Name': 'FirstDataset'},
    ... )
    >>> xml = omexml.tostring()
    >>> xml
    '<OME ...<Image ID="Image:0" Name="First Image">...</Image>...</OME>'
    >>> OmeXml.validate(xml)
    True

)_ifd_xmlr   datasetsexperimentersre  projectsr	  re  r   r  r  r  rz   r  r   r  zClassVar[list[Any]]_schemac                   UR                  SU5      nSU l        / U l        / U l        / U l        / U l        / U l        SU;   a  US   R                  S5      S   nOSSKJ	n  [        U" 5       5      n[        R                  USS[         3S	9nS
nSU SU SU SU SU S3U l        U R                  UR                  S0 5      5        U R!                  UR                  S0 5      5        g )NOMEr   UUIDr  rK  )uuid1Creatorztifffile.py r  z1http://www.openmicroscopy.org/Schemas/OME/2016-06z{declaration}<OME xmlns="zL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="r  z/ome.xsd" UUID="urn:uuid:"z?>{projects}{datasets}{experimenters}{images}{annotations}</OME>ExperimenterProject)rS  r  re  r   r  r  r  r  uuidr  rz   r   
_attributer*   r  _experimenter_project)rk  r   r  r  creatorschemas         rv   rn  OmeXml.__init__6  s   <<x0	 XF#))#.r2D"uw<D##i<})E $ 
 E!( ###)(!F8 4"V1WI .	
 		 	8<<;<hll9b12ru   N)r  c               r
  ^#^$ [        U R                  5      n/ nUR                  SU5      nUR                  SU5      n[        U[        [
        45      (       a  XV   nSU;   a;  SSKnUR                  U5      nSUS   ;   a  US   S	 UR                  US   5        US	  [        R                  " U5      R                  nSSS	S
SSSSSSSS.U   nUR                  SU5      U:w  a  SUS   < SU< 3n	[        U	5      eUu  pppUS:w  a  Sn	[        U	5      eUS:X  d  US:X  d  Sn	[        U	5      e[        S U 5       5      n[        U5      S:  d  [        U5      S::  a  Sn	[        U	5      e[         R#                  X#XE5      u  nnSU;   a.  US[%        UR'                  S5      UR'                  S5      5       nOUSUR'                  S5       nU R)                  UX%U5      u  nnUSSS2   nUR                  S S!5      S!S"S#S$S%S&4 H  m#UT#;   d  M    O   S'U< S(U< S)3n	[        U	5      eSn/ m$T# HU  nUS:X  a  M  UU;   a  X$R'                  U5         OSnUS*:X  a  UnUU-  nUU;   a  UUU   S   -  nT$R+                  U5        MW     S+R-                  S, [/        T#T$S-S.9 5       5      nS U;   a8  US    nS+R-                  U#U$4S/ jU 5       5      nUU;  a  S0U< 3n	[        U	5      e[/        T#T$S-S.9 H3  u  nnUR                  S1U 3U5      U:w  d  M!  S2U S3U< 3n	[        U	5      e   T$T#R'                  S*5      ==   U-  ss'   U
[        T$S4S 5      :w  a  S5n	[        U	5      e[         R1                  UR                  S6S+5      U
T#T$5      n[         R3                  UR                  S7S+5      UUU5      n[         R5                  US85      n[         R5                  US95      n[         R7                  US:SU 3S;9n[         R9                  USS<S=S>S?S@SASBSCSD5      nUS:  d  US:  a  US:  a  SEOSFn SGU  SH3n OS+n U R;                  UR                  SI0 5      SJU SK35        U R=                  UR                  SLU5      U5        S+R-                  U5      n!U R?                  UR                  SM5      5      n"U R                  R+                  SNU SHU SOU U" U SPU SQT# SRU SHU U  U SOU SSU R@                   STU
 SKU SUU! SV35        U =R@                  U
-  sl         g! [         a    SU< S3n	[        U	5      Sef = f)Wa  Add image to OME-XML.

The OME model can handle up to 9 dimensional images for selected
axes orders. Refer to the OME-XML specification for details.
Non-TZCYXS (modulo) dimensions must be after a TZC dimension or
require an unused TZC dimension.

Parameters:
    dtype:
        Data type of image array.
    shape:
        Shape of image array.
    storedshape:
        Normalized shape describing how image array is stored in
        TIFF file as (pages, separate_samples, depth, length, width,
        contig_samples).
    axes:
        Character codes for dimensions in ``shape``.
        By default, ``axes`` is determined from the DimensionOrder
        metadata attribute or matched to the ``shape`` in reverse order
        of TZC(S)YX(S) based on ``storedshape``.
        The following codes are supported: 'S' sample, 'X' width,
        'Y' length, 'Z' depth, 'C' channel, 'T' time, 'A' angle,
        'P' phase, 'R' tile, 'H' lifetime, 'E' lambda, 'Q' other.
    **metadata:
        Additional OME-XML attributes or elements to be stored.

        Image/Pixels:
            Name, Description,
            DimensionOrder, TypeDescription,
            PhysicalSizeX, PhysicalSizeXUnit,
            PhysicalSizeY, PhysicalSizeYUnit,
            PhysicalSizeZ, PhysicalSizeZUnit,
            TimeIncrement, TimeIncrementUnit,
            StructuredAnnotations, BooleanAnnotation, DoubleAnnotation,
            LongAnnotation, CommentAnnotation, MapAnnotation,
            Dataset, Experimenter
        Per Plane:
            DeltaT, DeltaTUnit,
            ExposureTime, ExposureTimeUnit,
            PositionX, PositionXUnit,
            PositionY, PositionYUnit,
            PositionZ, PositionZUnit.
        Per Channel:
            Name, AcquisitionMode, Color, ContrastMethod,
            EmissionWavelength, EmissionWavelengthUnit,
            ExcitationWavelength, ExcitationWavelengthUnit,
            Fluor, IlluminationType, NDFilter,
            PinholeSize, PinholeSizeUnit, PockelCellSetting.

Raises:
    OmeXmlError: Image format not supported.

r  ImagePixelsr   NIDint8int16int32rP  r  uint32rY  doublecomplexzdouble-complexbit)r  r  r  rP  r  r  r  float64	complex64
complex128r   z
data type r^  Typezmetadata Pixels Type z does not match array dtype rY   zImageDepth not supportedzinvalid stored shapec              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   "OmeXml.addimage.<locals>.<genexpr>[7  s     ,ec!ffer  zempty arrays not supportedrS  r  rK  DimensionOrderXYCZTXYZCTXYZTCXYCTZXYTCZXYTZCzdimension order z not supported (dim_search=rz  r  r=  c              3  8   #    U  H  u  pS U SU S3v   M     g7f)z Size="r  Nrt   )r   r  r   s      rv   r   r  7  s(      
@ B4r$q!@r  Tr4  c              3  \   >#    U  H!  nTTR                  U5         S :  d  M  Uv   M#     g7fr  rd  )r   r  dimorderdimsizess     rv   r   r  7  s+      "(rHX^^B5G,H1,L[s   ,	,z'metadata DimensionOrder does not match Sizezmetadata Sizez does not match rT  !shape does not match stored shapePlaneChannelAcquisitionDateDescriptionNamer  SignificantBitsPhysicalSizeXPhysicalSizeXUnitPhysicalSizeYPhysicalSizeYUnitPhysicalSizeZPhysicalSizeZUnitTimeIncrementTimeIncrementUnitfalsetruez Interleaved="r  Datasetz<ImageRef ID="Image:"/>StructuredAnnotationsr  z<Image ID="Image:rr   z<Pixels ID="Pixels:z" DimensionOrder="z" Type="z<TiffData IFD="z" PlaneCount="z	</Pixels>z</Image>)!r   re  rS  r   rM  r~   rd  deepcopyr  r   r   r   r  r   r   r@   r   r  r  r  _modulor   r   r  _planes	_channels_elementr  _attributes_dataset_annotationsr  r  )%rk  r   r   r|  r  r   r  annotation_refsrd  r   rh  separaterZ  _length_widthcontigr\  hiaxesmodulononmodulo_hiaxes
dim_searchsizecr  r   r  omedimorderplaneschannelsacquisitiondater   r   r  interleavedannotationrefexperimenterrefr  r  s%                                      @@rv   r>  OmeXml.addimage6  s   ~ DKK %' <<x0<<2hu..Hx}}X.Hx))X&t,OOHX./"	-KK&++E   """#&. E" <<&%/'(8'; <..3Y8  c""?J<
efA:,Cc""A1(CS/!,e,,u:>WU^q0.Cc""UHg$;AC

3CABF+DJJsO,F#'<<E_$
   &dd+
LL)73
H X%
 %TH,HZMKCc""BSy,.$J5B(ADSyV|r
1%OOD!   
(4@
 
 x'"#34K'' "(" K ,?xH!#&& Hht<HB||d2$K.$6%bT)9%C!#&& =
 	$%'1%!"..5CS/!LL"%z8X
 ##LLB'
 !//(4EFooh>  6U5'? K''

 a<6A:%-\'vK*;-q9KKLLB'+?wc)J	
 	LL0(;_	
 0,,X\\.-IJwavQm!% )'j )G1gml!jdii[zl#ho	
$ 			Z	m  	-ui~6Cc",	-s   1T T6Fr  c          	     ~   SR                  U R                  5      nSR                  U R                  5      nSR                  U R                  5      nSR                  U R                  5      nSR                  U R
                  5      nU(       a  SU S3nU(       a  SnOSnU R                  R                  UUUUUUS9$ )zOReturn OME-XML string.

Parameters:
    declaration: Include XML declaration.

r=  z<StructuredAnnotations>z</StructuredAnnotations>z&<?xml version="1.0" encoding="UTF-8"?>)r  r  r  r  re  r   )r   r  r  r  re  r   r  r   )rk  r  r  r  r  re  r   declaration_strs           rv   r  OmeXml.tostring7  s     774==)774==) 2 23%ggd../)+6NO  FO Oyy''#   
 	
ru   c                "    S[        U 5      S S3$ )Nz<tifffile.OmeXml @0xrM	  rr   rN	  r  s    rv   r+  OmeXml.__repr__7  s    %bht_A66ru   c                d   U R                  5       n SSKJn  UR                  SS9nUR	                  X5      nUR                  USSSS9R                  5       nU$ ! [         a     U$ [         a?  n[        R                  " SUR                  R                   SU 3[        S	S
9   SnAU$ SnAff = f)zReturn OME-XML string.r   etreeT)remove_blank_textr  )r
  pretty_printxml_declarationz<tifffile.OmeXml.__str__> rD  rT  rU  N)r  lxmlr  	XMLParserr
  r  ImportErrorr  rh  ri  r  r  rj  )rk  xmlr  parsertreer  s         rv   r  OmeXml.__str__ 8  s    mmo	"__t_<F##C0D..wT4 ! fh  
  	 
  	MM,S]]-C-C,DBseL
 
	s   AA 
B/'	B/04B**B/c                   [        U [        5      (       d  [        U 5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      $ )	zReturn escaped string of value.&z&amp;rr   z&gt;rs   z&lt;r  z&quot;)r   rz   r  r  s    rv   _escapeOmeXml._escape8  s[     %%%JEc7+c6*c6*}}S(++ru   c                j    U R                  X5      nUc  gSU S[        R                  U5       SU S3$ )z1Return XML formatted element if name in metadata.r=  rs   rr   </)rS  r   r  )r   r   r  rO  s       rv   r  OmeXml._element8  s?    
 T+=4&&../04&::ru   c               \   ^  T (       d  gU 4S jU 5       nSR                  S U 5       5      $ )zReturn XML formatted elements.r=  c              3  P   >#    U  H  n[         R                  TU5      v   M     g 7fry   )r   r  r   r   r   s     rv   r   #OmeXml._elements.<locals>.<genexpr>.8  s     FFOOHd33   #&c              3  6   #    U  H  o(       d  M  Uv   M     g 7fry   rt   )r   r  s     rv   r   r  /8  s     0(Qaqq(   
	r#
  )r   r  elementss   `  rv   	_elementsOmeXml._elements)8  s*     FFww0(000ru   c               H   U R                  X5      nUc  gUbK  [        U[        [        45      (       a   XB   nO*US:  a$  [        U5      R                  < S3n[        U5      eSU S[        R                  U5       S3$ ! [         a  nSU< 3n[	        U5      UeSnAff = f)	z3Return XML formatted attribute if name in metadata.Nr=  z&list index out of range for attribute r   z is not a list or tupler  r  r  )
rS  r   rM  r~   r4  rw  r  r   r   r  )r   r   r  r  rO  r  r   s          rv   r  OmeXml._attribute18  s     T+=%$//3!LE e--00GHn$4&6>>%0133 " 3B4(KC$S/s23s   B   
B!
BB!c                 ^ ^ T (       d  gTc  U 4S jU 5       nOQ[        T [        [        45      (       a  T T   m U 4S jU 5       nO$[        T [        5      (       a  UU 4S jU 5       nOgSR	                  S U 5       5      $ )z Return XML formatted attributes.r=  c              3  P   >#    U  H  n[         R                  TU5      v   M     g 7fry   r   r  r  s     rv   r   %OmeXml._attributes.<locals>.<genexpr>T8  !     N&++Hd;;r  c              3  P   >#    U  H  n[         R                  TU5      v   M     g 7fry   r  r  s     rv   r   r  W8  r  r  c              3  R   >#    U  H  n[         R                  TUT5      v   M     g 7fry   r  )r   r   rH
  r   s     rv   r   r  Y8  s&      FKd!!(D&99e   $'c              3  6   #    U  H  o(       d  M  Uv   M     g 7fry   rt   )r   as     rv   r   r  ^8  s     2*Qqq*r  )r   rM  r~   r  r   )r   rH
  r  r  s   ``  rv   r  OmeXml._attributesI8  su     >NNJ4-00'HNNJ$''FKJ ww2*222ru   c                   Uu  pEpgp[        U 5      n
SnUc  U	S:w  d  U SS XxS4:X  a  SnU	nOUS:w  d  U
S:X  a  U SS SXx4:X  a  SnUnOSn[        U5      U
s=::  a  SU;   a  SOS	::  d  O  U
 S
3n[        U5      eUR                  SS5      SSS2   nUSU;   a  SOS	U
-
  S U-   n[        U5      U
:w  a'  S[        U5      < S[        U 5      < 3n[        U5      eGOUR	                  5       n[        U5      U
:w  a  Sn[        U5      eUR                  S5      (       d)  UR                  S5      (       a  SU;  d  Sn[        U5      e/ nU HC  nUS;  a  SU< S3n[        U5      eX;   a  SU< S3n[        U5      eUR                  U5        ME     U
SU;   a  SOS:  a  Sn[        U5      eU	S:w  az  U	nU
S:  a  Sn[        U5      eUS   S:X  a&  SU;   a  Sn[        U5      eUR                  SS5      nOUS   S:w  a  S n[        U5      eU S   U	:w  d	  U S!   U:w  a  S"n[        U5      eOUS:w  ay  UnU
S:  a  Sn[        U5      eUS   S:X  a&  SU;   a  Sn[        U5      eUR                  SS5      nOUS   S:w  a  S n[        U5      eU S   U:w  d	  U S   U:w  a  S"n[        U5      eXR                  S#5         U:w  d  XR                  S$5         U:w  a  S"n[        U5      eX+4$ )%zReturn resolved axes string and samples count.

Raises:
    OmeXmlError: Axes are not supported.
    ValueError: Axes do not match shape or stored shape.

rY   Nr  rt  r  rv  rx  rS  r  z dimensions not supportedr  r  rK  
len(axes)= != len(shape)=zaxes do not match shape)rx  rt  YXCz"dimensions must end with YX or YXSTZCYXSAPRHEQz
dimension r^  z	multiple z dimensionsr;  rP  z$more than 8 dimensions not supportedr   z$dimensions do not match stored shaper  zinvalid axeszaxes do not match stored shapery  r  r  r  )	r   r   rS  r   rN  rZ  r   r  r  )r   r|  r  r   _planecountr  _depthrY  rX  r  r  r\  r   
dim_prefixuniquer  s                   rv   r  OmeXml._axes`8  sZ    @K<vu5z<{eBCjVA,>> Q	eBCjQ,>>"t9AcTkqA78!#&&&ll+;WEeqeLJC4KqQ$>@ADHD4yD #T$4U6 o% !
 ::<D4yD / o%m,,MM%((S_:!#&&F^+&rfN;C%c**<%bV;7C%c**b!  C4KqQ/<!#&&{ !8@C$S/)8s?d{,(o-<<S1D"X_:C$S/)9&%)u*<=C$S/) += Q"!8@C$S/)8s?d{,(o-<<S1D"X_:C$S/)9(E"I,>=C$S/)C!U*eJJsO.D.N5CS/!}ru   c                   [        S U 5       5      (       d  0 U4$ 0 nSnSSSSSSS	.nUR                  S
0 5      n[        U5       H{  u  pU
S;   al  X;   a	  SX    S3nOSnXS-
  U	 nU(       a  US;   a  Xz   X)   U4X\'   M<  S H(  nX;  d  M
  X;  d  M  X;  d  M  Xz   X)   U4X\'   Xl-  n  Mh     Sn[        U5      eXj-  nM}     SR	                  S UR                  5        5       5      nUR                  S[        U R                  5       S35        U R                  R                  S[        U R                  5       SU S35        XV4$ )zReturn modulo dict and non-modulo hiaxes string.

Appends a modulo XMLAnnotation to self.annotations when modulo axes
are present.

Raises:
    OmeXmlError: More than 3 modulo dimensions.

c              3  *   #    U  H	  oS ;   v   M     g7f)APRHEQNrt   )r   r  s     rv   r   !OmeXml._modulo.<locals>.<genexpr>8  s     3Fb>Frx  r=  anglephaser   lifetimelambdar3  )APRrQ  EQTypeDescriptionr%  zTypeDescription="" rY   TZCzmore than 3 modulo dimensionsc           
   3  R   #    U  H  u  nu  p#nS U SU SU SUS-
   S3	v   M     g7f)z<ModuloAlongz Type="r1  zStart="0" End="rY   r  Nrt   )r   r  axtyper   	typedescrs        rv   r   r&  9  sF      
 2@--V9 2$gfXR	{dQhZs,1?s   %'<AnnotationRef ID="Annotation:r  z<XMLAnnotation ID="Annotation:z" Namespace="openmicroscopy.org/omero/dimension/modulo"><Value><Modulo namespace="http://www.openmicroscopy.org/Schemas/Additions/2011-09">z!</Modulo></Value></XMLAnnotation>)	r;  rS  r  r   r   r`  r   r   r   )rk  r  r   r   r  r  r  axestypeaxestypedescrr  r  r5  r  r   moduloalongs                  rv   r  OmeXml._modulo8  s     3F333v:!#
 !%6;v&EAX~&"3M4E3Fb II "Iq51%e (eh	 AFI #- ! !(0eh	(IFI$MH! # >)#..5 ': gg 
 28
 

 	,S1A1A-B,C3G	
 	,S1A1A-B,C DI
 m
	
 ru   c                T  ^^ U (       d  g[        U4S jS 5       5      n/ n[        U5       Hh  n[        R                  U USSSSSS	S
SSS5      n[        R
                  " XcSS SS9mU4S jU 5       u  pn
UR                  SU SU	 SU
 SU S3	5        Mj     SR                  U5      $ )zReturn Plane XML elements.r=  c              3  L   >#    U  H  nTS S R                  U5      v   M     g7frT  Nrd  )r   r  r  s     rv   r   !OmeXml._planes.<locals>.<genexpr>!9  s%     @%B!"++B//%s   !$CZTDeltaT
DeltaTUnitExposureTimeExposureTimeUnit	PositionXPositionXUnit	PositionYPositionYUnit	PositionZPositionZUnitrT  NF)r
  c              3  @   >#    U  H  n[        TU   5      v   M     g 7fry   r  )r   r  	unraveleds     rv   r   r>  39  s     ;(Qs9Q<(((rD	  z<Plane TheC="z" TheZ="z" TheT="r  z/>)r~   r  r   r  r   unravel_indexr   r   )planeattributesrh  r  r  cztorder
plane_listr  r  r  zr.  rL  s     `        @rv   r  OmeXml._planes9  s     @%@@
z"A++"J ++A|3GI;(;GA!s(1#XaS*RH# #* wwz""ru   c                    / n[        U5       HN  nSn[        R                  U USSSSSSSS	S
SSSSS5      nSnUR                  SU SU SU SU SU U S35        MP     SR	                  U5      $ )zReturn Channel XML elements.z<LightPath/>r  AcquisitionModeColorContrastMethodEmissionWavelengthEmissionWavelengthUnitExcitationWavelengthExcitationWavelengthUnitFluorIlluminationTypeNDFilterPinholeSizePinholeSizeUnitPockelCellSettingr=  z<Channel ID="Channel:r  z" SamplesPerPixel="r  rr   z
</Channel>)r  r   r  r   r   )	channel_metadatar  r\  r  channel_listr  	lightpathr  r  s	            rv   r  OmeXml._channels:9  s     uA&I  ++ ! $(&*"!#!J& M'was 3$$+9A,a /+9 H ww|$$ru   c                   [        U R                  5      nUc  gU(       d  US:X  a  gU(       dx  US-  nSU R                  U   ;   a0  U R                  U   R                  SU S35      U R                  U'   gU R                  U   R                  SU S35      U R                  U'   gUR                  SS5      nU(       a  S[        R                  U5       S	3nUR                  S
S5      nU(       a  S[        R                  U5       S3n/ nU R                  X5        SR                  U5      nU R                  R                  SU S	U SU U U S3	5        g)z%Add Dataset element to self.datasets.Nr   rY   z<AnnotationRefz
</Dataset>r  r=   Name="r  r  <Description></Description>z<Dataset ID="Dataset:rr   )	r   r  r  rS  r   r  r  r   r   )rk  r   imagerefr  r   r   r  r  s           rv   r  OmeXml._dataseti9  s`   DMM"EQJQJE4==#77'+}}U';'C'C$
.&A(e$  (,}}U';'C'C XJj"9(e$  ||FB'V^^D12!4Dll="5{ ;<NK  &((40#E7!D6mjo		
ru   c           
        U(       d  g[        U[        [        45      (       a  SnU H  nU R                  U5      nM     U$ [        U[        5      (       d  g[        U R                  5      n[        R                  USSSSSSS5      n/ nU R                  X5        SR                  U5      nU R                  R                  S	U S
U SU S35        SU S3$ )zuAdd Experimenter element to self.experimenters.

Return ExperimenterRef XML string, or empty string if no metadata.

r=  N	FirstName
MiddleNameLastNameEmailInstitutionUserNamez<Experimenter ID="Experimenter:r  rr   z</Experimenter>z"<ExperimenterRef ID="Experimenter:r  )r   rM  r~   r  r  r   r  r   r  r  r   r   )rk  r   refr-  r  r  r  r  s           rv   r  OmeXml._experimenter9  s     hu..C((+ J(D))D&&'''	

 &((40!!-eWAj\o	

 4E7#>>ru   c           
     4   U(       d  g[        U[        [        45      (       a  U H  nU R                  U5        M     g[        U[        5      (       d  g[        U R                  5      nUR                  SS5      nU(       a  S[        R                  U5       S3nUR                  SS5      nU(       a  S[        R                  U5       S3n/ nU R                  X5        SR                  U5      nU R                  R                  S	U SU S
U U S35        g)z%Add Project element to self.projects.Nr  r=  rf  r  r  rg  rh  z<Project ID="Project:rr   z
</Project>)r   rM  r~   r  r  r   r  rS  r   r  r  r   r   )rk  r   r-  r  r   r   r  r  s           rv   r  OmeXml._project9  s    hu..a  (D))DMM"||FB'V^^D12!4Dll="5{ ;<NK  &((40#E7!D6mo	
ru   c                L   1 Skn1 SknUR                  5        GH  nUu  pgU(       d  M  Xd;   a!  [        R                  " SU< S3[        SS9  M7  Xc;  a  M>  [	        U[
        [        45      (       d  U/nU GH  nSn	Sn
[	        U[        5      (       a  UR                  5       nUR                  SS5      n
U
(       a  S	[        R                  U
5       S
3n
UR                  SS5      n	U	(       a  S[        R                  U	5       S3n	UR                  SU5      nUS:X  at  [	        U[        5      (       d  Sn[        U5      eUR                  5        VVs/ s H4  u  pS[        R                  U5       S[        R                  U5       S3PM6     nnnOyUS:X  a  [        U5       R                  5       /nOWUS:X  a  [        [!        U5      5      /nO;US:X  a  [        [#        U5      5      /nO[        R                  [        U5      5      /nUR%                  S['        U R(                  5       S35        U R(                  R%                  SR+                  SU S['        U R(                  5       SU	 S3U
SSR+                  U5      SSU S345      5        GM!     GM     gs  snnf ) z8Add annotations to self.annotations and annotation_refs.>   MapAnnotationLongAnnotationDoubleAnnotationBooleanAnnotationCommentAnnotation>   TagAnnotationFileAnnotationListAnnotationTermAnnotationTimestampAnnotationz<tifffile.OmeXml> z is not supportedr   rU  r=  r  rg  rh  	Namespacez Namespace="r  Valuerw  zMapAnnotation is not a dictz<M K="z">z</M>rz  rx  ry  r6  r  rs   z ID="Annotation:rr   z<Value>z</Value>r   N)r`  rh  ri  rj  r   rM  r~   r  rd  r  r   r  r   r   r  rz   r   rY  r   r   r   r   )rk  r   r  
_supported_unsupportedr  r   annotation_valuesrO  	namespacer   r   r   r  r  s                  rv   r  OmeXml._annotations9  s   


 NN$D&*#D$#(0AB 
 %/$??%6$7!*	 eT**!JJLE"'))M2">K"+%~~k:;,- $
 !&		+r :I &26>>)3L2MQ$O	!IIgu5E?*%eT22;(o- %*KKM$1DA !!2 32fnnQ6G5HM$1  F 00!%e4467F--!#e*o.F//!%,/0F$nnSZ89F&&4S9I9I5J4K3O   ''GGv &..1$2B2B.C-DA(k, (%GGFO& aL	G +# %Js   ;J 
T)assert_c                 SSK Jn  Ub\  UR                  S5      (       a  UR                  SS5      S   n UR	                  UR                  UR                  5       5      5      nGOW[        R                  nU(       Gd,  [        R                  R                  [        R                  R                  [        5      S5      n[        R                  R                  U5      (       a&  [!        US	5       nUR#                  5       nSSS5        O8SSKnUR&                  R)                  S
5       nUR#                  5       nSSS5        UR                  S5      (       a  UR                  SS5      S   n UR+                  UR	                  UR                  UR                  5       5      5      5        U(       a  US   c  gUS   nU R                  S5      (       a  U R                  SS5      S   n UR                  U 5      n	U(       a  UR-                  U	5        g[/        UR1                  U	5      5      $ ! [         a     gf = f! , (       d  f       GN
= f! , (       d  f       GN= f! [         a    UR+                  S5         Nf = f)a=  Return if OME-XML is valid according to XMLSchema.

Parameters:
    omexml:
        OME-XML string to validate.
    omexsd:
        Content of OME-XSD schema to validate against.
        By default, the 2016-06 OME XMLSchema is downloaded on first
        run.
    assert\_:
        Raise AssertionError if validation fails.

Returns:
    ``True`` if validation passed.
    ``False`` if validation failed and ``assert\_`` is ``False``.
    ``None`` if the XMLSchema could not be loaded.

Raises:
    AssertionError:
        Validation failed and ``assert\_`` is ``True``.

r   r  N   <?xml   >rY   rK  zome.xsdrE  z:https://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd<?xmlrr   T)r  r  r  r  	XMLSchemar
  r  r  r   r  r  rE  r   rG  __file__rF  rD  r   urllib.requestrequesturlopenr   r  r   r  )
r   omexsdr  r  r  r  omexsd_pathrl  urllibr  s
             rv   r  OmeXml.validate-:  s   < 	  **dA.r2)9)9&--/)JK
 nnG ggllGGOOH-y 77>>+..k40B!# 10 *//6 !#	
 $$X..#\\$226F)NN(8(8(IJ gaj0QZFW%%\\#q)"-F'NN4 FOOD)**Q   10
  ! )NN4()s;   .H, /H<(I-=I  ,
H98H9<
I
I I>=I>)r   rg   r6  r   )r   r3  r   rE  r|  1tuple[int, int, int, int, int, int] | StoredShaper  rQ  r   rg   r6  r   )r  r   r6  rz   rK  )rO  rJ  r6  rz   ry   )r   r   r   rz   r  rQ  r6  rz   )r   r   r  rz   r6  rz   r  )
r  r3  r  rg   r   r   r   rz   r6  rz   )r   r   rH
  r3  r  rz   r6  rz   )
r   rM  r|  r  r  rQ  r   r   r6  tuple[str, int])
r  rz   r   rM  r   r   r  r	  r6  ztuple[dict[str, Any], str])
rN  rg   rh  r   r  rz   r  r>  r6  rz   )
ra  rg   r  r   r\  r   r  r   r6  rz   )r   r*  ri  rz   r6  r   )r   rg   r6  rz   )r   r   r  r	  r6  r   )r  r9  r   rz   r  r   r6  r%  )r  r  r  r  r  rG  rL  r  rn  r>  r  r+  r  rN  r  r  r
  r  r  r  r  r  r  r  r  r  r  r  r   rt   ru   rv   r   r   t6  s*   'RI !&#(#
I
I#%G %)3b  w w  w  G	w  w  w  
w r /4 
:7* , , CG; ;(+;6@;	; ; 1 1 
 !4 	4
 4 44 
4 4. 3 33 	3
 
3 3, ddFd d !	d
 
d dLN N  N  !	N 
 #N  
$N `  # # #  # 	 #
 
 #  #D ,%,%,% ,% 	,%
 
,% ,%\+
Z"?H
:T&T9BT	Tl   $M+
 M+ M+M+
 M+ 
M+ M+ru   r   c                      \ rS rSr% SrS\S'   S\S'   SS jr\SS j5       r\SS	 j5       r	\SS
 j5       r
\SS j5       rSrg)CompressionCodeci~:  zMap :py:class:`COMPRESSION` value to encode or decode function.

Parameters:
    encode: Return encode functions if ``True``, else decode functions.

dict[int, Callable[..., Any]]_codecsr   _encodec              >    S[         0U l        [        U5      U l        g r*  identityfuncr  r   r  rk  rg  s     rv   rn  CompressionCodec.__init__:      <(F|ru   c               X   XR                   ;   a  U R                   U   $  U=S:X  a*    U R                  (       a  [        e[        R                  nGO=S:X  a*    U R                  (       a  [        e[        R
                  nGO=S:X  a*    U R                  (       a  [        e[        R                  nGO=S:X  a6    U R                  (       a  [        R                  nGO[        R                  nGO==S:X  a  O=S:X  a  O	=S:X  a  O  OC    U R                  (       a  US;   a  [        e[        R                  nGO7[        R                  nGO%==S	:X  a  O=S
:X  a  O
=S:X  a  O  GO    [        [        S5      (       aT  [        R                  R                  (       a5  U R                  (       a  [        R                  nGO[        R                  nGO[        [        S5      (       aT  [        R                   R                  (       a5  U R                  (       a  [        R"                  nGOJ[        R$                  nGO8 SSKJn  U R                  (       a  UR"                  nGOUR$                  nGO=S:X  a6    U R                  (       a  [        R,                  nGO[        R.                  nGO==S:X  a  O=S:X  a  O=S:X  a  O	=S:X  a  O  O7    U R                  (       a  [        R0                  nGO[        R2                  nGOr=S:X  a6    U R                  (       a  [        R4                  nGOH[        R6                  nGO6=S:X  a6    U R                  (       a  [        R8                  nGO[        R:                  nGO=S:X  a    [        [        S5      (       aT  [        R<                  R                  (       a5  U R                  (       a  [        R>                  nGO[        R@                  nGO SSKJn  U R                  (       a  UR>                  nGOdUR@                  nGOV=S:X  a6    U R                  (       a  [        RB                  nGO,[        RD                  nGO==S:X  a  O	=S:X  a  O  O7    U R                  (       a  [        RF                  nGO[        RH                  nGO=S:X  a6    U R                  (       a  [        RJ                  nGO[        RL                  nGO==S:X  a  O	=S :X  a  O  O    [        [        S!5      (       aT  [        RN                  R                  (       a5  U R                  (       a  [        RP                  nGO,[        RR                  nGO SSKJn  U R                  (       a  URP                  nOURR                  nO==S":X  a  O	=S#:X  a  O  O5    U R                  (       a  [        RT                  nO[        RV                  nO==S$:X  a  O=S%:X  a  O	=S&:X  a  O  O*    U R                  (       a  [        e[        RX                  nO`=S':X  a  O	=S(:X  a  O  O4  U R                  (       a  [        RZ                  nO-[        R\                  nO  [_        U5      < S)3n[c        U5      eX R                   U'   U$ ! [*         a    SSKn GNRf = f! [*         a    SSKn GNf = f! [*         a    SSKn GN^f = f! [`         a    U S*3n Nkf = f! [d        [*        4 a   n[_        U5      < S+3n[c        U5      UeSnAf[         a   n[_        U5      < S,3n[c        U5      UeSnAff = f)-zReturn encode or decode function for COMPRESSION value.

Raises:
    KeyError: COMPRESSION value is not supported or requires
        missing 'imagecodecs' package.

rT  r   r  r  r  r  r  >   r  r  rP  r  r  DEFLATEr  rY   rZ   r   Nr  r  r  r  r  r  r  r  LZMAr  r  r  r  r  n  ZSTDr  o  r  rj  rk  r  r  r^  z is not a known COMPRESSION# requires the 'imagecodecs' package not implemented)3r  r  r   r(  r'  r  r(  
lzw_encode
lzw_decodejpeg_encoder  r   r  	availabledeflate_encodedeflate_decoder  zlib_encodezlib_decoder=  r[   r  packbits_encodepackbits_decodejpeg2k_encodejpeg2k_decodelerc_encodelerc_decodejpeg8_encodejpeg8_decoder  lzma_encodelzma_decode
png_encode
png_decodejpegxr_encodejpegxr_decodejetraw_encodejetraw_decoder  zstd_encodezstd_decodewebp_encoder  r  jpegxl_encodejpegxl_decoder   r   r  r   )rk  r   codecr[   r   r  s         rv   r  CompressionCodec.__getitem__:  s    ,,<<$$T	)||11'77E||11'88E||11'88E|| + 6 6 + 6 6"QU]||*,"55 + 7 7 + 7 7&Q&Y77'//99<<$/$>$>E$/$>$>EV44',,66<<$/$;$;E$/$;$;E06  <<$0$<$<E$0$<$<E|| + ; ; + ; ;2UUUU2|| + 9 9 + 9 9|| + 7 7 + 7 7|| + 8 8 + 8 8V44',,66<<$/$;$;E$/$;$;E06  <<$0$<$<E$0$<$<E|| + 6 6 + 6 6"UU]|| + 9 9 + 9 9|| + 9 9 + 9 9"UU]V44',,66<<$/$;$;E$/$;$;E06  <<$0$<$<E$0$<$<E"UU]|| + 7 7 + 7 7*UUU*||11'22EU]|| + 9 9 + 9 9B!,S!1 4NC #3-' "SQ  + 0/0L  + 0/0B  + 0/0. & B!$%@AB , 	) %((KLC3-S(" 	) %((89C3-S(	)s  /[ .[ .[ 1([ [ -A[ 6[ A0[ :[ A[ #[ 6Y= <[ [ )([ [ %A[ )[ ;([ %[ 7([ ![ 3A[ [ $Z *[ 	[ ([ [ 4[ 	[ ([ [ A([ [ Z' [ 8[ 4[ :[ A[ 2[  [ [ Z< "[ =Z[ Z[ Z$ [ #Z$$[ 'Z95[ 8Z99[ <[[ [[ \)![<<\)	\$$\)c               .     X     g! [          a     gf = fNFTr  r  s     rv   rF	  CompressionCodec.__contains__2;  %    	I   		    
c                ,    [        U R                  5      $ ry   r  r  r  s    rv   r  CompressionCodec.__iter__;;      DLL!!ru   c                ,    [        U R                  5      $ ry   r   r  r  s    rv   r  CompressionCodec.__len__?;      4<<  ru   r  r  Nrg  r   r6  r   r   r   r6  zCallable[..., Any]r   rg   r6  r   r6  zIterator[int]rK  r  r  r  r  r  rL  rn  rb   r  rF	  r  r  r   rt   ru   rv   r  r  ~:  sl     +*M$ a aF   " " ! !ru   r  .c                      \ rS rSr% SrS\S'   S\S'   SS jr\SS j5       r\SS	 j5       r	\SS
 j5       r
\SS j5       rSrg)PredictorCodeciD;  zMap :py:class:`PREDICTOR` value to encode or decode function.

Parameters:
    encode: Return encode functions if ``True``, else decode functions.

r  r  r   r  c              >    S[         0U l        [        U5      U l        g r*  r  r  s     rv   rn  PredictorCodec.__init__P;  r  ru   c               2   XR                   ;   a  U R                   U   $  U=S:X  a4    U R                  (       a  [        R                  nO[        R                  nO=S:X  a4    U R                  (       a  [        R
                  nO[        R                  nO=S:X  a    U R                  (       a  SS jnOSS jnO{=S:X  a    U R                  (       a  SS jnO]SS	 jnOW=S
:X  a    U R                  (       a  SS jnO9SS jnO3S:X  a  U R                  (       a  SS jnOSS jnO U S3n[        U5      eX R                   U'   U$ ! [         a   n[        U5      < S3n[        U5      UeSnAf[         a   n[        U5      < S3n[        U5      UeSnAff = f)zReturn encode or decode function for PREDICTOR value.

Raises:
    KeyError: PREDICTOR value is not supported or requires
        missing 'imagecodecs' package.

rT  r   r  Nc                .    [         R                  " XUSS9$ NrT  r  r   distr(  delta_encoder  r  r   s      rv   r  )PredictorCodec.__getitem__.<locals>.codeco;      #.#;#; $Sq$ ru   c                .    [         R                  " XUSS9$ r  r(  delta_decoder  s      rv   r  r  v;  r  ru   r  c                .    [         R                  " XUSS9$ Nr  r  r  r  s      rv   r  r  ~;  r  ru   c                .    [         R                  " XUSS9$ r  r  r  s      rv   r  r  ;  r  ru   r  c                .    [         R                  " XUSS9$ r  r(  floatpred_encoder  s      rv   r  r  ;      #.#?#? $Sq$ ru   c                .    [         R                  " XUSS9$ r  r(  floatpred_decoder  s      rv   r  r  ;  r  ru   r  c                .    [         R                  " XUSS9$ r  r  r  s      rv   r  r  ;  r  ru   c                .    [         R                  " XUSS9$ r  r  r  s      rv   r  r  ;  r  ru   z is not a known PREDICTORr  r  )rK  N)r  r  r(  r  r  r  r  r  r   r   r   )rk  r   r  r   r  s        rv   r  PredictorCodec.__getitem__T;  sB    ,,<<$$P	)|| + 8 8 + 8 8|| + < < + < <||
 ||
 ||
 ||
  E!:;C"3-' "S  	)s^&&IJC3-S(" 	)s^&&67C3-S(	)sk   )E 
E (E E E 3E 9E E E ;E E E #E 
FE))F6FFc               .     X     g! [          a     gf = fr  r  r  s     rv   rF	  PredictorCodec.__contains__;  r  r  c                ,    [        U R                  5      $ ry   r  r  s    rv   r  PredictorCodec.__iter__;  r  ru   c                ,    [        U R                  5      $ ry   r  r  s    rv   r  PredictorCodec.__len__;  r  ru   r  Nr  r  r  r  rK  r  rt   ru   rv   r  r  D;  sl     +*M$ ] ]~   " " ! !ru   r  c                      \ rS rSrSrSr Sr Sr Sr Sr	 Sr
 S	r S
r Sr Sr Sr Sr Sr Sr Sr Sr Sr SrSrg)r   i;  zTIFF tag data types.rY   rT  r   r  r  r  r  rP  r;  r  r>  r  r     r  r  r  r  rt   N)r  r  r  r  r  BYTEASCIISHORTLONGRATIONALSBYTE	UNDEFINEDSSHORTSLONG	SRATIONALFLOATDOUBLEIFDUNICODECOMPLEXLONG8SLONG8IFD8r   rt   ru   rv   r   r   ;  s    D!EFE"D"HNEI/F E ILE0F0
C%G)G3E,F*D/ru   r   c                  D   \ rS rSrSrSr SrSrSrSr	Sr
Sr SrS	r S
r SrSrSrSrSrSr SrSrSrSrSrSrSr SrSrSrSrSr Sr!Sr"Sr#S r$S!r% S"r& S#r' S$r( S%r)S&r*S'r+S(r,S)r- S*r.S+r/S,r0S-r1S.r2S/r3 S0r4S1r5 S2r6S3r7S4r8 S5r9 S6r: S7r; S8r< S9r= S:r> S;r? S<r@S=rAS>rBSBS? jrCS@rDgA)Cr   i;  zDValues of Compression tag.

Compression scheme used on image data.

rY   rT  r   r  r  r  r  rP  r;  r  c   g   r  r  i  i  i  i  i  i  r  i)  i  i  i  i  i  i  r  i  r  r  r  r  ie  it  iu  i  r  i  i  i  i  i  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rj  rk  c                    U S:  $ r*  rt   r  s    rv   r  COMPRESSION.__bool__P<      axru   rt   Nr  )Er  r  r  r  r  r   CCITTRLE	CCITTFAX3CCITT_T4	CCITTFAX4CCITT_T6LZWr  JPEGADOBE_DEFLATEJBIG_BW
JBIG_COLORJPEG_99IMPACJ	KODAK_262JPEGXR_NDPINEXTSONY_ARW
PACKED_RAWSAMSUNG_SRWCCIRLEWSAMSUNG_SRW2PACKBITSTHUNDERSCANIT8CTPADIT8LWIT8MPIT8BL	PIXARFILMPIXARLOGr  DCSAPERIO_JP2000_YCBCJPEG_2000_LOSSYAPERIO_JP2000_RGBALT_JPEGJBIGSGILOGSGILOG24LURADOCJPEG2000	NIKON_NEFJBIG2
MDI_BINARYMDI_PROGRESSIVE
MDI_VECTORLERC
JPEG_LOSSYr  ZSTD_DEPRECATEDWEBP_DEPRECATEDPNGJPEGXRJETRAWr  WEBPJPEGXLPIXTIFF
JPEGXL_DNGEER_V0EER_V1EER_V2r  r   rt   ru   rv   r   r   ;  s    D#HIHIH
CEDMGJGFIK"DHJKGLH&KHEEEIHG
C)O('H
 DFHGHIEJOJD0JD,OO
CAF/FDDFGJFFFru   r   c                  D    \ rS rSrSrSr Sr Sr SrSr	Sr
S	rSS
 jrSrg)r   iT<  ziValues of Predictor tag.

A mathematical operator that is applied to the image data before
compression.

rY   rT  r   r  r  r  r  c                    U S:  $ r*  rt   r  s    rv   r  PREDICTOR.__bool__g<  r  ru   rt   Nr  )r  r  r  r  r  r   
HORIZONTALFLOATINGPOINTHORIZONTALX2HORIZONTALX4FLOATINGPOINTX2FLOATINGPOINTX4r  r   rt   ru   rv   r   r   T<  s:     D.J"M1LLOOru   r   c                  f    \ rS rSrSrSr Sr Sr Sr Sr	Sr
 S	r S
rSrSrSr SrSrSrSrSrSrg)r   ik<  zIValues of PhotometricInterpretation tag.

The color space of the image.

r   rY   rT  r   r  r  r  rP  r;  r  #  L  M  r    /  rt   N)r  r  r  r  r  rG  rF  rH  rJ  r^  	SEPARATEDrI  CIELABICCLABITULABr]  LOGLLOGLUV
LINEAR_RAW	DEPTH_MAPSEMANTIC_MASKr   rt   ru   rv   r   r   k<  sn     JAJA
C1G9DIGEJFFF
CDFJIMru   r   c                  @    \ rS rSrSrSr Sr Sr Sr Sr	 Sr
 S	rS
rg)r   i<  zOValues of NewSubfileType tag.

A general indication of the kind of the image.

r   rY   rT  r  rP  r  r  rt   N)r  r  r  r  r  r
  REDUCEDIMAGEPAGEr^  MACROENHANCEDDNGr   rt   ru   rv   r   r   <  s>     I-L?D3D7EJH.
Cru   r   c                  (    \ rS rSrSrSrSrSrSrSr	g)	r
   i<  z%Values of deprecated SubfileType tag.r   rY   rT  r   rt   N)
r  r  r  r  r  r
  IMAGErn  ro  r   rt   ru   rv   r
   r
   <  s    /IELDru   r
   c                  "    \ rS rSrSrSr SrSrg)r	   i<  zDValues of FillOrder tag.

The logical order of bits within a byte.

rY   rT  rt   N)r  r  r  r  r  MSB2LSBLSB2MSBr   rt   ru   rv   r	   r	   <  s     GIG?ru   r	   c                  8    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrg)r   i<  z`Values of Orientation tag.

The orientation of the image with respect to the rows and columns.

rY   rT  r   r  r  r  r  rP  rt   N)r  r  r  r  r  TOPLEFTTOPRIGHTBOTRIGHTBOTLEFTLEFTTOPRIGHTTOPRIGHTBOTLEFTBOTr   rt   ru   rv   r   r   <  s1     GHHGGHHGru   r   c                  "    \ rS rSrSrSr SrSrg)r   i<  zXValues of PlanarConfiguration tag.

Specifies how components of each pixel are stored.

rY   rT  rt   N)r  r  r  r  r  rK  rL  r   rt   ru   rv   r   r   <  s     FEHAru   r   c                  @    \ rS rSrSrSr Sr Sr Sr Sr	 SS jr
S	rg
)r   i<  zYValues of ResolutionUnit tag.

The unit of measurement for XResolution and YResolution.

rY   rT  r   r  r  c                    U S:  $ r*  rt   r  s    rv   r  RESUNIT.__bool__<  r  ru   rt   Nr  )r  r  r  r  r  r   rn  
CENTIMETER
MILLIMETER
MICROMETERr  r   rt   ru   rv   r   r   <  s6     D*DJJJru   r   c                  (    \ rS rSrSrSr Sr SrSrg)r   i<  zMValues of ExtraSamples tag.

Interpretation of extra components in a pixel.

r   rY   rT  rt   N)	r  r  r  r  r  UNSPECIFIED
ASSOCALPHA
UNASSALPHAr   rt   ru   rv   r   r   <  s!     KJ9J"ru   r   c                  :    \ rS rSrSrSr Sr Sr Sr Sr	 Sr
S	rg
)r   i<  z?Values of SampleFormat tag.

Data type of samples in a pixel.

rY   rT  r   r  r  r  rt   N)r  r  r  r  r  r  INTr  VOID
COMPLEXINTCOMPLEXIEEEFPr   rt   ru   rv   r   r   <  s9     D
CFDJM!ru   r   c                  .    \ rS rSrSrSr Sr Sr SrSr	g)	r   i=  zEZarrStore chunk modes.

Specifies how to chunk data in Zarr stores.

r   rY   rT  r   rt   N)
r  r  r  r  r  STRILEPLANEro  FILEr   rt   ru   rv   r   r   =  s)     F!ED!D!ru   r   c                     \ rS rSr% Sr\SDS j5       r\SDS j5       r\SDS j5       r\SDS j5       r	\SDS j5       r
\SES j5       r\  SFS	 j5       r\SGS
 j5       r\SGS j5       r\SGS j5       r\SHS j5       r\SIS j5       r\SES j5       r\SES j5       r\SES j5       r\SES j5       r\SJS j5       r\SHS j5       r\SKS j5       r\SLS j5       r\SMS j5       r\SMS j5       r\SMS j5       r\SMS j5       r\SNS j5       r\  SOS j5       r\SPS j5       r \SPS j5       r!\SQS j5       r"\SRS  j5       r#\SSS! j5       r$\SSS" j5       r%\&SPS# j5       r'\&STS$ j5       r(\&SUS% j5       r)\&SUS& j5       r*\&  SVS' j5       r+\&SHS( j5       r,\&SPS) j5       r-\&SHS* j5       r.\&SHS+ j5       r/\&SHS, j5       r0\&SHS- j5       r1\&SHS. j5       r2\S/ 5       r3\S0 5       r4\&S1 5       r5\&STS2 j5       r6\&STS3 j5       r7\&STS4 j5       r8\&STS5 j5       r9\&SUS6 j5       r:\&SUS7 j5       r;\&SWS8 j5       r<\&SPS9 j5       r=\&SXS: j5       r>\&SYS; j5       r?\SZS= j5       r@\SZS> j5       rA\SZS? j5       rBS@rCS<\DSA'   SBrEgC)[r   i7=  z@Delay-loaded constants, accessible via :py:attr:`TIFF` instance.c                &    [        SSSSSSSSS	SS
9
$ )z!32-bit little-endian TIFF format.rR  rs   r  r	  rT  <Hr  r	  z<I4s
rn  r   rD  rg  r'  rC  rE  r$  r%  r(  r   r  s    rv   ra  _TIFF.CLASSIC_LE:=  /      
 	
ru   c                &    [        SSSSSSSSS	SS
9
$ )z32-bit big-endian TIFF format.rR  rr   r  z>IrT  >Hr  >HHz>I4sr  r  r  s    rv   rc  _TIFF.CLASSIC_BEJ=  r  ru   c                &    [        SSSSSSSSSSS9
$ )	z!64-bit little-endian TIFF format.rO  rs   rP  r  r	  r	  z<Q8sr  r  r  s    rv   r`  _TIFF.BIG_LEZ=  r  ru   c                &    [        SSSSSSSSSSS9
$ )	z64-bit big-endian TIFF format.rO  rr   rP  z>Qr	  r  z>Q8sr  r  r  s    rv   rb  _TIFF.BIG_BEj=  r  ru   c                &    [        SSSSSSSSS	S
S9
$ )z532-bit little-endian TIFF format with 64-bit offsets.rR  rs   rP  r  rT  r  r  r	  z<I8sr  r  r  r  s    rv   rf  _TIFF.NDPI_LEz=  r  ru   c                    [        S5      $ )z?Registry of TIFF tag codes and names from TIFF6, TIFF/EP, EXIF.(  )r>  ProcessingSoftware)r  NewSubfileType)r  SubfileType)r  
ImageWidth)r  ImageLength)r  BitsPerSample)r  Compression)r  PhotometricInterpretation)i  Thresholding)i  	CellWidth)i	  
CellLength)
  	FillOrder)i  DocumentName)r  ImageDescription)r  r  )i  r  )r  StripOffsets)  Orientation)r  SamplesPerPixel)r  RowsPerStrip)r  StripByteCounts)i  MinSampleValue)i  MaxSampleValue)r  XResolution)r  YResolution)r  PlanarConfiguration)r  PageName)i  	XPosition)i  	YPosition)   FreeOffsets)i!  FreeByteCounts)i"  GrayResponseUnit)i#  GrayResponseCurve)r  	T4Options)i%  	T6Options)r  ResolutionUnit)i)  
PageNumber)i,  ColorResponseUnit)r  TransferFunction)r  r  )r  rh  )i;  Artist)i<  HostComputer)r  	Predictor)i>  
WhitePoint)i?  PrimaryChromaticities)r  ColorMap)iA  HalftoneHints)r  	TileWidth)r  
TileLength)r  TileOffsets)r  TileByteCounts)iF  BadFaxLines)iG  CleanFaxData)iH  ConsecutiveBadFaxLines)r  SubIFDs)iL  InkSet)iM  InkNames)iN  NumberOfInks)iP  DotRange)iQ  TargetPrinter)r  ExtraSamples)r  SampleFormat)iT  SMinSampleValue)iU  SMaxSampleValue)iV  TransferRange)iW  ClipPath)iX  XClipPathUnits)iY  YClipPathUnits)iZ  Indexed)r  
JPEGTables)i_  OPIProxy)  GlobalParametersIFD)i  ProfileType)i  
FaxProfile)i  CodingMethods)i  VersionYear)i  
ModeNumber)i  Decode)i  DefaultImageColor)i  
T82Options)i  r  )r	  JPEGProc)re  JPEGInterchangeFormat)rf  JPEGInterchangeFormatLength)i  JPEGRestartInterval)i  JPEGLosslessPredictors)i  JPEGPointTransforms)i  JPEGQTables)i  JPEGDCTables)i	  JPEGACTables)i  YCbCrCoefficients)r  YCbCrSubSampling)  YCbCrPositioning)r  ReferenceBlackWhite)i/  StripRowCounts)r~  XMP)i  GDIGamma)i  ICCProfileDescriptor)i  SRGBRenderingIntent)i   
ImageTitle)i  SiffCompress)i  USPTO_Miscellaneous)r  AndorId)i  AndorTemperature)i  AndorExposureTime)i  AndorKineticCycleTime)i  AndorAccumulations)i  AndorAcquisitionCycleTime)i  AndorReadoutTime)i  AndorPhotonCounting)i  AndorEmDacLevel)i  AndorFrames)i   AndorHorizontalFlip)i!  AndorVerticalFlip)i"  AndorClockwise)i#  AndorCounterClockwise)i(  AndorVerticalClockVoltage)i)  AndorVerticalShiftSpeed)i+  AndorPreAmpSetting)i,  AndorCameraSerial)i/  AndorActualTemperature)i0  AndorBaselineClamp)i1  AndorPrescans)i2  
AndorModel)i3  AndorChipSizeX)i4  AndorChipSizeY)iP  AndorBaselineOffset)if  AndorSoftwareVersion)iFG  Rating)iGG  
XP_DIP_XML)iHG  
StitchInfo)iIG  RatingPercent)iP  ResolutionXUnit)iP  ResolutionYUnit)iP  ResolutionXLengthUnit)iP  ResolutionYLengthUnit)iP  
PrintFlags)iP  PrintFlagsVersion)iP  PrintFlagsCrop)iP  PrintFlagsBleedWidth)i	P  PrintFlagsBleedWidthScale)i
P  HalftoneLPI)iP  HalftoneLPIUnit)iP  HalftoneDegree)iP  HalftoneShape)iP  HalftoneMisc)iP  HalftoneScreen)iP  JPEGQuality)iP  GridSize)iP  ThumbnailFormat)iP  ThumbnailWidth)iP  ThumbnailHeight)iP  ThumbnailColorDepth)iP  ThumbnailPlanes)iP  ThumbnailRawBytes)iP  ThumbnailSize)iP  ThumbnailCompressedSize)iP  ColorTransferFunction)iP  ThumbnailData)i P  ThumbnailImageWidth)i!P  ThumbnailImageHeight)i"P  ThumbnailBitsPerSample)i#P  ThumbnailCompression)i$P  ThumbnailPhotometricInterp)i%P  ThumbnailImageDescription)i&P  ThumbnailEquipMake)i'P  ThumbnailEquipModel)i(P  ThumbnailStripOffsets)i)P  ThumbnailOrientation)i*P  ThumbnailSamplesPerPixel)i+P  ThumbnailRowsPerStrip)i,P  ThumbnailStripBytesCount)i-P  ThumbnailResolutionX)i.P  ThumbnailResolutionY)i/P  ThumbnailPlanarConfig)i0P  ThumbnailResolutionUnit)i1P  ThumbnailTransferFunction)i2P  ThumbnailSoftwareUsed)i3P  ThumbnailDateTime)i4P  ThumbnailArtist)i5P  ThumbnailWhitePoint)i6P  ThumbnailPrimaryChromaticities)i7P  ThumbnailYCbCrCoefficients)i8P  ThumbnailYCbCrSubsampling)i9P  ThumbnailYCbCrPositioning)i:P  ThumbnailRefBlackWhite)i;P  ThumbnailCopyRight)iAP  InteroperabilityIndex)iBP  InteroperabilityVersion)iP  LuminanceTable)iP  ChrominanceTable)i Q  
FrameDelay)iQ  	LoopCount)iQ  GlobalPalette)iQ  IndexBackground)iQ  IndexTransparent)iQ  	PixelUnit)iQ  PixelPerUnitX)iQ  PixelPerUnitY)iQ  PaletteHistogram)r  SonyRawFileType)i2p  VignettingCorrParams)i5p  ChromaticAberrationCorrParams)i7p  DistortionCorrParams)i  ImageID)i  WangTag1)i  WangAnnotation)i  WangTag3)i  WangTag4)i  ImageReferencePoints)i  RegionXformTackPoint)i  WarpQuadrilateral)i  AffineTransformMat)i  Matteing)i  DataType)r  
ImageDepth)r  	TileDepth)i  ImageFullWidth)i  ImageFullLength)i  TextureFormat)i  TextureWrapModes)i  FieldOfViewCotangent)i  MatrixWorldToScreen)i  MatrixWorldToCamera)i}  Model2)i  CFARepeatPatternDim)i  
CFAPattern)i  BatteryLevel)i  KodakIFD)i  rB  )i  FNumber)i  	Copyright)r  	MDFileTag)i  MDScalePixel)i  MDColorTable)i  	MDLabName)i  MDSampleInfo)i  
MDPrepDate)i  
MDPrepTime)i  MDFileUnits)i  NiffRotation)i  NiffNavyCompression)i  NiffTileIndex)r  
OlympusINI)r*  ModelPixelScaleTag)r  
OlympusSIS)i5  AdventScale)i6  AdventRevision)r  UIC1tag)r  UIC2tag)r  UIC3tag)r  UIC4tag)黃  IPTCNAA)iB  ExtendedTagsOffset)i~  IntergraphPacketData)i  IntergraphFlagRegisters)r'  IntergraphMatrixTag)i  INGRReserved)r,  ModelTiepointTag)郄  
LeicaMagic)i  Site)i  ColorSequence)i  	IT8Header)i  RasterPadding)i  BitsPerRunLength)i  BitsPerExtendedRunLength)i  
ColorTable)i  ImageColorIndicator)i  BackgroundColorIndicator)i  ImageColorValue)i  BackgroundColorValue)i  PixelIntensityRange)i  TransparencyIndicator)i  ColorCharacterization)i  HCUsage)i  TrapIndicator)i  CMYKEquivalent)r  CZ_SEM)ih  	AFCP_IPTC)i  PixelMagicJBIGOptions)iׅ  JPLCartoIFD)iJ  IPLAB)r.  ModelTransformationTag)i  WB_GRGBLevels)i  LeafData)r  	MM_Header)r  MM_Stamp);  
MM_Unknown)iI  ImageResources)R  MM_UserBlock)r  
CZ_LSMINFO)i  ExifTag)r  InterColorProfile)r  FEI_SFEG)r  
FEI_HELIOS)i{  	FEI_TITAN)i  FXExtensions)i  MultiProfiles)i  
SharedData)i  
T88Options)i  MarCCD)i  
ImageLayer)r"  GeoKeyDirectoryTag)鰇  GeoDoubleParamsTag)r&  GeoAsciiParamsTag)i  JBIGOptions)i  rP  )i"  ExposureProgram)i$  SpectralSensitivity)%  GPSTag)r  OlympusSIS2)'  ISOSpeedRatings)r  PhotographicSensitivity)i(  OECF)i)  	Interlace)i*  TimeZoneOffset)i+  SelfTimerMode)i0  SensitivityType)i1  StandardOutputSensitivity)i2  RecommendedExposureIndex)i3  ISOSpeed)i4  ISOSpeedLatitudeyyy)i5  ISOSpeedLatitudezzz)i\  HylaFAXFaxRecvParams)i]  HylaFAXFaxSubAddress)i^  HylaFAXFaxRecvTime)i_  FaxDcs)iq  FedexEDR)i  
LeafSubIFD)i  	Aphelion1)i  	Aphelion2)i  AphelionInternal)   ExifVersion)  DateTimeOriginal)  DateTimeDigitized)	  GooglePlusUploadCode)  
OffsetTime)i  OffsetTimeOriginal)i  OffsetTimeDigitized)r  TVX_Unknown)i  TVX_NumExposure)i  TVX_NumBackground)r  TVX_ExposureTime)r  TVX_BackgroundTime)i  r  )r   
TVX_SubBpp)i
  TVX_SubWide)i  TVX_SubHigh)i  TVX_BlackLevel)i  TVX_DarkCurrent)i  TVX_ReadNoise)i  TVX_DarkCurrentNoise)r  TVX_BeamMonitor)i   TVX_UserVariables)i  ComponentsConfiguration)i  CompressedBitsPerPixel)i  ShutterSpeedValue)i  ApertureValue)i  BrightnessValue)i  ExposureBiasValue)i  MaxApertureValue)i  SubjectDistance)i  MeteringMode)i  LightSource)i	  Flash)i
  FocalLength)i  FlashEnergy)i  SpatialFrequencyResponse)i  Noise)i  FocalPlaneXResolution)i  FocalPlaneYResolution)i  FocalPlaneResolutionUnit)i  ImageNumber)i  SecurityClassification)i  ImageHistory)i  SubjectLocation)i  ExposureIndex)r  TIFFEPStandardID)i  SensingMethod)i:  CIP3DataFile)i;  	CIP3Sheet)i<  CIP3Side)i?  StoNits)i|  	MakerNote)i  UserComment)i  
SubsecTime)i  SubsecTimeOriginal)i  SubsecTimeDigitized)i/  MODIText)i0  MODIOLEPropertySetStorage)i1  MODIPositioning)r{  AgilentBinary)iF  AgilentString)r  TVIPS)iK  TVIPS1)iL  TVIPS2)\  ImageSourceData)i   Temperature)i  Humidity)i  Pressure)i  
WaterDepth)i  Acceleration)i  CameraElevationAngle)i@  XPos)A  YPos)B  ZPos)rG  MC_IpWinScal)rG  	RecipName)rI  RecipNumber)iC  
SenderName)iD  Routing)iE  CallerId)iF  TSID)iG  CSID)iH  FaxTime)餜  MC_IdOld)i  
MC_Unknown)  InteroperabilityTag)i  XPTitle)i  	XPComment)i  XPAuthor)i  
XPKeywords)i  	XPSubject)i   FlashpixVersion)i  
ColorSpace)i  PixelXDimension)i  PixelYDimension)i  RelatedSoundFile)i  SamsungRawPointersOffset)i  SamsungRawPointersLength)i  SamsungRawByteOrder)i  SamsungRawUnknown)i  r   )i  r!  )i  r"  )i  r#  )i  r$  )i  r%  )i  r&  )i  r'  )i  r(  )i  r)  )i  r*  )i  zTIFF-EPStandardID)i  r,  )i   
FileSource)i  	SceneType)i  r  )i  CustomRendered)i  ExposureMode)i  WhiteBalance)i  DigitalZoomRatio)i  FocalLengthIn35mmFilm)i  SceneCaptureType)i  GainControl)i  Contrast)i	  
Saturation)i
  	Sharpness)i  DeviceSettingDescription)i  SubjectDistanceRange)i   ImageUniqueID)i0  CameraOwnerName)i1  BodySerialNumber)i2  LensSpecification)i3  LensMake)i4  	LensModel)i5  LensSerialNumber)i`  CompositeImage)ia  SourceImageNumberCompositeImage)ib  !SourceExposureTimesCompositeImage)r  GDAL_METADATA)r{  GDAL_NODATA)i   Gamma)r  NIHImageHeader)i  ExpandSoftware)i  
ExpandLens)i¯  
ExpandFilm)iï  ExpandFilterLens)iį  ExpandScanner)iů  ExpandFlashLamp)i  PixelFormat)i  Transformation)i  Uncompressed)i  	ImageType)i  r  )i  ImageHeight)i  WidthResolution)i  HeightResolution)i  ImageOffset)i  ImageByteCount)i¼  AlphaOffset)iü  AlphaByteCount)iļ  ImageDataDiscard)iż  AlphaDataDiscard)iS  	KodakAPP3)i'  OceScanjobDescription)i(  OceApplicationSelector)i)  OceIdentificationNumber)i*  OceImageLogicCharacteristics)iO  Annotations)r  MC_Id)iq  MC_XYPosition)ir  MC_ZPosition)is  MC_XYCalibration)it  MC_LensCharacteristics)iu  MC_ChannelName)iv  MC_ExcitationWavelength)iw  MC_TimeStamp)x  MC_FrameProperties)i  PrintImageMatching)i?  PCO_RAW)is  OriginalFileName)i  USPTO_OriginalContentType)i  USPTO_RotationCode)i  CR2Unknown1)i  CR2Unknown2)i  CR2CFAPattern)r  LercParameters)r  
DNGVersion)i  DNGBackwardVersion)i  UniqueCameraModel)i  LocalizedCameraModel)i  CFAPlaneColor)i  	CFALayout)i  LinearizationTable)i  BlackLevelRepeatDim)i  
BlackLevel)i  BlackLevelDeltaH)i  BlackLevelDeltaV)i  
WhiteLevel)i  DefaultScale)i  DefaultCropOrigin)i   DefaultCropSize)i!  ColorMatrix1)i"  ColorMatrix2)i#  CameraCalibration1)i$  CameraCalibration2)i%  ReductionMatrix1)i&  ReductionMatrix2)i'  AnalogBalance)i(  AsShotNeutral)i)  AsShotWhiteXY)i*  BaselineExposure)i+  BaselineNoise)i,  BaselineSharpness)i-  BayerGreenSplit)i.  LinearResponseLimit)i/  CameraSerialNumber)i0  LensInfo)i1  ChromaBlurRadius)i2  AntiAliasStrength)i3  ShadowScale)i4  DNGPrivateData)i5  MakerNoteSafety)i@  RawImageSegmentation)iZ  CalibrationIlluminant1)i[  CalibrationIlluminant2)i\  BestQualityScale)i]  RawDataUniqueID)i`  AliasLayerMetadata)i  OriginalRawFileName)i  OriginalRawFileData)i  
ActiveArea)i  MaskedAreas)i  AsShotICCProfile)i  AsShotPreProfileMatrix)i  CurrentICCProfile)i  CurrentPreProfileMatrix)rn  IJMetadataByteCounts)r  
IJMetadata)r0  RPCCoefficientTag)i  ColorimetricReference)i  SRawType)i  PanasonicTitle)i  PanasonicTitle2)i  RSID)i  GEO_METADATA)i  CameraCalibrationSignature)i  ProfileCalibrationSignature)i  ExtraCameraProfiles)i  AsShotProfileName)i  NoiseReductionApplied)i  ProfileName)i  ProfileHueSatMapDims)i  ProfileHueSatMapData1)i  ProfileHueSatMapData2)i  ProfileToneCurve)i  ProfileEmbedPolicy)i  ProfileCopyright)i  ForwardMatrix1)i  ForwardMatrix2)i  PreviewApplicationName)i  PreviewApplicationVersion)i  PreviewSettingsName)i  PreviewSettingsDigest)i  PreviewColorSpace)i  PreviewDateTime)i  RawImageDigest)i  OriginalRawFileDigest)i  SubTileBlockSize)i  RowInterleaveFactor)i%  ProfileLookTableDims)i&  ProfileLookTableData)i@  OpcodeList1)iA  OpcodeList2)iN  OpcodeList3)iO  	FibicsXML)ia  NoiseProfile)ic  	TimeCodes)id  	FrameRate)ir  TStop)i  ReelName)i  OriginalDefaultFinalSize)i  OriginalBestQualitySize)i  OriginalDefaultCropSize)i  CameraLabel)i  ProfileHueSatMapEncoding)i  ProfileLookTableEncoding)i  BaselineExposureOffset)i  DefaultBlackRender)i  NewRawImageDigest)i  RawToPreviewGain)i  	CacheBlob)i  CacheVersion)r  MicroManagerMetadata)i  DefaultUserCrop)i  ZIFmetadata)i  ZIFannotations)rb  DepthFormat)i  	DepthNear)i  DepthFar)i  
DepthUnits)i  DepthMeasureType)i  EnhanceParams)i-  ProfileGainTableMap)i.  SemanticName)i0  SemanticInstanceID)i1  CalibrationIlluminant3)i2  CameraCalibration3)i3  ColorMatrix3)i4  ForwardMatrix3)i5  IlluminantData1)i6  IlluminantData2)i7  IlluminantData3)i8  MaskSubArea)i9  ProfileHueSatMapData3)i:  ReductionMatrix3)i?  	RGBTables)i@  ProfileGainTableMap2)r  C2PAManifestStore)iC  ColumnInterleaveFactor)iD  ImageSequenceInfo)iF  
ImageStats)iG  ProfileDynamicRange)iH  ProfileGroupName)iI  JXLDistance)iJ  	JXLEffort)iK  JXLDecodeSpeed)i  AperioUnknown55000)i  AperioMagnification)i  	AperioMPP)i  AperioScanScopeID)i  
AperioDate)i  Padding)i  OffsetSchema)i  JEOL_Header)i  FlexXMLr%   r  s    rv   r  
_TIFF.TAGS=  s     CE
 E	
ru   c                   0 S[         _S[         _S[        _S[        _S[        _S[        _S[
        _S[        _S	[        _S
[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[         _S["        _S[$        _S[&        _S[        _S[        _S [        _S![        _E$ )"Nr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r>  r  r  rT  r  r  r  r  r  r  r  r  rW  r~  r    i  )read_colormap
read_bytesr  read_uic2tagread_uic3tagread_uic4tagread_cz_semread_mm_headerread_mm_stampr  read_cz_lsminforead_fei_metadataread_tvips_headerread_nih_image_header	read_jsonread_sis_iniread_sisread_exif_ifdread_gps_ifdread_interoperability_ifdr  s    rv   r  _TIFF.TAG_READERSU@  s   
&
&
&

 :&
 <&
 <&
 <&
 <&
 ;&
 >&
 =&
 :&
 :&
  ?!&
" $#&
$ $%&
& $'&
( :)&
* :+&
, (-&
0 :1&
2 :3&
4 :5&
6 :7&
8 99&
: <;&
< 8=&
> =?&
@ <A&
B ,C&
D :E&
F :G&
H :I&
J :K&
 &	
ru   c                    [        S5      $ )N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  re  rf  r  r  r{  rn  r  	frozensetr  s    rv   r  _TIFF.TAG_LOAD@  s     
 	
ru   c                    [        S5      $ )N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rW  r\  r  s    rv   rt  _TIFF.TAG_FILTERED@  s     
 	
ru   c                    [        S5      $ )N)r  r  r  r  r  r  r  r  re  rf  r  r  r  rn  r\  r  s    rv   r  _TIFF.TAG_TUPLE@  s     
 	
ru   c                x    0 SS_SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$S%S&.E$ )'Nr  r   r  rO  r  rP  r  r   r  r   r  rV  r  r   r  r  r  r   r  r   r  r   r  r   r  rR  r  rS  r  rp  r  r   r  r   r   rQ  rT  )r  r  r  rt   r  s    rv   r  _TIFF.TAG_ATTRIBUTES@  s    


 

 
 
 
 
 "
 
 
 
 
  !
" #
$ %
& '
* +
, 1
 	
ru   c                v    [         [        [        [        [        [
        [        [        [        [        [        S.$ )N)r  r  r  r  r  r  r  r  r  r  r  )r   r
   r   r   r	   r   r   r   r   r   r   r  s    rv   r  _TIFF.TAG_ENUM@  s1      !
 	
ru   c                Z    [        S5      nUR                  [        R                  5        U$ )z>Registry of EXIF tags, including private Photoshop Camera RAW.))r  	OwnerName)rj  SerialNumber)rk  Lens)iL  RawFile)iM  	Converter)iN  rk  )iQ  Exposure)iR  Shadows)iS  
Brightness)iT  rp  )iU  rq  )iV  rr  )iW  
Smoothness)iX  MoireFilter)r%   r  r   r  )rk  r  s     rv   	EXIF_TAGS_TIFF.EXIF_TAGSA  s*     
$ 	DIIru   c                    [        S5      $ )z?Registry of private TIFF tags for Hamamatsu NDPI (65420-65458).)*)i,  OffsetHighBytes)i-  ByteCountHighBytes)r  
FileFormat)r  Magnification)i  XOffsetFromSlideCenter)i  YOffsetFromSlideCenter)  ZOffsetFromSlideCenter)i  TissueIndex)r~  r  )  
SlideLabel)i  AuthCode)i  65429)i  65430)i  65431)r  r  )i  65433)i  Fluorescence)i  ExposureRatio)i  RedMultiplier)i  GreenMultiplier)i  BlueMultiplier)rG  FocusPoints)i  FocusPointRegions)r  CaptureMode)i  ScannerSerialNumber)i  65443)i  JpegQuality)i  RefocusInterval)i  FocusOffset)i  
BlankLines)i  FirmwareVersion)i  Comments)i  LabelObscured)i  
Wavelength)i  65452)i  LampAge)i  rB  )i  	FocusTime)i  ScanTime)i  	WriteTime)i  FullyAutoFocus)r>  DefaultGammarD  r  s    rv   r  _TIFF.NDPI_TAGS(A  s     +-
 -	
ru   c                    [        S5      $ )zRegistry of GPS IFD tags.) )r   GPSVersionID)rY   GPSLatitudeRef)rT  GPSLatitude)r   GPSLongitudeRef)r  GPSLongitude)r  GPSAltitudeRef)r  GPSAltitude)r  GPSTimeStamp)rP  GPSSatellites)r;  	GPSStatus)r  GPSMeasureMode)r>  GPSDOP)r  GPSSpeedRef)r  GPSSpeed)r  GPSTrackRef)r  GPSTrack)r  GPSImgDirectionRef)r  GPSImgDirection)r  GPSMapDatum)r  GPSDestLatitudeRef)r	  GPSDestLatitude)r  GPSDestLongitudeRef)   GPSDestLongitude)   GPSDestBearingRef)r  GPSDestBearing)   GPSDestDistanceRef)   GPSDestDistance)   GPSProcessingMethod)   GPSAreaInformation)   GPSDateStamp)   GPSDifferential)   GPSHPositioningErrorrD  r  s    rv   GPS_TAGS_TIFF.GPS_TAGS[A  s     !#
 #	
ru   c                    [        S5      $ )z&Registry of Interoperability IFD tags.))rY   rc  )rT  rd  )r^  RelatedImageFileFormat)i  RelatedImageWidth)i  RelatedImageLengthrD  r  s    rv   IOP_TAGS_TIFF.IOP_TAGSA  s     
 	
ru   c                f    0 SS_SS_SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_$ )z=Map :py:class:`PHOTOMETRIC` to number of photometric samples.r   rY   rT  r   r  r  r  rP  r;  r  r_  r`  ra  r  rb  rc  rt   r  s    rv   rU  _TIFF.PHOTOMETRIC_SAMPLESA  s    
q
q
 q
 q	

 q
 q
 q
 q
 q
 
 1
 1
 1
 1
 1
  1!
 	
ru   c                f    0 SS_SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_$ )z2Map :py:class:`DATATYPE` to Python struct formats.rY   1BrT  1sr   1Hr  1Ir  2Ir  1br  rP  1hr;  1ir  2ir>  1fr  1dr  r  1Qr  1qr  rt   r  s    rv   r  _TIFF.DATA_FORMATSA  s    
t
t
 t
 t	

 t
 t
 t
 t
 t
 
 
 
 
  !
" #
$ %
 	
ru   c                "    SSSSSSSSS	S
SSSS.$ )z(Map NumPy dtype to :py:class:`DATATYPE`.rY   rT  r   r  r  r  rP  r;  r  r>  r  r  r  )r  r  rQ  r  r  r
  r+  r  r  r  r  r/  qrt   r  s    rv   r  _TIFF.DATA_DTYPESA  s5     
 	
ru   c                   0 SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S_S$S_S%S&_S'S_E0 S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_E0 S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_SDS_SES_SFS_SGS&_SHSI_SJSK_ESLSMSNSOSOSPSQSRSSSSQSRST.E$ )Uz>Map :py:class:`SAMPLEFORMAT` and BitsPerSample to NumPy dtype.r  r   r  r  )rY   r   )rY   r  )rY   r  )rY   r  )rY   r  )rY   rP  )rY   r;  rQ  )rY   r  )rY   r>  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  r  )rY   r  )rY   r  )rY   r	  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r  )rY   r)  )rY   r  r/  r  )r  rT  )r  r   r(  )r  r  )r  r  )r  r  )r  rP  )r  r;  )r  r  )r  r>  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r	  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r)  )r  r  )rT  rP  r
  rT  r  r+  r  r  r  r  r  rJ  Dr.  ))rT  r)  )rT  r  )r   r  )r   r  r   r)  )r   r  )r  r  )r  r  )rY   r  r  r  )r  r  )r  r)  )r  r  rt   r  s    rv   r  _TIFF.SAMPLE_DTYPESA  s   X
CX
 CX
 C	X

 CX
 CX
 CX
 CX
 CX
 CX
 SX
 SX
 SX
 SX
 SX
  S!X
" S#X
$ S%X
& S'X
( S)X
* S+X
, S-X
. S/X
0 S1X
2 S3X
4 S5X
6 S7X
8 S9X
: S;X
< S=X
> S?X
@ SAX
B SCX
D SEX
H CIX
J CKX
L CMX
N COX
P CQX
R CSX
T CUX
V CWX
X CYX
Z S[X
\ S]X
^ S_X
` SaX
b ScX
d SeX
f SgX
h SiX
j SkX
l SmX
n SoX
p SqX
r SsX
t SuX
v SwX
x SyX
z S{X
| S}X
~ SX
@ SAX
B SCX
D SEX
F SGX
H SIX
L CMX
N SOX
P oX
 X	
ru   c                    [        SS9$ )z3Map :py:class:`PREDICTOR` value to encode function.Trg  r  r  s    rv   rR  _TIFF.PREDICTORS.B  s     T**ru   c                    [        SS9$ )z3Map :py:class:`PREDICTOR` value to decode function.Fr  r  r  s    rv   r"  _TIFF.UNPREDICTORS3B  s     U++ru   c                    [        SS9$ )z7Map :py:class:`COMPRESSION` value to compress function.Tr  r  r  s    rv   rx  _TIFF.COMPRESSORS8B  s      t,,ru   c                    [        SS9$ )z9Map :py:class:`COMPRESSION` value to decompress function.Fr  r  r  s    rv   r!  _TIFF.DECOMPRESSORS=B  s      u--ru   c                
    1 Sk$ )N>   r  r  r  r  r  r  r  r  r  r  r  rj  rk  r  r  r  r  r  rt   r  s    rv   rQ  _TIFF.IMAGE_COMPRESSIONSBB  s    

 	
ru   c           	     @   0 S[         _S[        _S[        _S[        _S[        _S[
        _S[        _S[        _S	[        _S
[        _S[        _S[        _S[        _S[        _S[        _S[        _S[         _["        [$        [&        [(        [*        [,        [.        S.E$ )zxMap series kind to series parser function.

The order determines dispatch priority in
:py:meth:`TiffFile._get_series`.

r   lsmr  r   r   ndtifffluoviewstksissvsscnqpir@  bifavseerphilips)	scanimageindicanihmdgelgeotiffr  rS  )series_shaped
series_lsmseries_mmstack
series_omeseries_imagejseries_ndtiffseries_fluoview
series_stk
series_sis
series_svs
series_scn
series_qpiseries_ndpi
series_bif
series_avs
series_eerseries_philipsseries_scanimageseries_indica
series_nihseries_mdgelseries_geotiffseries_uniformr  r  s    rv   r  _TIFF.SERIES\B  s    
m
:
 ~
 :	

 m
 m
 
 :
 :
 :
 :
 :
 K
 :
 :
  :!
" ~#
$ *#!%%%1
 	
ru   c                t    0 SS_SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$0E$ )%aZ  Map axes character codes to dimension names.

- **X : width** (image width)
- **Y : height** (image length)
- **Z : depth** (image depth)
- **S : sample** (color space and extra samples)
- **I : sequence** (generic sequence of images, frames, planes, pages)
- **T : time** (time series)
- **C : channel** (acquisition path or emission wavelength)
- **A : angle** (OME)
- **P : phase** (OME. In LSM, **P** maps to **position**)
- **R : tile** (OME. Region, position, or mosaic)
- **H : lifetime** (OME. Histogram)
- **E : lambda** (OME. Excitation wavelength)
- **Q : other** (OME)
- **L : exposure** (FluoView)
- **V : event** (FluoView)
- **M : mosaic** (LSM 6)
- **J : column** (NDTiff)
- **K : row** (NDTiff)

There is no universal standard for dimension codes or names.
This mapping mainly follows TIFF, OME-TIFF, ImageJ, LSM, and FluoView
conventions.

r  rX  r  r  r	  rZ  rS  sampler  r3
  r  rm  r  channelr+  r'  r,  r(  r-  r   rQ  r)  r.  r*  LexposureVeventMmosaicr/  r3  JcolumnKrowrt   r  s    rv   
AXES_NAMES_TIFF.AXES_NAMESB  s    8


 
 	

 
 
 
 
 
 
 
 
 
 
  !
" #
$ %
& '
 	
ru   c                    [         R                  R                  5        VVs0 s H  u  pX!_M	     nnnSUS'   SUS'   U$ s  snnf )zYMap dimension names to axes character codes.

Reverse mapping of :py:attr:`AXES_NAMES`.

r	  rQ  r-  position)r   r/  r`  )rk  r  r   r  s       rv   r>
  _TIFF.AXES_CODESB  sI     /3oo.C.C.EF.E
.EFc
j Gs   ?c                h     SSK Jn  U$ ! [         a     " S S[        R                  5      n U$ f = f)z:py:class:`geodb.GeoKeys`.rY   )GeoKeysc                      \ rS rSrSrg)_TIFF.GEO_KEYS.<locals>.GeoKeysiB  rt   N)r  r  r  r  r   rt   ru   rv   r5  r7  B  s    ru   r5  )geodbr5  r  enumIntEnum)rk  r5  s     rv   rG  _TIFF.GEO_KEYSB  s9    	&   	$,,  	s   
 #11c                :     SSK Jn  U$ ! [         a    0 n U$ f = f)z/Map :py:class:`geodb.GeoKeys` to GeoTIFF codes.rY   )rH  )r8  rH  r  )rk  rH  s     rv   rH  _TIFF.GEO_CODESB  s.    	(   	I	s   
 c                    1 Skn[        [        5       Vs1 s H  nUS S S:X  d  M  USS  U;  d  M  USS  iM      sn$ s  snf )N>   jfifmaskr`   rK
  reducedr   
subsampledr  r   r   )dirr   rk  excluder  s      rv   r  _TIFF.PAGE_FLAGSB  s\    	
 ]
"!u~ "#AB%w"6 AabE"
 	
 
s   >>	>c                    SS1n[        [        5       Vs1 s H  nUS S S:X  d  M  USS  U;  d  M  USS  iM      snR                  [        R                  5      $ s  snf )Nr   
appendabler   r   )rC  r   unionr   r  rD  s      rv   ra  _TIFF.FILE_FLAGSB  sq     l+ ]
"!u~ "#AB%w"6 AabE"
 %
 		! 
s   AA	Ac                
    SS0$ )Nr  a  (?ix)
                # 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}))?
                rt   r  s    rv   FILE_PATTERNS_TIFF.FILE_PATTERNSB  s      	 	 		ru   c                    g)zKnown TIFF file extensions.)r   r"  zome.tifr  r  r   pcorawqptiffptiffptifgelseqr  r  r  zifr@  r  tf8tf2btfr  rt   r  s    rv   FILE_EXTENSIONS_TIFF.FILE_EXTENSIONSB  s    
ru   c                    [         R                   Vs/ s H  nUR                  5        S3SU 34PM     snS/-   $ s  snf )N filesz*.)z	All filesr   )r   rY  rN  )rk  ra  s     rv   FILEOPEN_FILTER_TIFF.FILEOPEN_FILTERC  sT    
 ++
+ 		}F#r#Z0+
   ! 	! 
s   "<c                
    / SQ$ )N):)MagicNumberu4)StructureSizei4)
DimensionXrc  )
DimensionYrc  )
DimensionZrc  )DimensionChannelsrc  )DimensionTimerc  )r~  rc  )
ThumbnailXrc  )
ThumbnailYrc  )
VoxelSizeXf8)
VoxelSizeYrl  )
VoxelSizeZrl  )OriginXrl  )OriginYrl  )OriginZrl  )ScanTypeu2)SpectralScanrs  )
TypeOfDatara  )OffsetVectorOverlayra  )OffsetInputLutra  )OffsetOutputLutra  )OffsetChannelColorsra  )TimeIntervallrl  )OffsetChannelDataTypesra  )OffsetScanInformationra  )OffsetKsDatara  )OffsetTimeStampsra  )OffsetEventListra  )	OffsetRoira  )OffsetBleachRoira  )OffsetNextRecordingra  )DisplayAspectXrl  )DisplayAspectYrl  )DisplayAspectZrl  )DisplayAspectTimerl  )OffsetMeanOfRoisOverlayra  )OffsetTopoIsolineOverlayra  )OffsetTopoProfileOverlayra  )OffsetLinescanOverlayra  )ToolbarFlagsra  )OffsetChannelWavelengthra  )OffsetChannelFactorsra  )ObjectiveSphereCorrectionrl  )OffsetUnmixParametersra  )OffsetAcquisitionParametersra  )OffsetCharacteristicsra  )OffsetPalettera  )TimeDifferenceXrl  )TimeDifferenceYrl  )TimeDifferenceZrl  )InternalUse1ra  )
DimensionPrc  )
DimensionMrc  )DimensionsReserved16i4)OffsetTilePositionsra  )r=  9u4)OffsetPositionsra  rt   r  s    rv   r  _TIFF.CZ_LSMINFO#C  s    >
 >	
ru   c           	         0 S[         _S[        _S[        _S[        _S[        _S[        _SS _S[
        _S	[
        _S
S _S[        _SS _SS _SS _SS _SS _SS _S [        S S S S S S.E$ )NScanInformation
TimeStamps	EventListChannelColors	PositionsTilePositionsVectorOverlayInputLut	OutputLutrz  ChannelDataTypesKsDataRoi	BleachRoiNextRecordingMeanOfRoisOverlayTopoIsolineOverlay)TopoProfileOverlayChannelWavelengthSphereCorrectionChannelFactorsUnmixParametersAcquisitionParametersCharacteristics)read_lsm_scaninforead_lsm_timestampsread_lsm_eventlistread_lsm_channelcolorsread_lsm_positionsread_lsm_lookuptableread_lsm_channeldatatypesread_lsm_channelwavelengthr  s    rv   CZ_LSMINFO_READERS_TIFF.CZ_LSMINFO_READERSfC  s    
0
-
 +
 3	

 +
 /
 T
 ,
 -
 T
  9
 d
 4
 
 T
   !
" !$#
$ #'!; $"#%)#1
 	
ru   c                    SSSSSSSSSSSS.$ )NZCYXCZXCTXTCYXTCZXTZCYX)r   rY   rT  r   r  r  r  r  rP  r;  r  rt   r  s    rv   CZ_LSMINFO_SCANTYPE_TIFF.CZ_LSMINFO_SCANTYPEC  s/     
 	
ru   c                    SSSSSSSS.$ )	Nrd  re  rf  rg  rh  r  r  )r  r  r	  r  r  r,  r)  rt   r  s    rv   CZ_LSMINFO_DIMENSIONS_TIFF.CZ_LSMINFO_DIMENSIONSC  s#     $ 
 	
ru   c                    SSSSS.$ )Nzvarying data typesz8 bit unsigned integerz12 bit unsigned integerz32 bit float)r   rY   rT  r  rt   r  s    rv   CZ_LSMINFO_DATATYPES_TIFF.CZ_LSMINFO_DATATYPESC  s     $'(	
 	
ru   c                    SSSSS.$ )NzOriginal scan datazCalculated dataz3D reconstructionzTopography height map)r   rY   rT  r   rt   r  s    rv   CZ_LSMINFO_TYPEOFDATA_TIFF.CZ_LSMINFO_TYPEOFDATAC  s     $ "&	
 	
ru   c           	         SSSSSSSSS	.$ )
NTracksLasersDetectionChannelsIlluminationChannelsBeamSplittersDataChannelsTimersMarkers)i    i   0i   `r  l      @ l        i   i   rt   r  s    rv   CZ_LSMINFO_SCANINFO_ARRAYS _TIFF.CZ_LSMINFO_SCANINFO_ARRAYSC  s&     ! +.'& !	
 		
ru   c           	         SSSSSSSSS	.$ )
NTrackLaserDetectionChannelIlluminationChannelBeamSplitterDataChannelr)   Marker)i   @i   Pi   pl        l      ` l        i   i   rt   r  s    rv   CZ_LSMINFO_SCANINFO_STRUCTS!_TIFF.CZ_LSMINFO_SCANINFO_STRUCTSC  s&      *-&% 

 
	
ru   c                Z   0 SS_SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_0 S#S$_S%S&_S'S(_S)S*_S+S,_S-S._S/S0_S1S2_S3S4_S5S6_S7S8_S9S:_S;S<_S=S>_S?S@_SASB_SCSD_E0 SESF_SGSH_SISJ_SKSL_SMSN_SOSP_SQSR_SSST_SUSV_SWSX_SYSZ_S[S\_S]S^_S_S`_SaSb_ScSd_SeSf_E0 SgSh_SiSj_SkSl_SmSn_SoSp_SqSr_SsSt_SuSv_SwSx_SySz_S{S|_S}S~_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SGS _GSGS_GSGS_GSGS_GSGS_GS	GS
_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSS_GSS_GSGS _GS!GS"_GS#GS$_GS%GS&_GS'GS(_GS)GS*_GS+GS,_E0 GS-S_GS.S_GS/S_GS0GS1_GS2GS3_GS4GS5_GS6GS7_GS8GS9_GS:GS;_GS<GS=_GS>GS?_GS@GSA_GSBGSC_GSDGSE_GSFGSG_GSHGSI_GSJGSK_E0 GSLGSM_GSNGSO_GSPGS_GSQGS_GSRGSS_GSTS_GSUS_GSVS_GSWGSX_GSYS_GSZS_GS[GS\_GS]GS^_GS_S_GS`S_GSaS_GSbS_E$ (c  Ni  r  i  r  i  Notesi  	Objectivei  ProcessingSummaryi  SpecialScanModei  rr  i  ScanModei	  NumberOfStacksi
  LinesPerPlanei  SamplesPerLinei  PlanesPerVolumei  ImagesWidthi  ImagesHeighti  ImagesNumberPlanesi  ImagesNumberStacksi  ImagesNumberChannelsi  LinscanXySizei  ScanDirectioni  
TimeSeriesi  OriginalScanDatai  ZoomXi  ZoomYi  ZoomZi  Sample0Xi  Sample0Yi  Sample0Zi  SampleSpacingi  LineSpacingi  PlaneSpacingi  
PlaneWidthi   PlaneHeighti!  VolumeDepthi#  Nutationi4  Rotationi5  
Precessioni6  Sample0timei7  StartScanTriggerIni8  StartScanTriggerOuti9  StartScanEventi@  StartScanTimeiA  StopScanTriggerIniB  StopScanTriggerOutiC  StopScanEventiD  StopScanTimeiE  UseRoisiF  UseReducedMemoryRoisiG  UseriH  UseBcCorrectioniI  PositionBcCorrection1iP  PositionBcCorrection2iQ  InterpolationYiR  CameraBinningiS  CameraSupersamplingiT  CameraFrameWidthiU  CameraFrameHeightiV  CameraOffsetXiW  CameraOffsetYiY  	RtBinningiZ  RtFrameWidthi[  RtFrameHeighti\  RtRegionWidthi]  RtRegionHeighti^  	RtOffsetXi_  	RtOffsetYi`  RtZoomia  RtLinePeriodib  Prescanic  ScanDirectionZi  @MultiplexTypei  @MultiplexOrderi  @SamplingModei  @SamplingMethodi  @SamplingNumberi  @Acquirei  @SampleObservationTimei  @TimeBetweenStacksi  @i  @Collimator1Namei  @Collimator1Positioni  @Collimator2Namei  @Collimator2Positioni  @IsBleachTracki  @IsBleachAfterScanNumberi  @BleachScanNumberi  @	TriggerIni  @
TriggerOuti  @IsRatioTracki  @BleachCounti  @SpiCenterWavelengthi  @	PixelTimei!  @CondensorFrontlensi#  @FieldStopValuei$  @IdCondensorAperturei%  @CondensorAperturei&  @IdCondensorRevolveri'  @CondensorFilteri(  @IdTransmissionFilter1i)  @IdTransmission1i0  @IdTransmissionFilter2i1  @IdTransmission2i2  @RepeatBleachi3  @EnableSpotBleachPosi4  @SpotBleachPosxi5  @SpotBleachPosyi6  @SpotBleachPoszi7  @
IdTubelensi8  @IdTubelensPositioni9  @TransmittedLighti:  @ReflectedLighti;  @SimultanGrabAndBleachi<  @BleachPixelTimei  Pi  Pi  PPoweri  pIntegrationModei  pSpecialModei  pDetectorGainFirsti  pDetectorGainLasti  pAmplifierGainFirsti  pAmplifierGainLasti  pAmplifierOffsFirsti  pAmplifierOffsLasti	  pPinholeDiameteri
  pCountingTriggeri  pi  pPointDetectorNamei  pAmplifierNamei  pPinholeNamei  pFilterSetNamei  p
FilterNamei  pIntegratorNamei  pChannelNamei  pDetectorGainBc1i  pDetectorGainBc2i  pAmplifierGainBc1i  pAmplifierGainBc2i  pAmplifierOffsetBc1i   pAmplifierOffsetBc2i!  pSpectralScanChannelsi"  pSpiWavelengthStarti#  pSpiWavelengthStopi&  pDyeNamei'  p	DyeFolderl       l       l       r  l       Aquirel       DetchannelNamel       PowerBc1l       PowerBc2l     ` 	FilterSetl     ` Filterl     ` l       l       l       rU  l       
SampleTypel       r  l       	RatioTypel       RatioTrack1l   	    RatioTrack2l   
    RatioChannel1l       RatioChannel2l       RatioConst1l       RatioConst2l       RatioConst3l       RatioConst4l       RatioConst5l       RatioConst6l       RatioFirstImages1l       RatioFirstImages2l       l       l       Spectruml       i  i  i  Intervali  i  i  ActivationTimei  ActivationNumberi  i  i  i  rt   r  s    rv   CZ_LSMINFO_SCANINFO_ATTRIBUTES$_TIFF.CZ_LSMINFO_SCANINFO_ATTRIBUTESC  s   E
E
 E
 	E

 E
 +E
 )E
 
E
 
E
 (E
 E
 (E
 )E
 E
 E
  ,!E
" ,#E
$ .%E
& 'E
( )E
* +E
, *-E
. /E
0 1E
2 3E
4 
5E
6 
7E
8 
9E
: ;E
< =E
> ?E
@ AE
B CE
D EE
F 
GE
H 
IE
J KE
L ME
N ,OE
P -QE
R (SE
T UE
V +WE
X ,YE
Z [E
\ ]E
^ 	_E
` .aE
b cE
d )eE
f /gE
h /iE
j (kE
l mE
n -oE
p *qE
r +sE
t uE
v wE
x yE
z {E
| }E
~ E
@ (AE
B CE
D EE
F GE
H IE
J 	KE
L (ME
P QE
R (SE
T UE
V (WE
X (YE
Z 	[E
\ /]E
^ +_E
` aE
b )cE
d -eE
f )gE
h -iE
j kE
l 1mE
n *oE
p qE
r sE
t uE
v wE
x -yE
z {E
| ,}E
~ (E
@ -AE
B +CE
D -EE
F )GE
H /IE
J )KE
L /ME
N )OE
P QE
R -SE
T (UE
V (WE
X (YE
Z [E
\ ,]E
^ *_E
` (aE
b /cE
d )eE
h iE
j 	kE
l mE
p )qE
r sE
t +uE
v *wE
x ,yE
z +{E
| ,}E
~ +E
@ )AE
B )CE
D 	EE
F +GE
H IE
J KE
L ME
N OE
P (QE
R SE
T )UE
V )WE
X *YE
Z *[E
\ ,]E
^ ,_E
` .aE
b ,cE
d +eE
f 	gE
h iE
l mE
n oE
p qE
r sE
t (uE
v 
wE
x 
yE
| }E
~ E
@ AE
D EE
F 	GE
H IE
J KE
L ME
N OE
P QE
R SE
T UE
V WE
X YE
Z [E
\ ]E
^ _E
` aE
b cE
d +eE
f +gE
h 	iE
j kE
l 
mE
n 	oE
r sE
t uE
v 
wE
x yE
z {E
| (}E
~ *E
B CE
D EE
F GE
H IE
 E	
ru   c                8     " S S[         R                  5      nU$ )Nc                  ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)
,_TIFF.CZ_LSM_LUTTYPE.<locals>.CZ_LSM_LUTTYPEiD  r   rY   rT  r   r  r  rt   N)r  r  r  r  NORMALORIGINALRAMPPOLYLINESPLINEGAMMAr   rt   ru   rv   CZ_LSM_LUTTYPEr  D  s     FHDHFEru   r  r9  r:  )rk  r  s     rv   r  _TIFF.CZ_LSM_LUTTYPED  s    	T\\ 	 ru   c                8     " S S[         R                  5      nU$ )Nc                  0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)8_TIFF.CZ_LSM_SUBBLOCK_TYPE.<locals>.CZ_LSM_SUBBLOCK_TYPEiD  r   rY   rT  r   r  r  r  rt   N)r  r  r  r  r  r  
BRIGHTNESSCONTRASTr  KNOTSPALETTE_12_TO_12r   rt   ru   rv   CZ_LSM_SUBBLOCK_TYPEr  D  s&    CEJHDE ru   r  r  )rk  r  s     rv   r  _TIFF.CZ_LSM_SUBBLOCK_TYPED  s    	!4<< 	! $#ru   c                    / SPSPSPSPSPSPSPSPS	PS
PSPSPSPSPSPSPSPSSS/4PSSS/4PSPSPSPSPSPSPSPSPSPSPS PS!PS"PS#PS$PS%PS&PS'PS(PS)PS*PS+PS,PS-PS.PS/PS0P$ )1N)FileIDS8)nLinesi2)PixelsPerLiner  )Versionr  )
OldLutModer  )
OldnColorsr  )Colorsu1r  )OldColorStartr  )
ColorWidthr  )ExtraColorsrs  )r  r   )nExtraColorsr  )ForegroundIndexr  )BackgroundIndexr  )XScalerl  )Unused2r  )Unused3r  )UnitsIDr  p1)r  r  )yr  p2)CurveFitTyper  )nCoefficientsr  )Coeffrl  r  )UMsizer  )UMS15)UnusedBooleanr  )	BinaryPicb1)
SliceStartr  )SliceEndr  )ScaleMagnificationf4)nSlicesr  )SliceSpacingr  )CurrentSlicer  )FrameIntervalr  )PixelAspectRatior  )
ColorStartr  )ColorEndr  )nColorsr  )Fill13u2)Fill2r  )Tabler  )LutModer  )InvertedTabler  )ZeroClipr  )	XUnitSizer  )XUnitS11)	StackTyper  rt   r  s    rv   NIH_IMAGE_HEADER_TIFF.NIH_IMAGE_HEADERD  s   0
0
0
 $0
 	0

 !0
 !0
 &0
 $0
 !0
 *0
 #0
 &0
 &0
 0
 0
  !0
" #0
$ K-.%0
& K-.'0
( #)0
* $+0
, -0
. /0
0 10
2 $30
4  50
6 !70
8 90
: );0
< =0
> #?0
@ #A0
B $C0
D 'E0
F !G0
H I0
J K0
L M0
N O0
P Q0
R S0
T $U0
V W0
X  Y0
Z [0
\  ]0
 0	
ru   c                    g)N)
CustomTableAppleDefaultPseudo20Pseudo32RainbowFire1Fire2IceGraysr  rt   r  s    rv   NIH_COLORTABLE_TYPE_TIFF.NIH_COLORTABLE_TYPED  s    
ru   c                    g)N)PseudoColorOldAppleDefaultOldSpectrum	GrayScaleColorLutCustomGrayscalert   r  s    rv   NIH_LUTMODE_TYPE_TIFF.NIH_LUTMODE_TYPED  s    
ru   c                    g)N)StraightLinePoly2Poly3Poly4Poly5ExpoFitPowerFitLogFit
RodbardFit	SpareFit1UncalibratedUncalibratedODrt   r  s    rv   NIH_CURVEFIT_TYPE_TIFF.NIH_CURVEFIT_TYPEE  s    
ru   c                    g)N)
NanometersMicrometersMillimetersCentimetersMeters
KilometersInchesFeetMilesr  
OtherUnitsrt   r  s    rv   NIH_UNITS_TYPE_TIFF.NIH_UNITS_TYPEE  s    
ru   c                
    / SQ$ )N)*)r  rc  )	CommentV1S80)HighTensionrc  )SphericalAberrationrc  )IlluminationAperturerc  )rx  rc  )PostMagnificationrc  )r  rc  )Defocusrc  )Astigmatismrc  )AstigmatismDirectionrc  )BiprismVoltagerc  )SpecimenTiltAnglerc  )SpecimenTiltDirectionrc  )IlluminationTiltDirectionrc  )IlluminationTiltAnglerc  )	ImageModerc  )EnergySpreadrc  )ChromaticAberrationrc  )ShutterTyperc  )DefocusSpreadrc  )	CcdNumberrc  )CcdSizerc  )	OffsetXV1rc  )	OffsetYV1rc  )PhysicalPixelSizerc  )Binningrc  )ReadoutSpeedrc  )GainV1rc  )SensitivityV1rc  )ExposureTimeV1rc  )FlatCorrectedrc  )DeadPxCorrectedrc  )	ImageMeanrc  )ImageStdrc  )DisplacementXrc  )DisplacementYrc  )DateV1rc  )TimeV1rc  )ImageMinrc  )ImageMaxrc  )ImageStatisticsQualityrc  rt   r  s    rv   TVIPS_HEADER_V1_TIFF.TVIPS_HEADER_V1%E  s    +
 +	
ru   c                
    / SQ$ )N)6)	ImageNameV160)ImageFolderr9  )
ImageSizeXrc  )
ImageSizeYrc  )
ImageSizeZrc  )
ImageSizeErc  )ImageDataTyperc  )r  rc  )r  rc  )CommentV1024)r(  rA  )Scaling16f4)ImageStatistics16c16)r  rc  )ImageDisplayTyperc  )
PixelSizeXr  )
PixelSizeYr  )ImageDistanceZr  )ImageDistanceEr  )	ImageMisc32f4)TemTyper9  )TemHighTensionr  )TemAberrationsrL  )	TemEnergyrL  )TemModerc  )TemMagnificationr  )TemMagnificationCorrectionr  )r  r  )TemStageTyperc  )TemStagePosition5f4)TemImageShift2f4)TemBeamShiftrX  )TemBeamTiltrX  )TilingParameters7f4)TemIllumination3f4)
TemShutterrc  )TemMiscrL  )
CameraTyper9  )PhysicalPixelSizeXr  )PhysicalPixelSizeYr  )OffsetXrc  )OffsetYrc  )BinningXrc  )BinningYrc  )rB  r  )Gainr  )ReadoutRater  )FlatfieldDescriptionr9  )Sensitivityr  )Doser  )CamMiscrL  )FeiMicroscopeInformationrA  )FeiSpecimenInformationrA  )Magicra  rt   r  s    rv   TVIPS_HEADER_V2_TIFF.TVIPS_HEADER_V2UE  s    8
 8	
ru   c                F    / SQnSSSSSSSS	S
SUS4SSSSSSSSSSU4SSS/$ )N))r  S16)r  rc  )Originrl  )
Resolutionrl  )UnitS64)
HeaderFlagr  )r  r  )r8  S257)
OffsetDatara  )PaletteSizerc  )OffsetPalette0ra  )OffsetPalette1ra  )CommentSizerc  )OffsetCommentra  
Dimensionsr  )OffsetPositionra  )MapTyper  )MapMinrl  )MapMaxrl  )MinValuerl  )MaxValuerl  )	OffsetMapra  )r  rl  )Offsetrl  GrayChannel)OffsetThumbnailra  )
VoiceFieldrc  )OffsetVoiceFieldra  rt   )rk  MM_DIMENSIONs     rv   	MM_HEADER_TIFF.MM_HEADERE  sf    
 !! !$$!#<,$L)% &/
 	
ru   c                    SSSSSSSSSSS	.
$ )
Nr  r  r	  r  r  r-  r'  r%  )
r  r  r	  r  CH
WAVELENGTHTIMEXYEVENTEXPOSURErt   r  s    rv   MM_DIMENSIONS_TIFF.MM_DIMENSIONSE  s,     
 	
ru   c                *   / S[         4PS[         4PS[         4PS[         4PS[        4PS[        4PS[        4PS[        4PS	[         4PS
[         4PSPS[         4PS[         4PS[         4PS[         4PS[         4PS[        4PS[        4PS[         4PSPSPS[        4PS[        4PS[        4PS[        4PS[        4PS[         4PS[         4PSPSPSPS PS!PS"PS#PS$PS%[        4PS&PS'[        4PS([        4PS)PS*PS+PS,PS-PS.PS/PS0[         4PS1PS2[         4PS3PS4[         4PS5[        4PS6[        4PS7[         4PS8[         4PS9[         4PS:[        4PS;[        4PS<[         4PS=[         4PS>[         4PS?[        4PS@[        4PSA[         4PSB[         4P$ )CN	AutoScaleMinScaleMaxScaleSpatialCalibrationXCalibrationYCalibrationCalibrationUnitsr  ThreshStateThreshStateRed)tagid_10NThreshStateGreenThreshStateBlueThreshStateLoThreshStateHiZoom
CreateTimeLastSavedTimecurrentBuffer)grayFitN)grayPointCountNgrayXgrayYgrayMingrayMaxgrayUnitNameStandardLUT
wavelength)StagePosition
(%i,2,2)u4)CameraChipOffsetr  )OverlayMaskN)OverlayCompressN)OverlayN)SpecialOverlayMaskN)SpecialOverlayCompressN)SpecialOverlayNImageProperty)
StageLabel%ipAutoScaleLoInfoAutoScaleHiInfo)	AbsoluteZz(%i,2)u4)AbsoluteZValidz(%i,)u4)r  r  )GammaRedr  )
GammaGreenr  )	GammaBluer  )	CameraBinr  NewLUT)ImagePropertyExNPlaneProperty)UserLutTablez	(256,3)u1RedAutoScaleInfoRedAutoScaleLoInfoRedAutoScaleHiInfoRedMinScaleInfoRedMaxScaleInfoGreenAutoScaleInfoGreenAutoScaleLoInfoGreenAutoScaleHiInfoGreenMinScaleInfoGreenMaxScaleInfoBlueAutoScaleInfoBlueAutoScaleLoInfoBlueAutoScaleHiInfoBlueMinScaleInfoBlueMaxScaleInfo)r   rW   rz   r  read_uic_propertyr  s    rv   UIC_TAGS_TIFF.UIC_TAGSE  s   D
#D
D
 D
 "3'	D

 X&D
 X&D
  %D
 SMD
 C D
 s#D
 D
  %D
 $D
 c"D
 c"D
  SM!D
" ?+#D
$ o.%D
& c"'D
( )D
* %+D
, h-D
. h/D
0 !1D
2 !3D
4 S!5D
6 C 7D
8 39D
: ,;D
< /=D
> "?D
@ &AD
B CD
D )ED
F -GD
H %ID
J /0KD
L "MD
N )OD
P )QD
R &SD
T *UD
V WD
X YD
Z  [D
\ ]D
^  _D
` sOaD
b &cD
d c"eD
f *gD
h  %iD
j "8,kD
l "8,mD
n $oD
p $qD
r "3'sD
t $X.uD
v $X.wD
x !#&yD
z !#&{D
| !#&}D
~ #H-D
@ #H-AD
B  %CD
D  %ED
 D	
ru   c                (   0 S[        SS 5      /[        4_SSS/[        4_SS/[        4_SS/[        4_SS/[        4_S	S/[        4_S
S/[        4_SS/[        4_SSS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SSS/[        4_SS/[        4_0 SS/[        4_SSS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_SS/[        4_S S/[        4_S!S/[        4_S"S/[        4_S#S/[        4_S$[        SS 5      /[        4_S%S/[        4_S&S/[        4_ES/[        4S/[        4S/[        4S/[        4S'.E$ )(NDetectorrY   
Pixel_sizer  Siliconr   Exposure_timeExposure_periodTauCount_cutoffThreshold_settingGain_settingrT  N_excluded_pixelsExcluded_pixels
Flat_field	Trim_file
Image_pathr  Energy_rangeDetector_distanceDetector_VoffsetBeam_xyFluxFilter_transmissionStart_angleAngle_incrementDetector_2thetaPolarizationAlphaKappaPhiPhi_incrementChiChi_incrementOscillation_axisN_oscillationsStart_position)Position_incrementShutter_timeOmegaOmega_increment)r  rz   rY  r   r  s    rv   PILATUS_HEADER_TIFF.PILATUS_HEADERF  s   (
%4.)3/(
Aq65/(
 U|(
 qc5\	(

 U|(
 QC<(
 aS#J(
  1#u(
 aVSM(
  1#s(
 Sz(
 A3*(
 1#s(
 A3*(
  A3,!(
" aVUO#(
$  1#u%(
& !e'(
( A)(
* aS#J+(
, "QC<-(
. QC</(
0 U|1(
2 U|3(
4 aS%L5(
6 qc5\7(
8 qc5\9(
: QC<;(
< qc5\=(
> QC<?(
@ qc5\A(
B %4.!13 7C(
D sCjE(
F sElG(
H %&3,S%Lc5\!"U|O(
 (	
ru   r   c                "    SS K nUR                  $ r  )mmapr  )rk  r	  s     rv   r  _TIFF.ALLOCATIONGRANULARITY=F  s     	)))ru   c                l   S[         R                  ;   a'   [        S[        [         R                  S   5      5      $ Sn [        [         R                  " S5      5      nUc  g[        S[        SUS-  5      5      $ ! [         a     NKf = f! [        [        4 a    [         R                  " 5       n NTf = f)zDefault maximum number of threads for de/compressing segments.

The value of the ``TIFFFILE_NUM_THREADS`` environment variable if set,
else half the CPU cores up to 32.

TIFFFILE_NUM_THREADSrY   Nr   r)  rT  r  environrk  r   r   r   sched_getaffinityr   r]  	cpu_countr  rk  r  s     rv   r  _TIFF.MAXWORKERSDF  s     "RZZ/1c"**-C"DEFF !%		'B0034I 2s1i1n-..  
 ( 	'I	's"   %A; B ;
BB%B32B3c                X   S[         R                  ;   a'   [        S[        [         R                  S   5      5      $ Sn [        [         R                  " S5      5      nUc  g[        SUS-   5      $ ! [         a     NAf = f! [        [        4 a    [         R                  " 5       n NJf = f)zDefault maximum number of I/O threads for reading file sequences.

The value of the ``TIFFFILE_NUM_IOTHREADS`` environment variable if
set, else 4 more than the number of CPU cores up to 32.

TIFFFILE_NUM_IOTHREADSrY   Nr   r  r)  r  r  r  s     rv   rI
  _TIFF.MAXIOWORKERSZF  s     $rzz11c"**-E"FGHH !%		'B0034I 2y1}%%  
 ( 	'I	's"   %A1 B 1
A>=A>%B)(B)   r
  rt   N)r6  r   )r6  r%   )r6  z@dict[int, Callable[[FileHandle, ByteOrder, int, int, int], Any]])r6  zfrozenset[int])r6  zdict[int, str])r6  zdict[int, type[enum.Enum]])r6  zdict[int, int]r  )r6  z,dict[tuple[int, int | tuple[int, ...]], str])r6  z Mapping[int, Callable[..., Any]])r6  zset[int])r6  z<dict[str, Callable[[TiffFile], list[TiffPageSeries] | None]]r
  )r6  type[enum.IntEnum])r6  zdict[int, type[enum.IntEnum]]r  r  )r6  zlist[tuple[str, str]])r6  z-dict[str, Callable[[FileHandle], Any] | None])r6  zlist[tuple[Any, ...]])r6  zlist[tuple[str, Any]]r  rK  )Fr  r  r  r  r  rX   ra  rc  r`  rb  rf  r  r  r  rt  r  r  r  rr  r  r  r  rU  r  r  r  rR  r"  rx  r!  rQ  r  r/  r>
  rG  rH  r  ra  rM  rL  rY  r]  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r5  rq  r  r  r  r  r  r  rI
  r
  rL  r   rt   ru   rv   r   r   7=  s   J
 
 
 
 
 
 
 
 
 
 H
 H
T *
	I*
 *
X 
 
> 
 
@ 
 
* 
 
: 
 
.  0 0
 0
d %
 %
N 

 

 
 
* 
 
. 
 
$ Z
 Z
x + + , , - - . . 
 
2 "
	E"
 "
H /
 /
b 	 	 	 	   
 
$ ! !   
 
6 ! ! @
 @
D 
	6
 
@ 
 
  

 

 
 
 
 
 

 

 
 
 F
 F
P 	 	 
$ 
$ 1
 1
f 
 
 
 
 
 
  
 
 -
 -
^ 9
 9
v !
 !
F 
 
 G
 G
R +
 +
Z * * / /* & &*  JIru   r   nmMbP?	nanometer
nanometers   µmr  ummicronmicronsr	  micrometersmmg     @@
millimetermillimeterscm     @
centimetercentimetersr-  g    .Ametermetersr
  SU2UMc                  SU R                   l        U R                   R                  S5        U R                   R                  nUR                  =(       d    UR
                  (       + nU R                   R                  US9n[        U5      S:X  a  UR                  nUR                  nO([        U5      /UR                  Q7nSUR                  -   n[        X4UR                  USS9/$ )z0Return all images in TIFF file as single series.Tr   r  rY   r  r  r   )r  rl  r  r   ri  r5  r  r   r   r  r   r   )r   r  r  r  r   r  s         rv   r   r   F  s    CIIII199??D%%45HII1E
5zQ

yyU)djj)TYY5T	JKKru   c               ~  ^ U R                   nUR                  SS9  SUl        UR                  (       a  UR	                  5         / n0 mSU4S jjnU H{  nU" U5        UR
                  c  M  [        UR
                  5       HH  u  pVUS:  a  M   U R                  R                  U5        [        XR                  U45      nU" U5        MJ     M}     TR                  5        He  n	U	S   n[        U	5      /UR                   Q7n
S	UR"                  -   nS
U;  a
  U
S-  n
US
-  nUR%                  ['        XUR(                  USS95        Mg     [        U5      S:H  U l        U R,                  (       d  [/        U5        U=(       d    S$ ! [         a-  n[        5       R                  U < SU<S 35         SnAGM5  SnAff = f)z)Return image series grouped by page hash.Fr  c                  > U R                   (       d  g U R                  nUT;   a=  TU    H  nUR                  U R                  :X  d  M    g    TU   R                  U 5        g U /TU'   g ry   r   r#  r   r   r  r   r  
seriesdicts      rv   addpageseries_generic.<locals>.addpageF  ^    zzii*_88t{{* % 3&&t,#fJsOru   NrP  z generic series raised r_  r   r  rS  r  rS  r,  rY   r  r  r6  r   )r  r  rl  r  r  rp  r  r#  r\  r   r  r  r7   rm  r  r   r   r  r   r   r   r7  r  pyramidize_series)r   r  r   r2  r  r  r   r  r  pagelistr   r  r1  s               @rv   r  r  F  s   IIE	LLuLEO{{#%F8:J% <<#&t||4	A:$GGLL(%cJJ?;F FO 5   %%'{X,,TYYd?TMECKD8DJJ9M	
 ( [A%CN>>&!>T+ ! H$$'!8tE s   2F
F<!F77F<c                  ^ ^^  S                 SU 4S jjjm      S	UUU 4S jjmST R                   l        T" T R                   / 5      nUc  g[        U5      S:H  T l        [	        USS9  U$ )
z8Return image series in tifffile 'shaped' formatted file.Nc                 > [        US   [        5      (       d   eUS   n[        UR                  U5      (       + n	U	(       a5  [	        5       R                  T< SUR                   S[        U5       35        U	(       d  Ub  UcD  UR                  nUR                  n[        U5      S:  a  [        U5      /UQ7nSU-   nU	(       a  Un[        U5      n
[        U5      nUR                  (       a  X:  a  X-  S:X  a  Uc  SnSU-   nX-  /UQ7n [        X#U5      nUnS nU(       a,  UR                  5        VVs0 s H  u  pUS	;  d  M  X_M     nnnU R                  [!        UUUR"                  UUUS
[%        U5      S95        g ! [         a+  n[	        5       R                  T< SU<S 35         S nANS nAff = fs  snnf )Nr   z2 shaped series metadata does not match page shape r  rY   r/  Tz) shaped series failed to reshape, raised r_  >   r  r   r   r  r   )r  r   r   r  )r   r   check_shaper   r7   rm  r~   r  r   r@   rE  rG   r   r  r`  r   r   r   r   )r   r  r  r   rt  r   r  r   r  failedr   resizer  r  r   r  r   s                   rv   r   series_shaped.<locals>.appendF  s    %(H----Qx W55H' "jj\eGn-=? T\U]JJE99D5zA~U,e,Tzu~!&-FMQ4F  	:D^,e,E	W5DE (, %NN,,DABB ,  
 	

y/		
  	HNN' ' 	s$   F :F>
F>
F;!F66F;c          
     "  > / n[        U 5      nSnXC:  Ga  [        U [        5      (       a,  U R                  U5        [	        [
        U R                  5      nO[	        [
        U S   5      nUR                  c  [        5       R                  T< S35        g S nS n [        UR                  5      nUR                  SS5      n	US   n
UR                  c  S OSnUR                  SU5      nS	U;   aM  [	        [        US	   5      n[        U5      [        U
5      :X  a  U
nOSn[        5       R                  T< S
35        U/n[        U
5      nUS:  a"  [!        U[        UR"                  5      5      u  pOSnSnU(       a  [        5       R                  T< S35        g SUs=:  a  X4-
  ::  a  O  OUR$                  c   eXR$                  R&                  -  nU(       a  SnOXS-      nUR(                  (       a0  Ub-  UR*                  U-   UR*                  :  a  UR                  c  SnO<Sn[-        US-   XN-   5       H%  nU U   nUc   eUUl        UR/                  U5        M'     T" UUUUU
U	UU5        XN-  nUR                  (       Ga  [        UR                  5      n[1        UR                  5       H  u  nnUS:  a  M  / n[1        U5       H  u  nn Ub&  UR                  b  [        UR                  5      U:  a  U< S3n[        U5      eTR2                  R5                  UR                  U   5        US:X  a  [        TUR6                  U45      nUnO[9        TUR6                  U4WS9n UR/                  U5        M     U(       d  M  T" X!5      nUc    g UnM     XC:  a  GM  U$ ! [         a     [        5       R                  T< S35         g f = f! [:         a-  n[        5       R                  T< SU<S 35         S nA    g S nAff = f)Nr   z1 invalid shaped series metadata or corrupted filez+ invalid shaped series description metadatar   r=  r   Fr  r  z& shaped series axes do not match shaperY   z. shaped series shape does not match page shaperP  z contains invalid subifdsr[  z shaped series raised r_  )r   r   r    r  r_   r   r  rf  r7   r  rf  r   rS  rp  rz   r@   r  r   r  r   r  r   r  r   r  r#  r\  r  r   r  )r  r   rp  lenpagesr  r  r  r   r   r   rt  r  spagesr   r  r  r  r2  subifds_sizer  r   r   r  	keysubifdr  r  r   detect_seriesr   s                             rv   rC  $series_shaped.<locals>.detect_seriesG  s    68 u:%++""5)%..9  %(3**2g G G DE6// <<+Dw'G ( 0 0 8eI [)<I!C&!12t9G,#EDHNN'!GH :B
F7#Dax$T78>>+BCgKL 6-X--222000F +D )) ,$OOd2T[[@$,,4$)	 %*	!&uqy%.!AA#(8D#'#33#3,4DM"MM$/	 "B
 	 OE "8#3#34!*8+;+;!<IAvz  G#,V#44( $#'<<#7#&t||#4|#C)-0I&J&0o 5GGLLa9 Av)1#

A)G,2	)2$'%)ZZO-6*"  v.3 $54 w!.w!?!>#'!'E "=w | Q  gHI 	x  ) ("HNN#&' ***-!7 $((s1   N* BOO*'OO
P!!P		PTrY   rA  ry   )r   r  r  r	  r  rQ  r   r/  rt  rM  r   rz   r  r%  r   r*  r6  r   )r  z-TiffPages | list[TiffPage | TiffFrame | None]r   r  r6  list[TiffPageSeries] | None)r  rl  r   r7  r6  )r   r   r   rC  s   ` @@rv   r
  r
  F  s     +/<
$<
0<
 <
 &	<

 !<
 <
 <
 (<
 
<
 <
|O<O$O 
%	O Ob CII399b)F~[A%CNfd+Mru   c                 ^/ U R                   R                  nUR                  nUc  gU R                   nUR                  SS9  SUl        UR
                  (       a  UR                  5         / n0 m/S)U/4S jjnU H{  nU" U5        UR                  c  M  [        UR                  5       HH  u  pxUS:  a  M   U R                  R                  U5        [        XR                  U45      n	U" U	5        MJ     M}     UR!                  S5      nUR!                  S	5      nUR!                  S
5      nSnSnSnSnSnUb  Ub  [#        US   5      n[#        US   5      n[%        US   [&        5      (       a  US   OUn[#        US   5      [#        US   5      U-  -
  n[#        US   5      [#        US   5      U-  -   nUUSUSU* 4nOUb  [)        [#        US   S   5      5      n[)        [#        US   S   5      5      n[#        US   S   5      n[#        US   S   5      n[#        US   S   5      [#        US   S   5      [#        US   S   5      [#        US   S   5      [#        US   S   5      [#        US   S   5      4nSnUR!                  S5      nUb  [+        U5      OSnUS:X  a   UR!                  S5      nUb  [+        U5      nOUR!                  S5      nUb  [+        U5      n0 nSn0 nUR!                  S5      nUb  [+        U5      US'   UR!                  S5      nUb  [+        U5      US'   UR!                  S5      nUb  [-        U5      US'   UR!                  S5      nUb  [+        U5      US'   Ub  UUS'   U R.                  nUb  UUS'   USL=(       a    UR!                  S5      S:H  n US:  ac  US:  a]  UR0                  n!UR2                  n"U!S:  a  UUU!U-  -   4US'   U"S:  a  UUU"U-  -
  4US '   SS!KJn#  U#R!                  U5      n$U$b  U$U$S".nT/R9                  5        H~  n%U%S   n[;        U%5      /UR<                  Q7n&S#UR>                  -   n'S$U';  a
  U&S%-  n&U'S$-  n'URA                  [C        U%U&URD                  U'S&Xa:X  a  UOSXa:X  a  UOSXa:X  a  UOSS'95        M     [;        U5      S:H  U l#        [I        UU S(9  U(       a  U(       a  US   n(UR0                  n)UR2                  n*U(RJ                  SS  H  n+U+RL                  n,U)S:  d  M  U*S:  d  M  U)U,R0                  -  n-U*U,R2                  -  n.Ub  [O        U5      U+l(        UUU,R0                  U-  U--  -   4U+RR                  S'   UUU,R2                  U-  U.-  -
  4U+RR                  S '   U+RT                  RW                  U+RR                  5        M     U=(       d    S$ ! [         a-  n
[        5       R                  U < SU
<S 35         Sn
A
GMT  Sn
A
ff = f)*z?Return image series in GeoTIFF or Cloud Optimized GeoTIFF file.NFr  c                  > U R                   (       d  g U R                  nUT;   a=  TU    H  nUR                  U R                  :X  d  M    g    TU   R                  U 5        g U /TU'   g ry   r/  r0  s      rv   r2  series_geotiff.<locals>.addpageG  r4  ru   rP  z GeoTIFF series raised r_  r+  r-  r/  rj  r   rY   r   r  GTModelTypeGeoKeyProjLinearUnitsGeoKeyGeogLinearUnitsGeoKeyProjectedCSTypeGeoKeyProjectedCSTypeGeographicTypeGeoKeyGeographicTypeGTCitationGeoKeycitationGTRasterTypeGeoKey
RasterTypegeotransformr   LAYOUTIFDS_BEFORE_DATAr  r  )LINEAR_UNIT_NAMESr  r  r  rS  r  r	  )r   r  r  r	  rE  r5  ),r  r   r  r  rl  r  r  rp  r  r#  r\  r   r  r  r7   rm  rS  rY  r   rM  r-  r   rz   r   rO  rP  r8  rX  r  r   r   r  r   r   r   r7  r6  r  r  r  r	  r  r	  r  )0r   r  geor  r   r2  r  r  r   r  r  pixel_scaletiepointtransformationsxsyorigin_xorigin_yrU  tplinear_unit
model_typemodel_type_vallur  r	  r  epsggeogrR  raster_type	gdal_metais_cogsizexsizeyrX  	unit_namer7  r   r  baseline
base_widthbase_lengthr   level_kfrxryr1  s0                                                  @rv   r  r  G  sF   IIOOE


C
{IIE	LLuLEO{{#%F8:J% <<#&t||4	A:$GGLL(%cJJ?;F FO 5 " ''+,Kww'HWW23N	B	BHH-1L8#7;q>";q>"&x{D99Xa[xA<%1,"33A<%1,"33 "c8S2#>		#~a(+,-~a(+,-*1-.*1-..#A&'.#A&'.#A&'.#A&'.#A&'.#A&'
 K,-J(2(>S_ANWW,->b'KWW,->b'K  F#'EE 77*+D#&t9 77)*D"%d)ww)*HMj''./K!+.l ,n,,I,5()O)--"9=O"O  
Av"q&  !!19#X
%:;F3K19#X
%:;F3K,%))+6	 #)4E%%'{X,,TYYd?TMECKD

!%vD#}e$#}e$		
 (( [A%CNff- &!9%%
''__QR(E~~HA~+/("5"55 8#7#77$#';ELx22R7"<<&c"
 x33b82==&c" &&--emm< )" >Ta ! H$$'!8tE s   62W


X!W<<Xc               7  ^u SSK Jn  U R                  nUc  g UR                  U5      nSnStS jnU" U 5        UR                  R                  S5      nXp0U l	        U R                  R                  nSn	S	n
/ n0 n/ n0 nU H  nUR                  R                  S
5      (       d  M%  U H  nUR                  R                  S5      (       d  M%  UR                  R                  S5      nUR                  R                  S5      nU(       d  Md  Uc  Mi  [        R                  " [         ["        5         [%        U5      UU'   SSS5        M     M     U GHN  nUR                  R                  S5      (       a   [        5       R'                  U < S35          GOUR                  R                  S5      (       Ga  U GH  nUR                  R                  SS5      R                  S5      (       d  M6  0 =UUR                  S   '   nU GHL  nU GHA  nU GH6  nUR                  SS R                  S5      (       d  M)  UR                  S   nUR                  R                  SS5      n[(        R*                  U   nSUR                  ;   az  [%        UR                  R                  SS5      5      n[%        UR                  S   5      n[%        UR                  S   5      U-   n[-        [.        R0                  " UUU5      5      nO>[-        U Vs/ s H'  nUR                  R                  S5      (       d  M%  UPM)     sn5      nUU4UU'   GM9     GMD     GMO     GM     UR                  R                  S5      (       d  GM,  U H4  nUR                  R                  S5      (       d  M%  UR                  S   n  O   SnSn U HR  n!U!R                  R                  S5      (       d  M%  U!R                  R                  S5      n"U"(       a  U"U;   a  UU"   n   O   UR                  n#U#R                  S5      n$U GHh  n%U%R                  R                  S 5      (       d  M&  U%R                  n#U#n&SR3                  [5        U#S!   5      5      n'U' V(s/ s H  n([7        U#S"U(-      5      PM     n)n(/ n*Sn+S#n,/ n-/ n./ n/0 muU% GHz  n0U0R                  R                  S$5      (       Ga  U0R                  n#U,(       aU  S	n,[7        U#R                  S%U+5      5      n+U+S:  a1  [9        U'5       V1V(s/ s H  u  n1n(U(S&:X  a  U)U1   U+-  OU)U1   PM     n)n1n(O,[7        U#R                  S%S5      5      U+:w  a  S'n2[!        U25      eU#R                  S5      =(       d    U#R                  S5      n3U3(       a  U-R;                  U35        U#R                  S(5      n4U4bB  [        R                  " [         ["        5         U/R;                  [%        U45      5        SSS5        U#R                  S)5      n5U5bB  [        R                  " [         ["        5         U.R;                  [%        U55      5        SSS5        GM  U0R                  R                  S*5      (       az  U0R                  n#U#R                  S+5      n6U6bW  [7        U#R                  S,S5      5      n7U7Tu;  a6  [        R                  " [         ["        5         [%        U65      TuU7'   SSS5        GMC  U0R                  R                  S-5      (       d  GMf  U0R                  n#[7        U#R                  S.S5      5      n8[7        U#R                  S/S.U#;   a  SOS5      5      n9[7        U#R                  S0U95      5      n9U'SS1  V(s/ s H!  n([7        U#R                  S2U(-   S5      5      PM#     n:n( [7        [.        R<                  " U:U)SS1 5      5      n;U0 GH  n<U<R                  R                  S5      (       d  M&  Uc  U<R@                  b|  U<R                  R                  S4S5      RC                  5       U RD                  RC                  5       :X  a6  U<R@                  nU R                  S   U R                  U'   U R                  S	 OU<R@                  U R                  ;  a  U RF                  (       d
  / s  s  s  s  $ U<R                  S4   n= U RH                  RJ                  (       d  [         e[M        [N        RP                  R3                  UU=5      U S59n>U" U>5        U>U R                  U<R@                  '   U>RY                  5         U R                  U<R@                     RZ                  n? U9=(       d    [-        U?5      nU*RW                  S/UU;-   [-        U*5      -
  -  5        []        U5       H  n1U?U8U1-      U*U;U1-   '   M       GM     U RZ                  n? U9=(       d    [-        U?5      nU*RW                  S/UU;-   [-        U*5      -
  -  5        []        U5       H  n1U?U8U1-      U*U;U1-   '   M     GM}     U*(       a  [a        S; U* 5       5      (       a  GM"  U* H  n@U@c  M  W@U@Rb                  :X  d  M  W@nA  O   [9        U*5       H  u  n1n@U@c  M  W@Rd                  RH                  Rf                  nBUB(       a$  W@Rd                  RH                  Ri                  5         W@Rd                  RZ                  Rk                  U@Rl                  5        [o        [p        U@Rd                  RZ                  U@Rl                     5      nAUAU*U1'   WB(       a$  WARd                  RH                  RY                  5           O   WARr                  (       a  S#n
S	nCU* H*  n@U@(       d  M  W@Rd                  WARd                  :w  d  M(  S#nC  O   U+S:  aC  WARt                  S:X  a  U)R;                  U+5        U'S<-  n'O/ U)SS1 QU+PU)S1S Qn)U'SS1 S<-   U'S1S -   n'S<U';  a  U)R;                  S5        U'S<-  n'[w        [y        U)5      WARz                  -  S5      nU[-        U*5      :  a1  [        5       R?                  U < S=U S>[-        U*5       35        U*SU n*O\U[-        U*5      :  aM  [        5       R?                  U < S?U[-        U*5      -
   S@35        U*RW                  S/U[-        U*5      -
  -  5        [}        U)U'5      S   nDWAR~                  [        UD[-        UAR~                  5      * S 5      :w  aQ  [        5       R?                  U < SAWAR~                   SB[        WD[-        UAR~                  5      * S 5       SC35        A*G	M1  WARd                  RH                  R                  UA0nE[9        U*5       GH  u  n1nFUFc  M  WFRd                  RH                  nGUGR                  WE;  a  WFRb                  UF:w  a  WGRf                  nBUB(       a  WGRi                  5         WFRd                  RZ                  Rk                  UFRl                  5        UFRd                  RZ                  UFRl                     nFUFU*U1'   WB(       a  WGRY                  5         [o        [p        WF5      WEWGR                  '   WFRb                  UF:w  d  GM  WEWGR                     WFl1        GM     0 nHSDU';   a  U)U'Rm                  SD5         OSnISEU';   a  U)U'Rm                  SE5         OSnJS&U';   a  U)U'Rm                  S&5         OSnKU&R                  SF5      nLULb"  WIS:  a   [%        WL5      nMUMS:  a
  SGWIWM-  4WHSD'   WJS:  ai  [-        Tu5      WJ:X  aZ  [a        Uu4SH j[]        WJ5       5       5      (       a7  [.        R                  " []        WJ5       VNs/ s H  nNTuUN   PM
     snN5      WHSE'   O6U&R                  SI5      nOUOb"  WJS:  a   [%        WO5      nPUPS:  a
  SGWJWP-  4WHSE'   [-        U/5      WK:X  a2  [-        [        U/5      5      WK:X  a  [.        R                  " U/5      WHS&'   Oi[-        U.5      WK:X  a2  [-        [        U.5      5      WK:X  a  [.        R                  " U.5      WHS&'   O([-        U-5      WK:X  a  [.        R                  " U-5      WHS&'   U&R                  SJ5      nQUQb6   [%        WQ5      nRU)U'Rm                  SK5         nSURS:  a  WSS:  a
  SGWSWR-  4WHSK'   U&R                  SL5      nTUTb6   [%        WT5      nUU)U'Rm                  SM5         nVUUS:  a  WVS:  a
  SGWVWU-  4WHSM'   0 nWU&R                  SN5      nXUXbi  WAR                  b\  [        R                  " [         ["        5         [7        WX5      WAR                  R                  SO-  :w  a  [7        WX5      WWSP'   SSS5        U b  U S:  a  U WWSQ'   SnYU&R                  SJ5      nZU&R                  SL5      n[UZb  W[b   [%        WZ5      nR[%        W[5      nU[        R                  U&R                  SRSS5      RC                  5       ST5      n\[        R                  U&R                  SUSS5      RC                  5       ST5      n]WRU\-  n^WUU]-  n_U^S:  aU  W_S:  aO  SVSVSW.nYW\ST:w  a  SKWH;   a  SG[%        WHSK   S   5      W\-  4UHSK'   W]ST:w  a  SMWH;   a  SG[%        WHSM   S   5      W]-  4UHSM'   U&R                  SXSS5      n`SDWH;   aM  [        R                  W`RC                  5       ST5      naWYc  0 nYSVWYSD'   WaST:w  a  SG[%        WHSD   S   5      Wa-  4UHSD'   U&R                  SYSZ5      nbSEWH;   a)  Wb(       a"  WYc  0 nYSZS[S\S]S^S_S`Sa.R                  WbUb5      WYSE'   UR;                  U5        UR;                  [        U*U)WAR                  U'U U$WCSbWHWWWYSc95        A*GMk     GMQ     U	S:  a   [        5       R?                  U < S6U	 Sd35        [        XS#Se9 GH  u  ncnUU;  a  M  [        WcR~                  5      n)UcR                  n'UU   R                  5        H  u  nu  nnU'Rm                  U5      n1U)U1   U:X  a  U'R                  UUS5      n'M8  U)U1   U-  S:X  a:  U)U1==   U-  ss'   U)R                  U1S-   U5        U'R                  UUU-   S5      n'M~  [        5       R?                  U < SfU SgU ShU)U1    35        M     [        U)5      WclN        U'UclO        GM     U
(       Ga  [        SiSj9ndU GH  ncUcRb                  nAUARr                  (       d  M#  [-        WARr                  5      ne[]        Ue5       Vfs/ s H  nf/ PM     ngnfS/We-  nhWc GHm  nFUFc  Wg H  niUiR;                  S5        M     M#  WFRr                  c  Wg H  niUiR;                  S5        M     ML  WFRd                  RH                  nGWdRi                  UG5         []        We5       H  njWFRr                  Uj   SO:  a  WgWj   R;                  S5        M,  WGR                  WFRr                  Wj   5        UFRb                  UF:X  a1  WhWj   c+  [q        WFRd                  UFRl                  WjS-   45      n@U@WhUj'   O:WhWj   c  Skn2[        U25      e[        WFRd                  UFRl                  WjS-   4WhUj   Sl9n@WgWj   R;                  W@5        M     WdRY                  WG5        GMp     WcR                  nkUcRb                  R                  nlUcRb                  R                  nm[9        Wg5       GH  u  njn*[a        Sm U* 5       5      (       a&  [        5       R?                  U < SnWjS-    So35          GOlWhWj   nnUnc  SpWjS-    3n2[        U25      e[        WcR~                  5      n)UcR                  n'[9        U'5       H4  u  n1n(U(SK:X  a  WnR                  U)U1'   M  U(SM:X  d  M%  WnR                  U)U1'   M6     0 noSnp0 nqWkb  WlS:  a  WmS:  a}  WlWnR                  -  nrWmUnR                  -  nsSVSVSW.npSGUnR                  WkS   -  Ur-  4WqSK'   SGUnR                  UkS   -  Us-  4UqSM'   WcR                  R                  SQ5      ntUtb  WtWr-  WoSQ'   WcR                  R;                  [        U*[        U)5      WnR                  U'U SqWjS-    3SbWo=(       d    SWq=(       d    SWpSr9
5        GM     WcR                  (       a  GM  SsWclA        GM     WdR                  5         [-        U5      S:H  =(       a    U
(       + U lZ        U$ ! UR                   a+  n[        5       R                  U < SU<S 35         SnAgSnAff = f! , (       d  f       GM  = fs  snf s  sn(f s  sn(n1f ! , (       d  f       GNo= f! , (       d  f       GN+= f! , (       d  f       GN= fs  sn(f ! [          a-  n[        5       R?                  U < S3U<S 35         SnAGM  SnAff = f! [R        [T        [         4 a  nU	S:X  a&  [        5       R?                  U < S6U=< S7U<S S835        U	S-  n	U9(       a  U9nOUS:X  a  S9n2[!        U25      UeU*RW                  S/UU;-   [-        U*5      -
  -  5         SnA  GM  SnAff = f! [^         a,  n[        5       R?                  U < S:U<S 35         SnAGNSnAff = f! [^         a-  n[        5       R?                  U < S:U<S 35         SnAGM(  SnAff = f! [         ["        4 a     GNf = fs  snNf ! [         ["        4 a     GN6f = f! [         ["        4 a     G
NYf = f! [         ["        4 a     G
N&f = f! , (       d  f       G	N= f! [         ["        4 a    SG=nRnU G	Nf = fs  snff ! WdRY                  WG5        f = f)uz(Return image series in OME-TIFF file(s).r   ElementTreeNz OME series raised r_  rK  c                   SU R                   l        SU R                   l        U R                   R                  S5        U R                   R	                  S 5        g )NTr   )r  r  rl  r  r  )atifs    rv   
load_pagesseries_ome.<locals>.load_pages~H  s>    

#



"

ru   r  F
Instrumentr  r  NominalMagnification
BinaryOnlyz4 OME series is BinaryOnly, not an OME-TIFF root filer  r  r=  r  Alongr  r3  StartSteprY   EndLabelr  AnnotationRefObjectiveSettingsr  r  r  r  Tr  r  r  z2OME series cannot handle differing SamplesPerPixelrW  rY  r  r@  TheTTiffDatar  	NumPlanes
PlaneCountry  Firstz4 OME series contains invalid TiffData index, raised FileNamerx  z OME series failed to read r  z. Missing data are zeroedz*OME series missing NumPlanes or PlaneCountz0 OME series contains index out of range, raised c              3  (   #    U  H  oS L v   M
     g 7fry   rt   r  s     rv   r   series_ome.<locals>.<genexpr>nI  s     7$QDy$   rS  z OME series expected z frames, got z OME series is missing z  frames. Missing data are zeroedz1 OME series cannot handle discontiguous storage (r  rz  r	  r  r  rj  c              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   )r   r.  plane_deltass     rv   r   r  I  s     @<a\)<r  r  r  r  r  r  r  rP  r   magnificationr  r  r  r  r	  rY  r  r  secondmillisecondmicrosecond
nanosecondminutehourdayr  msu   µsnsr  r+  r  r   )r  r   r	  r   r  r  r	  r\  r4  z OME series modulo z size z does not divide r  r   zno keyframe foundr[  c              3  (   #    U  H  oS L v   M
     g 7fry   rt   )r   r  s     rv   r   r  J  s     3dsd{dr  z OME series level z	 is emptyzno keyframe found for level Level )r  r   r   r  r  r	  Baseline)ry  r   r6  r   )[	xml.etreerw  rj  r
  
ParseErrorr7   r  attribrS  rS  r#  rG  r  rZ  r  r  r   r   rY  r$  r   r>
  r   r   r  r   reversedr   r  r   rG
  rm  textr  r  r   r  rD  r   r  rE  r]  r^  r  r  r  r  r4  rl  r  r  r  rD  r  r  r_   r   rp  r   rk  r@   r   r  r   r~   r   r  r!  r   r   r*  r   r  rM  r  r`  r  r  r  r  r   r\  ra  r   r  rO  rP  r&  r  r  r7  )vr   rw  r   ry  r  r   rz  	root_uuidrG  rV
  r	  	modulorefr  r   
objectiveselementr  obj_idr  annotr  rO  	modulo_nsalongr  newaxisr  r  r  r  labelr  image_magnificationchildobj_refr  r   pixelspixels_attribr  r  r   r  sppr   channel_namesexcitation_wavelengthsemission_wavelengthsr  r  r   ch_nameewxwdelta_tthe_t	ifd_indexr	  idxsidxr  r  ftifr  r  r  isclosedr	  r  	keyframesr  rl  r  sizezsizetr  pszpsz_fr.  titi_fpsxpsx_frl  psypsy_frm  r  sbitsr	  psx_valpsy_valxuyumpp_xmpp_ypsz_unitzuti_unitaseries	filecache
num_levelsr   levels_pageslevels_keyframeslevel_pagesr   base_mpprp  rq  level_keyframelevel_attrslevel_unitslevel_coordsr^  r_  base_magr  sv                                                                                                                        @rv   r  r  kH  s    &F~%%f- D sO'I!CJggooGMLI46F#%F#%J;;--77##K00 ZZ^^D1F**..)?@Cv#/'00YG16sJv. HG   ;;--HNN'MN ;; 788 ||''R8AA(KK355u||D)*S"E%*	%.E#(99Sb>#:#:7#C#C (#(99R=D&+ll&6&6vw&GG&*oog&>G&%,,6',U\\-=-=fa-H'I(-ell7.C(D',U\\%-@'AD'H),U\\%t-L)M), 6;%&5:E+099+=+=g+F ).5:%&*" *1&(9CI' &/ &+ #	 !6 {{##G,,Eyy!!/22 %T 2 
 !M -1Eyy!!"566,,**40w*4*4W*='  ~~xxF::&&x00==D M778D)9$:;<D6:;dSfrk*+dE;DCE')M24"02 -/L88$$Y//;;D %!$((+<c"BC7 .7t_%-<EAr 469aC%( J-< " % TXX&7;<C.  )o-"hhv.@$((4.G%,,W5"67B~'00YG077b	B H"89B~'00YG299%)D H88$$W--;;D"hhx0G* #DHHVQ$7 8 4!+!4!4Z!K6;GnU 3 "Lxx((44{{ 23	$((;Ud]JK$((<56AEcrK2DHHWr\156Ke55dE#2JGHC !D88,,V44 !) II1 KKOOJ;AAC"||1134
 %)II	03

40@

9-JJt,#**4"~~ $&II#';;z#:"#&>>#9#9&0 0#+ "Wh ?&)$D 't,2 15

499-

JJtyy177E	"0c%jTFdSj3t9.D$EF!&tA,1)a-,@DqM "- G !L  IIE	"0c%jTFdSj3t9.D$EF!&tA,1)a-,@DqM "-I X 37$777 ?scll':"H	  (oFAs#&::#8#8#?#?#JJ11668

((55cii@#'$JJ,,SYY7$ #+Q#$OO66<<> .  # I33::8 $I 
 Qw((A-LL%CKD;eCRj;#;bc
;E9s?T"#Y6D$Q wu~6:Dc$i  g24& 9t9+' ET{D	!  g4c$i'((HJ TFdSY&678#E403H~~xX^^1D0D0F'G!HH  g  'tXs8>>':&:&<=>?qB
  **//.I %T?4<[[++77)+}},#%99#GGI))66tzzB#{{00<"&Q#HHJ)-h)=Ibgg&==D($-bgg$6DM# +( &(F.1TkE$**S/*qE.1TkE$**S/*qE.1TkE$**S/*qE##O4C519!#JEqy'*EEM&:s 	%.@5<@@@#kk.3El;l\!_l;s #&&7>eai$Ry!8+.*=F3K ()U2012e;#kk*>?s*+u4234=#kk*@As]#u,#kk-8s##O4C!#JE!$**S/2EqyUQY'*EEM&:s  ##O4C!#JE!$**S/2EqyUQY'*EEM&:s
 %'E!%%&78E X^^%?((Y?5zX^^%<%<q%@@14Uo. @ #.3F3J)<o& ,0E#''8G#''8G"w':(!'NE!'NE YY!%%&95AGGI3 YY!%%&95AGGI3 

19".\BESySF]'*E&+a.,AB,F&GsSySF]'*E&+a.,AB,F&Gs$(()<eDHf}YYx~~/5=E)c
9#&fSk!n(=(B"CF3K#''(;XFGf}=E!'(&# #gw' c
 ]+MMNN'! U s J qg0vF	

 #&f"E&W]]#||%+M%:%@%@%B!D/7D

4 AQx4||D'15qDA%aT!QUD)||D$.!<  g0 7 6!258*> &C u' #F, 2&	G''H##X--.J!*-E-q-  E 8<fz6I  <'3#**40 (4<<''3#**40 (4 [[++r"(!&z!2<<.2(/66t<$U 34 MMT1 0 7 ? #+ $!%UQY 7#C 7:,U3-e4<"5C".s"33"+ $!%UQY 7)9%)@#C
 %U+22373 "36 OOB'[  ` {{H ))44J!**66K(6t3d333H$$'!3EAI;iH !1%!8!)8DC&s++ W]]+||&t_EArSy#1#<#<as#1#=#=a	 - /159/1'JN{Q#n&?&??B$~'A'AAB(4<"HK&11HQK?"D)L%
 &22Xa[@2E)L%  '~~11/BH+7?"}O4 %%"e&,,"%eai[1")1T+3t)U  7r <<<)u x 	[A%:l*:CNMO !! # 3C<$<@AD HG:%&J <"% HG HG "L!K L " H$$' ")),t6 J $-&  "
  -1 & 0 0'*g-H'/l)C<$< H>%>!"
 *Q.M  #'*!%%> !$ '1o3 > KK$*s4y2H(IJ!/"@ & (("g &&&)\D\3  & (("g &&&)\D\3 d #I.  < '	2 * #I.  #I.  @?, #I. ($''EE(xEh OOB's  Ad /Ae 	$Ae1AeAe Ae Ae#	6Ae5	Af	(Af
0#AfAAg*AAi0AAj)Ak#Ak:Ak?B5AlC%5Al-E5AmGAmT4Am1V>C(Am6dAd=d!Ad8d8Ad=e 
Aee#
Ae2e5
Aff
Aff
Ag	f(!Ag	gAg	gAi-g-A3Ai(i(Ai-i0
Aj&i:!Aj!j!Aj&j)
Ak 	j3!Ak	kAk 	k#Ak7k6Ak7k?AllAllAl*l)Al*l-Amm Amm
AmmAm.m-Am.m6An	c                  U R                   nUc  gU R                  nSUl        UR                  S5        U R                  R                  nUR                  SS5      R                  5       nUR                  SS5      nUR                  SS5      nUR                  S	S5      nUR                  S
S5      nUS:  d  US:  d  US:  d  US:  a  [        5       R                  U < S35        gUS:X  d&  UR                  S   S:  a  UR                  S   U:X  a  XV-  nO%XU-  :X  a  UR                  S   U:X  a  SnOXV-  U-  nUS:X  a  UR                  (       a  [        U5      nXR                  -  n	UR                  (       d  Sn
OUR                  S   U	-   U R                  R                   :  a  [        5       R#                  U < S35        gUS::  a  Sn
O9UR                  (       a&  UR                  S   U	-   US   R$                  :  a  Sn
OSn
U
(       a  U/OUSS nU==S:X  a  O	=S:X  a  O  O	    SnXVU4nOk=S:X  a    SnXeU4nO]=S:X  a    SnXWU4nOO=S:X  a    SnXuU4nOA=S:X  a    SnXgU4nO3S:X  a  SnXvU4nO' SnXVU4n[        5       R                  U < SU< 35        U['        U5      -  nUS:  a(  [        5       R)                  U < S35        U/UQ7nSU-   nUR                  S   S:  a/  US   S:X  d   eUSS UR*                  -   nXR,                  SS -  nOXR*                  -  nXR,                  -  nSU;  a
  US -  nUS-  nU
=(       a'    UR                  (       + =(       a    UR                  U	:g  n0 nUR                  S!S5      nUR                  S"S5      nUR                  S#S5      nUR                  S$5      n[/        U[0        [2        45      (       aE  US:  a?  US:  a9  [/        U[0        [2        45      (       a  [3        U5      * U-  OS%nUUUU-  -   4US&'   UR                  S'5      n[/        U[0        [2        45      (       a  US::  a7  UR                  S(5      n[/        U[0        [2        45      (       a  US:  a  S)U-  n[/        U[0        [2        45      (       a  US:  a  US:  a
  S%UU-  4US*'   UR                  S+5      n[/        U[4        5      (       a(  [        U5      U:X  a  [6        R8                  " U5      US'   [/        U[0        [2        45      (       a  U(       d"  [/        U[0        [2        45      (       a  U(       a  S,UR:                  ;   a  UR=                  5       u  nnU(       aU  US:  aO  UR*                  UR,                  R?                  S-5         nUS:  a!  S)U-  n[3        U5      * U-  nUUUU-  -   4US-'   U(       aU  US:  aO  UR*                  UR,                  R?                  S.5         nUS:  a!  S)U-  n[3        U5      * U-  n U U UU-  -   4US.'   0 n!Sn"UR                  S/S05      n#[/        U#[@        5      (       a  U#(       a  [B        R                  U#R                  5       5      n$U$b  S1OU#n%U$bz  U$S):w  at  S2 Hn  n&UR                  U&5      n'U'c  M  [/        U'[D        5      (       a$  [        U'5      S3:X  a  U'S   U$-  U'S   U$-  4UU&'   MR  [6        RF                  " U'5      U$-  UU&'   Mp     U%U%S4.n"S&U;   a  U%U"S&'   UR                  S55      n([/        U([@        5      (       a  U((       a  U(U!S5'   SU l$        [K        UUURL                  US6UUU!U"S79	/$ )8z#Return image series in ImageJ file.NTr   r
  cztrr  rY   rJ
  r  re  z1 ImageJ series metadata invalid or corrupted filer  Fr  r2  ctzZTCzctTCZztcCTZtczZCTtzcr?  z  ImageJ series of unknown order z. ImageJ series contains unidentified dimensionr  rK  r  rS  r  xoriginyoriginzoriginspacingrj  r	  	fintervalfpsr  r  r  r  r  r  r  pixelr	  r	  rT  rY  r   r   )r   r  r  r  r	  )'r  r  rl  r  r   rS  r  r7   rm  r   rj  r   r   r  r  r  r   r  r   r@   r$  r   r  r   r   rY  rM  r   r  r  r  r  rz   r*  r~   r   r7  r   r   ))r   rH  r  r  r
  rr  rJ
  r  re  r   	isvirtual	page_listr  r   remainr  r  r  r  r  r  z0r  fps_valr  xresyresrX  pixel_widthx0r  pixel_heighty0r  r	  r  r  unit_outr  r	  r   s)                                            rv   r  r  J  s    D|IIEEO	q99??DHHWe$**,EXXh"FXXh"Fxx
A&HXXh"FzVaZ6A:AgFG	
 1}Q!+A(0J	F?	"t{{1~'A8+{u))Ukk!F
 ==				!	v	%(;(;	;gFG	
 	1				 0 0 3f <uQx N		 7@TFU1XI
 UYDX.EDX.EDv.EDv.EDv.EDv.EDX.EH'9%C wu~%FzgCD	
  % Tz{{1~Bx3cr
TZZ'		!"		
$ N%"4"44N9NI  Fhhy!$Ghhy!$Ghhy!$Ghhy!G'C<((Wq[VaZ 'C<00 7^Og% 	
 2 001s%Ii#u..)q.((5/gU|,,1gI)c5\**y1}!FY./sXXhF&$CK8$;kk&)s 
Gc5\	*	*wwe--'

((*
dtaxJJtyys34Eqy!DjGn_{2!2(;#;<staxZZ		 45Fz"TzGn_|3!2(=#=>sE#'E88FG$D$		$**,'#(#4<$#%jjn?!#u--#c(a-&)!func!fun%Er
%*]]3%7%%?r
 & X.&=!E#J88FD$fCNJJ
	
 ru   c          
        [        U 5      nUc  gU R                  nUc  U$ U R                  R                  n0 n0 n0 nSSSSSSSS	S
S.	n[	        UR                  SS5      5      n[        UR                  SS5      5      n	U	S:X  a*  UR                  SS5      R                  5       =(       d    Sn
OUR                  U	5      n
U(       a  U
(       a  [	        UR                  SS5      5      =(       d    Sn[        R                  U
R                  5       5      nUb  SOU
n[        R                  " SUR                  U-  U=(       d    S-  UR                  SS9US'   [        R                  " SUR                  U-  U-  U=(       d    S-  UR                  SS9US'   XS'   XS'   [	        UR                  SS5      5      nU(       aS  U(       aH  U
(       aA  [        R                  U
R                  5       5      nX-  U=(       d    S-  US'   Ub  SOU
US'   OXS'   [	        UR                  SS5      5      nU(       a	  XS'   SUS '   U(       a  US   R                  R                  U5        S!US   l        US   R"                  R                  U5        US   R$                  R                  U5        US   R&                  R                  U5        U$ )"z&Return image series in NIH Image file.Nr  r	  r"  r&  r(  	kilometerinchfootmile)	r   rY   rT  r   r  r  r  r  rP  r  rj  r  r;  r  r  r=  r  r  r   Fr	  r  r  r  slice_spacingr	  r  frame_intervalr  r  r  )r   r  r  r   rY  rS  r   rc  r*  r  r   r  rO  rP  r	  r  r   r  r	  r&  )r   r   rH  r  r  r  r	  	nih_unitsxscaleunits_idunit_straspectr  r   r  r  s                   rv   r  r  K  s   C F~D|99??DFEE
!I 488Hc*+F488Iq)*H2~#xx4::<D==*(txx 2C89@S 		(..*+#(#4<(nnOOf$5OO	
s nnv%.%,3?	
s c
c
$((>378MhIIhnn./E%2%;u|%LE/").):E#J%2/"488OS9:N"0c
q	&F1IN
1IV$
1I%%f-
1IE"Mru   c                  U R                   nUc  gU R                  R                  SS9nUS   SSS2   nSR                  S U 5       5      n[	        S U 5       5      n0 n0 nU GH:  nUu  ppn[
        R                  R                  U	R                  5       S	5      nUS
;   d  M@  US:  d  MH  X;   d  MO  [        U[        5      (       a  U(       a  [        R                  UR                  5       5      n[        U5      U=(       d    S-  [        U5      [        U
5      [        U5      -  -   U=(       d    S-  4Xn'   Ub  SX~'   M  US:X  a  SSSSSSSS.R                  X5      X~'   GM  XU'   GM
  [        U5      [        U5      [        U
5      [        U5      -  -   4Xn'   GM=     0 nSU l        [        UUUS   R                   UU=(       d    SU=(       d    SU=(       d    SUS   SS9	/$ )z%Return image series in FluoView file.NFr  r  rK  r=  c              3     #    U  H6  n[         R                  R                  US    R                  5       S5      v   M8     g7f)r   r/  N)r   r  rS  rN  r  s     rv   r   "series_fluoview.<locals>.<genexpr>L  s0     Kd4%%))!A$**,<<ds   >A c              3  >   #    U  H  n[        US    5      v   M     g7fr  r  r  s     rv   r   r  L  s     *T#ad))Ts   r/  >   r  r  r  r	  r   r  r	  r  r  r  r  r  r  r  r  r  Tr8  r  )r  r  r	  r   r   )r  r  r  r   r~   r   r  rS  rN  r   rz   r*  r  rY  r7  r   r   )r   rH  r  mmhdr  r   r  r	  r6
  r   r   originr  r  r  r  r  s                    rv   r  r  L  s     D|II.Edd#D77KdKKD*T**E  FE),&F$!!%%djjlC8''D1H$$$		$**,/&MU\c26]U4[5;%>>|% 
 $".EKS[%+,*'#"# c$o K #'$K &M&ME$K%+$== 5 < ECN!HNN>T-4-4k"
	
 ru   c               	   U R                   nUc  gU R                  R                  nUS   nUR                  SS5      nU/UR                  Q7n0 n0 n0 nUR                  S5      n	US:  GaH  U	GbD  [
        R                  " U	S:g  5      (       Ga%  SUR                  -   n
UR                  S	5      n[        U[        5      (       a  UR                  5       S
;  a  [        R                  UR                  5       5      n[
        R                  " S/[
        R                  " U	SS 5      /5      R                  [
        R                  5      U=(       d    S-  US'   Ub  SOUUS'   GO[
        R                  " S/[
        R                  " U	SS 5      /5      R                  [
        R                  5      US'   OUS:  a  [
        R                  " [
        R                   " US   5      S:g  5      (       ah  SUR                  -   n
UR                  S5      nUbD  XS   -
  [
        R"                  " SS5      -  R                  [
        R                  5      US'   SUS'   OSUR                  -   n
UR                  S5      nUb  [%        U5      U:X  a  [
        R&                  " U[
        R                  S9nUS   S:w  a2  [
        R                  " XS   :H  5      (       a  [)        US   5      US'   O"[
        R                  " US:H  5      (       d  XS'   UR                  S	5      n[        U[        5      =(       a    UR                  5       S
;  nU(       a#  [        R                  UR                  5       5      OSnUR                  S5      nUR                  S5      nUR                  SS5      (       am  U(       af  [)        U5      S:w  aW  [
        R*                  " S[)        U5      UR,                  -  U=(       d    S-  UR,                  SS9US'   U(       a
  Ub  SOUUS'   UR                  SS5      (       am  U(       af  [)        U5      S:w  aW  [
        R*                  " S[)        U5      UR.                  -  U=(       d    S-  UR.                  SS9US'   U(       a
  Ub  SOUUS'   S U l        [3        U/UUR4                  U
U=(       d    SU=(       d    SU=(       d    SUUS:  S!S"9
/$ )#z Return image series in STK file.Nr  r  r=  r  rY   r   r	  r  >   r=  r  r  rj  rK  r  r	  r  r  DatetimeCreatedr  r  r  Wavelengthsrz  r  wavelengthsr  r  r  Fr	  r  r  Tr  )r  r  r	  r   r  r   )r  r  r   rS  r   r   rl  r  r   rz   r  r*  concatenatecumsumr,   r  r  timedelta64r   r   rY  r  rO  rP  r7  r   r   )r   rH  r  r  r   r   r  r  r	  zdistr  	cal_unitsr  datetime_createdr  wlis_physicalxcalycals                      rv   r  r  KL  s#   D|99??D.!F88FBD!djj!EFEEHH[!Eze'EIIeqj,A,ATYYHH/0	i%%)//*; D
 +

 IIioo/0E++U3BZ01fU]]#u|5F3K */):	E#J++U3BZ01fU]]# 3K 
!		%**T--@"AQ"FGGTYY88$56'!Q$77##As+,fU]]# 3K "E#JTYY((=)K3{#3v#=]];emm<a5C<EIIbqEk22"'1,E,29%%#%- +,IY, 1B K 2K
 -8EIIioo'(TE88N#D88N#Dxx$a((TeDkQ6Fnn$K$//)U\c:OO	
s ).):	E#Jxx$a((TeDkQ6Fnn$K$***els;	
s ).):	E#JCNFJJ>T-4-4qj	
 ru   c          
     :  ^ U R                   nUc  gSU R                  l        U R                  R                  S5        U R                  R                  nUS   S;   aP  [
        R                  " [
        R                  5      nUS   S   US   S   -  mUS   S:X  a	  SU4S	 jjnO&SU4S
 jjnOUR                  c   eUR                  nSn0 nUR                  S5      nU(       a  XeS'   SU l	        [        U/UR                  UUR                  U=(       d    SUSS9/$ )z#Return image series in MD Gel file.NFr   FileTag>   rT  r  
ScalePixelrY   rT  c               N   > U R                  [        R                  5      S-  T-  $ )NrT  r,   r   r  r  r  s    rv   r	  series_mdgel.<locals>.transformL  s     xx.!3e;;ru   c               H   > U R                  [        R                  5      T-  $ ry   r%  r&  s    rv   r	  r'  L  s    xx.66ru   	FileUnits
file_unitsr  )r  r	  r   )r  r  r6  r  )r  r  rl  r  r   r   r   r  rS  r7  r   r   r  )r   rH  r  r   r	  r  r*  r  s          @rv   r  r  L  s   D|CIIII199??DI("EMM*\"1%\(:1(==	?a< <
7 7 zz%%%

	E+&J(lCNFJJII-4	

 
ru   c                  / nU R                   R                  nUR                  S:X  az  [        U R                   5      S:  a  gUR	                  [        U/UR                  UR                  UR                  SSS95        SU l	        U R                   S   R                  5       nUR                  S;  a+  [        5       R                  U < S	UR                   35        U$ S
U R                   l        U R                   R                  UR                  5        U R                   R!                  [#        UR                  S5      SS9n[        U5      S:X  a  UR                  nUR                  nO([        U5      /UR                  Q7nSUR                  -   nU(       d  S
U l	        0 nU R$                  nUb5  S H/  nX;   d  M
  ['        Xx   [(        [*        45      (       d  M)  Xx   Xh'   M1     [        UUUR                  USSU=(       d    SS9n	U	/UQ$ )z Return image series in EER file.rY   rT  N
integratedr  r   r   Fri  z) EER series with unsupported compression Tr  r  )exposureTimemeanDoseRate	totalDoserr  )r   r   r  )r  r   r   r   r   r   r   r   r  r7  r6  r7   rm  rl  r  r  r  r  r  r   r   rY  )
r   r   r  r  r   r  r  rH  r   rr  s
             rv   r  r  L  s   #%F99??D1syy>A



		!		
 yy|""$44g 77;7G7G6HJ	
 CIIII4::&IIuTZZ6GE
5zQ

yyU)djj)TYYED@C{z$)c5\BB!Y
 A 

mtF Vru   c          
        U R                   R                  SS9nU R                   R                  nSnU R                  nUc  0 OUR	                  S0 5      nSU;   a`   US   n [        U5      nSn [        US   5      nUc  [        [        U5      X-  -  S5      nXxU/UR                  Q7nS	UR                  -   nUc(  [        U5      /UR                  Q7nSUR                  -   n0 n0 nU(       Ga  UR	                  SS5      nUS:  a"  SW;   a  X;R#                  S5         nSX-  4US'   UR	                  S5      n[%        U[        [&        45      (       a  US::  a  UR	                  SS5      nUS:  a#  SW;   a  X;R#                  S5         nSUU-  4US'   UR	                  S5      n[%        U[        [&        45      (       a  US:  a  UUS'   UR	                  S5      n[%        U[(        5      (       a  [        U5      S:X  ar  [+        S U 5       5      (       a[   [-        US   S   US   S   -
  5      n[-        US   S   US   S   -
  5      nUS:  a  SW;   a  SU4US'   US:  a  SW;   a  SU4US'   SU l        [3        UUUR4                  WSU=(       d    SU=(       d    SS9/$ ! [         a    Sn GNLf = f! [        [        [        4 a<  n	Sn[        U5      U-  (       a  Sn
[        U
5      U	e[        U5      U-  n Sn	A	GNSn	A	ff = f! [         a,  n	[        5       R!                  U < S
U	<S 35         Sn	A	GNSn	A	ff = f! [        [.        4 a     Nf = f)z&Return image series in ScanImage file.Fr  Nr  zSI.hChannels.channelSaverY   zSI.hStackManager.framesPerSlicez"unable to determine framesPerSlicer  z ScanImage series raised r_  r  zSI.hRoiManager.scanFramePeriodrj  r   r  z%SI.hStackManager.actualStackZStepSizezSI.hStackManager.stackZStepSizer	  zSI.objectiveResolutionobjectiveResolutionzSI.hRoiManager.imagingFovUmr  c              3  l   #    U  H*  n[        U[        5      =(       a    [        U5      S :H  v   M,     g7fr=  )r   rM  r   )r   r  s     rv   r   #series_scanimage.<locals>.<genexpr>NM  s'     EAJq$'7CFaK7s   24r   r  r  Tr  )r   r  r  )r  r  r   r  rS  r   r   r   r  OverflowErrorr   rk  r   r  r  r7   rm  r  r   rY  rM  rl  r-  r4  r7  r   r   )r   r  r  r   rH  r  r  rJ
  rr  r  r   r  r  r  periodr  zstepr  oresfovx_extenty_extents                         rv   r  r  M  su   II.E99??DE!!Dlb(AI!Y.	N !;<Hx= F0Y'HIJ ~SZF,=>BX;

;E499$D }U)djj)TYY  FE?EA:#+**S/*E/F3KEF%#u..%1*MM"CSIE19**S/*E.F3K}}56dS%L))dQh+/E'(mm9:sD!!CAEEEEs1vay3q6!945s1vay3q6!945a<C4K#&/F3Ka<C4K#&/F3K CNJJ>T-4	

 
y  
 mZ8 0u:(>C$S/s2Ux/0  	NHw&?|d|LMM	NR z* sy   L "J* -L 0J= >=L AM
 *J:6L 9J::L =L1L	L 	LL 
M!MM
MMc               
  ^ U R                   mTc  g[        R                  R                  TS   5      nUc$  [	        5       R                  U < STS   < 35        gU R                  R                  nUR                  S:X  a#  UR                  SS5      R                  SS5      nO3UR                  S	:X  a  O"UR                  S:X  a  UR                  SS5      nTR                  S
S5      S:  a  SU-   nTR                  SS5      S:  a  SU-   n[        U4S jU 5       5      nTR                  SS5      nU R                  R                  [        SSS	5      SS9nUS   R                  n0 n0 n0 n	TR                  SS5      n
TR                  SS5      nTR                  SS5      nU
S:  a4  XS'   SU;   a*  SX1R                  S5         U
-  [         S   -  4US'   SU	S'   US:  a4  XS'   SU;   a*  SX1R                  S5         U-  [         S   -  4US'   SU	S'   US:  a;  XS'   SU;   a1  X1R                  S5         nUS:  a  SX-  [         S   -  4US'   SU	S'   SU;   a  X1R                  S5         nTR                  S5      n[#        U[$        R&                  5      (       a   [)        U5      U:X  a  US:  a  XS   -
  US'   O(TR                  SS5      nUS:  a  US:  a
  SUU-  4US'   TR                  S5      nSU;   Ga  X1R                  S5         nTR                  S5      nTR                  S 5      (       ai  [#        U[$        R&                  5      (       aJ  UR*                  US	4:X  a8  [$        R,                  " US:  5      (       a  USS2S4   USS2S4   -   S!-  US'   OlUbi  UR                  S"5      n[#        U[.        5      (       aC  [)        U5      U:X  a4   [$        R0                  " U Vs/ s H  n[3        U5      PM     sn5      US'   [9        UUUUUS#UUU	=(       d    SS$9	/n[;        [<        U R                  S   5      nUR>                  (       a  U R                  R                  [        SSS	5      SS9nUR                  nSnSnU[)        U5      :  aB  U[)        U5      S	-
  :  a0  UUU   -  nUS-  nU[)        U5      :  a  U[)        U5      S	-
  :  a  M0  USU UR*                  -   nUSU UR@                  -   nURC                  [9        XSXaUS#S%95        SU l"        U$ s  snf ! [4        [6        4 a    [$        R0                  " U5      US'    GNHf = f)&z Return image series in LSM file.Nrr  z LSM unknown ScanType rY   r  r=  r  XCrT  r  r   r,  r  r)  c              3  b   >#    U  H$  n[        T[        R                  U      5      v   M&     g 7fry   )r   r   r  )r   r  lsmis     rv   r   series_lsm.<locals>.<genexpr>}M  s)     IDq#d455a89::Ds   ,/r  Fr  rk  rj  rm  rn  r-  r	  r  r	  r  r  rz  r  r  rt  g       @
ColorNamesr  r   r   r  r  r	  r-  )#r  r   r  rS  r7   rm  r  r   r   r  r  r~   r  r  r   r  r*  r   r   r8  r   r   rl  rM  r  rY  r   r   r   r_   r   r  r  r   r7  )r   r  r  r   r   r  r   r  r  r	  vsxvsyvszr  r  
timestampsr  ccr  cwr  r  r   r  cpr  r?  s                             @rv   r  r  hM  s)   D|##''Z(89D|C7"8j9I8LMNIIOOEQ||C$,,S$7			q	 			!	#||C$xxa 1$Tzxxa 1$TzIDIIE88FBDIIuQa05AE!HNNE  FEE
((<
%C
((<
%C
((<
%C
Qw!l$;jjo 6 <uSz IJF3K%E#J
Qw!l$;jjo 6 <uSz IJF3K%E#J
Qw!l$;**S/*Eqy"EK%*$<=s)c

d{jjo&XXl+
z5==11J5(	$!}4F3K/3/BAv%!)"EBJ/s	/	"B
d{jjo&XX)*HH^$$2u}}--UAJ&		"q&!!ad8bAh.#5F3K^FF<(E%&&3u:+>5"'++.GAuQx.G"HF3K
 	-4
	
F #))A,'D		""5D!#4u"E

3u:o!c%j1n"4%(NBFA 3u:o!c%j1n"4 bq	DJJ&BQx$))#54eL	
 CNME /H"I. 5"'++e"4F3K5s$   T- 2T(
T- (T- -)UUc               .  ^^ ^!^"^#^$^% U R                   nUb  SU;  d  SU;  a  gUS   m%US   nX"SS2S4   R                  5          nST%;  d  ST%;  a  g[        R                  " USS2SS24   SS9S	-   R	                  5       m!SS	S
SS.mT%R                  SS5      (       a  SOSnUT%R                  SS5      (       a  SOS-  nSSSSS.m"[        UU!U"U%4S jU 5       5      m$[        T$5      n[        U4S jU 5       5      m S6U U#U$4S jjnXBR                  S   :  nU(       a  U R                  R                  (       d7  [        5       R                  U < SU R                  R                  < 35        SnOSU R                  ;  a   [        5       R                  U < S35        SnOiST%;   aE  T%S   nU R                  R                  U5      (       d  [        5       R                  U < S35        SnOU R                  R!                  S5      S   nU(       a  ["        R$                  R'                  U R                  R(                  WS -   5      n[*        R*                  " U5      n	[-        U	5      S	:X  a  SnOS/U-  m#U" X5      n
U	 H  nU R                  ["        R$                  R/                  U5      :X  a  M2  [1        U5       n[3        UR                  S15      S   nX"SS2S4   R                  5          nX" X5      -  n
SSS5        M     U(       a  GOXBR                  S   :  a  T$n[        R4                  " USS2SS24   SS9n[        R                  " USS2SS24   SS9nUR7                  5       nUSS2SS24==   U-  ss'   [        S! [9        UR	                  5       UR	                  5       SS"9 5       5      m$[        U$4S# jT  5       5      m$[        T$5      nS/U-  m#U" X5      n
[        5       R                  U < S$T$< S%U< 35        OS/U-  m#U" X5      n
W
U:w  a"  [        5       R                  U < S&XJ-
   S'35        U R:                  R<                  nUUR>                  -   nT$UR                  -   n0 n0 nSnT%R                  S(S)5      nUS:  aR  UUS('   S*S*S+.nS,U;   a  UURA                  S,5         nS)UU-  4US,'   S-U;   a  UURA                  S-5         nS)UU-  4US-'   S.U;   a?  T%R                  S/S)5      nUS:w  a'  UURA                  S.5         nS)U[C        U5      -  4US.'   S0U;   a6  T%R                  S1S)5      nUS:  a  UURA                  S05         nS)UU-  4US0'   S2U;   ab  T%R                  S35      nUURA                  S25         n[E        U[F        5      (       a(  [-        U5      U:X  a  [        RH                  " U5      US2'   [K        T#UURL                  UU S4U=(       d    SU=(       d    SUUS59
/$ ! , (       d  f       GM  = f)7z3Return image series in Micro-Manager stack file(s).NrM  rN  r  MicroManagerVersionFramesr   r  rY   rT  r   )r  r	  r  r-  	TimeFirstTTRRTSlicesFirstZCCZChannelsSlicesr  )r  r	  r-  r  c           
   3     >#    U  H3  n[        TTU      [        TR                  TU   S 5      5      5      v   M5     g7fr  )rk  r   rS  )r   r  indexmap_indexindexmap_shaper*	  summarys     rv   r   !series_mmstack.<locals>.<genexpr>N  sJ      
 B	 	>"-.DHa()	
 	
 s   ;>c              3  .   >#    U  H
  nTU   v   M     g 7fry   rt   )r   r  rV  s     rv   r   rY  
N  s     =">"-r	  c           
        > SnUS S 2S4   R                  5       n[        R                  " US S 2T4   R                  T5      R                  5       nU R                  R
                  nU R                  R                  UR                  S   -
  S-
  n[        XCSS9 H`  nUu  pXR                  :X  a  UTU'   US-  nM"  SU	s=:  a  U::  a  O  OU	S-   4n
UR                  nUS-  nOS=pSn	[        U UU	U
UUS9TU'   Mb     U$ )	Nr   r     Tr4  rY   r  r  )r  r   rG
  r  r  r   r  r   r  r  r   r   )ry  indexmap
page_countr  r  r  r  r  r  r   r  r  indexmap_orderr  r   s               rv   add_file series_mmstack.<locals>.add_fileN  s   
1a4.'')))Q&'))5

&( 	 ::##??''(*A*A!*DDsJ 6D ME('ea
6%X%%|o!)!8!8a
 043$'-!E%L 7, ru   z/ MMStack multi-file series cannot be read from F_MMStackz MMStack file name is invalidPrefixz_MMStack*.tifc              3  4   #    U  H  u  pX!-
  S -   v   M     g7fr  rt   r1  s      rv   r   rY  bN  s#      
 EAI   r4  c              3  .   >#    U  H
  nTU   v   M     g 7fry   rt   r   r  r   s     rv   r   rY  hN  s     71eAhr	  z3 MMStack series is missing files. Returning subset z of z MMStack is missing z pages. Missing data are zeroedPixelSize_umrj  r	  rY  r  r  r	  	z-step_umr  Interval_msr  ChNamesr  )	r   r   r  r  r   r  r  r	  r	  )ry  r   r]  r  r6  r   )'rC  argsortr   rk  r  rS  r~   r@   r   r  rD  r7   rm  r#  r  r  r  r  rE  r   rG  r   r   basenamer   rC   r  rd  r  r  r   r  r  r-  r   rM  r  r   r   )&r   settingsr]  r  r   r`  r	  prefixr   	filenamesr^  r  r  	old_shape	min_index	max_indexr  	full_axes
full_shaper  r  r	  pxsizerl  rm  r7  r  intervalr  ch_namesr  rV  r_  rW  r*	  r  r   rX  s&                                  @@@@@@@rv   r  r  M  s    ((HH$X%
 y!G
#HA..01HG+xw/F iiBQBa81<DDFN1115N;;{D114tDGKKt44D$>D 	D  
  E 5>D===N" "H ~~a((I~~%%H'H>>%%(* Is||+Hw&CDEI X&F<<**622  C7*G!HI!	\\''
3A6F'',,NN""F_$<
 IIg&	y>QIFTME!#0J%<<277#3#3H#==h'49*   "H  (A(>(>(@AH(4"::J (' & 	q!	!	IIhq"1"uoA6	IIhq"1"uoA6	==?BQB9$ 
  "I$4$4$6t
 
 777u~c,
g   %yYM;	
 c,
Tg)$*;)< =' '	

 yyHx}}$I'J  FE#'E[[-Fz &n"6)ys34E/F3K)ys34E/F3K
iK-A:ys34EE
 23F3K
i;;}c2a<ys34E 01F3K
i;;y)9??3/0h%%#h-5*@++h/F3K 	..>T-4	
 _ ('s   >X
X	c                 ^^7^8^9^: U R                   R                  (       d5  [        5       R                  U < SU R                   R                  < 35        g[
        R                  R                  U R                   R                  S5      n[
        R                  R                  U5      (       d  [        5       R                  U < S35        g0 nSnSSSSS	S
SS.n0 n0 nSn[        U5       GH  u
  m7nn	n
nnnnnnX;   a  US-  nX(   n[        UR                  USUU	4UR                  S9nUR                  SS X4:w  a!  SUR                  SS  SX4 3n[        U5      eUS:w  a  SU< S3n[        U5      eUR                   S:w  a  SUR                   < 3n[        U5      eX;  a  SU 3n[        U5      eXL   u  nnUR"                  U:w  a  SUR"                   SU 3n[        U5      eOSnXR$                  :X  a  U R&                  R(                  nO\[+        [
        R                  R                  U R                   R                  U5      5       nUR&                  R(                  nSSS5        WX('   U(       aY  T7R-                  5        H)  u  nn[/        U[0        5      (       d  M  US0UU'   ST7U'   M+     Sn[3        T7R5                  5       5      m8OjU(       ac  UR-                  5        HO  u  nnT7U   n[/        U[0        5      (       d   eUU;  a  [7        UR9                  5       5      S-   UU'   UU   T7U'   MQ     [3        T7R5                  5       5      T8:w  aV  [3        T7R5                  5       5      n[        5       R                  U < SU ST8 35        [;        U5      [;        T85      :w  a  GM  UU[3        U74S jT8 5       5      '   GM     [<        R>                  " [A        UR5                  5       5      [<        RB                  S9n[<        RD                  " USS9RG                  5       m9[<        R6                  " USS9RG                  5       n[3        S [I        T9USS9 5       5      m:[K        USS9n[3        U:4S  jU 5       5      m:[3        U84S! jU 5       5      m8UR-                  5        V^Vs0 s H  u  mn[3        UU94S" jU 5       5      U_M     nnn[<        RL                  " T:5       Vs/ s H  nURO                  U5      PM     n nU(       d  [        5       RQ                  U < S#35        g[S        [U        UR9                  5       5      5      nT:UR                  -  m:S$R                  S% T8 5       5      n!U!URV                  -  n!U!S[Y        T85       n"0 n#[I        T8U"SS9 Hm  u  n$n%U$U;   d  M  UU$   n&[7        U&R9                  5       5      S-   n'S$/U'-  n(U&R-                  5        H  u  n)mU)U(T'   M     [<        R>                  " U(5      U#U%'   Mo     0 n*Sn+U RZ                  n,U,Gbb  U,RO                  S&0 5      n-U-RO                  S'S(5      n.U.S:  aR  U.U*S''   S)S)S*.n+S+U!;   a  T:U!R]                  S+5         n/S(U/U.-  4U#S+'   S,U!;   a  T:U!R]                  S,5         n0S(U0U.-  4U#S,'   S-U!;   a6  U-RO                  S.S(5      n1U1S:  a  T:U!R]                  S-5         n2S(U2U1-  4U#S-'   S/U!;   a6  U-RO                  S0S(5      n3U3S:  a  T:U!R]                  S/5         n4S(U4U3-  4U#S/'   S1U!;   ah  S1U#;  ab  U-RO                  S25      n5T:U!R]                  S15         n6[/        U5[@        5      (       a(  [Y        U55      U6:X  a  [<        R>                  " U55      U#S1'   SU l/        [a        U T:UR"                  U!U#=(       d    SU*=(       d    SU+U S3[Y        U5      S:  S49
/$ ! , (       d  f       GNm= fs  snnf s  snf )5z,Return image series in NDTiff v2/v3 file(s).z NDTiff.index not found for NrB  z NDTiff.index not foundr   )rP  rP  )r  r  )r  r  )r  r  )r  r  )r  r>  )r   rY   rT  r   r  r  r  TrY   r  rT  z'NDTiff.index does not match TIFF shape r  zNDTiff.index compression=r^  z2NDTiff.index does not match TIFF page.compression=z NDTiff.index unknown pixel type z1NDTiff.index pixeltype does not match TIFF dtype Fz NDTiff.index axes_dict.keys=c              3  @   >#    U  H  n[        TU   5      v   M     g 7fry   r  )r   r6
  	axes_dicts     rv   r    series_ndtiff.<locals>.<genexpr>%O  s     :Tcc)C.))TrD	  rz  r  c              3  4   #    U  H  u  pX!-
  S -   v   M     g7fr  rt   r1  s      rv   r   r|  +O  s     O(N!%!)(Nre  r4  r  c              3  .   >#    U  H
  nTU   v   M     g 7fry   rt   rg  s     rv   r   r|  /O  s     *Eq%(Er	  c              3  .   >#    U  H
  nTU   v   M     g 7fry   rt   r   r  r  s     rv   r   r|  0O  s     (%Qa%r	  c              3  :   >#    U  H  nTU   TU   -
  v   M     g 7fry   rt   )r   r  r  rr  s     rv   r   r|  2O  s     3Uc!fy|#Us   z NDTiff.index has no keyframesr=  c              3  ~   #    U  H3  n[         R                  R                  UR                  5       S 5      v   M5     g7f)r/  N)r   r>
  rS  r  r  s     rv   r   r|  ?O  s*     E14??&&qwwy#66s   ;=rM  rh  rj  r	  rY  r  r  r	  ri  r  rj  r  rk  r  )	r   r   r  r  r  r	  r  r   r	  )1r  rD  r7   rm  r#  r  rE  r   rG  rF  rD   r   r  r  r   r   r   r   r  r  r   r   r`  r   rz   r~   r*	  rk  r  r!  r   r  rM  r  r  r  r  
order_axesr
  rS  r  r  r  r  r   rC  r  r7  r   );r   	indexfiler  r  pixel_typesr  r   r   r  r  rX  r  	pixeltyper   _metaoffset_metabytecount_metacompressionr  r  r   r   r   r  r  r  r  dims_indices_arrayrs  r
  r  rO  r  r  dim_axesr  r6
  r  mappingr   r  r  r  r	  r!  summrv  rl  rm  r7  r  rw  r  rx  r  r{  r  rr  r   s;                                 `                        @@@@rv   r  r  N  s    >>!!g1#..2D2D1GH	
 S^^33^DI77>>)$$C7"9:;%'I IK <>G,.JE 
9	%	 NI *H!'M'66D zz"1~&0=zz"1~&dF?*;=  !o%a2k^>B o%1$K$:J:J9NO o%+8D o%"-HE1zzU"Gzzl$ug/  !o% # I<<'yyGGLL!7!7B::++D #'I (0eeS))(-qzJt$&'IdO  1 E)*D * 0 0 2f!$!%----&$'$81$<F5M"(-	$ !3 !"d*)..*+EH'6ugT$H 5zSY&>B:T::;Q 
&V KKW\\^ 4EKKHM		-a0779I		-a0779IOIy(NOOE }e4E*E**E(%((D "--/)JC 	3U33U:)   %*MM%$80$8SC$8 
 0 # >?@D))+,-H	X^^E77EEEDHMMD Kc$i HFtXd3R* oGw~~'(1,D!#tF%mmo
s#s .V,F2J 4 E#'E		"	"B	~vvi$ .#.A:$*E.!&\:Ed{djjo."EFN3sd{djjo."EFN3s $;HH[#.Eqydjjo."EEM2s $;xxs3H!|djjo."EH$45s $;3f,xx	*H$**S/*E(D))c(mu.D#kk(3sCN..>T-4)nq(	
 e V
0s   _2$_!1_'
_	c                  U R                   nUc  gU R                  R                  SS9nU R                  R                  nSU;   a+  SU;   a%  US   UR                  -   nUS   UR
                  -   nO([        U5      /UR                  Q7nSUR
                  -   nSU l        0 n0 n0 n[        UR                  SS	5      5      n	[        UR                  S
S	5      5      n
U	(       a+  SU;   a%  U	[        S   -  nS	UR                  U-  4US'   SUS'   U
(       a+  SU;   a%  U
[        S   -  nS	UR                  U-  4US'   SUS'   SU;   a  UR                  S0 5      nUR                  SS5      nUR                  S0 5      R                  S5      nXER                  S5         nUb3  [        U5      U:X  a$  UR                  [        5      US'   U(       a  XS'   Og[        UR                  SS	5      5      n[        UR                  SS	5      5      nU(       a*  U[        R                   " U5      U-  -   US'   U(       a  XS'   SU;   ac  UR                  S0 5      R                  S5      nXER                  S5         nUb,  [        U5      U:X  a  UR                  [        5      US'   SUS'   SU;   a  UR                  S5      nXER                  S5         nU(       aZ  [        U5      U:X  aK  U Vs/ s H  nUR                  SS5      PM     nn[#        U5      (       a  [        R$                  " U5      US'   UR                  S5      nU(       a  [        U5      US'   UR                  S5      nUb  UR'                  5       US'   UR                  SS5      =(       d    Sn[)        UUUR*                  UUS U=(       d    SU=(       d    SU=(       d    SS!9	/$ s  snf )"z(Return image series in Olympus SIS file.NFr  r   r  r  T
pixelsizexrj  
pixelsizeyr  r-  r	  r  r	  r  UnitZr=  rJ  StepZ	StartPosZr  r  TimePosr  r  BandBandNamer  rU   r   r  rB  )r  r  r  r   r   r  r   r7  rY  rS  r*  rO  rP  r  r,   r   r  r;  r  r  r   r   )r   rH  r  r  r   r  r  r  r	  r  r  mppxmppyr  unit_zz_posnzstep_zstart_ztime_posntbandsncr
  
band_namesr  r  r   s                               rv   r  r  O  s   D|II.E99??D$6T>W

*F|dii'U)djj)TYYCNFEE txxc23Jtxxc23JcTkE#J&DOOd23s!c
cTkE#J&D,,t34s!c
 d{xx#'2&b!%%f-::c?#Ur!1,,u-F3K#c
488GS12FDHH[#67G%R(86(AAs!'#J d{88FB'++I6::c?#CMR$7"//%0F3K&E#J d{ ::c?#SZ2%9>?A!%%
B/J?:#kk*5sHH_-M!&}!5o	*	B	~LLNj88FB'4D 	JJ>T-4-4
	
  @s   (Oc               
   [        U 5      nU(       d  gU GH  nSUl        UR                  S   S:X  a  SUR                  SS -   Ul        UR                  (       GaO  UR
                  R                  R                  S5      =(       d    SUl        SUR                  ;   a  UR                  S   n/ nUR                  SU  Ho  n[        U[        5      (       d  M  UR                  R                  S	5      n[        U[        [        45      (       d  MR  UR                  [        U5      S
-  5        Mq     [!        U5      U:X  aV  [!        [#        U5      5      S:  a>  [$        R&                  " U5      UR(                  S'   UR*                  R-                  S5        UR.                   GH   nUR
                  nUR                  R                  S5      n	[        U	[        [        45      (       a  U	S:  a  XR0                  S'   UR3                  SS9u  pU
S:  d  Ms  US:  d  M{  SU
-  nSU-  nSUR4                  U-  4UR(                  S'   SUR6                  U-  4UR(                  S'   SSS.nSUR(                  ;   a	  XrL a  SUS'   Xl        UR*                  R;                  S5        GM     GM  UR
                  R                  R                  S5      n	U	c  GM  U	S:X  a
  SUl        GM  U	S:X  d  GM  SUl        GM     SU l        U$ )z+Return pyramidal image series in NDPI file.Nr@  r   r  r	  rY   r~  r  r{  r  r  r  r	  r  r  rj  r  r  rY  g      Macrog       MapF)r  r   r  r  r	  r  r  r  r   r   r	  r   r   r   rY  r   r   r!  r   r  r  r	  r$  r  r&  r  rO  rP  r	  r  r7  )r   r   r  z_sizez_valspgz_vr   r  r  rs  rt  r  r  r	  s                  rv   r  r  O  sv   C F66!9AGGABK'AG>>>ZZ__,,U3AzAFagg~((7F+B!"h// ggooe4%cC<88"MM%*t*;<	 ,
 v;&(SV-=-A%*[[%8AIIcN&&**3/~~ii''.cC<00S1W47LL1,,,,?6b1f"HE"HE*-t/F)GEMM#&*-t/?/?%/G)HEMM#&".\BEaii'EJ%1c
#(L**11*= "  jjoo%%e,?d{ U X CNMru   c               	   [        U 5      nU(       d  g[        U5      S:w  a(  [        5       R                  U < S[        U5       35        US   nSUl        UR
                  S   S:X  a  SUR                  SS -   Ul        UR                  (       a  S	Ul        [        U5      S:X  a$  [        USS S
SS9 H  u  p4XCl        SUl        M     U R                  nU(       Ga  SSKJn  SnSnSn	[        R                  " [        5         UR!                  U5      n
U
R#                  S5      nUb<  [        R                  " [$        5         ['        U5      nXrR(                  S'   SSS5        U
R#                  S5      nU
R#                  S5      nU(       aa  U(       aZ  [        R                  " [$        5         [*        R,                  " U SU 3S5      R/                  5       UR(                  S'   SSS5        UR0                  R3                  SS9u  pUS:  a  US:  a  SU-  nSU-  n	SSS.Ul        U
R#                  S5      nU(       a  SUR
                  ;   a  [        R                  " [$        5         ['        U5      nUR6                  UR
                  R9                  S5         nUS:  a/  US:  a)  SUU-  US-
  -  4UR:                  S'   SUR4                  S'   SSS5        SSS5        Ubp  U	c   eSUR0                  R<                  U-  4UR:                  S'   SUR0                  R>                  U	-  4UR:                  S'   UR@                  RC                  S5        UR                  (       Ga  Uc  UGb  UR0                  R<                  nUR0                  R>                  nURD                  SS  H  nUUR0                  R<                  -  nUUR0                  R>                  -  nUb  U	c   eUU-  nU	U-  nSSS.Ul        SUR0                  R<                  U-  4UR:                  S'   SUR0                  R>                  U-  4UR:                  S'   UR@                  RC                  S5        Uc  M  UU-  UR(                  S'   M     SU l#        U$ ! , (       d  f       GN6= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f)z*Return pyramidal image series in AVS file.Nr   z# AVS series expected 3 series, got r   r  r  r	  rY   r  )r  r  Tr4  rv  ObjectiveMagnificationr  r  AcquisitionTimer  z%m.%d.%Y %H:%M:%SrU   r&  r  r%  r	  rY  ZRangerj  r  r  F)$r  r   r7   rm  r   r  r  r	  r   r  r  r  rw  r  r  r  r
  findtextr   rY  r&  rh  rI   r  r  r  r	  r   r  r  rO  rP  r	  r  r  r7  )r   r   r  s2r   r  rw  r  mpp_valr  ry  mag_textdate_strtime_strr  r  zrange_textzranger  rp  rq  r   ratio_xratio_ylevel_mpp_xlevel_mpp_ys                             rv   r  r  P  s7   C F
6{ag8VF	
 	q	AAFvvayC#~~
6{aF12J(8FHBGBG G 

C
)!% $"  +))#.D}}%=>H#((4$XH08HH_- 5 }}%67H}}%67HH((4+3+<+<#*AhZ02E,ik HHZ( 5 222EJDaxD1H*d
!-LA--1Ksaff}((4";/F c!23Bzb1f +.v{b1f/E)F		#(4 5- ,B $$$!1::#8#87#BCAIIcN!1::#9#9E#ABAIIcN%%j1>>>w2h6J..J**00K!"$u~~'@'@@%(B(BB& ,,,")G"3K"''/K)5L#IEL11K?*EMM#&
 22[@*EMM#& **11*='4<w4FELL1% &( CNMs 54 54 54- ,+sX   A SR AS28R!*BS/A)R3S
R	S!
R0	+S3
S	=S
Sc               	  ^ / nU R                   nSUl        SUl        UR                  S5        UR	                  5         UR
                  n0 n0 nSnSn [        UR                  5      nUR                  S5      n	[        U	[        [        45      (       a>  U	S:  a8  [        U	5      nSSS.nSUR                  U-  4US	'   SUR                  U-  4US
'   UR                  S5      n
U
b  XS'   [#        U5      S:X  aJ  SU l        ['        U/UR(                  UR*                  UR,                  SSU=(       d    SU=(       d    SUS9	/$ US   n['        U/UR(                  UR*                  UR,                  SSS9nUR(                  U/0nSnU[#        U5      :  a  [/        [0        X/   5      nUR2                  (       a  UR4                  (       a  OSUR(                  U;   a  XR(                     R7                  U5        OU/XR(                  '   US-  nU[#        U5      :  a  M  [#        XR(                     5      m[9        U4S jUR;                  5        5       5      (       d3  [        5       R!                  U < S35        SmU H  nUU   SS UU'   M     ['        XR(                     T/UR(                  Q7UR*                  SUR,                  -   SSU=(       d    SU=(       d    SUS9	nUR                  S5      nUR=                  5        H  u  nnUUR(                  :X  a  M  US   nUR                  UR                  -  n0 n0 nSnUb2  UU-  nSSS.nSUR                  U-  4US	'   SUR                  U-  4US
'   Ub  UU-  US'   UR>                  R7                  ['        UT/UR(                  Q7UR*                  SUR,                  -   SSU=(       d    SU=(       d    SUS9	5        M     UR7                  U5        UR7                  U5        [A        S5       H  nU[#        U5      :X  a    OtX/   n[        U[0        5      (       d   eURB                  S:X  a  SOSnUR7                  ['        U/UR(                  UR*                  UR,                  USS95        US-  nM     SU l        U$ ! [         a,  n[        5       R!                  U < SU<S 35         SnAGNSnAff = f)z'Return image series in Aperio SVS file.TFr   NMPPr	  rY  rj  r  r  AppMagr  z" SVS description metadata failed: r_  rY   r  r  )r   r   r  r  r	  	Thumbnailr-  rT  c              3  @   >#    U  H  n[        U5      T:H  v   M     g 7fry   r
  )r   r   zsizes     rv   r   series_svs.<locals>.<genexpr>P  s     @us5zU"rD	  z% SVS series focal planes do not matchr	  rv  r;  r  r  )"r  r  rl  r  r  r   svs_description_metadatar   rS  r   r   rY  rO  rP  r  r7   rm  r   r7  r   r   r   r  r_   r   r^  r  r   rl  r  r`  r  r  r   )r   r   r  r  r  r  r  r	  rH  r  r  r  r  	thumbnailr  r  r   ro  r  r   ratior  lmppr   r   r  s                            @rv   r  r  tP  s   FIIEEKEO	q	KKM KKE EF G#'E
'(9(9:hhuocC<((S1WCjG&\:E 0 07 :;F3K 1 1G ;<F3Khhx ?%(/" 5zQ

mt~

 	
 8D	



		I kkE7#FE
#e*
Hel+}}::::%%d+"&F::
 #e*
 {{#$E@@@@C7"GHIE"5M"1-F5M {{	ejjmt~
H yy)HuEKKQx  4??2&(U?D&\:E$ 67F3K 0 04 78F3K+3e+;K($$

dii!!)T~
	
! ': MM(
MM) 1XCJ|$))))**a/wW



				
 	
! " CNMe  
g7|d|D	
 	

s   BR$ $
S.!SSc                  SSK Jn  U R                  nU R                  nU(       d  gUR	                  U5      n/ nSUl        SUl        UR                  S5        UR                  5         U GH  nUR                  R                  S5      (       d  M&  U GH  nUR                  R                  S5      (       d  M&  UR                  R                  SS	5      n[        UR                  R                  S
S5      5      S:  a  Sn	[        U	5      eU GH4  n
U
R                  R                  S5      (       d  M&  0 nU
 H  nUR                  R                  S5      (       d  M%  [        UR                  R                  SS5      5      n[        UR                  R                  SS5      5      n[        UR                  R                  SS5      5      n[        UR                  S   5      nX;   a3  X   n[        US   U5      US'   [        US   U5      US'   UUS   X4'   M  UUX4U0S.X'   M     U(       d  GM'  / n[!        UR#                  5       5       H  u  nnUS   S-   US   S-   4nSnS/[%        U5      -  n[!        US   R#                  5       5       H  u  u  pnUU   UUUS   -  U-   '   M     US   c   eUUS   R&                  -  nUUS   R(                  -  nUS   R*                  nUR-                  [/        UUUUU USS95        M     US   R0                  R3                  USS 5        UR-                  US   5        GM7     GM     GM     SU l        U$ )z0Return pyramidal image series in Leica SCN file.r   rv  NTF
collectionimager   UnknownsizeZrY   z@SCN series: Z-Stacks not supported. Please submit a sample file.r  	dimensionr  rQ  rW  r  r  r  r  )r  r  r  rR  r  )r  r   r   )r  rw  r  rn  r
  r  rl  r  r  r  rZ  r  rS  r   r   rk  ru  r`  r@   r  r   r   r   r   r  r  r7  )r   rw  r  scnxmlry  r   r  r  r   r   r  resolutionsr  r  rQ  rW  r  r   r  _rr   r  r  r   s                           rv   r  r  Q  sS    &IIEF!!&)DFEKEO	q	KKM
~~&&|44E99%%g..<<##FI6D5<<##GQ/0143  *#..zz**8449;!'I$==11+>> I,,00a89AI,,00a89AI,,00a89Ai..u56C' +,/j0A1,Ej)),U7^Q)?g03fqf- )*%&&'VSM* "($ #!'(9(9(;!<IBj)A-g*.E  D?CfwH ?D (.eFm.A.A.C'D16sQq\A-. (E  7...DGLL(DT!W]]*E GMMEMM& !! #&!%!&
% "=: q	  ''qr
3fQi(o     L CNMru   c               Z   / nU R                   nSUl        SUl        UR                  S5        UR	                  5         UR
                  n/ nSnSUR                  -   nUR                  nUR                  nU[        U5      :  a<  X%   n	U	R                  U:w  a  O'UR                  U	5        US-  nU[        U5      :  a  M<  [        U5      /UQ7n
UR                  [        XJXvSSS95        U[        U5      :  aE  X%   n	UR                  [        U	/U	R                  U	R                  U	R                  S	SS95        US-  nUR                  (       a  U[        U5      :  a  US   S
-  US   S
-  /US
S Q7n/ nU[        U5      :  a<  X%   n	U	R                  U:w  a  O'UR                  U	5        US-  nU[        U5      :  a  M<  [        U5      [        US   5      :w  a  OJ[        U5      /UQ7n
US   R                  R                  [        UU
UUSSS95        U[        U5      :  a  M  US   R                  (       a  U[        U5      :  a  X%   n	UR                  [        U	/U	R                  U	R                  U	R                  SSS95        US-  nU[        U5      :  a@  X%   n	UR                  [        U	/U	R                  U	R                  U	R                  SSS95        US   nSnSnU R                  nU(       a  [         R"                  " [$        5         SSKJn  UR+                  U5      nUR-                  S5      nUb.  [         R"                  " [.        5         [1        U5      nSSS5        UR-                  S5      nUb.  [         R"                  " [.        5         [1        U5      nSSS5        SSS5        UcF  [         R"                  " [$        5         UR3                  SS9u  nnUS:  a  US:  a  SU-  nSSS5        Uba  SSS.Ul        SUR6                  U-  4UR8                  S'   SUR:                  U-  4UR8                  S'   UR<                  R?                  S5        Ub  XR@                  S'   UR                  (       a  Uc  Ub  UR6                  nUR                  SS  H  nUURB                  R6                  -  nUbz  UU-  nSSS.Ul        SURB                  R6                  U-  4UR8                  S'   SURB                  R:                  U-  4UR8                  S'   UR<                  R?                  S5        Uc  M  UU-  UR@                  S'   M     SU l"        U$ ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f)z,Return image series in PerkinElmer QPI file.TFr   r  rY   r  r   r-  r  rT  Nrv  r  r  rv  z.//Magnificationz.//PixelSizeMicronsr&  r  r%  r	  rY  rj  r  r  r  )#r  r  rl  r  r  r   r  r   r   r   r   r   r^  r  r	  r{  r  r  r  r  rw  r
  r  r   rY  r  r	  rO  r  rP  r	  r  r&  r  r7  )r   r   r  r  r  r  r  r   pshaper  r   r  r  r  r  rw  ry  r  mpp_textr  r  rp  r   r  	level_mpps                            rv   r  r  `Q  s6   FIIEEKEO	q	KKMKKE DEDKKE[[F
#e*
|::D
 #e*
 Y  E
MMtEjuM s5z|



		 		
 	
~~c%j Qi1nfQi1nBvabzBFD#e*$|::'D!
 #e*$ 4yCq	N*Y((E1I##%	 c%j . ay%#e*"4|



				
 	
3u:<DMMFJJJJII 	 	q	A!H G


C
  +-))#.D}}%78H#((4$XH 5}}%:;H#((4#HoG 5 ,   +--<-@JD$axD1H* , %L9u//'9:		#u007:;		#	!!*-$,!~~7.(2F%%
XXab\E!:!::E"#eO	%1ENN--	9&c"
 NN..:&c" &&--j9#0850@_- "" CNMM 54 54 ,+ ,+sI   AV	U%&6V	U7(V	$V%
U4	/V	7
V	V		
V
V*c                  / nSnU R                   nSUl        SUl        UR                  S5        UR	                  5         U GH  n[        [        U5      nUR                  R                  S5      (       a>  UR                  [        U/UR                  UR                  UR                  SSS95        Mr  UR                  S	:X  d   UR                  R                  S
5      (       a>  UR                  [        U/UR                  UR                  UR                  S
SS95        M  SUR                  ;  a?  UR                  [        U/UR                  UR                  UR                  SSS95        GM/  Uc5  [        U/UR                  UR                  UR                  SSS9nU/UQnGMg  UR                  R                  [        U/UR                  UR                  UR                  SSS95        GM     [        5       R!                  U < S35        UGb&  SSKJn  UnSnSnSn	U R&                  n
U
(       a  [(        R*                  " [,        5         UR/                  U
5      nUR0                  S:X  a  UOUR3                  S5      nUb  UR5                  S5      nUb  [7        U5      nUR5                  S5      nUb  [7        U5      nUR5                  S5      nUR5                  S5      nUb  Ub  [9        U5      S:  a  [7        U5      n	SSS5        Ubu  SSS.Ul        SUR<                  R>                  U-  4UR@                  S'   SUR<                  RB                  U-  4UR@                  S'   URD                  RG                  S5        U	bv  SUR                  ;   af  UR                  UR                  RI                  S5         nSUU	-  4UR@                  S'   URD                  RK                  S5        SUR:                  S'   Ub  XvRL                  S'   URN                  (       Ga  Uc  UGb  SS jnUR                  SS  GH  nU" UR<                  R                  5      nUb  UURL                  S'   Ub  U(       a|  X-  U-  nSSS.Ul        SUR<                  R>                  U-  4UR@                  S'   SUR<                  RB                  U-  4UR@                  S'   URD                  RG                  S5        OUb  UR<                  R>                  UR<                  R>                  -  nUU-  URL                  S'   Ubz  UU-  nSSS.Ul        SUR<                  R>                  U-  4UR@                  S'   SUR<                  RB                  U-  4UR@                  S'   URD                  RG                  S5        U	c  GM~  SUR                  ;   d  GM  UR                  UR                  RI                  S5         nSUU	-  4UR@                  S'   URD                  RK                  S5        SUR:                  S'   GM     SU l(        U$ ! , (       d  f       GNC= f) z.Return image series in Ventana/Roche BIF file.NTFr   r  Overviewr  r-  r  Probabilityr   r  r  rv  z" BIF series tiles are not stitchedrv  iScanrx  ScanResz	Z-spacingzZ-layersrY   r	  rY  rj  r  r  r	  r  c                    U R                  5        H*  nUR                  S5      (       d  M   [        USS  5      s  $    g ! [        [        4 a       g f = f)Nzmag=r  )r  r  rY  r   r4  )r   tokens     rv   	parse_magseries_bif.<locals>.parse_magfR  s\     )..0E''//(#(qr#33 1  !+J7 (#'(s   A  AA)r   rz   r6  r  ))r  r  rl  r  r  r_   r   r   r  r   r   r   r   r  r  r7   rm  r  rw  r  r  r  r  r
  r  r  rS  rY  r   r	  r  rO  r  rP  r	  r  r  r$  r&  r	  r7  )r   r   ro  r  r  rw  r  r  r  zspacingr  ry  iscanr  scanreszspzlayersr  r  r   	level_magr  r  s                          rv   r  r  Q  s   F&*HIIEEKEO	q	KKMHd#&&w//MMFJJJJII#	 ,0@0@0K0K1
 1
 MMFJJJJII&	 D,,,MMFJJJJII"	 %



		H ((FOO""FJJJJII%	c x Hw@AB )!% $!%$$Y/"--c2 $G 379K$))O4C#(:#ii	2G*"'.))K0C#ii
3G#/L1,#(:# 0$ )=AH!1::#8#87#BCAIIcN!1::#9#9G#CDAIIcN%%j1C166MGGAFFLL-.E!58#34AIIcN""3'(AHHSM(0HH_%>>>w2h6J	 !"%enn&@&@A	(4=ELL1*x$+$6$B	-9'M!NN55	A.c*
  !NN66B.c* ..55jA)JJ11ENN4M4MME4<u4DELL1*$+eO	-9'M!NN55	A.c*
  !NN66B.c* ..55jA'C5::,=!KK

(8(8(=>E*-ux/?)@EMM#&**..s3(4ELL%G &J CNMc 0/s   B8Y
Yc               @   SSK Jn  / nU R                  nSUl        SUl        UR                  S5        UR                  5         U R                  nU(       d  g UR                  U5      nUR                  S5       Vs/ s HL  nUR                  c  M  [        S	 UR                  R                  S
S5      R!                  5        5       5      PMN     nn[#        U5      S:  a+  [        5       R                  U < S[#        U5      < S35        g0 n	/ U	S'   / U	S'   U H  n
[%        U
[&        5      (       d   eU
R(                  R+                  S5      (       a  U
/U	S'   MB  U
R(                  R+                  S5      (       a  U
/U	S'   Mj  U
R,                  (       d  U	S   R/                  U
5        M  U	S   R/                  U
5        M     U	R1                  S5      n[#        U5      [#        U5      :w  a7  [        5       R                  U < S[#        U5      < S[#        U5      < 35        gUS   R2                  nUS   R4                  nUS   u  p[7        USS USS SS9 GH<  u  n
u  nnU[9        UU-  5      -  nU[9        UU-  5      -  nU
R2                  U
R:                  -
  U:  am  [        5       R=                  U < SU
R>                  < SU
R2                  < SU
R:                  < SU< 3	5        U
=R2                  U
R:                  S-
  -  sl        OTU
R2                  U:  a=  [        5       R=                  U < SU
R>                  < SU
R2                  < SU< 35        OUU
l        U
R2                  nU
R4                  U
R@                  -
  U:  am  [        5       R=                  U < SU
R>                  < SU
R4                  < SU
R@                  < SU< 3	5        U
=R4                  U
R@                  S-
  -  sl        OUU
l        U
R4                  nU
RB                  S   S:  a  UUU
RD                  S   4U
l"        O4U
RB                  S   S:  a  U
RD                  S   UU4U
l"        O	UU4U
l"        / U
RB                  SS QUPUPU
RB                  SS Q7U
l!        GM?     [G        US   /S S!S"9/n[I        USS 5       H4  u  nn
US   RJ                  R/                  [G        U
/SUS-    3S!S"95        M6     U	RM                  5        H*  u  nnU H  n
UR/                  [G        U
/US!S"95        M      M,     US   n[7        URJ                  USS9 H  u  nu  nnUS#-  nUS#-  nS$S$S%.Ul'        S&URP                  R2                  U-  4URR                  S''   S&URP                  R4                  U-  4URR                  S('   URT                  RW                  S%5        M     SU l,        U$ ! UR                   a+  n[        5       R                  U < SU<S 35         SnAgSnAff = fs  snf ))z1Return pyramidal image series in Philips DP file.r   rv  TFNz Philips series raised r_  z].//*/DataObject[@ObjectType="PixelDataRepresentation"]/Attribute[@Name="DICOM_PIXEL_SPACING"]c              3  8   #    U  H  n[        U5      v   M     g 7fry   )rY  r	  s     rv   r   !series_philips.<locals>.<genexpr>R  s     C B1eAhh Br  r  r=  rT  z# Philips series len(pixel_spacing)=z < 2LevelOtherr  r  z Philips series len(levels)=z != len(pixel_spacing)=rY   r4  z Philips series page.index=z page.imagewidth=z-page.tilewidth=z >= imagewidth=z < imagewidth=z page.imagelength=z-page.tilelength=z >= imagelength=rK  r  r  r-  r  r	  rY  rj  r  r  )-r  rw  r  r  rl  r  r  rs  r
  r  r7   r  findallr  r~   r  r  r   r   r   r   r  r^  r   r  rO  rP  r  roundrR  rm  r  rS  r   r   r   r  r  r`  r	  r  r  r	  r  r7  )r   rw  r   r  rH  r  r  elempixel_spacingseries_dictr  r  imagewidth0imagelength0h0w0r+  rG  rO  rP  r  r   rO  r  r   r  r  s                              rv   r  r  R  s   %FIIEEKEO	q	KKMD%%d+ LL6

D
 99 	DC		 1 1#r : @ @ BCC
   =A# D]1C0ETJK-/KKK$))))&&w//$(6K ((11$(6K  ''- ''-  __W%F
6{c-((g 6{n4]!3 57	
  )&&K!9((L1FBF12Jab(9$Gfq! E!b&M1
"eAFm3??T^^+z9H'5$** 7$??$$5dnn%6 7-!
 OOt~~11O__z)H'5$** 7$??$O
}6
 )DO__
doo-<H'5$** 7%##%%7t&8 9 ."
 ! 33*D&&;;r?Q%z4::b>BDJ[[^a**Q-jADJ%z2DJ
[[!_

 
 [[	
K HX fQi[z	JKFVABZ(4q	D6%AwiH	
 ) "'')
UDMM.$c	JK  *
 	q	AQXX}TBv1DD)=!5>>#<#<u#DEc!5>>#=#=#EFc%%j1 C CNMW !! # 7|d|DEs$   W =X>XX-!XXc          
     	   SSK Jn  U R                  nU(       d  g UR                  U5      n[        UR                  S5      5       VVs/ s H*  u  pVUR                  R                  S[        U5      5      PM,     nnn0 nUR                  S5       H  n	[        R                  " [        [         5         [#        U	R                  S	   5      n
[#        U	R                  S   5      n[#        U	R                  S
   5      nX;  a  0 X'   XU
   U'   SSS5        M     U R$                  nSUl        SUl        UR+                  S5        UR-                  5         U(       d  g/ nU(       a  [.        R0                  " U5      OSn[        [3        UR5                  5       5      5       H  u  nnUU   n[3        U5       Vs/ s H
  oUU      PM     nn[7        S U 5       S5      nUc  MC  [9        U5      nUS:  a  UUR:                  UR<                  4nSnOUR:                  UR<                  4nSnUS:X  a  SOSU 3n[?        UUUR@                  UUSS9nUb3  US:  a-  USU URB                  S'   URD                  RG                  S5        URI                  U5        M     U(       d  SU l%        gUS   nUUl&        SnSn[        R                  " [N        5         URP                  nURR                  n[#        URT                  5      nUS:X  a  US   S:  a	  SUS   -  nOUS:X  a  US   S:  a  SUS   -  nSSS5        [        R                  " [N        5         URW                  S5      nUb  [Y        UR                  S   5      nSSS5        Uc  Ub  URP                  R<                  n U H  n!U U!RP                  R<                  -  n"Ubz  UU"-  n#SSS.U!l-        SU!RP                  R<                  U#-  4U!RB                  S'   SU!RP                  R:                  U#-  4U!RB                  S '   U!RD                  R]                  S5        Uc  M  UU"-  U!R^                  S!'   M     SU l%        U/$ ! UR                   a+  n[        5       R                  U < SU<S 35         SnAgSnAff = fs  snnf ! , (       d  f       GM$  = fs  snf ! , (       d  f       GN= f! , (       d  f       GNY= f)"z1Return pyramidal image series in IndicaLabs file.r   rv  Nz Indica series raised r_  r$  r   z./image/pixels/dimensionr   r  TFc              3  T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fry   )r   r   r  s     rv   r    series_indica.<locals>.<genexpr>GS  s     <1Jq($;QQs   (	(rY   CYXrx  r  r  r  r-  r  r   r%  rT  g     @z.//objectiverO  r	  rY  rj  r  r  r  )0r  rw  rw  r
  r  r7   r  r  r  r  rS  rz   r  r  r  r  r   r   r  r  rl  r  r  r   r  ru  r*	  r  r   rP  rO  r   r   r  r	  r$  r   r7  r  r  r  r   r   r  rY  r	  r  r&  )$r   rw  rH  r  r  r  r$  r  levels_ifdsr6
  lvchr  r  
all_levelsc_coordslv_numchannel_ifdslv_pages
first_pagenchr   r  r   	lv_seriesro  r  r  rg  resrur  rp  r   r  r  s$                                       rv   r  r  S  s   %D%%d+ $DIIi$899JA 	63q6*9   .0K||67  :6SZZ()BSZZ	*+Bcjj'(C$"$"%OB 76 8 IIEEKEO	q	KKM (*J-:u{{=)Hvk&6&6&89:	6"6*6<\6JK6J,r*+6JK<<d

 (m7&&%%&E
 D++Z-B-BCED!Vz6&):"
	 C!G%-ds^Ic"&&**3/)$? ;B !}H HO !G!H			Y	'mm""#7s1vzA&G1WQ!A&G 
( 
		Y	'ii'?SZZ01H 
( h2&&11
E!:!::E"#eO	%1ENN--	9&c"
 NN..:&c" &&--j9#0850@_-  " CN:Y !! # 6slTlCD
 76, LR 
(	' 
(	'sI   Q! 
1R3AR%6R8AR=-S!R1!RR%
R5	=
S
S)maxifds
customtagsc         
      
  ^# US:X  a  US-   nSnUS-   nSn	US-   n
O'US:X  a  US-   nSnUS-   nS	n	US
-   n
OSn[        U5      eUc  0 nUc  Sn/ n[        R                  nU R                  5       n[	        U5      U:  GaZ   U" XR                  U5      5      S   nUS:  a"  [        5       R                  SU SU 35         U$ 0 nU R                  X-  5      nU R                  5       nSn[        U5       GHI  nU" U
UUUU	-    5      u  nnnnUU	-  nUR                  U[        U5      5      n [        R                  U   nU[        R                  " U5      -  nU U[!        US   5      -   US    3nUU:  d  UU;   a  U" UU5      S   nUS:  d  UU-   U R"                  :  a!  [        5       R                  SU SU 35        M  U R%                  U5        UU;   a  UU   nU" XUUU5      n OUS;   a=  U R                  U5      n [	        U 5      U:w  a  [        5       R'                  SU 35        OFUU;   a  U" UU R                  U5      5      n O'[)        XUUU5      n OUS;   a  USU n OU" UUSU 5      n UU;  =(       a    U[        R*                  ;  =(       a    US:g  n!U!(       a8  US:X  a2  U R-                  S5      n  U R/                  S5      R1                  5       n OXU[        R4                  ;   a)  [        R4                  U   m# [7        U#4S  jU  5       5      n U!(       a  [	        U 5      S:X  a  U S   n U UU'   GML     UR9                  U5        U R%                  U5        U" X`R                  U5      5      S   nUS:X  a   U$ XR"                  :  a   [        5       R                  S#U< 35         U$ U R%                  U5        [	        U5      U:  a  GMZ  U$ ! [        R                  [        4 a,  n[        5       R                  SU SU<S 35         SnAU$ SnAff = f! [         a%    [        5       R                  SU< SU 35         GM^  f = f! [2         a^     U R/                  S5      R1                  5       n  GNK! [2         a-  n"[        5       R'                  SU SU"<S 35         Sn"A" GN}Sn"A"ff = ff = f! [          a2  n"US!;  a!  [        5       R'                  S"U SU"<S 35         Sn"A"GNSn"A"ff = f)$a  Read tag values from chain of IFDs.

Parameters:
    fh:
        Binary file handle to read from.
        The file handle position must be at a valid IFD header.
    byteorder:
        Byte order of TIFF file.
    offsetsize:
        Size of offsets in TIFF file (8 for BigTIFF, else 4).
    tagnames:
        Map of tag codes to names.
        For example, :py:class:`_TIFF.GPS_TAGS` or
        :py:class:`_TIFF.IOP_TAGS`.
    maxifds:
        Maximum number of IFDs to read.
        By default, read the whole IFD chain.
    customtags:
        Mapping of tag codes to functions reading special tag value from
        file.

Raises:
    TiffFileError: Invalid TIFF structure.

Notes:
    This implementation does not support 64-bit NDPI files.

r  r  rT  rQ  r  HHI4srP  r/  r	  HHQ8szinvalid offset sizeNrv  r   z)<tifffile.read_tags> corrupted tag list @r  r_  r^  z: suspicious number of tags zinvalid data type z
 for tag #rY   zinvalid value offset r  z8<tifffile.read_tags> could not read all values for tag #r  r+  r  r  z><tifffile.read_tags> coercing invalid ASCII to bytes for tag #z	, due to c              3  4   >#    U  H  nT" U5      v   M     g 7fry   rt   r  s     rv   r   read_tags.<locals>.<genexpr>3T  s     %:EqaddEr  r  z<tifffile.read_tags> tag #z.<tifffile.read_tags> invalid next page offset=)r   re  re  rX  r   r   r  r]  r7   r  rS  rz   r   r  r  r  r   r   r\  rm  r  r  r  r  rc  r  r  r~   r   )$rl  r   rD  tagnamesr  r  rg  r'  rC  rE  r&  r   r  re  r   r  r  r  r  rm  r  r   r  r   r  
valuebytesr   r  r  r  r  r  rO  processr  r.  s$                                      @rv   	read_tagsr  S  ss   \ Q 3	#o#g-	q 3	#o#g-#o
#%F]]FWWYF
f+
	;	(:;A>E 4<HNN;F8 D--2G5 L MI www'ggiuA-3eego!>.*D%
 WE<<c$i0D"//6
  <<I+3{1~../q>"$ 
 :%);$\:>qA?kI&=&GHNN/}JtfM $:%)$/H$RE5*MEi'GGI.E5zY.((BBFI X%"3	(:;E&reUJOE)#":I.sJz	$:; J& .QJ 
 5A: W-	!LL1779E 4==(d+A %%:E%: : s5zQ!!HEDJc f 	d 	ggj&9:1=Q; M WWHNNLVINO M 	g f+
j Mc g& 	HNN;F8 Dd% X Mc	4  !3E9JtfMNd *  %X 6 < < >- ((..2V9SL4LJ  & z1"H,,"<TF C**-!7sr    O -P$ QSP!5!PP!$*QQ
R>!R
R:!R5.R>5R::R>
S='S88S=c                  [        XU[        R                  SS9S   nS H?  n[        R                  " [
        [        [        5         [        XV   5      XV'   SSS5        MA     [        UR                  S5      [        5      (       aG  US   SS n US:X  a  [        US   SS 5      US'   U$ US	:X  a  US   SS R                  S
5      US'   U$ U$ ! , (       d  f       M  = f! [        [        4 a     U$ f = f)zRead EXIF tags from file.

Post-process ExifVersion and FlashpixVersion to strings, and decode
UserComment according to its character-code prefix (ASCII or UTF-16).

rY   r  r   )r  r^  Nr2  rP  s   ASCII   s   UNICODE utf-16)r  r   rr  r  r  r  r   r  	bytes2strr   rS  r{   r  r   )rl  r   r   r  rD  exifr   idcodes           rv   rW  rW  OT  s    RJJ1MD2  96HI"4:.DJ JI 3 $((=)511m$Ra(	--&/]0CAB0G&H]#
 K	 >)&*=&9!"&=&D&DX&N]# K4K JI #N3 	K	s$   CC" , C" 
C	"C65C6c               <    [        XU[        R                  SS9S   $ )zRead GPS tags from file.rY   r  r   )r  r   r  rl  r   r   r  rD  s        rv   rX  rX  mT       RJqI!LLru   c               <    [        XU[        R                  SS9S   $ )z%Read Interoperability tags from file.rY   r  r   )r  r   r  r  s        rv   rY  rY  yT  r  ru   c                  U[         R                  " US:X  a  SOU[        R                  U   S   -   5      R                  -  nU R                  U5      n[        U5      U:w  a(  [        5       R                  SU S[        U5       35        U$ )zRead tag data from file.rT  r  rK  z%<tifffile.read_bytes> failed to read r
  )	r   r   r   r  r   r   r   r7   rm  )rl  r   r   r  rD  r  r  s          rv   rI  rI  T  s     	
++A:C9t/@/@/G/K#K

(	  779D
4yI'[SYKA	
 Kru   rz   c                   U R                  U5      n UR                  5       $ ! [         a(  n[        5       R	                  SU<S 35         SnAOSnAff = fUR                  S5      $ )z!Read unicode tag value from file.z<tifffile.read_utf8> raised r_  Nzlatin-1)r   r  r  r7   rm  rl  r   r   r  rD  r  r  s          rv   	read_utf8r  T  sc     775>DF{{} F7|d|DEEF;;y!!s   # 
AAAc               n    U R                  US:X  a  SU5      $ U[        R                  U   S   -   U5      $ )z%Read NumPy array tag value from file.rT  r
  rK  )r  r   r  r  s        rv   r  r  T  sD     ==z (4+<+<U+CB+GG ru   c                   U R                  U[        R                  U   S   -   U5      nUS-  S:X  a  UR                  S5      nU$ [	        5       R                  SU< S35        U$ )z6Read ColorMap or TransferFunction tag value from file.rK  r   r   )r   rK  z*<tifffile.read_colormap> unexpected count=z, cannot reshape to (3, N))r  r   r  rt  r7   rm  )rl  r   r   r  rD  cmaps         rv   rH  rH  T  ss     ==T%6%6u%=b%AA5IDqyA~||G$ K	 	95( ;' '	
 Kru   c                   U R                  U5      n [        R                  " [        U5      5      $ ! [        [
        4 a(  n[        5       R                  SU<S 35         SnAgSnAff = f)zRead JSON tag value from file.z<tifffile.read_json> raised r_  N)r   jsonloadsr  r   r  r7   rm  r  s          rv   rT  rT  T  sd     775>DFzz)D/***+ F7|d|DEEFs   2 A*A%%A*c                  [        U R                  [        R                  " [        R
                  5      US95      nUS    Vs/ s HG  n[        US   5      R                  5       US   US   US   [        US   5      R                  5       4PMI     snUS'   US   n[        US   5      R                  5       US   US   US   [        US   5      R                  5       4US'   U$ s  snf )	z,Read FluoView mm_header tag value from file.r  r  r   rY   rT  r   r  r  )recarray2dictr
  r   r   r   r  r  rc  )rl  r   r   r  rD  rH  r  s          rv   rN  rN  T  s     
u{{4>>2iHD
 l##A 
1Q4			 !A$!adIadO4I4I4KL#D 	]A!A$	!	!	!!A$D Ks   AC%c               ,    U R                  US-   S5      $ )z+Read FluoView mm_stamp tag value from file.rl  rP  )r  r  s        rv   rO  rO  T  s     ==T)1--ru   c               t   US;  d  US:w  a  SU U 3n[        U5      e0 nUS:X  a=  U R                  SSU-  5      R                  US45      nSUSS2S	4   USS2S
4   -  0nU$ [        U5       H  n	[        R
                  " SU R                  S5      5      S	   n
US
:  a  U
S;   a  U R                  S5        MK  [        X
US5      u  pUS:X  aa  U R                  5       nU R                  US-   5        UR                  U/ 5      R                  [        U 5      5        U R                  U5        M  XU'   M     U$ )z`Read MetaMorph STK UIC1Tag value from file.

Return empty dictionary if planecount is unknown.

>   r  r  rs   zinvalid UIC1Tag r  <u4rT  r  Nr   rY   r	  r  >   r  r  %   (   )   Tr  )r   r  rt  r  re  re  r   read_uic_tagrX  r\  rP  r   r  )rl  r   r   r  rD  rh  r   r  r  r   rM  r   rO  rm  s                 rv   r  r  U  s9    Fi3. E73oFzua%i088%Dvad|fQTl:;  M uAMM$
3A6EA~%+?"?
&r*dCKD&ggi	"!!$+223DR3HI$t  Mru   c                   US:w  d  US:w  a  Sn[        U5      eU R                  SSU-  5      R                  US45      nUSS2S4   USS2S4   -  USS2S	4   USS2S
4   USS2S4   USS2S4   S.$ )z+Read MetaMorph STK UIC2Tag value from file.r  rs   zinvalid UIC2Tagr%  r  Nr   rY   rT  r   r  )r  DateCreatedr  DateModifiedr  r   r  rt  rl  r   r   r  rD  r   r  s          rv   rJ  rJ  0U  s     zY#%o]]5!e),44eQZ@FAqD\F1a4L0ad|ad|q!tq!t ru   c                   US:w  d  US:w  a  Sn[        U5      eU R                  SSU-  5      R                  US45      nSUSS2S4   USS2S	4   -  0$ )
z+Read MetaMorph STK UIC3Tag value from file.r  rs   zinvalid UIC3Tagr%  rT  r  Nr   rY   r-  r.  s          rv   rK  rK  FU  sd     zY#%o]]5!e),44eQZ@F6!Q$<&A,677ru   c                   US:w  d  US:w  a  Sn[        U5      e0 n [        R                  " SU R                  S5      5      S   nUS:X  a   U$ [	        XUS5      u  pXU'   MG  )z+Read MetaMorph STK UIC4Tag value from file.r  rs   zinvalid UIC4Tagr  rT  r   F)r   re  re  r   r)  )
rl  r   r   r  rD  r   r  rM  r   rO  s
             rv   rL  rL  VU  su     zY#%oF
]]44Q7A: M #2eU;t ru   c                   ^  SU 4S jjnSU 4S jjn [         R                  U   u  pg[         R                  S   S   nU(       as  T R                  5       n	U[        S1;  aW  U" 5       n
U
S:  a9  U[
        L a  US4$ US	:X  a  Xj4$ [        5       R                  S
U< SU
 35        Xj4$ T R                  U
5        Uc  SU-   nU" 5       nGOU[        L a	  U" 5       nGOXxL a  U" 5       nUS   US   -  nGOU[        L a  U" 5       n [        U6 nGOxU[        L a  [        T 5      nGObU[
        L a  U" 5       nSUs=::  a  S:  a?  O  O<[        R                  " U S3T R                  U5      5      S   SS n[!        U5      nGOU(       a!  Sn[        5       R                  SU< 35        GOSU 3n[        U5      eUS:X  a  SnGOUS:X  a  / n[#        U5       H  nU" 5       nSUs=::  a  S:  aN  O  OK[        R                  " U S3T R                  U5      5      S   SS nUR%                  [!        U5      5        Me  U(       a  [        5       R                  SU< 35        M  SU 3n[        U5      e   GOSU-   nSU;   a  Xr-  nSU;   a  T R'                  US5      S   nUR(                  S   S:X  a  US   R+                  [,        R.                  5      nUS   R+                  [,        R.                  5      n[,        R0                  " UR(                  [,        R2                  5      nUS:g  nUU   UU   -  UU'   ON[        R                  " UT R                  [        R4                  " U5      5      5      n[7        U5      S:X  a  US   nU(       a  T R                  W	S-   5        Xk4$ ! [         a    SU 3U" 5       4s $ f = f! [        [        4 a-  nSn[        5       R                  SU SU<S 35         SnANrSnAff = f) z]Read single UIC tag value from file and return tag name and value.

UIC1Tags use an offset.

c                 h   > [        [        R                  " ST R                  S5      5      S   5      $ )Nr	  r  r   )r   re  re  r   rl  s   rv   read_intread_uic_tag.<locals>.read_intxU  s&    6==rwwqz21566ru   c                    > [         R                  " STR                  S5      5      n [        U S   5      [        U S   5      4$ )Nz<2IrP  r   rY   )re  re  r   r   )rO  rl  s    rv   	read_int2read_uic_tag.<locals>.read_int2{U  s6    eRWWQZ058}c%(m++ru   _TagIdr  rY   NrP  r=  r(  z/<tifffile.read_uic_tag> invalid offset for tag r  r   r   z <tifffile.read_uic_tag> reading r  r_  r  r  rK  z.<tifffile.read_uic_tag> invalid string in tag zinvalid string size r  zinvalid string size: rs   z%ir	  rT  ).rY   rT  rK  )r6  tuple[int, int])r   r  r4  rX  r   rz   r7   rm  r\  r  r   r5  r  re  re  r   r  r  r   r  r   r,   r   r  fullnanr  r   )rl  rM  rh  r   r4  r7  r   r   rW   rm  offrO  r  r   r   r   stringdenomnumerr@  s   `                   rv   r)  r)  lU  s   7,,mmE*
 }}Q"Hggid#*CQwC<8OB;9$  ..2XRu> y GGCL }Tz
	#
		a58#	/	!	#U+E 
#	#!"%	#zuMMTF!*bggdm<Q?DEe$EEH@I )/CS/!	q	%z"A:DD 5 $qz2774=A!DSbIYv./  DTHM .dV4 o% # e5=&E%<MM%+A.E{{2!# f,,U]];f,,U]];

5;;		:z#DkE$K7d MM%1G)HIE5zQa
a;S  ,w++,R M* 	EH24&tM 	s)   N$ O  $N=<N= O=#O88O=c               D   [         R                  " SU R                  S5      5      S   n[        [         R                  " U S3U R                  U5      5      S   5      n[         R                  " SU R                  S5      5      u  p4US:X  a2  [         R                  " SU R                  S5      5      nUS   US   -  nO^[         R                  " SU R                  S5      5      S   n[        [         R                  " U S3U R                  U5      5      S   5      nX#US	.$ )
z8Read UIC ImagePropertyEx or PlaneProperty tag from file.r  rY   r   r  z<IBr  <IIrP  )r   r9  rO  )re  re  r   r  )rl  r   r   r9  r  rO  s         rv   r  r  U  s    ==bggaj)!,DV]]dV1:rwwt}=a@AD--rwwqz2KEqyeRWWQZ0a58#}}S"''!*-a0&--4&
BGGDMB1EF599ru   c                  US:w  a  Sn[        U5      e[        R                  " SU R                  S5      5      u  pgUS;  a  Sn[        U5      eU R	                  S[
        R                  5        [        R                  nU[        R                  " U5      R                  :  aL  / n	Sn
U HA  u  pU
[        R                  " U5      R                  -  n
X:  a    OU	R                  X45        MC     OUn	[        U R                  [        R                  " U	5      US95      n[        R                  R!                  5        Hy  u  pUc  M
  UR#                  S
U-   S5      nUS:  a  M'  U R	                  U5        [$        R&                  " [         [        R(                  [*        5         U" U 5      X'   S	S	S	5        M{     U$ ! , (       d  f       M  = f)z$Read CZ_LSMINFO tag value from file.rs   zinvalid CZ_LSMINFO structurerB  rP  >   LI LI ir   r  Nr  )r   re  re  r   r\  r  r  r   r  r   r   r   r   r"  r
  r  r`  rS  r  r  r  r]  )rl  r   r   r  rD  r   magic_numberstructure_sizer  lsminfor   r   typestrr  readerr   s                   rv   rP  rP  U  sy    C,o#)==
#C L//,oGGBJJ/888)+'MDEKK(111D$NND?+	 ( *
u{{7+yAF
 //557>HtOQ/A:
  V\\7C!":FL DC 8 M DCs   "F;;
G
	c               t    [         R                  " SU R                  S5      5      S   nU R                  SUS9$ )z%Read LSM channel data type from file.r	  r  r   r%  r  re  re  r   r  rl  r   s     rv   r  r  +V  s2    ==rwwqz*1-D==d=++ru   c               t    [         R                  " SU R                  S5      5      S   nU R                  SUS9$ )z-Read LSM channel wavelength ranges from file.<ir  r   z<2f8rL  rM  rN  s     rv   r  r  1V  2    ==rwwqz*1-D==t=,,ru   c               t    [         R                  " SU R                  S5      5      S   nU R                  SUS9$ )zRead LSM positions from file.r	  r  r   z<3f8rL  rM  rN  s     rv   r  r  7V  rQ  ru   c                   [         R                  " SU R                  S5      5      u  pUSSU-  -   :w  a0  [        5       R	                  S5        [
        R                  " SS5      $ U R                  SUS9$ )zRead LSM time stamps from file.z<iirP  z;<tifffile.read_lsm_timestamps> invalid LSM TimeStamps blockr  <f8rL  )re  re  r   r7   rm  r   rB  r  )rl  r   r  s      rv   r  r  =V  se    --rwwqz2KDAII	
 {{4''==e=,,ru   c               D   [         R                  " SU R                  S5      5      S   n/ nUS:  an  [         R                  " SU R                  S5      5      u  p4nUS:  a  [        U R                  US-
  5      5      OSnUR	                  XEU45        US-  nUS:  a  Mn  U$ )zCRead LSM events from file and return as list of (time, type, text).rB  rP  rY   r   z<IdIr  r=  )re  re  r   r  r   )rl  r  eventsesizeetimeetypeetexts          rv   r  r  IV  s    MM%,Q/E+-F
!)$mmFBGGBK@e27"*	"''%"*-."uU+,
	 !)
 Mru   c                  S/ / S.nU R                  5       n[        R                  " SU R                  S5      5      u  p4pVpxXE:w  a  [	        5       R                  S5        U$ [        U5      US'   U R                  X&-   5        U R                  [        R                  US-  S9n	U	R                  US45      n	U	R                  5       US	'   U R                  X'-   5        U R                  X7-
  5      n
/ n[        U
5      S:  aV  [        R                  " S
U
SS 5      S   nUR                  [        U
SSU-    5      5        U
SU-   S n
[        U
5      S:  a  MV  XS'   U$ )z+Read LSM ChannelColors structure from file.F)Monor  rA  z<IIIIIIr  zE<tifffile.read_lsm_channelcolors> invalid LSM ChannelColors structurer\  r  rL  r  r	  Nr   r   rA  )rX  re  re  r   r7   rm  r   r\  r  r   rP  rt  r  r   r   r  )rl  r  rm  r   ncolorsnnamescoffsetnoffsetmonocolorsr
  r  namesizes                rv   r  r  UV  sG   &+rLF
'')C4:MM2772;51D6G 2	
 $ZF6NGGCM]]5;;gk]:F^^WaL)F}}F8GGCMWWT^$FE
f+/==vbqz215Yva!h,789H' f+/ !<Mru   c               ,   0 n[         R                  " SU R                  S5      5      u  nnnnnnUS:  a  [        5       R	                  S5        U$ U R                  S5        [
        R                  U5      US'   XaS'   XAS'   XqS	'   / =US
'   n[        U5       GHw  n	[         R                  " SU R                  S5      5      S   n
U
S::  a    U$ [         R                  " SU R                  S5      5      S   S-
    SU
s=:  a  S:  a  O  OU R                  SUS9nOU
S:X  a%  U R                  SUS-  S9nUR                  S5      nOU
S:X  aR  [         R                  " SU R                  S5      5      S   nU R                  SXL-  S-  S9nUR                  XLS45      nOJU
S:X  a%  U R                  SUS-  S9nUR                  S5      nO[        5       R	                  SU
 35          U$ UR                  [
        R                  U
5      US.5        GMz     U$ )z!Read LSM lookup tables from file.z<iiiiiir  <   zB<tifffile.read_lsm_lookuptable> invalid LSM LookupTables structure$   LutTypeAdvancedNumberChannelsCurrentChannel	SubBlocksrP  r  r   rP  rT  rL  z<i4)rK  rT  rT  r  rT  r  z<i2r^  )rK  r^  z:<tifffile.read_lsm_lookuptable> invalid LSM SubBlock type )r  Data)re  re  r   r7   rm  r   r  r  r  rt  r   r  )rl  r  r   
nsubblocks	nchannelsluttypeadvancedcurrentchannel	subblocksr   sbtyper  nknotss                rv   r  r  tV  s   F 	i-by1	
 GGEN++G4F9!:(-&((F;):tRWWQZ03Q;2 M1 	dBGGAJ'*Q.v>>==i=8Dq[==i!m=<D<<
+Dq[]]44Q7F==i.@1.D=ED<<A 67Dq[==i$.>=?D<<
+DH--3H6  M 	..v6E	
3 8 Mru   c                  0 nU/n[         R                  n[         R                  " SU R                  S5      5      S   S:w  a  [        5       R	                  S5        U$ U R                  S5         U" SU R                  S5      5      u  pEnUS	:X  a  [        U R                  U5      5      nOWUS:X  a  U" S
U R                  S5      5      S   nO5US:X  a  U" SU R                  S5      5      S   nOSnU R                  U5        U[        R                  ;   a-  UR                  U5        [        R                  U   n/ n	XU'   U	nOU[        R                  ;   a'  UR                  U5        0 n
UR                  U
5        U
nOPU[        R                  ;   a  Xq[        R                  U   '   O&US:X  a  U(       a  UR                  5       nOXqSUS 3'   U(       d   U$ GMl  )z&Read LSM ScanInfo structure from file.r	  r  r   r  z;<tifffile.read_lsm_scaninfo> invalid LSM ScanInfo structurerP  z<IIIr  rT  rP  r  z<drU  Entry0xr  )re  re  r   r7   rm  r  r   r  r   r  r  r  )rl  blockblocksre  entryr   r   rO  r   newlistnewdicts              rv   r  r  V  s    E$)7F]]F}}T2771:&q)Z7I	
 GGAJ
#FBGGBK8dA:bggdm,EaZ4,Q/EaZ4,Q/EEGGDMD333MM% 2259D,.G!$KEd666MM% &(GLL!Ed999@E$55e<=j 

 */GE!9%&LM ru   c               p   0 n[         R                  " SU R                  S5      5      u  pgpppUS:w  a  Sn[        U5      e[	        U5      US'   [
        R                  " [        5         [        SU-   U
S-   XU5      US'   S	S	S	5        U R                  S
U-  5      n[        SUS
-  S
5       H  n [         R                  " SUUUS
-    5      u  nnnUS:X  a  U R                  U5         [         R                  " SU R                  S5      5      u  nnnnnn[        R                  " SU5      nUU-  US'   UU-  US'   UUS'   [	        U5      US'   [	        U5      US'   M  US:X  d  M  M     U$ ! , (       d  f       N= f! [         R                   a       U$ f = f! [         R                   a     GM  f = f)zaRead OlympusSIS structure from file.

No specification is available. Only few fields are known.

z<4s6xhhhhh6x32sHre  s   SIS0zinvalid OlympusSIS structurer   il  rY   rU   NrP  r   z<hhIz<10xhdd8xd2x34s32sp   r  r  r  r  
cameranamepicturetype)re  re  r   r   r  r  r  rh  r  r  r\  ro  pow)rl  r   r   r  rD  r  magicr  r  r  monthyearr   tagcountr   r  r  tagtyper	  r   lenexpr  r   r  camnamepictyper-  s                              rv   rV  rV  V  s     F<BMMBGGBK=9E4e4 ,ot_F6N			Z	(%4KCv
z 
)
 771x< D1hlA&	&,mmFDQUO&L#GVV a<GGFO<BMM("''#,=9dC'
 V$A#'!8F< #'!8F< &)F?##,W#5F< $-g$6F=!]- '> MK 
)	( || 	6 M9	 << s0   )E/1!F *-F/
E= FFF54F5c                    [        [        U R                  U5      5      5      $ ! [        [        [
        [        4 a*  n[        5       R                  SU<S 35        0 s SnA$ SnAff = f)z%Read OlympusSIS INI string from file.z'<tifffile.olympus_ini_metadata> raised r_  N)	olympus_ini_metadatar  r   r   r  r   r  r7   rm  )rl  r   r   r  rD  r  s         rv   rU  rU  !W  s^    #Ibggen$=>>*NHE 5c\D\B	
 		s   "% A)A$A)$A)c               j   0 n[         R                  nU R                  [        R                  " U5      US9nU H  u  pXx   R                  5       XX'   M     US   S:X  a  [         R                  n
U R                  [        R                  " U
5      US9nUS   S:w  a  [        5       R                  S5        0 $ U
 HP  u  pUR                  S5      (       a!  [        Xx   R                  5       SS	5      XX'   M<  Xx   R                  5       XX'   MR     U$ US   S
:w  a  [        5       R                  S5        0 $ U$ )z%Read TVIPS EM-MENU headers from file.r  r  rT  rp  l   *UU z:<tifffile.read_tvips_header> invalid TVIPS v2 magic numberr'  z	utf-16-leignorerY   z9<tifffile.read_tvips_header> unknown TVIPS header version)r   r5  r
  r   r   r  rq  r7   rm  r  r  r  )rl  r   r   r  rD  r  	header_v1rm  r   _typestr	header_v2rI  s               rv   rR  rR  3W  s*     F$$I^^EKK	2i^HF#|**, $iA((	I 6)L'?j(HL I&MD!!#&&(L((*K   &|224 '" M 
		a	G	
 	Mru   c               p   0 n0 n[        U R                  U5      5      nUR                  5        Hr  nUR                  5       nUR	                  S5      (       a  0 nXeUSS '   M4   UR                  SS5      u  p[        U
R                  5       5      XiR                  5       '   Mt     U$ ! [         a     M  f = f)z'Read FEI SFEG/HELIOS headers from file.r  rY   rK  rH  )r  r   
splitlinesrc  r  r  r   r,   )rl  r   r   r  rD  r  sectionr  r	  r   rO  s              rv   rQ  rQ  ^W  s      F GRWWU^$D!zz|??3G!(4":	C+JC  &ekkm4		 " M  		s   $B''
B54B5c          	        SS0nSn[        U R                  U5      5      nUR                  5        H  nUR                  5       (       a  UR	                  5       nM*  U(       a   UR                  SS5      u  pU
R                  5       n
Sn U
R                  5       u  p[        U[        [        45      nX:w  a  Un
UnU	R                  5       U
4XV'   U(       a  XV==   U4-  ss'   SnM  US==   [        U[        [        45      4-  ss'   M     U$ ! [         a+     UR                  SS5      u  p N! [         a      GM  f = ff = f! [        [        4 a2    [        U
[        [        45      nX:w  a  Un
U
S;   a  Sn
 NU
S	;   a  S
n
 Nf = f)zuRead Zeiss SEM tag from file.

See https://sourceforge.net/p/gwyddion/mailman/message/29275000/ for
unnamed values.

r=  rt   NrH  rY   r  >   NoOffF>   OnYesT)r  r   r  isupperr  r  r   rc  r,   r   rY  r   )rl  r   r   r  rD  r  r   r  r	  r   rO  r  r  r  numbers                  rv   rM  rM  xW  s}    !"XF
CRWWU^$D!<<>>**,C"jja0 KKMED!{{}C<0;"ED  ::</FKw&C2J6$e577JA "B M7  "&**S!"4KD%!  	* !U|4?"EM)!Em+ E!sB   #D
1E
ED00
E :E?E  E5F	>F	F	c                   U R                  [        R                  US9nUR                  UR                  R                  U5      5      n[        U5      nUS   SUS    US'   US   SUS    US'   U$ )z*Read NIH_IMAGE_HEADER tag value from file.r  r  Nr  r  r  )r
  r   r  r  r   r
  r"  )rl  r   r   r  rD  arrr  s          rv   rS  rS  W  s|     ....).
DC
((399)))4
5C*3/FWo&;{(;<F7O$< 2&"23F4LMru   c               x   U R                  S5         [        R                  " SU R                  S5      5      u  pUS:w  d  US:w  a  Sn[	        U5      eU R                  S5        [        R                  " SU R                  S5      5      u  pBpVUS	:w  d  US
;  a  SU< SU< 3n[	        U5      e [        [        U R                  U5      SS 5      5      nUS:  a  [        U SSUS5      O0 n	XU4$ ! [
         a  nSn[	        U5      UeSnAf[        R                  [        4 a  nSn[	        U5      UeSnAff = f)a  Read ScanImage BigTIFF v3 or v4 static and ROI metadata from file.

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

Frame data and ROI groups can alternatively be obtained from the Software
and Artist tags of any TIFF page.

Parameters:
    fh: Binary file handle to read from.

Returns:
    - Non-varying frame data, parsed with :py:func:`matlabstr2py`.
    - ROI group data, parsed from JSON.
    - Version of metadata (3 or 4).

Raises:
    ValueError: File does not contain valid ScanImage metadata.

r   z<2sHr  rL  rO  znot a BigTIFF filer  z<IIIIir  zinvalid magic=z or version=z"file must be opened in binary modeNz%not a ScanImage BigTIFF v3 or v4 filerK  rY   rs   )r\  re  re  r   r   r  r  r]  r9   r  rT  )
rl  r   rn  r   r  size0size1r  
frame_dataroi_datas
             rv   rE   rE   W  s/   . GGAJ'#]]62771:>	B&CS/!
'-}}Wbggbk'J$J'"7#UHM
3CS/! #8 is(;<=J27!)yS!UA.H((  '2o3&LL'" '5o3&'s$   BC1 1
D9;D		D9&D44D9c                  Uc  1 SknU R                  S5         SSS.U R                  S5         nU R                  S5        [        R                  " US	-   U R                  S5      5      u  nn0 nUS:X  a  XGS'    [        R                  " US	-   U R                  S5      5      u  nn	US:w  aG  XS'   U	S:w  a  SU	< 3n[        U5      e[        R                  " US-   U R                  S5      5      S   n	SU;   aO  U R                  U	5      n
[        U
5      U	:w  a  Sn[        U5      e[        R                  " [        U
5      5      US'   U$  [        R                  " US-   U R                  S5      5      u  nnnnnn	SU;   ag   US:w  a  SU< 3n[        U5      eU R                  U	5      n
[        U
5      U	:w  a  Sn[        U5      e[        R                  " [        U
5      5      US'   SU;   a   US:w  a  SU< 3n[        U5      eU R                  U5        [        R                  " US	-   U R                  S5      5      u  nnUS:w  a  S n[        U5      eU R                  US!-  5      n
[        R                   " XS"-   US#-  5      R#                  S$5      US'   S&U;   Ga   US':w  a  S(U< 3n[        U5      eU R                  U5        [        R                  " US	-   U R                  S5      5      u  nnUS):w  aW  U R                  US*-   5        [        R                  " US	-   U R                  S5      5      u  nnUS):w  a  S+U< 3n[        U5      eU R                  U5      n
[        U
5      U:w  a  Sn[        U5      e[        R                  " [        U
5      5      US&'   SUS'    US-:X  a  S.U;   a  U R                  U5        [        R                  " US	-   U R                  S5      5      u  nnUS/:w  aS  U R                  US*-   5        [        R                  " US	-   U R                  S5      5      u  nnUS/:w  a  S0n[        U5      eU R                  U5      n
[        U
5      U:w  a  Sn[        U5      e[        R                  " [        U
5      5      US.'   U$ US:X  a  XS'   U$ US:X  a	  US:X  a   U$ S.U;   a  S1U< 3n[        U5      e U$ ! [        [        R
                  [        4 a  nS
n[        U5      UeSnAff = f! [        R
                  [        [        [        4 a,  n[        5       R                  SU SU<S 35         SnAU$ SnAff = f! [        R
                  [        4 a*  n[        5       R                  SU<S 35        Us SnA$ SnAff = f! [        R
                  [        [        [        4 a)  n[        5       R                  SU<S 35         SnAGNSnAff = f! [        R
                  [        [        4 a)  n[        5       R                  S%U<S 35         SnAGNSnAff = f! [        R$                  R&                   a     GN[        R
                  [        [        [        4 a)  n[        5       R                  S,U<S 35         SnAGN SnAff = f! [        R
                  [        [        [        4 a)  n[        5       R                  S2U<S 35         SnAU$ SnAff = f)3a  Return Micro-Manager non-TIFF settings from file.

The settings can be used to read image data without parsing any TIFF
structures.

Parameters:
    fh: Open file handle to Micro-Manager TIFF file.
    keys: Name of keys to return in result.

Returns:
    Micro-Manager non-TIFF settings, which may contain the following keys:

    - 'MajorVersion' (str)
    - 'MinorVersion' (str)
    - 'Summary' (dict):
      Specifies the dataset, such as shape, dimensions, and coordinates.
    - 'IndexMap' (numpy.ndarray):
      (channel, slice, frame, position, ifd_offset) indices of all frames.
    - 'DisplaySettings' (list[dict]):
      Image display settings such as channel contrast and colors.
    - 'Comments' (dict):
      User comments.

Notes:
    Summary metadata are the same for all files in a dataset.
    DisplaySettings metadata are frequently corrupted, and Comments are
    often empty.
    The Summary and IndexMap metadata are stored at the beginning of
    the file, while DisplaySettings and Comments are towards the end.
    Excluding DisplaySettings and Comments from the results may
    significantly speed up reading metadata of interest.

References:
    - https://micro-manager.org/Micro-Manager_File_Formats
    - https://github.com/micro-manager/NDTiffStorage

N>   rM  r  rN  DisplaySettingsr   rs   rr   )rL  rM  rT  rP  IIznot a Micro-Manager TIFF fileia rA  i$# MinorVersionzinvalid summary_length=r  r  rM  znot enough dataz<<tifffile.read_micromanager_metadata> failed to read NDTiffvz summary settings, raised r_  IIIIIIr  zD<tifffile.read_micromanager_metadata> failed to read header, raised zinvalid summary_header=zN<tifffile.read_micromanager_metadata> failed to read summary settings, raised rN  iCzinvalid index_header=i4 zinvalid headerr	  ra  r  )rK  r  zG<tifffile.read_micromanager_metadata> failed to read index map, raised r  izinvalid display_header=idrv  zinvalid display header=zN<tifffile.read_micromanager_metadata> failed to read display settings, raised i}r  iezinvalid comments headerzinvalid comments_header=zF<tifffile.read_micromanager_metadata> failed to read comments, raised )r\  r   re  re  r  r  r]  r   r   r  r   r  r  r7   rm  r   r  rt  decoderJSONDecodeError)rl  r*	  r   index_headerindex_offsetr  r   r  summary_headersummary_lengthr  display_headerdisplay_offsetcomments_headercomments_offsetrm  r  s                    rv   rC   rC   W  s   P |EGGAJ	',RWWQZ8	

 MM)d*BGGAJ7	
  Fv!-~	 i$.
;()7~&!W,4^$56C$S/)!'y3
!KA!ND ww~.t9.+C$S/)$(JJy$?y!  MM)h.<	
 D	(0 12 o%77>*D4yN*' o% $

9T? ;F9 T	x'.0 o%GGL!"MM)d*:BGGAJGMFE & o%7752:&D!&!1!1$&	"gg : D 	*0 12 o%GGN#"MM)d*:BGGAJGMFE"./ &i$.>
 KY&4VI6C$S/)775>D4yE!' o%(,

9T?(CF$% F>
h&T!( &i$.>
 KX%GGOe34$*MM)d2BBGGAJ$OMFE)7(o-wwu~t9%+C$S/)%)ZZ	$%@z" M &%4>" M !o&: M 4-_./CS/!   Mg fllG, '-o3&'4 gz3EF 	H))5 7' 
 	$ LL'" \D\#	
 " gz3EF 	H;;>,,H 	( gz2 	H447<$<A 	2 ||++ 	gz3EF 	H;;>,,H 	B LL':/AB 
\D\#	
 	

 M
s   AS ;CT 0U A&V 0B*W/ "D X: (C1Z* 
Z* 'Z* 6Z* T/S==T$U)!UUV2VVV$W,W''W,/X7X22X7:Z'#Z'>Z""Z'*$[7[22[7c             #    #    [        U S5       n UR                  S5      n[        U5      S:w  a  O [        R                  " SU5      S   n[
        R                  " UR                  U5      5      n[        R                  " SUR                  S5      5      S   nUR                  U5      R                  SSS9n[        R                  " SUR                  S	5      5      u  nnn	n
nnnnUUUUU	U
UUUU4
v   M  SSS5        g! [        R                  [
        R                  [        4 a)  n[        5       R                  S
U<S 35         SnAMV  SnAff = f! , (       d  f       g= f7f)a   Return iterator over fields in Micro-Manager NDTiff.index file.

Parameters:
    file: Path of NDTiff.index file.

Yields:
    Fields in NDTiff.index file:

    - axes_dict: Axes indices of frame in image.
    - filename: Name of file containing frame and metadata.
    - dataoffset: Offset of frame data in file.
    - width: Width of frame.
    - height: Height of frame.
    - pixeltype: Pixel type.
      0: 8-bit monochrome;
      1: 16-bit monochrome;
      2: 8-bit RGB;
      3: 10-bit monochrome;
      4: 12-bit monochrome;
      5: 14-bit monochrome;
      6: 11-bit monochrome.
    - compression: Pixel compression. 0: Uncompressed.
    - metaoffset: Offset of JSON metadata in file.
    - metabytecount: Length of metadata.
    - metacompression: Metadata compression. 0: Uncompressed.

rE  r  r	  r   r  r  )errorsz	<IiiiiIiir)  z$<tifffile.read_ndtiff_index> raised r_  N)rD  r   r   re  re  r  r   r  r  r  r   r7   rm  )r   rl  r
  r   r{  r  r  r  rX  r  r  r   
metaoffsetmetabytecountmetacompressionr  s                   rv   rD   rD   X  sV    @ 
dD	R
A1v{MM$*1- JJrwwqz2	MM$
3A6771:,,WY,G MM+rwwr{;	!#  1  
	( LL$"6"6
C   :3,,G 	) 
	sF   E(#EB6D)E9	E()E+E	EEE
E%!E(c                  U R                  S5         U R                  S5      nUS;  a  Sn[        U5      eUS:X  a  SOSn[        R                  " US-   U R                  S5      5      S   nU R                  S	S
S.U   5        U R                  S5      R                  5       nUSS S:w  a  g[        USS 5      nU R                  U5      R                  5       n0 nUR                  5        H?  n	SU	;   d  M  U	R                  SS5      u  pUR                  5       XR                  5       '   MA     U$ ! [         a     gf = f)zRead non-TIFF GDAL structural metadata from file.

Return ``None`` if the file does not contain valid GDAL structural
metadata. The metadata can be used to optimize reading image data from
a COG file.

r   rT  >   rL  rM  znot a TIFF filerL  rs   rr   rQ  rP  r  )rR  rO  rO  Nr  zGDAL_STRUCTURAL_METADATA_SIZE=rf  rH  rY   )r\  r   r   re  re  r  r   r  r  r  rc  )rl  byteorder_bytesr   r   rn  rm  r   linesr  r	  r   rO  s               rv   rB   rB   X  s,    GGAJ''!*.0#CS/!*e3C	--	C<Q?
QB()##%#2;::6"R=!$$&  F  "$;C+JC"'++-F99; # M  s   BD1 --D1 1
D>=D>c                   [         e)zwRead MetaSeries non-TIFF hint catalog from file.

Raise ValueError if the file does not contain a valid hint catalog.

r  r3  s    rv   read_metaseries_catalogr  Y  s
     ru   c          
     6   U (       d  gSSS.U   /nS/n/ nS$S jnS%S jnS&S jnS'S	 jnS
SU4SSU4SSU4SSU4SSU4SSU4SSU4SSU44n	U	 GH;  n
U
u  pnUR                  5       U ;   a  UR                  5       nOX;  a  M5  US:X  a  USSS2   nX   n[        U[        5      (       a@  UR                  5        VVs/ s H  o  H  n[	        U5      PM     M     nnn[        U5      nO6XL a  U/nSnO,[        U[        [        45      (       a  [        U5      nOU/nSnUR                  U[        R                  " US-   U5      -   5        U H7  nU" UU5      nUR                  U5        UR                  [        U5      5        M9     GM>     U(       d  gSR                  U5      nSR                  U5      nUU-   n[        U5      US'   [        R                  " US[        U5      -  -   /UQ76 nS S[        U5      US!4S"S#[        U5      S#-  US!44$ s  snnf )(a  Return IJMetadata and IJMetadataByteCounts tags from metadata dict.

Parameters:
    metadata:
        May contain the following keys and values:

        'Info' (str):
            Human-readable information as string.
        'Labels' (Sequence[str]):
            Human-readable label for each image.
        'Ranges' (Sequence[float]):
            Lower and upper values for each channel.
        'LUTs' (list[numpy.ndarray[(3, 256), 'uint8']]):
            Color palettes for each channel.
        'Plot' (bytes):
            Undocumented ImageJ internal format.
        'ROI', 'Overlays' (bytes):
            Undocumented ImageJ internal region of interest and overlay
            format. Can be created with the
            `roifile <https://pypi.org/project/roifile/>`_ package.
        'Properties' (dict[str, str]):
            Map of key, value items.

    byteorder:
        Byte order of TIFF file.

Returns:
    IJMetadata and IJMetadataByteCounts tags in :py:meth:`TiffWriter.write`
    ``extratags`` format.

rt      IJIJ   JIJIrq   r   c               6    U R                  SSSS.U   -   5      $ Nr  belerq   r  r  r   s     rv   _string$imagej_metadata_tag.<locals>._stringSY       {{8Dt&<Y&GGHHru   c               L    [         R                  " U [        U 5       S3/U Q76 $ )Nr  )re  rf  r   r  s     rv   _doubles%imagej_metadata_tag.<locals>._doublesVY  s%    {{i[T15===ru   c               "    U R                  5       $ ry   )r  r  s     rv   _ndarray%imagej_metadata_tag.<locals>._ndarrayYY  s    ||~ru   c                   U $ ry   rt   r  s     rv   _bytes#imagej_metadata_tag.<locals>._bytes\Y  r  ru   r     infor     lablr     rangr     lutsr     plotr     roi r     overr     proprs   NrK  rY   r  ru   r  Trn  r  )r  rz   r   ro   r6  r{   )r  zSequence[float]r   ro   r6  r{   )r  r  r   ro   r6  r{   r  r{   r   ro   r6  r{   )r  r   r  r`  rz   r   rM  r~   r   re  rf  r   )r   r   header_listbytecount_list	body_listr  r  r  r  metadata_typesr  r   mtyper  r  kvr  r  rO  r  bodyrm  r  s                          rv   r3   r3   )Y  sX   H  w/	:;KSNII> 
'"	7G$	7H%	(#	&!	 	Wf%	w(		  D99;("))+C $B$KEfd##'-||~B~r!c!frf~FBKEXFEu..KEXFE56;;y3#FFGEy)DT"!!#d), - 6 88IDXXk"FD=DFN1S3~../2@J 
3t9dD)	3z?a'T: 5 Cs   >Hc          
        SS jnSS jnS S jnS!S jnSU4SU4SU4SU4S	U4S
U4SU4SU4S.nUR                  UR                  5        VV	s0 s H  u  pUSSS2   U	_M     sn	n5        U(       d  Sn
[        U
5      eU SS S;  a  Sn
[        U
5      eUS   nUS:  d  US:  a  Sn
[        U
5      eUS-
  S-  n[        R                  " USU-  -   U SSUS-  -    5      nSUS-  -   nSn0 n[        USSS2   USSS2   SS9 H  u  nn/ nUR                  U[        U5      U45      u  nn[        U5       H+  nUS-  nXU   -   nUR                  U" XU U5      5        UnM-     US:X  a  US   OUUUR                  5       '   M     UR                  S5      n[        U[        5      (       a5  [        U5      S-  S:X  a#  [        [        R                   " US5      5      US'   U$ s  sn	nf )"a  Return IJMetadata tag value.

Parameters:
    data:
        Encoded value of IJMetadata tag.
    bytecounts:
        Value of IJMetadataByteCounts tag.
    byteorder:
        Byte order of TIFF file.

Returns:
    Metadata dict with optional items:

        'Info' (str):
            Human-readable information as string.
            Some formats, such as OIF or ScanImage, can be parsed into
            dicts with :py:func:`matlabstr2py` or the
            ``oiffile.SettingsFile()`` function of the
            `oiffile <https://pypi.org/project/oiffile/>`_  package.
        'Labels' (Sequence[str]):
            Human-readable labels for each channel.
        'Ranges' (Sequence[float]):
            Lower and upper values for each channel.
        'LUTs' (list[numpy.ndarray[(3, 256), 'uint8']]):
            Color palettes for each channel.
        'Plot' (bytes):
            Undocumented ImageJ internal format.
        'ROI', 'Overlays' (bytes):
            Undocumented ImageJ internal region of interest and overlay
            format. Can be parsed with the
            `roifile <https://pypi.org/project/roifile/>`_  package.
        'Properties' (dict[str, str]):
            Map of key, value items.

c               6    U R                  SSSS.U   -   5      $ r  r  r  s     rv   r   imagej_metadata.<locals>._stringY  r  ru   c               T    [         R                  " US[        U 5      S-  -  -   U 5      $ )Nr  rP  )re  re  r   r  s     rv   r  !imagej_metadata.<locals>._doublesY  s%    }}Y#Ta*@A4HHru   c               j    [         R                  " U [         R                  5      R                  S5      $ )N)rK  r  )r   r  rP  rt  r  s     rv   _lutimagej_metadata.<locals>._lutY  s$    ekk2::9EEru   c                   U $ ry   rt   r  s     rv   r  imagej_metadata.<locals>._bytesY  r  ru   r  r  r  r  r  r  r  r  )r  r  r  r  r  r  r  r  NrK  zno ImageJ metadatar  >   r  r  zinvalid ImageJ metadatar   r  i$  z#invalid ImageJ metadata header sizerP  4sIrT  rY   Tr4  )r  r{   r   ro   r6  rz   )r  r{   r   ro   r6  ztuple[float, ...])r  r{   r   ro   r6  zNDArray[numpy.uint8]r  )r  r`  r   re  re  r  rS  r  r  r   rc  r   rM  r   r  r  batched)r  r  r   r  r  r  r  r  r   r  r   header_sizentypesrm  rm  counterr  r  r  r  r   r  r   pos1r  s                            rv   r  r  Y  sF   NIIF '"G$H%$&!f%(		  .2F2F2HI2H$!1TrT7A:2HIJ"oBQx))'oQ-KR;,3oAo!#F]]EFN"DQ!^$<F fqj.CGFF3Q3K1dCu#''	%0@&/IJ
duAqLGG,,DMM$t~y9:C	 
 -2QJvayFtzz| D ::l#D$#d)a-1"4#I$5$5dA$>?|ME Js   G%
c               l   SS jn0 nU R                  5        HY  n UR                  SS5      u  pEUR                  5       nUR                  5       n[        [
        U4 H  n U" U5      n  O   XRU'   M[     SU;  a  SU;  a  SU< 3n[        U5      eU$ ! [         a     M  f = f! [         a     MU  f = f)a
  Return metadata from ImageJ image description.

Raise ValueError if not a valid ImageJ description.

>>> description = 'ImageJ=1.11a\nimages=510\nhyperstack=true\n'
>>> imagej_description_metadata(description)
{'ImageJ': '1.11a', 'images': 510, 'hyperstack': True}

c               .    SSS.U R                  5          $ )NTF)r  r  r  )r	  s    rv   _bool*imagej_description_metadata.<locals>._boolZ  s    u-ciik::ru   rH  rY   r  SCIFIOz!not an ImageJ image description: )r	  rz   r6  r   )r  r  r   rc  r   rY  r  )r   r  r  r	  r   r	  r   r   s           rv   r  r  Y  s    ;  F&&(	zz#q)HC iikiik5%(ECj ) s ) v(&"81&<oM  		  s#   B!B%
B"!B"%
B32B3r  c                 SU;   a4  [         R                  " S[        SS9  [        UR	                  S5      5      nUR	                  SS5      nUR	                  SS5      nUR	                  SS5      nUR	                  S	S
5      nU(       a  SnSn[        XUS9n U S   S;   n/ n	SU 3/n
U
R                  S[        U SS 5       35        Uc  SnU	R                  S5        O4U	R                  S[        [        U5      5      R                  5        35        U S   S:  a  U
R                  SU S    35        Uc  U(       d	  U(       d  SnU(       a  U(       a  U	R                  SU 35        U S   S:  a  U
R                  SU S    35        U S   S:  a+  U
R                  SU S    35        Uc  U	R                  S5        Ub4  U	R                  S[        [        U5      5      R                  5        35        UR                  5        Ha  u  pUS;  d  M  [        U[        5      (       a  [        U5      R                  5       OUnU	R                  UR                  5        SU 35        Mc     S R                  X-   S!/-   5      $ )"a  Return ImageJ image description from data shape and metadata.

Parameters:
    shape:
        Shape of image array.
    axes:
        Character codes for dimensions in ``shape``.
        ImageJ can handle up to 6 dimensions in order TZCYXS.
        ``Axes`` and ``shape`` are used to determine the images, channels,
        slices, and frames entries of the image description.
    rgb:
        Image is RGB type.
    colormapped:
        Image is indexed color.
    **metadata:
        Additional items to be included in image description:

        ImageJ (str):
            ImageJ version string. The default is '1.11a'.
        hyperstack (bool):
            Image is a hyperstack.
            The default is ``True`` unless ``colormapped`` is ``True``.
        mode (str):
            Display mode: 'grayscale', 'composite', or 'color'.
            The default is 'grayscale' unless ``rgb`` or ``colormapped``
            are ``True``. Ignored if ``hyperstack`` is ``False``.
        loop (bool):
            Loop frames back and forth. The default is ``False``.
        finterval (float):
            Frame interval in seconds.
        fps (float):
            Frames per seconds. The inverse of ``finterval``.
        spacing (float):
            Voxel spacing in ``unit`` units.
        unit (str):
            Unit for ``spacing`` and X/YResolution tags.
            Usually 'um' (micrometer) or 'pixel'.
        xorigin, yorigin, zorigin (float):
            X, Y, and Z origins in pixel units.
        images, channels, slices, frames (int):
            Ignored.

Examples:
    >>> print(imagej_description((51, 5, 2, 196, 171)))
    ImageJ=1.11a
    images=510
    channels=2
    slices=5
    frames=51
    hyperstack=true
    mode=grayscale
    loop=false
    <BLANKLINE>


colormapedzi<tifffile.imagej_description colormaped parameter is deprecated since 2026.2.28. Use colormapped instead.rT  rU  r   N
hyperstackloopr  z1.11aFr  rK  r  rW  zimages=r  Tzhyperstack=truezhyperstack=rY   z	channels=	grayscalezmode=zslices=r   zframes=z
loop=falsezloop=>   r  rr  re  rJ
  r  rH  r  r=  )rh  ri  rV  r   r  rT  r   r@   rz   r  r`  r   r   )r   r  r  r  r   r   r  r  rn  r   r  r   rO  r	  s                 rv   r2   r2    Z  sM   @ xF		
 8<<56<<%DlD1J<<%Dll8W-G
d3E
)v
CFy!"F
MMGGE#2J/012
'(CZ(8$9$?$?$A#BCDQx!|	%(,-|CddVn%Qx!|az*+Qx!|az*+<MM,'c$t*o335678nn&
JJ(25$(?(?#e*""$UCMMSYY[M3%01 '
 99V_t+,,ru   r  c                 [        S U  5       5      n [        U 5      nUS:  d  US:  a  Sn[        U5      eUb  [        U5      U:w  a  Sn[        U5      eSnUR                  5       nU H+  nSR	                  U5      nXu:  a  Sn[        U5      eUS-   nM-     / nSnS H;  nXS:  a"  XbU   :X  a  UR                  X   5        US-  nM*  UR                  S5        M=     US	   S
;  a  Sn[        U5      e[        U5      $ Uc  U S	   S;   =(       a    US:  nU(       a  U S	   S;  a  Sn[        U5      eU(       d  US:X  a  U S	   S:w  a  Sn[        U5      eU(       d	  U S	   S:X  a  SSU-
  -  U -   $ SSU-
  -  U -   S-   $ )zReturn shape normalized to 6D ImageJ hyperstack TZCYXS.

Raise ValueError if not a valid ImageJ hyperstack shape or axes order.
Shape must be 1-6 dimensional.

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

c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   imagej_shape.<locals>.<genexpr>Z  s     (%Q#a&&%r  rY   r  z)ImageJ hyperstack must be 1-6 dimensionalz-ImageJ hyperstack shape and axes do not matchr   TZCYXSz.ImageJ hyperstack axes must be in TZCYXS orderrK  >   rY   r   r  z1ImageJ hyperstack must contain 1, 3, or 4 samplesr  rT  z$ImageJ hyperstack is not a RGB imagez*ImageJ hyperstack is not a grayscale imager  r  )r~   r   r   rN  r  r   )	r   r  r  r  r   r  r  r2  newshapes	            rv   rT  rT  Z  s     (%((Eu:Dax4!89ot9ACS/!zz|Bb!AuF o%AA  BxBq'M)Q"  B<y(ECS/!X
{Bi6!.dQh
uRy&4o419ra:o
eBi1nq4x 5((1t8u$t++ru   c                   SnSnU(       d?  U S:X  a  SnO6U S:X  a  U(       d  SnSnO$U S:X  a  SnOU S:  a  [        U 5      R                  nUS:w  a  SnXE4$ )a  Return JPEG and output color space for ``jpeg_decode`` function.

Parameters:
    photometric: Photometric interpretation tag value.
    planarconfig: Planar configuration tag value.
    extrasamples: Extra samples tag value.
    jfif: Whether the JPEG data has a JFIF marker.

Returns:
    Tuple of JPEG colorspace and output colorspace for ``jpeg_decode``.
    A value of ``None`` leaves the colorspace at its default.

Nr  rT  r  r  r   rY   )r   r   )r   r   r   r?  r  r  s         rv   r%  r%  Z  sm    ( "J&*M!MA
MAM1_'499Mq$$ru   c                  SnU[        U 5      :  a  [        R                  " SXUS-    5      S   nUS-  nUS:X  a  M;  US:X  a  OSUs=::  a  S::  a  O  OMT  US:X  a  M\  [        R                  " SXUS-    5      S   nUS-  nS	Us=::  a  S
::  a  O  O[        R                  " SXUS-    5      $ US:X  a  OXS-
  -  nU[        U 5      :  a  M  Sn[        U5      e)zReturn bitdepth and shape of JPEG image.

Returns:
    Tuple of (precision, height, width, ncomponents) from the SOF marker.

Raises:
    ValueError: No SOF marker found.

r   r  rT              i  >BHHBr    zno SOF marker found)r   re  re  r   )jpegr  markerrY  r   s        rv   r  r  Z  s     	
A
c$i-tTa!e_5a8	QVVV%v%VtTa!e_5a8	QV%v% ==$1q5/::V 	
aZ; c$i->  C
S/ru   c                  SnSnSnSnSnSnU[        U 5      :  GaT  [        R                  " SXUS-    5      S   nUS-  nUS:X  a  M<  US:X  a  GO SUs=::  a  S::  a  O  OMV  US	:X  a  M^  [        R                  " SXUS-    5      S   nUS-  nUS
:X  a   [        R                  " SXUS-    5      S   nOUS:X  a  US-   n[        R                  " SXUS-    5      u  ppUS-  nSnSn[        U5       HC  n[        R                  " SXUS-    5      u  pnUS-  n[	        XOS-	  5      n[	        X_S-  5      nME     US-  nUS-  nUS-
  nOUS:X  a  Xh-   S-
  nOXhS-
  -  nU[        U 5      :  a  GMT  US:X  d  US:X  d  US:X  a  Sn[        U5      eUnX-  nU SU [        R                  " SUU5      -   XS-   U -   nUUU4$ )zReturn tile shape and JPEG header from JPEG with restart markers.

Returns:
    Tuple of (tilelength, tilewidth, jpegheader).

Raises:
    ValueError: Missing required JPEG markers (DRI, SOF0, SOS).

r   rY   r  rT  r  r   r  r  r  i  r  r  r  z>BBBr   r  r  rP  r  zmissing required JPEG markersNr  )r   re  re  r  rk  r   rf  )r  restartinterval	sofoffset	sosoffsetmcuwidth	mcuheightr  r  rY  
_precision	_imlength_imwidthncomponentsr   _cidfactor_tabler   rS  rR  rW  s                        rv   r  r  '[  s/    OIIHIA
c$i-tTa!e_5a8	QVVV%v%VtTa!e_5a8	QV$mmD$1q5/B1EOv AI;A==!a%<8J8 FAHI;''-}}VTa!e_'M$fQx15	C<8		 (
 MHNIAAv
QI 	
aZe c$i-h !yA~a-o J*IZi
++eZ
3	4
1}y
)	* 
 y*,,ru   c               H    [         R                  " S[        U 5      0UE5      $ )zReturn JSON image description from data shape and other metadata.

>>> shaped_description((256, 256, 3), axes='YXS')
'{"shape": [256, 256, 3], "axes": "YXS"}'

r   )r  dumpsrM  )r   r   s     rv   rf  rf  z[  s!     ::wU8x899ru   c                   U SS S:X  a(  [        S U SS R                  S5       5       5      nSU0$  [        R                  " U 5      $ ! [         a     Of = fS	U SS
 < 3n[	        U5      e)aU  Return metadata from JSON formatted image description.

Raise ValueError if ``description`` is of unknown format.

>>> description = '{"shape": [256, 256, 3], "axes": "YXS"}'
>>> shaped_description_metadata(description)
{'shape': [256, 256, 3], 'axes': 'YXS'}
>>> shaped_description_metadata('shape=(256, 256, 3)')
{'shape': (256, 256, 3)}

Nr  rR  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   .shaped_description_metadata.<locals>.<genexpr>[  s     C&Bc!ff&Br  r  rK  r|  r   zinvalid image description r  )r~   r  r  r   r   )r   r   r   s      rv   rf  rf  [  s     2A("Ck!B&7&=&=c&BCCzz+&& &{3B'7&:
;C
S/s   A	 	
AAc                  U R                  S5      (       d  Sn[        U5      eUc  SS1n0 nU/nUnSnU R                  5        GH  nU(       d  UR                  5       nU(       d  M$  US   S:X  a  USS S	:X  al  US
	 US
   nUSS nU(       a  SR	                  XX   5      XX'   USS S:X  a8  [
        R                  " XX   [
        R                  S9n	U	R                  S5      XX'   M  SnUSS
 nUSS S:X  a  / nOX;   a  / nSnO0 nUR                  U5        XSU'   M  U(       a  UR                  U5        M  UR                  SS5      n
[        U
5      S:X  a  SXZS   R                  5       '   GM+  U
u  pUSS S:X  a)  UR                  S UR                  5        5       5        GMa  [        UR                  5       5      X[R                  5       '   GM     U$ )aU  Return metadata from FluoView image description.

The FluoView image description format is unspecified. Expect failures.

>>> descr = (
...     '[Intensity Mapping]\nMap Ch0: Range=00000 to 02047\n'
...     '[Intensity Mapping End]'
... )
>>> fluoview_description_metadata(descr)
{'Intensity Mapping': {'Map Ch0: Range': '00000 to 02047'}}

r  z"invalid FluoView image descriptionNzRegion Info (Fields)zProtocol DescriptionFr   r  z End]rK  rY   r  r  zLUT rz  )rK  r   TrH  zRGB c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  )r   r  s     rv   r   0fluoview_description_metadata.<locals>.<genexpr>[  s     =}3s88}r  )r  r   r  rc  r   r   r  rP  rt  r   r  r   r  r,   )r   ignoresectionsr   r  sectionsr  commentr	  r   r  r  r   rO  s                rv   fluoview_description_metadatar!  [  s   " !!#&&2o02HIFxHGG&&(::<D7c>BCyG#RL"2,Abz$(IIgm$<GM8v%GMEA$%IIg$6GMG":DBQx6!'OOG$"4LNN4 

3"u:?(,G!HNN$%
r7fNN=u{{}==#)%++-#8GIIK U )V Mru   c               (  ^	 0 nU R                  S5      (       d  U$ S H  nU R                  US5      n M     U R                  S5       GH  nUSS S:w  a  M  UR                  5       nU(       d  M(  US   nU[        R                  ;  a!   [        SR                  U5      S	5      US
'   Mb  [        R                  U   u  nm	[        US   [        5      (       a  [        U5      S:X  d   eXFS      nOU Vs/ s H  oU   PM	     nnT	[        L a  US   S:X  a  S/n[        U	4S jU 5       5      nT	[        L a  SR                  U5      nO[        U5      S:X  a  US   nXqU'   GM     U$ ! [         a    SR                  USS 5      X'    Nf = fs  snf )a  Return metadata from Pilatus image description.

Return metadata from Pilatus pixel array detectors by Dectris, created
by camserver or TVX software.

>>> pilatus_description_metadata('# Pixel_size 172e-6 m x 172e-6 m')
{'Pixel_size': (0.000172, 0.000172)}

r  z#:=,()r  r  NrT  r  r   %Y-%m-%dT%H %M %S.%frh  rY   notNaNc              3  4   >#    U  H  nT" U5      v   M     g 7fry   rt   r   r  r   s     rv   r   /pilatus_description_metadata.<locals>.<genexpr>\  s     0AuQxxr  )r  r  r  r   r  rI   r   r   r   r  r   rY  r~   rz   )
r   r  r  raw_linetokensr   r  r  r  r   s
            @rv   r  r  [  s     F!!$''!))!S1   %%d+BQ<4!ayt***4%-HHV$&<&z"
 ,,T2gaj%((w<1$$$ ,F)01AQiF1E>fQi50WF000C<XXf%F[AAYFt; ,< M%  4"xxqr
34 2s   
E)5F) FFc               l   U R                  S5      (       d  Sn[        U5      e0 nU R                  S5      nUS   R                  5       US'   USS  HM  n UR                  5       R                  SSS	9u  pV[	        UR                  5       5      X%R                  5       '   MO     U$ ! [         a     M`  f = f)
zReturn metadata from Aperio image description.

The Aperio image description format is unspecified. Expect failures.

>>> svs_description_metadata('Aperio Image Library v1.0|AppMag = 20')
{'Header': 'Aperio Image Library v1.0', 'AppMag': 20}

r  z invalid Aperio image descriptionrI  r   HeaderrY   NrH  )maxsplit)r  r   r  rc  r,   )r   r   r  r`  r  r   rO  s          rv   r  r  \  s     !!),,0oFc"EQx~~'F8ab		++C!+<JC %U[[]3yy{  M	  		s    B%%
B32B3c                  U R                  5       n U (       d  / $ / nU R                  S5       H  nUR                  5       (       d  M  0 nUR                  5        H  nUR                  SS5      n[        U5      S:  a/  Uu  pg[	        UR                  5       5      X6R                  5       '   MS  US   R                  5       nU(       d  Mo  SU;   a  US   R                  U5        M  U/US'   M     U(       d  M  UR                  U5        M     U$ )zReturn metadata from MetaMorph image description.

The MetaMorph image description format is unspecified. Expect failures.

>>> stk_description_metadata('name: value')
[{'name': 'value'}]

r  r  rY   r   r=  )rc  r  r  r   r,   r   )r   r  planer  r	  r  r   rO  s           rv   stk_description_metadatar0  /\  s     ##%K	 F""6*{{}}$$&DJJsA&E5zA~#"("7**,a(5Qw"U+!&" ' 1MM!% +& Mru   c               *  ^^ U R                  S5      (       d  Sn[        U5      eSSKnSSKJn  UR                  U 5      n[        [        S S UR                  S.m      SUU4S	 jjmT" U0 5      nS
U;   a  US
   R                  SS5      US
'   U$ )z2Return metadata from MetaSeries image description.r  z$invalid MetaSeries image descriptionr   Nrv  c                    [        U SS5      $ )Nonr=  )asboolr  s    rv   r  1metaseries_description_metadata.<locals>.<lambda>f\  s    &D%0ru   c                    [        U S5      $ )N%Y%m%d %H:%M:%S.%f)rI   r  s    rv   r  r5  g\  s    (1&:;ru   )rY  r   r   rm  guidc               :  > U  Hx  nUR                   nU(       d  T" U0 5      XR                  '   M-  SU;   d  M5  US   nUR                  SS5      nUR                  SS5      nUT;   a   TU   " U5      X'   Mt  XaU'   Mz     U$ ! [        [        4 a    XaU'    M  f = f)NrO	  rw  r=  rO  )r  r  rS  r   r   )	ry  r  r  r  r  r.  r  r(
  typess	          rv   r(
  .metaseries_description_metadata.<locals>.parsem\  s     E\\F$)%$4yy!v~4LJJvr*JJw+:&$)!HQK	 !"1I   	 '	2 &$%q	&s   )BBBr  z
&#13;&#10;r  )ry  ElementTree.Elementr  r   r6  r   )
r  r   r  r  rw  r
  rY  r   r  r  )r   r   r  rw  ry  r  r(
  r:  s         @@rv   r  r  Y\  s    !!,//4o%!!+.D0;		,E!+9	 , #4_F &} 5 = =$!
} Mru   c                   [        U 5      $ )z1Return metadata from ScanImage image description.)r9   r  s    rv   scanimage_description_metadatar>  \  s    $$ru   c                    [         R                  " U 5      $ ! [         a(  n[        5       R	                  SU<S 35         SnAgSnAff = f)z*Return metadata from ScanImage artist tag.z,<tifffile.scanimage_artist_metadata> raised r_  N)r  r   r   r7   rm  )artistr  s     rv   scanimage_artist_metadatarA  \  sN    
zz&!! 
:3,,G	
 	
 	
s    
A
AA
c               t   S S jnSS0n0 n/ nSnSnSn0 nSn	U R                  5        GHU  n
U
R                  5       n
U
S:X  d	  U
S   S:X  a  M%  U
S   S:X  a  U
S	   S
:X  a  U
SS	 n0 =X7'   nUS:X  a  / =US'   n/ =US'   nMX  US:X  a  / X7'   Md  US:X  a  SU;   a  / =X7   S'   nM{  M}  US:X  a  SU;   a  / =X7   S'   nM  M  US:X  a-  US   S   n[        U5       Vs/ s H  nS/ 0PM	     nnXCU'   Sn	M  M  U
R                  SS5      u  nnUR                  5       nUR                  5       S:X  a  SnO3SU;   a"  [	        S UR                  S5       5       5      nO[        U5      nUS:X  a)  UX'   WR                  U5        WR                  U5        GMi  US:X  aA  US:X  a"  [        U5       Vs/ s H  n0 PM     snUS'   GM  U" U5      u  nnUUS   U   U'   GM  US:X  a[  USS S:X  a>  XI   S   n[        R                  " SU5      nUR                  US   US   US   /5        GM  U" U5      u  pUXI   U'   GM  USS S:X  a  Ub  UR                  U5        GM1  USS S:X  a  Ub  UR                  U5        GMQ  UX'   GMX     SU;   a  / n/ n[        US   US   SS9 HQ  u  nnUS:  d  M  UR                  UR                  UUS   R                  5       5      5        UR                  U5        MS     SR                  U5      US'   [	        U5      US'   [        R                  " [        [         5         ["        R$                  " US   S   SUS   S    ["        R&                  5      US   S'   SSS5        [        R                  " [        [         5         ["        R$                  " US   S   SUS   S    ["        R(                  5      US   S'   SSS5        U H.  n["        R$                  " US   ["        R*                  5      US'   M0     U$ s  snf s  snf ! , (       d  f       N= f! , (       d  f       N_= f)!zMReturn OlympusSIS metadata from INI string.

No specification is available.

c                   Sn[        U R                  S5      5      nU[        U 5      :  a  [        XS  5      S-
  nU S U n X4$ )Nr   
0123456789rY   )r   r  r   )r   r  r  s      rv   keyindex&olympus_ini_metadata.<locals>.keyindex\  sJ    

<()s3x<BL1$Ebq'Czru   r  r  Nr=  r   ;r  rK  r	  rY   	Dimensionr  r   ASDr	  rJ  r  r  LUTrH  r|  c              3  8   #    U  H  n[        U5      v   M     g 7fry   )r,   r	  s     rv   r   'olympus_ini_metadata.<locals>.<genexpr>\  s     B1AAfQii1Ar  Countr   r	  rT  r  r  Tr4  )r   rz   r6  r  )r  rc  r  r  r~   r,   r   re  rf  r  rS  rN  r   r  r  r   r   r   r  r  r  rP  )inistrrE  sisaxesr  r  zpostpossection_namer  ibandr	  r  r   nbandsr   r   rO  r  lutpackedr  r  bands                          rv   r  r  \  sM     &smGF"$E!D!DL GE!!#zz|2:aC7c>d2h#o":L-//F 7{*(**v*,,w%&')$$&(:<<F(04 )'&(=??F(3d )',V4.3Fm<m%m<',|$	 ( C+JC))+C{{}"BS1ABBu{*$C U#&'>16u$>AR$>F5M!)#JC05F5M%(-'r7e#,u-C#[[u5FJJq	6!9fQi@A!)#JC(-EL%RaF"t'7E"RaI%$*:E"$q $t wEDAq1uGKK1Q4::<89Q F v,w			Y
	3#kk3K :&"5c":;U]]
sF 
4 
		Y
	3$)KK6N9%&C{(;F(CDKK%
vy! 
4
 kk$u+u{{;U Mu =& %?8 
4	3 
4	3s$   P*P3;P;P)
P&)
P7c                 ^	 Sn0 n0 nU R                  5        GH  nUR                  5       nU(       d  M  USS R                  5       nUSS nUR                  S5      (       d3  Xa S3-   U;  a  XtXa S3-   '   SX6'   OXtXa X6    3-   '   X6==   S-  ss'   M~  USS nSU;   a%  UR                  SS5      u  pxUR                  5       nOSnUR                  5       nU(       d  SnGOEUS	   S
:X  a  [	        U5      S:  a$  [        5       R                  X& SU< 3-   5        GM  US   S
:X  a  USS nOS
U;   a  SU;   d$  [        5       R                  X& SU< 3-   5        GMF  USS R                  5       SS R                  S
S5      u  pxUR                  SS5      S   R                  5       nO~US	   S:X  aE  US   S:X  a<  USS nSU;   a  [        O[        m	[        U	4S jUR                  S5       5       5      nO0US:X  a  SnO'US:X  a  SnOSU;   a  [        U5      nO [        U5      nXd;   a  [        5       R                  X& S3-   5        XtU'   U(       d  GMA  XXa S3-   '   US	   S:X  d  GMV  SU;   d  GM_  USS R                  SS5      S	   XFU S3-   '   GM     U$ ! [         a&    [        5       R                  X& SU< 3-   5         GM  f = f)zReturn metadata from AstroTIFF image description.

>>> astrotiff_description_metadata(
...     'SIMPLE  =                    T / FITS standard'
... )
{'SIMPLE': True, 'SIMPLE:COMMENT': 'FITS standard'}

z*<tifffile.astrotiff_description_metadata> NrP  rH  0rY   /r=  r   r   rT  z: invalid string rK  r;  r	  rz  r}  c              3  P   >#    U  H  nT" UR                  5       5      v   M     g 7fry   )rc  r'  s     rv   r   1astrotiff_description_metadata.<locals>.<genexpr>I]  s!     E4Dq%	**4Dr  r|  r  TrJ  Fz: invalid value z: duplicate keyCOMMENTr  r	  UNIT)r  rc  r  r  r   r7   rm  rY  r   r~   r   )
r   seplogmsgcountsr  r	  r   rO  r   r   s
            @rv   r  r  ]  s    :FFF&&(zz| 2AhnnQR$$ uAYf,*/suAY'6;suV[M223q ab	%<"[[a0NEmmoGGE1X_5zA~  E1B5)*L!LMRyCa w3'>H$$5(9%!CC !%ab!1!"!5!;!;C!C!--Q/399;1X_rc!1!BKE E\EsEEEKK4DEEEc\Ec\EE\%LEE

 =HV_&==>s7,335()qzS SG^-4QR[->->sA-Fq-IuD\)*U )X M    E1A%*K!KLs   J+KKc          	        [         R                  " S[         R                  5      n[         R                  " S5      n0 nUR                  U R	                  5       5       GH%  u  pV0 nUR                  U5       GH  nUu  pU
R	                  5       n
U
(       a  U
S:X  a  Sn
O&[        U
5      S:  a  U
S   S:X  a  U
S   S:X  a  U
SS n
U
b  S	U
;   aE  [        R                  " [        5         [        S
 U
R                  S	5       5       5      n
SSS5        OcSU
;   a/  [        R                  " [        5         [        U
5      n
SSS5        O.[        R                  " [        5         [        U
5      n
SSS5        XU	'   GM     XtU'   GM(     UR                  (       d_  UR                  5       nS H8  n US   US-      tpnUR                  U5        UR!                  SUS9US   U'   M:     UR                  U5        U$ ! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! ["        [$        [&        4 a     M  f = f)zwReturn metadata from Hamamatsu streak image description.

Read scaling arrays from ``fh`` if the file handle is open.

z!\[([a-zA-Z0-9 _\-\.]+)\],([^\[]*)z4([a-zA-Z0-9 _\-\.]+)=(\"[^\"]*\"|[\+\-0-9\.]+|[^,]*)r  NrT  r   rK  rY   r|  c              3  v   #    U  H/  nS U;   a  [        U5      O[        US   S:X  a  USS OU5      v   M1     g7f)r}  r   #rY   N)rY  r   r	  s     rv   r   .streak_description_metadata.<locals>.<genexpr>]  sH      & &6 $'!8 !&a%(!A$#+121%E!F &6s   79r}  )ScalingXScalingScalingYScalingrB  Filez<f4)r   r  )recompileDOTALLr  rc  r   r  r  r   r~   r  rY  r   r  rX  r\  r  r  r   r]  )r   rl  section_patternproperties_patternr  r  r  
propertiesr  r   rO  rm  scalingr   r  r   s                   rv   r	  r	  d]  s    jj,biiO ?  F*22;3D3D3FG%'
&..v6DJCKKMEESLUqU1X_rc9Ia %<#,,Z8 % & &+[[%5& ! 98 E\#,,Z8 %e 98 $,,Z8 #E
 9#sO1 72 %w7 H: 99ggi=G$*9$5g6F$G!-/]]u .; .y!'*	 > 	M? 98 98 98 i1 s6   '"G92H
!H.4H,9
H

H
H),IIc                  SSK Jn  UR                  U 5      n0 nUR                  S5       H  nUR                  R                  S5      nU(       d  M'  UR                  nUc  M8  US:X  a  SnOYUS:X  a  S	nOPUS
:X  a?  [        R                  " [        [        5         [        R                  " U5      nSSS5        O[        U5      nXcU'   UR                  R                  S5      nUc  M  XsU S3'   M     U$ ! , (       d  f       N?= f)zReturn metadata from EER (Electron Event Representation) XML tag values.

Boolean strings 'Yes' and 'No' are converted to bool.

r   rv  z./itemr   Nr  Tr  F	timestampr  z.unit)r  rw  r
  r  r  rS  r  r  r  r   r   rh  fromisoformatr,   )xmlstrrw  ry  r  r  r   rO  r  s           rv   r  r  ]  s     & !!&)DFX&kkoof%		=E>Ed]EK$$Y
; ..u5 <; 5MEs{{v&$(cU%=!) '* M <;s   C66
D	T)rescalec                ^^ Uc  SnTc  Sm[         R                  " T5      m[        U5      mTS:  d  [        U4S jU 5       5      (       a  SU 3n[	        U5      e[        U4S jS 5       5      n[         R                  " U TR                  U-   5      n[         R                  " UR                  [        U5      4T5      n[        U5       H  u  pU[        X(S	-   S 5      -	  n
U
S	U	-  S	-
  -  n
U(       aq  TR                  S
-  U	-  S	-   U	-  nXR                  R                  S
-  :  a  U
R                  S5      n
U
SU-  S	-
  SU	-  S	-
  -  -  n
U
SUTR                  S
-  -
  -  -  n
XSS2U4'   M     UR                  S5      $ )a  Return array from bytes containing packed samples.

Use to unpack RGB565 or RGB555 to RGB888 format.
Works on little-endian platforms only.

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

Returns:
    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), rescale=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]

Nr  z<Br)  c              3  F   >#    U  H  oTR                   S -  :  v   M     g7frP  N)r   )r   r  r   s     rv   r   unpack_rgb.<locals>.<genexpr>]  s     F1ENNQ..r  zsample size not supported: c              3  z   >#    U  H0  n[         R                  " U5      R                  S -  T:  d  M,  Uv   M2     g7frw  )r   r   r   )r   r  r>  s     rv   r   rx  ]  s-     FA%++a."9"9A"="Eaas   +;	;BHIrY   rP  r  rT  rK  )r   r   r  r;  r   r  r  r   rB  r   r   r  r   r,   rt  )r  r   r   rt  r   r  r  r  r  r*  r.  r  r>  s    `          @rv   r  r  ]  s   N !}KKE}DbyCFFFF+M?;o	FF	FB!!$"(<=J[[*//3}+=>FFM*#mEG455	a3h!^..1$,q0C7A##,,q00HHSM!Q$(3
++A!U^^a/011Aq!t + >>"ru   )r  c                  [         R                  " XSS9n[         R                  " USS5      nU(       a  [         R                  " U5      nU$ )a|  Return palette-colored image.

The colormap is indexed along its second axis (palette dimension).
The returned image array is of shape ``image.shape + (colormap.shape[0],)``
and dtype ``colormap.dtype``.

Parameters:
    image:
        Array of indices into colormap.
    colormap:
        RGB lookup table aka palette of shape ``(3, 2**bitspersample)``.
    contig:
        Return contiguous array.

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

rY   r  r   rK  )r   taker  r  )r  r   r  r  s       rv   rU  rU  ^  s>    2 ZZa0F^^FAr*F((0Mru   r	  c         	       ^^^^^^ Uc  SO
[        U5      nUct  Ub>  [        U5      S:w  d  US   [        U 5      :  a  S[        U 5      4 SU 3n[        U5      eS[        U 5      4[        [        U 5      5       Vs/ s H  ow4PM     snU 4$ [        R
                  R                  X5      nU(       d  Sn[        U5      e[        U[        5      (       a  [        R                  " U5      mO![        US5      (       a  UmOSn[        U5      eTc  0 mTR                  R                  5        VV	s0 s H  u  pX_M	     sn	nmSUUU4S	 jjn
U (       d  S
n[        U5      eU  Vs/ s H"  n[        R                  R!                  U5      PM$     nn[        U5      S:X  a#  [        R                  R#                  US   5      nO[        R                  R%                  U5      n[        U5      nSm/ nU H  nU
" UUS R'                  [        R(                  5      5      u  nmTc_  UmTbY  [        T5      [        T5      :w  d,  [+        U4S j[        [        T5      5       5       5      (       a  ST< ST< 3n[        U5      eOTU:w  a  Sn[        U5      eTb  [        U4S jT 5       5      mUR-                  T5        M     Tc   eTb  [        U4S jT 5       5      m[.        R0                  " U[.        R2                  S9n[.        R4                  " USS9nUU-  n[.        R6                  " USS9S-   nUc!  [        S UR9                  5        5       5      nOK[        U5      [        U5      :w  d   [+        S [;        UUSS9 5       5      (       a  SU SU 3n[        U5      eUR9                  5       nU Vs/ s H  n[        U5      PM     nnTX_U 4$ s  snf s  sn	nf s  snf s  snf )a  Return shape and axes from sequence of file names matching pattern.

Parameters:
    files:
        Sequence of file names to parse.
    pattern:
        Regular expression pattern matching axes names and chunk indices
        in file names.
        By default, no pattern matching is performed.
        Axes names can be specified by matching groups preceding the index
        groups in the file name, be provided as group names for the index
        groups, or be omitted.
        The predefined 'axes' pattern matches Olympus OIF and Leica TIFF
        series.
    axesorder:
        Indices of axes in pattern. By default, axes are returned in the
        order they appear in pattern.
    categories:
        Map of index group matches to integer indices.
        ``{'axislabel': {'category': index}}``
    _shape:
        Shape of file sequence. The default is
        ``maximum - minimum + 1`` of the parsed indices for each dimension.

Returns:
    - Axes names for each dimension.
    - Shape of file series.
    - Index of each file in shape.
    - Filtered sequence of file names.

Examples:
    >>> parse_filenames(
    ...     ['c1001.ext', 'c2002.ext'], r'([^\d])(\d)(?P<t>\d+)\.ext'
    ... )
    (('c', 't'), (2, 2), [(0, 0), (1, 1)], ['c1001.ext', 'c2002.ext'])

NrY   r   zshape z does not fit provided shape )r  zinvalid pattern
groupindexc                 > T
c   e/ n/ nTR                  U 5      nUc  SU < 3n[        U5      eS n[        UR                  5       5       H}  u  pgUnUc  M  US-   T;   a	  TUS-      nOUS   R	                  5       (       a  UnM:  Uc  Sn [        UT
;   a  T
U   U   OU5      nUR                  U5        UR                  U5        S nM     [        U5      [        U5      4$ ! [        [        4 a  n	SU< 3n[        U5      U	eS n	A	ff = f)Nz!pattern does not match file name rY   r   r/  zinvalid index )	searchr   r  groupsisalphar   r  r   r~   )r  r  r  matchesr   r  r  matchr-  r  r   r~  pattern_compileds             rv   r(
  parse_filenames.<locals>.parses^  s,   %%%"))(3?5h\BCS/!!'.."23HAAy1u
"A&1z/R:-=
2q)1E NN1KKOB% 4& T{E'N** ) /&qe, o3./s   C""D	2DD	zfiles is emptyc              3  ,   >#    U  H	  oT;  v   M     g 7fry   rt   )r   r  r   s     rv   r   "parse_filenames.<locals>.<genexpr>^  s     D3Ca	)3Cr  zinvalid axesorder z for z'dims do not match within image sequencec              3  .   >#    U  H
  nTU   v   M     g 7fry   rt   )r   r  r  s     rv   r   r  ^  s     2	1A	r	  c              3  .   >#    U  H
  nTU   v   M     g 7fry   rt   r  s     rv   r   r  ^  s     0iT!Wir	  rz  r  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   r  ^  s     ;&:c!ff&:r  c              3  .   #    U  H  u  pX:  v   M     g 7fry   rt   r1  s      rv   r   r  ^  s      />$!>r   Tr4  zparsed shape )r  rz   r6  z'tuple[tuple[str, ...], tuple[int, ...]])r~   r   r   r  r   rL  rS  r   rz   ri  rj  r   r~  r`  r  rE  normpathrG  rS
  lstripr_  r;  r   r   r  intpr  rk  r  r  )r   r   r   r   r  r   r   r  r   r  r(
  r  	normpaths
prefix_strro  r  r  lblr  
startindexparsedshapeindices_listr  r  r~  r  r  s     ``                   @@@@rv   r=   r=   #^  s   d NDfE#e*/U1XE
5JCJ=/)FugNCS/!ZM U,-,aT,-	
 	
   $$W6Go'3::g.	,	'	'"o
#3#>#>#D#D#FG#F41!$#FGJ+ +> o.34e!!!$eI4
9~WW__Yq\2
WW''	2
_F#'D%'G&'*11"&&9:S<D$I#d)+D5T3CDDD*9-uTHE o%S[;CS/! 2	22Cs " 0i00 KKuzz:M =q1JZM))M2Q6K};k&8&8&:;;	[	SZ	'3 /e[>/ , , k]*GwOo$1$8$8$:L)56uU|G6&&U .( HJ 5^ 7s   =O0O$)O6O"c             #  $   #    U  Sh  vN   g N7f)z=Return iterator over pages in data array of normalized shape.Nrt   )r  s    rv   rs  rs  ^  s     OOs   c             #    #    [         R                  " US   U-  5      nU  Ha  nUc  [        R                  " X5      nOUR	                  U5      nU H-  nU H$  n[        U5       H  n	XU-  U	S-   U-   v   M     M&     M/     Mc     g7f)a  Return iterator over strips in pages.

Parameters:
    pageiter:
        Iterator of pages, each of shape ``shape``, or ``None`` for missing
        pages. Missing pages are replaced with zero-filled arrays.
    shape:
        Normalized page shape ``(pages, depth, rows, cols, samples)``.
    dtype:
        Data type of page arrays.
    rowsperstrip:
        Number of rows per strip.

Yields:
    Strips of shape ``(rows, cols, samples)`` where rows <= rowsperstrip.

r  NrY   )ro  rp  r   r  rt  r  )
pageiterr   r   r   r  r  pagedatar/  rZ  r  s
             rv   r{  r{  ^  s     0 		%)l23I< {{50H||E*HEy)AL 0AE\3IJJ *   s   BBc             #  R  #    S[        U5      s=:  a  S:  a  O  O[        U5      [        U5      :w  a  Sn[        U5      e/ UQU R                  S   P7nU R                  nU R                  SS u  pg[        U5      S:X  a  Uu  pU  H  n
U
 H  n[	        US   5       H  nX-  n[        XU-
  5      n[	        US   5       H]  nX-  n[        XU-
  5      nUSXU-   2UUU-   24   nUR                  U:w  a#  [        R                  " XE5      nUUS	U2S	U24'   UnUv   M_     M     M     M     g	Uu  npU R                  S   nU  H  n
U
 H  n[	        US   5       H  nUU-  n[        UUU-
  5      n[	        US   5       H  nX-  n[        XU-
  5      n[	        US   5       Hp  nX-  n[        XU-
  5      nUUUU-   2XU-   2UUU-   24   nUR                  U:w  a&  [        R                  " XE5      nUUS	U2S	U2S	U24'   UnUS:X  a  US   OUv   Mr     M     M     M     M     g	7f)
a  Return iterator over full tiles in data array of normalized shape.

Tiles are zero-padded if necessary.

Parameters:
    data:
        Normalized array of shape ``(pages, depth, rows, cols, samples)``.
    tile:
        Tile shape as ``(rows, cols)`` or ``(depth, rows, cols)``.
    tiles:
        Number of tiles along each tiled dimension.

Yields:
    Tiles of shape ``(*tile, samples)``, zero-padded at image boundaries.

rY   r  zinvalid tile or tiles shaperK  r   r  rT  r   N)r   r   r   r   r  r  r   r  )r  r   r  r   r   r   r_  r^  r  r  r  r/  iytycyixtxcxr  chunk_rQ  sziztzczs                            rv   rr  rr  ^  sM    , s4y1D	SZ 7+o(4(B(JJJEZZ!_FB
4yA~Da/BBQRB#E!HoV G_ %a2grBG|&C D ;;*4%*[[%CF/4F3B38,$*E# . *    1ZZ]Da/BaBQRB#E!HoV G_"'a/B!#B!$QRB$) "R"Wb7lBbL H%E  %{{j8).Z)G8=ssCRC"} 5(../1f%(%? #2 . *  s   H%H'c             #  l  ^ ^^^^^#    T S::  a  g[        T5      TR                  -  mU(       a  SUUUU4S jjnO	SUU4S jjnUb  US:  d  T S:  a)  [        T 5       H  n	[        T5      n
U" U
5      v   A
M     gUc  [        R
                  S-  nTS:X  a  UnO[        XVT-  5      nT U::  a<  S	UU 4S jjn[        U5       nUR                  X" 5       5       Sh  vN   SSS5        g[        U5       nSn/ n[        T 5       HY  n	[        T5      n
U
b  US-  nUR                  U
5        X:X  d  M.  UR                  X5       Sh  vN   UR                  5         SnM[     U(       a  UR                  X5       Sh  vN   SSS5        g N! , (       d  f       g= f NV N"! , (       d  f       g= f7f)
zbReturn iterator over encoded chunks.

Chunks that are ``None`` yield b'' without calling encode.

r   Nc          	        > U c  g[         R                  " U T5      n U R                  T:w  a;  [        S [	        TU R
                  SS9 5       5      n[         R                  " X5      n T" U 5      $ )Nru   c              3  2   #    U  H  u  pS X-
  4v   M     g7fr0  rt   r1  s      rv   r   .encode_chunks.<locals>.func.<locals>.<genexpr>[_  s       E J Er3  Fr4  )r   r  r   r~   r  r   r  )r  r  r  r   rg  r   s     rv   r  encode_chunks.<locals>.funcT_  si    }++E59E||y(   #E5;;u E  		%-%= ru   c               J   > U c  g[         R                  " U T5      n T" U 5      $ )Nru   )r   r  )r  r   rg  s    rv   r  r  d_  s'    }++E59E%= ru   rT  c               3  R   >#    [        T5       H  n [        T5      nUv   AM     g 7fry   )r  r  )r   r  	chunkiterr  s     rv   r  encode_chunks.<locals>.chunks}_  s&     9%Y	 &r  rY   )r  r  r6  r{   )r6  Iterator[NDArray[Any] | None])r@   r   r  r  r   r
  rk  rT   r8  r   r  )r  r  rg  r   r   r   r   rK
  r  r   r  	maxchunksr  r;  r  
chunk_listr  s   `````           @rv   rz  rz  =_  s      A~/I	! 	! 	! 	! Z!^y1}y!AOEu+	 "
 	 __q(
A~	
)$;<	I	 	  
+x||D&(333 ,	J	'8
y!AOE 
e$!#<<999  " " ||D555 
(	' 4 ,+ : 6 
(	'sr   B;F4FFF"F46:F#4F#F	5F#>F!?F#	F4F
FF4F#!F##
F1-F4c               <   [        [        [        [        U5      5      nU=[        R                  :X  a    U $ =[        R                  :X  a    U SSSS2SS24   $ =[        R
                  :X  a    U SSSS2SS2SS24   $ =[        R                  :X  a    U SSSS2SSS2SS24   $ =[        R                  :X  a    [        R                  " U SS5      $ =[        R                  :X  a$    [        R                  " U SS5      SSSS2SS24   $ =[        R                  :X  a'    [        R                  " U SS5      SSSS2SS2SS24   $ [        R                  :X  a'  [        R                  " U SS5      SSSS2SSS2SS24   $  [        5       R                  SU< 35        U $ )zReturn reoriented view of image array.

Parameters:
    image:
        Non-squeezed output of ``asarray`` functions.
        Axes -3 and -2 must be image length and width respectively.
    orientation:
        Value of Orientation tag.

.NrK  r  ry  z(<tifffile.reorient> unknown orientation=)r_   r   r.   ry  rz  r|  r{  r}  r   swapaxesr~  r  r  r7   rm  )r  orientations     rv   reorientr  _  s`    {GK$EFK
 [  L![!!ddA&& [  ddAq))![!!ddDbD!+,, [  >>%R00![!!>>%R0ddA>>![!!>>%R0ddAqAA  >>%R0ddDbD!1CDDHHK;KLMLru   c               n   / n/ n/ n[         R                  " U 5      n [        U R                  U R                  USS9 H>  u  pVnUR                  Xg45        UR                  US45        UR                  Xg-  5        M@     [         R                  R                  R                  XUSS9R                  U5      $ )ae  Return read-only view into input array with elements repeated.

Zoom image array by integer factors using nearest neighbor interpolation
(box filter).

Parameters:
    a: Input array.
    repeats:
        Number of repetitions to apply along each dimension of input.
        Length must equal the number of dimensions in ``a``.
        All values must be positive integers.

Returns:
    Read-only view of ``a`` with each element repeated along each axis.

Examples:
    >>> repeat_nd([[1, 2], [3, 4]], (2, 2))
    array([[1, 1, 2, 2],
           [1, 1, 2, 2],
           [3, 3, 4, 4],
           [3, 3, 4, 4]])

Tr4  r   F)	writeable)r   r   r  stridesr   r  r   libstride_tricks
as_stridedrt  )r  repeatsrt  r   r  strider   repeats           rv   rF   rF   _  s    0 GEGaA #AIIqww Mfd^${#t}% !N 99""--	'U . ggru   c                   g ry   rt   data_or_shaper  s     rv   rH   rH   _  s     ru   c                   g ry   rt   r  s     rv   rH   rH   _  s    KNru   c               (   US:  a  SU< S3n[        U5      e[        U [        5      (       a%  [        U 5      U:  a  U $ SU[        U 5      -
  -  U -   $ U R                  U:  a  U $ SXR                  -
  -  U R
                  -   nU R                  U5      $ )a  Return image array or shape with at least ``ndim`` dimensions.

Prepend 1s to image shape as necessary.

Parameters:
    data_or_shape:
        Image array or shape tuple to expand.
    ndim:
        Minimum number of dimensions required.
        If the input already has at least ``ndim`` dimensions, it is
        returned unchanged.

Returns:
    Array or shape tuple with at least ``ndim`` dimensions.
    Ones are prepended as needed.

>>> import numpy
>>> 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)
>>> reshape_nd((2, 3), 3)
(1, 2, 3)

rY   zndim=r  r  )r   r   r~   r   r  r   rt  )r  r  r   r   s       rv   rH   rH   _  s    @ axtno-''}%  tc-001MAAT!D---.1D1DDE  ''ru   c                   g ry   rt   r   r  r  s      rv   r  r  `  s     58ru   c                   g ry   rt   r  s      rv   r  r  #`  s     ?Bru   c               ^   [        U 5      [        U5      :w  a  Sn[        U5      eU(       d  [        U 5      US4$ Uc  Sn/ n/ n/ n[        XSS9 HV  u  pxUS:  d  X;   a5  UR	                  S5        UR	                  U5        UR	                  U5        ME  UR	                  S5        MX     [        U5      S:X  a-  SUS	'   UR	                  U S	   5        UR	                  US	   5        [        U[        5      (       a  S
R                  U5      nO[        U5      n[        U5      U[        U5      4$ )a  Return shape and axes with length-1 dimensions removed.

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

Parameters:
    shape:
        Sequence of dimension sizes.
    axes:
        Character codes for dimensions in ``shape``.
    skip:
        Character codes for dimensions whose length-1 dimensions are
        not removed. The default is 'XY'.

Returns:
    shape:
        Sequence of dimension sizes with length-1 dimensions removed.
    axes:
        Character codes for dimensions in output ``shape``.
    kept:
        Dimensions were kept (True) or removed (False).

Examples:
    >>> squeeze_axes((5, 1, 2, 1, 1), 'TZYXC')
    ((5, 2, 1), 'TYX', (True, False, True, True, False))
    >>> squeeze_axes((1,), 'Q')
    ((1,), 'Q', (True,))

z)dimensions of axes and shape do not matchrt   )r  r  rX  r  rY  Tr4  rY   Fr   rK  r=  )r   r   r~   r  r   r   rz   r   )	r   r  r  r   keptr
  r~
  r   r  s	            rv   r  r  ,`  s   D 5zSY9oU|T2%%|4D "N!MD1!8rzKK!!$'  $KK 2 >aReBi(T"X&$ww}%]#.!4t55ru   c                  Uc  Sn[        U5      U R                  :w  a(  S[        U5      < SU R                  < 3n[        U5      e[        U5      nU H  nXT;  d  M
  SU< 3n[        U5      e   [	        U5       Vs/ s H  oUU;  d  M
  UPM     nnSR                  U5      U-   nU R                  S[        U5      -  U R                  -   5      n U R                  U Vs/ s H  oWR                  U5      PM     sn5      $ s  snf s  snf )a  Return image array with its axes permuted to match specified axes.

Parameters:
    image:
        Image array to permute.
    axes:
        Character codes for dimensions in image array.
        Length must equal the number of dimensions in ``image``.
    asaxes:
        Character codes for dimensions in output image array.
        The default is 'CTZYX'.

Returns:
    Transposed image array.
    A length-1 dimension is added for added dimensions.
    A view of the input array is returned if possible.

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

CTZYXr  z != image.ndim=zunknown axis r=  r  )
r   r  r   r]  r  r   rt  r   	transposer  )r  r  asaxesr   validr  missingrt  s           rv   rL   rL   j`  s    > ~
4yEJJT,.ofE?!"(CS/!  %V,?,b$r,G? 4'IMM$W-;<E??&A&BOOB/&ABB	 @ Bs   >	DD Dc                   g ry   rt   r  r   r  unknowns       rv   rG   rG   `  s     ru   c                   g ry   rt   r  s       rv   rG   rG   `  s     ru   c                  [        U5      n[        U5      n[        U 5      [        U5      :w  a'  S[        U 5      < S[        U5      < 3n[        U5      e[        U5      n[        U5      nXV:w  a  SU SU 3n[        U5      eU (       d   U(       d  [	        U [
        5      (       a  S$ S$ [        S[        U5      [        U5      -
  5      nU(       a  USU-  -   n[        U5      S	-
  nS	n	S	n
/ nUS
S
S2    H  nX-  n	US:  a)  X   S	:X  a!  US	:w  a  US	-  nUS:  a  X   S	:X  a  US	:w  a  M  XU   :X  a+  XX   -  :X  a!  XU   -  n
UR                  X   5        US	-  nMi  UR                  U=(       d    S5        M     [	        U [
        5      (       a  SR                  [        XS
 5      5      n U $ [        [        XS
 5      5      n U $ )a-  Return axes matching new shape.

Parameters:
    axes:
        Character codes for dimensions in ``shape``.
    shape:
        Input shape matching ``axes``.
    newshape:
        Output shape matching output axes.
        Size must match size of ``shape``.
    unknown:
        Character used for new axes in output. The default is 'Q'.

Returns:
    Character codes for dimensions in ``newshape``.

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

r  r  cannot reshape r  r=  rt   r   r  rY   NrK  r/  )
r~   r   r   r@   r   rz   rk  r   r   r  )r  r   r  r  r   r   r	  lendiffr  prodnsprodsr  r  s                rv   rG   rG   `  s   < %LEXH
4yCJT,U.o5>DhGwd8*5oc**r22 !SZ#h-/0GdWn,E
QAFEFttn !eA"'FA !eA"'q>f(881XEMM$'"FAMM'.S)  $wwxx 012 K XfX./0Kru   r  c         	       ^ [         R                  " [         R                  " [         R                  " U SS95      SS9m[	        S [         R
                  " TSS9 5       5      nU(       a  [	        U4S jU 5       5      nU$ )a  Return order of axes sorted by variations in indices.

Parameters:
    indices:
        Multi-dimensional indices of chunks in array.
        If only one row is provided, all axes appear non-varying and
        are returned in their natural order.
    squeeze:
        Remove length-1 dimensions of nonvarying axes.
        If all axes are constant, an empty tuple is returned.

Returns:
    Order of axes sorted by variations in indices.
    The axis with the least variations in indices is returned first,
    the axis varying fastest is last.

Examples:
    Axis 0 varies fastest; axis 1 is constant and squeezed out:
    >>> order_axes(
    ...     [(0, 2, 0), (1, 2, 0), (0, 2, 1), (1, 2, 1)], squeeze=True
    ... )
    (2, 0)

r   r  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  r  s     rv   r   order_axes.<locals>.<genexpr>a  s     C"BQ#a&&"Br  T)stablec              3  >   >#    U  H  nTU   S :w  d  M  Uv   M     g7fr0  rt   )r   r  r  s     rv   r   r  a  s     7A$q'Q,aas   	)r   r  r-  r  r~   rl  )r  r   r
  r  s      @rv   r  r  `  s\    < 99UYYuzz':;!DDC%--T"BCCE777Lru   c                8   [        U 5      n[        U5      nUS:X  a  US:X  a  gUS:X  d  US:X  a  gX2-  (       a  g[        [        U5      5      nSnS=pV[        U 5       H8  nXW-  nXS  H)  nUS-  nXh-  nXx:X  d  XV:X  a    M$  US:X  a  M!  Xe:w  d  M(      g   M:     g)a  Return if page and series shapes are compatible.

Compatible means the series product is a multiple of the page product
and the trailing dimensions of both shapes align such that pages tile
exactly into the series without remainder.

Parameters:
    page_shape: Shape of a single page.
    series_shape: Shape of the full series.

Returns:
    ``True`` if the page can tile exactly into the series, else ``False``.

r   TFrY   N)r@   r~   r  )	r|  series_shaper_  series_sizer  pipjr  r2  s	            rv   r:  r:   a  s    " 
#I,'KA~+*A~),/0L	AKBj!
 b!AFAGBvAvx "	 " ru   rT  c                   g ry   rt   r  r
  r  r  s       rv   subresolutionr  Ma       ru   c                   g ry   rt   r  s       rv   r  r  Sa  r  ru   c                  U R                   UR                   :w  d  U R                  UR                  :w  a  gSn[        U R                   R                  5       U R                  UR                  SS9 Hx  u  pVnUS;   ae  Uc;  [        U5       H*  nX(-  n	X:  a      gXi-  U:X  d  Xi-   S-
  U	-  U:X  d  M'  Un  MF       gX$-  n	X:  a    gXi-  U:w  a  Xi-   S-
  U	-  U:w  a    gMo  Mq  Xg:w  d  Mx    g   U$ )a  Return level of subresolution of series or page b vs a.

Parameters:
    a: Reference page or series.
    b: Candidate page or series to test against ``a``.
    p: Downsampling factor per pyramid level.
    n: Maximum number of pyramid levels to test.

Returns:
    Pyramid level of ``b`` relative to ``a``, or ``None`` if ``b`` is not a
    subresolution of ``a``. Level 0 means same resolution as ``a``.

NTr4  xyzrY   )r  r   r  r  r   r  )
r  r
  r  r  r   r  r  r2  rW  r  s
             rv   r  r  Ya  s    ( 	vv177agg-EFq; }qAAu# v{quqyQ&6!&; ! "  H56Q;AEAI!#3q#8 $9;V/ G0 Lru   )rA  samplingfactorsc              8   Uc  SnSnU[        U 5      :  Ga  X   nSnUS-   nUR                  R                  (       a  US-  nM=  U[        U 5      :  a  X   nU(       a"  UR                  R                  (       d  US-  nM<  Uc/  U H"  n[	        UR
                  S   XxS9S:X  d  M   Un  O+   US-  nMn  [	        UR
                  S   XuS9S:w  a  US-  nM  UR
                  R                  U5        X	 U[        U 5      :  a  M  US-  nU[        U 5      :  a  GM  gg)a  Pyramidize list of TiffPageSeries in-place.

TiffPageSeries that are a subresolution of another TiffPageSeries are
appended to the other's TiffPageSeries levels and removed from the list.
Levels are to be ordered by size using the same downsampling factor.
Each candidate series must be exactly one subresolution step below the
previously added level.
TiffPageSeries of subifds cannot be pyramid top levels.

Parameters:
    series:
        List of TiffPageSeries to pyramidize in-place.
    reduced:
        Only consider series whose keyframe is reduced image as pyramid
        levels.
    samplingfactors:
        Downsampling factors to probe when detecting the pyramid factor.
        The default is (2, 3, 4).

N)rT  r   r  r   rY   rK  r  )r   r  rc  r  r  r  r   )	r   rA  r  r  r  r  r2  r
  r  s	            rv   r6  r6  a  s   6 #	A
c&k/IE::FA#f+o	Aqzz44Qy(A$QXXb\1:a? )
 FAqxx|Q49QHHOOA	% #f+o& 	
Q7 c&k//ru   )rK
  r*  r   r   c              B   [        U 5      nUS:X  a  Sn[        U5      eUS:X  a&  Uc#  X5S'   U S   c   eU S   R                  " SSU0UD6$  [        S U  5       5      nUc   eUc  U/UR
                  Q7OUR
                  n	UR                  n
U
c   e[        XIU
5      nUb  US:  ax  UR                  n[        U[        R                  5      nUS:X  d  US:  a  S=p;OhUS	:  d6  US
::  a3  UR                  S:X  a#  UR                  S:X  a  UR                  S:X  a  SnO)SnO&US:X  a  S=p;OXc:  d  UR                  S
:  a  SnOUnSnXS'   UR                  R                   nUc=  UR"                  nU(       d  US:  d  US:  a  UR%                  S5        UR&                  nOSn[)        [+        SU5      US9nUc  UUUU4             SS jjnUS
:  a  [-        U 5       H  u  nnU" UU5        M     OTUR/                  5         [1        U5       nUR3                  X[5        U5      5       H  nM     SSS5        OSn[7        U5      eUR9                  5         U(       d  UR%                  S5        U$ ! [         a    Sn[        U5      Sef = f! , (       d  f       NT= f)a#  Return vertically stacked image arrays from sequence of TIFF pages.

Parameters:
    pages:
        TIFF pages or frames to stack.
    tiled:
        Organize pages in non-overlapping grid (not implemented).
    lock:
        Reentrant lock to synchronize seeks and reads from file.
    maxworkers:
        Maximum number of threads to concurrently decode pages or segments.
        By default, use up to :py:attr:`_TIFF.MAXWORKERS` threads.
    out:
        Output destination for frame data.
        By default, a new NumPy array is created.
        If a *numpy.ndarray*, a writable array to which the images
        are copied.
        If a string or open file, the file used to create a memory-mapped
        array.
    **kwargs:
        Additional arguments passed to :py:meth:`TiffPage.asarray`.

r   zno pagesrY   Nr   r   c              3  B   #    U  H  oc  M  UR                   v   M     g 7fry   r[  r  s     rv   r   stack_pages.<locals>.<genexpr>a  s     @AZQZZs   r  r   rT  Tr  )r   r*  c                   U c  X!   R                  S5        g UR                  U R                  R                  5        U R                  " SXBU   S.UD6  UR                  U R                  R                  5        g )Nr   )r*  r   rt   )fillrD  r  r  r   r  )r  r  r   r  r*  r   s         rv   r  stack_pages.<locals>.func#b  s[     |
"t{{556A$JA&A 6 67ru   ztiled stacking not implementedFrt   )r  r  r  r   r   rg   r  r   r*  r  r   r   r6  r   )r   r   r   r  r  r   r   r-   r   r  r   r  r   rV  r   r  r  r  r  r*  r   rk  r  r  rT   r8  r  r   r  )r  rK
  r*  r   r   r   r  r   r  r   r   page_maxworkersrl  haslockr  r  r  r  r;  r   s                       rv   r  r  a  s   B ZF{o{u})|Qx###Qx2C2622(@@@ &+mV"ekk"EKKE
E
*C Z!^**1
?o1+,,JaZq !!Q&1$1$JO	q'((
_		 0 01 4$
*<		 	 B|++JN/BKKwws1j1=I}
 #,9=%+	8-	8	8 	8 !		8
 7	8 #	8 	8" >(/tT5!  0 #J/8!d5=AA B 0/ /!#&&: OO
EJY  ("o4'(J 0/s   I4 #J4J
Jzw+)r   suffixr   c                 [        U5      n[        R                  " U5      nU cM  Uc  [        R                  " X5      $ U(       a  [        R                  " XU5      $ [        R
                  " X5      $ [        U [        R                  5      (       a  [        U5      [        U R                  5      :w  a  SU SU R                   3n[        U5      e[        R                  " X R                  5      (       d  SU SU R                   3n[        U5      eU R                  U:w  a  U R                  USS9n Ub  U R                  U5        U $ [        U [        5      (       aq  U R                  S5      (       a[  SSKnU S	S =(       d    SnUc  S
nUR#                  XS9 n	[        R$                  " XX#S9n Ub  U R                  U5        U sSSS5        $ [        R$                  " XX#S9n Ub  U R                  U5        U $ ! , (       d  f       N9= f)at  Return NumPy array where data of shape and dtype can be copied.

Parameters:
    out:
        Specifies kind of array of ``shape`` and ``dtype`` to return:

            ``None``:
                Return new array.
            ``numpy.ndarray``:
                Return view of existing array.
            ``'memmap'`` or ``'memmap:tempdir'``:
                Return memory-map to array stored in temporary binary file.
            ``str`` or open file:
                Return memory-map to array stored in specified binary file.
    shape:
        Shape of array to return.
    dtype:
        Data type of array to return.
        If ``out`` is an existing array, ``dtype`` must be castable to its
        data type.
    mode:
        File mode to create memory-mapped array.
        Only used when ``out`` is a file path or ``'memmap'``.
        The default is 'w+' to create new, or overwrite existing file for
        reading and writing.
    suffix:
        Suffix of ``NamedTemporaryFile`` if ``out`` is ``'memmap'``.
        Only used when ``out`` is ``'memmap'``.
        The default is '.memmap'.
    fillvalue:
        Value to initialize output array.
        By default, return uninitialized array.

Returns:
    NumPy array or memory-mapped array of ``shape`` and ``dtype``.

Raises:
    ValueError:
        Existing array cannot be reshaped to ``shape``
        or cast to ``dtype``.

Nr  r  zcannot cast Fr  r:   r   r  z.memmap)rC  r  )r   r   r   )r~   r   r   rB  r;  r  r   r8  r@   r   r   r  rt  r  rz   r  tempfileNamedTemporaryFiler:   )
r   r   r   r   r  r   r   r  tempdirrl  s
             rv   r-   r-   cb  s   h %LEKKE
{;;u,,::e66{{5((#u}}%%5>WSYY//#E7$syyk:CS/!~~eYY// tCII;7CS/!99++e%+0C HHY
#sx 8 8ab'/T>F((W(D,,reGC$#	 ED
 ,,su
@CJ EDs   +G99
Hc                 ^^^^ SU4S jjmSS jmSS.SS jjmSUU4S jjnSU ;   d  SU ;   a  0 nU R                  5        Hw  nUR                  5       nU(       a  US	   S
:X  d  SU;  a  M+  UR                  SS5      u  mnTR                  5       m[        U4S jS 5       5      (       a  Ml  U" U5      UT'   My     U$ U" U 5      $ )a  Return Python object from Matlab string representation.

Use to access ScanImage metadata.

Parameters:
    matlabstr: String representation of Matlab objects.

Returns:
    Matlab structures are returned as ``dict``.
    Matlab arrays or cells are returned as ``lists``.
    Other Matlab objects are returned as ``str``, ``bool``, ``int``,
    or ``float``.

Examples:
    >>> matlabstr2py('1')
    1
    >>> matlabstr2py("['x y z' true false; 1 2.0 -3e4; NaN Inf @class]")
    [['x y z', True, False], [1, 2.0, -30000.0], [nan, inf, '@class']]
    >>> d = matlabstr2py(
    ...     "SI.hChannels.channelType = {'stripe' 'stripe'}\n"
    ...     "SI.hChannels.channelsActive = 2"
    ... )
    >>> d['SI.hChannels.channelType']
    ['stripe', 'stripe']

c                 > S/n T" U 5      u  p#Uc  O_US:X  a  UR                  S5        OAUS:X  a  UR                  S5        O)US:X  a  UR                  S5        OUR                  U5        XS  n Mm  UR                  S5        U$ )Nr  rG  )r	  r  )r  r  r	  )r	  r	  )r  r   )r  r*  r.  r  
next_tokens       rv   lexmatlabstr2py.<locals>.lexb  s    a=DAyCxj)cj)cj)a "A  	cru   c                  [        U 5      nUS:X  a  gSnX!:  a:  X   R                  5       (       a#  US-  nX!:  a  X   R                  5       (       a  M#  X!:X  a  S U4$ X   S;   a	  X   US-   4$ X   S:X  a+  U R                  SUS-   5      nUS:  a  UOUnXUS-    US-   4$ X   S:X  a+  U R                  SUS-   5      nUS:  a  UOUnXUS-    US-   4$ UnX1:  a  X   S;  a  US-  nX1:  a
  X   S;  a  M  XU U4$ )	Nr   r  rY   z{[;]}r   rs   rr   z {[;]})r   isspacer  )r  rY  r  r2  s       rv   r   matlabstr2py.<locals>.next_tokenb  s*   QQ;jQT\\^^FA jQT\\^^;7N47?4Q;43;sAE"A!VAQ<Q&&43;sAE"A!VAQ<Q&&jQT1FA jQT11vqyru   Ffailc               
  ^  T R                  5       m T (       d  T $ T S   S:X  a)  U(       a	  T S   S:w  d	  ST SS ;   a  [        T 5      eT SS $ T S   S:X  a&  U(       a	  T S   S:w  d	  ST SS ;   a  [        T 5      eT $ U(       a%  [        U 4S jS 5       5      (       a  [        T 5      eT S   S	:X  a  T $ T S
;   a  gT S;   a  gT S S S:X  aP  [        R                  " T SS R                  S5       Vs/ s H  n[        U5      PM     sn5      R                  5       $ T S S S:X  aP  [        R                  " T SS R                  S5       Vs/ s H  n[        U5      PM     sn5      R                  5       $ ST ;   d  ST ;   a   [        T 5      $  [        T 5      $ s  snf s  snf ! [        [        4 a     N(f = f! [        [        4 a     Of = f [        T 5      $ ! [        [        4 a  nU(       a  [        Ue S nAT $ S nAff = f)Nr   r   rK  rY   rs   rr   c              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   )r   r  r  s     rv   r   .matlabstr2py.<locals>.value.<locals>.<genexpr>c  s     2	1Q	r  z ';[]{}r	  >   Truer  T>   Falser  Fr  zzeros(r|  r  zones(r}  r  )rc  r   r;  r   r  r  r   r  onesrY  r   )r  r  r  r  s   `   rv   rO  matlabstr2py.<locals>.valuec  s   GGIHQ43;2##1R. m#Qr7NQ43;2##1R. m#HC2	222Q-Q43;H  ""Ra5H;;!Bc0BC0B1A0BCDKKMMRa5G::q2w}}S/AB/A!s1v/ABCJJLL!8saxQx	q6M  DB z*  :& 			*8O:& 	* c) 	*sH   0F	F 
F! 
F7 !F43F47G
	G

G H)G==Hc               N  > U R                  5       n  T" U SS9$ ! [         a     Of = f/ =pU/nT" U 5       H  nUS;   a  / nUR                  U5        M  US;   a|  [        U5      S:  a    OUR	                  5       nUS   n[        U5      S:X  a4  [        US   [        [        45      (       a  UR                  US   5        M  UR                  U5        M  UR                  T" U5      5        M     [        U5      S:X  a#  [        US   [        [        45      (       a  US   $ U$ )	NTr   z[{z]}rT  rK  rY   r   )rc  r   r   r   r  r   rM  rz   )r  r  addtor  r.  r  r  rO  s         rv   r(
  matlabstr2py.<locals>.parse/c  s   GGI	&& 		 QADye$dv;?JJLr
q6Q;:adT3K#@#@LL1&LLOU1X&   v;!
6!9tSk B B!9s    
''r  r   %rH  rY   c              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   )r   r  r   s     rv   r   matlabstr2py.<locals>.<genexpr>Wc  s     /;a6;r  z	 ';[]{}<>)r  rz   r6  r	  )r  rz   r6  ztuple[str | None, int])r  rz   r  r   r6  rg   )r  rz   r6  rg   )r  rc  r  r;  )		matlabstrr(
  r  r	  r  r   r  r  rO  s	        @@@@rv   r9   r9   b  s    <&2 ', 'R > yDI-((*D::<D47c>S_::c1%DAq	A/;///8AaD + ru   c                   SnUb  U/UQ7OU H  n [         R                  " X5      s  $    SU < S3n[        U5      e! [         a     M=  f = f)a  Return datetime corresponding to date string using common formats.

Parameters:
    datetime_string:
        String representation of date and time.
    fmt:
        Format of ``datetime_string``.
        By default, several datetime formats commonly found in TIFF files
        are parsed.

Raises:
    ValueError: ``datetime_string`` does not match any known format.

Examples:
    >>> strptime('2022:08:01 22:23:24')
    datetime.datetime(2022, 8, 1, 22, 23, 24)

)r  r7  r#  z%Y-%m-%dT%H:%M:%S.%fz%Y-%m-%dT%H:%M:%Sz%Y:%m:%d %H:%M:%S.%fz%d/%m/%Y %H:%M:%Sz%d/%m/%Y %H:%M:%S.%fz%m/%d/%Y %I:%M:%S %pz%m/%d/%Y %I:%M:%S.%f %pz%Y%m%d %H:%M:%Sz%Y/%m/%d %H:%M:%Sz%Y/%m/%d %H:%M:%S.%fz%Y-%m-%dT%H:%M:%S%zz%Y-%m-%dT%H:%M:%S.%f%zz
time data z does not match any format)rh  rI   r   )datetime_stringr  formatsfmt_r   s        rv   rI   rI   ^c  sk    &G" $'?w?	$$_;; @
 ))C
DC
S/  		s   >
AAc                   g ry   rt   rO  r  r  s      rv   r4  r4  c       ru   c                   g ry   rt   r  s      rv   r4  r4  c  r  ru   c                   U R                  5       R                  5       n Ub  UO[        U [        5      (       a  SOSnUb  UO[        U [        5      (       a  SOSnX;   a  gX;   a  gU < S3n[	        U5      e)zReturn string as bool if possible, else raise TypeError.

Custom ``true`` and ``false`` sequences must contain lowercase strings.

>>> asbool(b' False ')
False
>>> asbool('ON', ['on'], ['off'])
True

s   true)r  s   false)r  TFz" is not a recognized boolean value)rc  r  r   r{   r   )rO  r  r  	true_vals
false_valsr   s         rv   r4  r4  c  s      KKM!E  	#E511gy   	$UE22h
 
 I7
8C
C.ru   c                   Uc  [         [        [        [        4nU H  n U" U 5      s  $    U $ ! [        [
        [        [        4 a     M/  f = f)a  Return argument converted to first matching type.

By default, tries to convert to ``int``, ``float``, ``bool``
(via ``asbool``), and ``str`` (via ``bytes2str``), in that order.

>>> astype('42')
42
>>> astype('3.14')
3.14
>>> astype('True')
True
>>> astype(b'Neee-Wom')
'Neee-Wom'

)r   rY  r4  r  r   r   r   r  )rO  r:  typs      rv   r,   r,   c  s[    ( }eVY/	u:  L 	
 	 	s   .AAc          	        [        U [        [        45      (       a  [        U S   U S   5      nODU S:X  a  g[        U 5      n[	        S[        S[        U5      -  5      5      nUR                  U5      nUR                  UR                  4$ )zReturn rational numerator and denominator from float or two integers.

>>> rational(0.5)
(1, 2)
>>> rational((3, 4))
(3, 4)
>>> rational(0)
(0, 1)

r   rY   r  rU  )
r   r~   rM  rW   r  r   r-  limit_denominator	numeratordenominator)rx  r  max_denominators      rv   rA   rA   c  sy     #t}%%SVSV$!8SMj#j3q6.A*BC0;;%%ru   c             #    #    [        5       n0 nU  Hs  nX1;  a  UR                  U5        Uv   M  UR                  US5      S-   X#'   U X#    3nXA;   a  X#==   S-  ss'   U X#    3nXA;   a  M  UR                  U5        Uv   Mu     g7f)zReturn iterator over unique strings, appending a counter to duplicates.

>>> list(unique_strings(iter(('a', 'b', 'a'))))
['a', 'b', 'a2']
>>> list(unique_strings(iter(('a', 'a2', 'a'))))
['a', 'a2', 'a3']

rY   N)r!  r$  rS  )stringsknownra  r  	candidates        rv   rw  rw  c  s      eEF>IIaLG

1a(1,FI#fi[)I$	Q	 c&)-	 $ IIi O s   A+B	/B	c               ^    X:  a  U S S3$ S H  nU S-  n X:  d  M  U S SU 3s  $    U S S3$ )zReturn file size as string from byte size.

Sizes below 1.5 KiB (1536 B) are shown in bytes; larger sizes are
shown in the largest unit that keeps the value below the threshold.

>>> format_size(1234)
'1234 B'
>>> format_size(12345678901)
'11.50 GiB'

z.0fz B)KiBMiBGiBTiBPiBg      @z.2fr  z PiBrt   )r   	thresholdr  s      rv   r0   r0   d  sU     s233Zq'' 4 3Ztru   c                   U $ )zCSingle argument identity function.

>>> identityfunc('arg')
'arg'

rt   )rx  r  r   s      rv   r  r  (d  s	     Jru   c                     g)z4Null function.

>>> nullfunc('arg', kwarg='kwarg')

Nrt   )r  r   s     rv   r<   r<   2d  s     ru   c               8    SnU  H  nU[        U5      -  nM     U$ )zReturn product of integers.

Equivalent of ``math.prod(iterable)``, but multiplying NumPy integers
does not overflow.

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

rY   r  )iterableprodr  s      rv   r@   r@   ;d  s&     DD	 Kru   c               @   ^ ^ [        T 5      mSUU 4S jjnTU" 5       4$ )a  Return first item and new iterator that includes first item.

The original iterator must not be used after calling this function.

Raises:
    StopIteration: Iterator is empty.

>>> first, it = peek_iterator(iter((0, 1, 2)))
>>> first
0
>>> list(it)
[0, 1, 2]

c               3  .   >#    T v   T S h  vN   g  N7fry   rt   )r   iterators   rv   newiterpeek_iterator.<locals>.newiter^d  s     s   
)r6  r  r  )r5  r6  r   s   ` @rv   rv  rv  Md  s'     NE  ')ru   c               R   ^ [         R                  " S5      mSU4S jjn[        XS9$ )zReturn naturally sorted list of strings.

Use to sort file names containing numbers.

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

z(\d+)c                  > TR                  U 5       Vs/ s H&  nTR                  U5      (       a  [        U5      OUPM(     sn$ s  snf ry   )r  	fullmatchr   )r  r  numberss     rv   sortkeynatural_sorted.<locals>.sortkeypd  sG    ;B==;K
;Kag''**CF1;K
 	
 
s   -Ar
  )r  rz   r6  zlist[int | str])ri  rj  ru  )r1  r=  r<  s     @rv   r;   r;   ed  s%     jj"G

 (((ru   c               @    [         R                  " U S-   US-  -   5      $ )zReturn datetime object from epicsTSSec and epicsTSNsec tag values.

>>> epics_datetime(802117916, 103746502)
datetime.datetime(2015, 6, 2, 11, 31, 56, 103746)

i%g    eA)rh  fromtimestamp)secnsecs     rv   epics_datetimerC  xd  s"     !!#	/D3J">??ru   c               B    [         R                  " U5      [        U S9-   $ )a_  Return datetime from Excel serial timestamp.

Use to convert LSM time stamps.

Parameters:
    timestamp:
        Excel serial date (days since epoch, fractional part is time).
    epoch:
        Ordinal of day 0. Default is 1899-12-30 (standard Excel epoch).

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

)days)rh  fromordinalr~  )rq  epochs     rv   excel_datetimerH  d  s    & &	)BBBru   c          
        U S::  a  SU < S3n[        U5      eU S-   nUS:  a*  [        R                  " US-
  S-  5      nUSU-   US-  -
  -  nUS	-   n[        R                  " US
-
  S-  5      n[        R                  " SU-  5      n[        R                  " XW-
  S-  5      nXW-
  [        SU-  5      -
  n	XS::  a  SOS-
  n
XjS:  a  SOS-
  nUn[	        US5      u  p[	        US5      u  p[	        US5      u  p[        XXXUS-  5      $ )a  Return datetime from days since 1/1/4713 BC and ms since midnight.

Convert Julian dates according to MetaMorph.
Algorithm after Meeus, "Astronomical Algorithms", ch. 7.

>>> julian_datetime(2451576, 54362783)
datetime.datetime(2000, 2, 2, 15, 6, 2, 783000)
>>> julian_datetime(1721423)
Traceback (most recent call last):
    ...
ValueError: no datetime before year 1 (julianday=1721423)

iOD z%no datetime before year 1 (julianday=rz  rY   i# g   @}<Ag    @r  i  gfffff^@g     v@gaTR'>@r  rT  il  ik  i6 i`  r  )r   ro  truncr   r  rh  )	juliandayr  r   r  rQ  r
  r  r  r  r  r  r  r  r  r  r  s                   rv   r  r  d  s"    G6I<q9oAA7{

A
Nh67	QY!##	DA

AI'(A

6A:A

AEW$%A
%#gk"
"C2g2&E	t,D	Bb.)HDI&JFD!JFDFBIFFru   r<  rr   rs   NATIVE_BYTEORDERc                   U S[         R                  1;   a  gSSS.nUR                  X 5      U[         R                     :H  $ )zReturn if byteorder matches the system's native byteorder.

The byte-order characters are '<' (little-endian), '>' (big-endian),
'=' (native), as well as the sys.byteorder strings 'little' and 'big'.

>>> byteorder_isnative('=')
True

rH  Trr   rs   )r<  rJ  )r_  r   rS  )r   r*	  s     rv   r  r  d  s?     S#--((#&D88I)T#---@@@ru   c               V    XS1;   d  US:X  a  gU S:X  a  [         n US:X  a  [         nX:H  $ )as  Return if two NumPy byte-order characters are equivalent.

The byte-order characters are '<' (little-endian), '>' (big-endian),
'=' (native), and '|' (not applicable). '|' matches any order.

>>> byteorder_compare('<', '<')
True
>>> byteorder_compare('>', '<')
False
>>> byteorder_compare('|', '>')
True
>>> byteorder_compare('=', '<')  # on a little-endian system
True

rI  TrH  )rL  )r   r3  s     rv   byteorder_comparerO  d  s9      CL ESLC$	| ru   c                  Ub  UR                  5       R                  SS5      R                  S5      (       aW  [        R                  " SU [        R
                  5      nUb  U S[        UR                  S5      5       n U R                  X5      $ U R                  S5      nUS:  a  U SU n  U R                  Uc  S	U5      $ UU5      $ ! [         a    Ub  e U R                  S
U5      s $ f = f)a  Return Unicode string from encoded bytes up to first NULL character.

Parameters:
    b:
        Bytes to decode.
    encoding:
        Character encoding of ``b``.
        The default is to try UTF-8, falling back to cp1252 on failure.
    errors:
        Error handling for :py:meth:`bytes.decode`.

Raises:
    UnicodeDecodeError:
        Decoding with the specified ``encoding`` failed.

N-r   utf_16s   ^((?:..)*?)\x00\x00rY   r+  r   r  r  )r  r  r  ri  r  rk  r   groupr  r  r  )r
  r
  r  r-  r  s        rv   r  r  d  s    &  0 8 8c B M M! ! II-q"))<=#C
O$Axx))	wAAvbqE*xx8#36JJ6JJ *xx&))*s   ,C C  C+*C+c               ^   0 nU R                   R                   H  nUSS u  p4X   nUR                  S:X  a%  UR                  5       nUS   S:X  a  [	        U5      nODUR                  S:X  a4  UR                  5       nUS   S:X  a  U Vs/ s H  n[	        U5      PM     nnXQU'   M     U$ s  snf )a   Return numpy.recarray as dictionary.

>>> r = numpy.array(
...     [(1.0, 2, 'a'), (3.0, 4, 'bc')],
...     dtype=[('x', '<f4'), ('y', '<i4'), ('s', 'S2')],
... )
>>> recarray2dict(r)
{'x': [1.0, 3.0], 'y': [2, 4], 's': ['a', 'bc']}
>>> recarray2dict(r[1])
{'x': 3.0, 'y': 4, 's': 'bc'}

NrT  r   rY   rS  )r   descrr  r  r  )recarrayr  rU  r   r   rO  r  s          rv   r"  r"  e  s     F%%BQi::?LLNEQx3!%(ZZ1_LLNEQx3/45u!1u5t & M 6s   	B*r|  )sanitizero  r_  c                 ^^^^^^ SSK Jn  U=(       d    Su  mmSUU4S jjmSUUUUU4S jjmT" UR                  U 5      5      $ )a  Return XML as dictionary.

Parameters:
    xml: XML data to convert.
    sanitize: Remove prefix from from etree Element.
    prefix: Prefixes for dictionary keys.
    sep: Sequence separator. Pass empty string to disable sequence parsing.

Examples:
    >>> xml2dict(
    ...     '<?xml version="1.0" ?><root attr="name"><key>1</key></root>'
    ... )
    {'root': {'key': 1, 'attr': 'name'}}
    >>> xml2dict('<level1><level2>3.5322,-3.14</level2></level1>')
    {'level1': {'level2': (3.5322, -3.14)}}

r   rv  )r=  r=  c               n  > [        U [        5      (       d  U $ T(       a]  TU ;   aW  / nU R                  T5       H5  nT" U5      n[        U[        5      (       a  U s  $ UR                  U5        M7     [	        U5      $ [
        [        [        4 H  n U" U 5      s  $    U $ ! [        [        4 a     M%  f = fry   )
r   rz   r  r   r~   r   rY  r4  r   r   )rO  r  r	  r  r.  r,   r_  s        rv   r,   xml2dict.<locals>.astypeOe  s    %%%L3%<F{{3'3Ka%% La 	 (
 = uf%Ax &
  z* s   B  B43B4c          	     H  > U R                   nT(       a  UR                  SS5      S   nUS 0n[        U 5      nU(       a  [        R                  " [        5      n[        TU5       H/  nUR                  5        H  u  pgXF   R                  U5        M     M1     XR                  5        VVs0 s H  u  pgU[        U5      S:X  a  US   OU_M     snn0nU R                  (       aQ  [        X!   [        5      (       d  0 X!'   X!   R                  U	U
4S jU R                  R                  5        5       5        U R                  (       aU  U R                  R                  5       nU(       d  U R                  (       a  U(       a  T	" U5      X!   TS-   '   U$ T	" U5      X!'   U$ s  snnf )N}rY   rK  r   c              3  B   >#    U  H  u  pTU-   T" U5      4v   M     g 7fry   rt   )r   r   r  r,   ats      rv   r   /xml2dict.<locals>.etree2dict.<locals>.<genexpr>se  s"     K:J$!266!9-:Js   rO  )r  rsplitrM  collectionsdefaultdictr8  r`  r   r   r  r   r  r  r  rc  )r.  r   r  childrendddcr   r  r  r,   r^  
etree2dictrW  r  s            rv   rf  xml2dict.<locals>.etree2dictce  s@   ee**S!$R(C $K7((.B*h/HHJDAELLO ' 0 Lq#a&A+!A$14LMA88afd++FMMK!((..:JKK6666<<>D188+1$<AF2<(    Ms   ,#F)rO  rg   r6  rg   )r.  r<  r6  r   )r  rw  r
  )	r  rW  ro  r_  rw  r,   r^  rf  r  s	    ` ` @@@@rv   rO   rO   2e  sB    2 &xFB ( 4 k,,S122ru   K   r  g      ?)rX  r  snipatr  ellipsisc                ^ [        U 5      nUS:  d  US:  d  US:  a  gUS:X  a,  Sn[        XA[        U5      -
  S-  U-  -  U5      nUS:  a  gSn	OgS[        SU-  5      -  n[        XA[        US-  5      -
  S-  U-  -  U5      nUS:  a  gSU-  [        US-  5      -   n[        R                  " Xh-  5      n	Ub  US:X  a  UnO1S
[	        U5      s=:  a  S:  a  O  O[        R
                  " X#-  5      nUS
:  a  X2-  n[        U5      nUS:X  d  U	S:X  a  S
U S	U 4/n
SnSnSU-  nO|U(       a  X::  a  S
U 4/n
OjUS
::  a  XU-
  -  nXUS	 4/n
OUX2:  d  US:  a  X-  nS
U S	U 4/n
O=X-  nXU-
  S-
  -  nXh-  (       a  XU-  -  nOX-  nS
U S	U 4Xm-
  U-
  S	4Xn-
  XU-
  S	 4/n
Uc3  U(       a)  US:  a#  S[        US-  5      US-  S-  -   S-
  -  nUS-  nOSnOUR                  S5      nS
S	Kn/ nU
 H  u  nnUc  UR                  U5        M  UR                  U5      n[        R                  " SSU5      n[        S
[        U5      U5       H  nUSU-  SU-  US-  -    mUS:  a  UUU-   -  OUnUSR                  U4S j[        S
SU-  S5       5       5      -  nUSU[        U5      -
  -  -  nUUUUU-    -  nUR                  U5        M     M     SR                  U5      R                  S5      $ )a  Return hexdump representation of bytes.

Parameters:
    data:
        Bytes to represent as hexdump.
    width:
        Maximum width of hexdump.
    height:
        Maximum number of lines of hexdump.
    snipat:
        Approximate position at which to split long hexdump.
    modulo:
        Number of bytes represented in line of hexdump are modulus
        of this value.
    ellipsis:
        Characters to insert for snipped content of long hexdump.
        The default is '...'.

Examples:
    >>> import binascii
    >>> hexdump(binascii.unhexlify('49492a00080000000e00fe0004000100'))
    '49 49 2a 00 08 00 00 00 0e 00 fe 00 04 00 01 00 II*.............'

rY   rT  r=  ru   r  s   %%0%ix: s   %xr   Nr       s   ...r  s   [^\x20-\x7f]   .c              3  2   >#    U  H  nTXS -    v   M     g7fr=  rt   )r   r2  r+  s     rv   r   hexdump.<locals>.<genexpr>e  s     O1NA1QQ<1Nrr     
r  )r   r  ro  rp  r-  floorr   rg  binasciir   hexlifyri  subr  r   r  )r  rX  r  ri  r  rj  r   addrbytesperlinenlinesrx  r  rg  end1end2elpsrr  r  bstrhexstrstrstrr  rW  r+  s                          @rv   r1   r1   e  s   D t9Dax519
{D	)a/F:;T
 ! S..D1H-!3>?
 !L 3tax=04./~1	
S[	1	FO,z[F {fkd=L)*+L v'd)	10uv,'(		VaZ#d4Cj/"$23<''D DUd[4&[$d{}-.
 L1$3tax=<1+<q+@@1DEDFNDDx(Ft<MM$!!$'($5q#d)\2Aq1uq1u|a'778A(.
U#AOq!l:JA1NOOOAQ((AA,--AMM! 3  ::f$$W--ru   c                   U R                  5       n U (       d  g[        U [        5      (       a  U R                  5       $  U R	                  5       R                  5       $ ! [
         a     gf = f)znReturn if all characters in string are printable.

>>> isprintable('abc')
True
>>> isprintable(b'\01')
False

TF)rc  r   rz   isprintabler  r  )r>  s    rv   r  r  e  s`     \\^F&#!!##}}**,, s   A 
A*)A*compactc              $   [         R                  " SSU 5      n [         R                  " SSU 5      n U R                  SS5      n U(       a8  [         R                  " SSU R                  SS5      R                  SS5      5      n U R                  5       $ )zReturn string with compressed whitespace.

>>> clean_whitespace('  a  \n\n\n  b ')
'a\n b'
>>> clean_whitespace('  a  \n\n  b ', compact=True)
'a b'

z(\r\n|\r|\n)+r  z[ \t]{2,}|\tr  z 
z[ r  )ri  rt  r  rc  )r>  r  s     rv   clean_whitespacer  f  sw     VV$dF3FVVOS&1F^^E4(FS&..s";"C"CD#"N
 <<>ru   c                     SR                  S U  5       5      nUR                  5        Vs/ s H  o"(       d  M  UPM     nnU(       d  gUS   /nUR                  S USS  5       5        SR                  U5      $ s  snf )a3  Return joined string representations of objects with indented lines.

The first line is not indented. Subsequent non-empty lines are indented
by two spaces. Empty lines are dropped.

>>> print(indent('Title:', 'Text'))
Title:
  Text
>>> print(indent('Title:', 'Line1', '', 'Line3'))
Title:
  Line1
  Line3

r  c              3  8   #    U  H  n[        U5      v   M     g 7fry   r  )r   rx  s     rv   r   indent.<locals>.<genexpr>0f  s     .#SXXr  r=  r   c              3  ,   #    U  H
  nS U-   v   M     g7fr 
  rt   r   r	  s     rv   r   r  5f  s     4)$$+)r"
  rY   N)r   r  r  )r  r  r	  r  r  s        rv   r%  r%  !f  st     99...D"oo/8/d4T/E8AhZF
MM4%)4499V 9s
   
A;A;c                  SSK Jn  [        U [        5      (       a  U OU R	                  5       n SSKJn  UR                  [        R                  " U5      5      nUR                  USSUR                  R                  =(       d    SS9n[        U[        5      (       d   e[        U5      nSR%                  S UR'                  5        5       5      $ ! [         aE     U" U5      R                  SS9n NH! [          a    [        U5      R#                  S	S
5      n  Npf = f[          aE     U" U5      R                  SS9n N! [          a    [        U5      R#                  S	S
5      n  Nf = ff = f)zReturn pretty formatted XML.r   )parseStringr  Tr  )r  r  r
  r  )r%  z><z>
<r  c              3     #    U  HL  nUR                  5       (       d  M  UR                  S S5      R                  SS5      R                  5       v   MN     g7f)r  r  	N)rc  r  r  r  s     rv   r   pformat_xml.<locals>.<genexpr>Yf  sF      'D::< 	<T3''c299;;'s
   A7A)xml.dom.minidomr  r   r{   rg  r  r  r(
  r}  r~  r  docinfor
  r  r  toprettyxmlr  r  r   r  )r  r  xmlbr  r  	formattedr  s          rv   pformat_xmlr  9f  sP   +#C//#SZZ\D;{{2::d+,NN \\**5g	 # 
	 )U++++9% 99 %%'    ;	; &22#2>F 	;t_,,T6:F	; ;	; &22#2>F 	;t_,,T6:F	;	;sH   A<C 
E-C33%DE-DE-)E  %E)%E-(E))E-r  r  )r  rX  	linewidthr  c                ^ SSK nUb  US:  a  SnUb  US:  a  SnTb  TS:  a  Um[        R                  " 5       n[        R                  " SUS9   [	        U [
        5      (       ar  U SS R                  5       S	:X  d	  U S
S S:X  a  [        U 5      n OF[        U 5      (       a  [        [        U 5      5      n O![        XUSS9[        R                  " S0 UD6  $ [	        U [        5      (       aJ  U SS R                  5       S:X  d	  U S
S S:X  a  US:X  a  U SSU-   O
[        U 5      n U R                  5       n OO[	        U [        R                  5      (       a  U R                  5       R                  5       n OUR                  XUSS9n [        R                  " S0 UD6  US:X  a  U SX"-   n [        U SS9n U ST $ [!        U R#                  5       5      nUS-  nUS-
  U-
  n	[%        U5      U:  a*  SR'                  U4S j/ USU QSPXy* S Q7 5       5      n U $ SR'                  U4S jUSU  5       5      n U $ ! [        R                  " S0 UD6  f = f)zsReturn pretty formatted representation of object as string.

Whitespace might be altered. Long lines are cut off.

r   NrY   r  r  r  )r-  r  r  r  r  s   OME>)rX  r  r  r  rX  r  F)rX  r  
sort_dictsTr  rT  r  c              3  ,   >#    U  H	  oS T v   M     g 7fry   rt   r   r	  r  s     rv   r   pformat.<locals>.<genexpr>f  s      
)M))Mr  r  c              3  ,   >#    U  H	  oS T v   M     g 7fry   rt   r  s     rv   r   r  f  s     C]TZi(]r  rt   )pprintr   get_printoptionsset_printoptionsr   r{   r  r  r  r  r1   rz   r  r  r
  r?   rM  r  r   r   )
rx  r  rX  r  r  r  npoptarglheadtails
      `      rv   r?   r?   `f  sQ    ~!}	IM	""$E	SE:/(c5!!2Aw}}(*c"#h'.AnS!!&y~6sqIN 	''K c32Aw}}')SX-? +1A+c+AI&;s;K **,CU\\****,%%'C& ..'e ! C 	''{/EM"sD1:I !DQ;DA:D
4y6ii 
)M4;)M)MUV)M
 

 J iiCT'6]CCJ# 	''s   A0H8 B.H8 8I)ri  rj  c                 Uc  SnUc  Sn[        U5      nU R                  5       n/ nU GH:  n[        U5      nX::  a  UR                  U5        M'  US:X  a  Un	O=S[        U5      s=:  a  S:  a  O  O[        R
                  " X-  5      n	O[        U5      n	U	S:  a  X-  n	[        U	S5      n	US:X  d  XS-   :  a2  U	S::  a  UR                  Xq* S 5        M  UR                  USU 5        M  U	S::  a  UR                  X7XA-
  S -   5        M  X:  d  XS-   :  a  UR                  USX-
   U-   5        GM  X-
  U-   n
XS-  -
  nX-   nUR                  USU U-   X|S -   5        GM=     SR                  U5      $ )	u  Return string cut to specified length.

Parameters:
    string:
        String to snip.
    width:
        Maximum length of returned string.
    snipat:
        Approximate position at which to split long strings.
        The default is 0.5.
    ellipsis:
        Characters to insert between splits of long strings.
        The default is '…'.

Examples:
    >>> snipstr('abcdefghijklmnop', 8, ellipsis='...')
    'abc...op'

N      ?u   …rY   r   r  rT  r  )	r   r  r   r-  ro  rq  r   rk  r   )r>  rX  ri  rj  rW  r  r  r	  linelenr  splitlenrx  ry  s                rv   r*  r*  f  s   6 ~ME""$JFd)MM$Q;EV q JJw/0EKE19EqMEA:*zd67m,d6El+aZMM(%-/%::;!2MM$/(:;.Hq=(D?DMM$u+04;>?= @ 99Vru   c               R    U R                   =(       d    [        U R                  5      $ )zXReturn short string representation of Enum member.

>>> enumstr(PHOTOMETRIC.RGB)
'RGB'

)r   rz   rO  )members    rv   r/   r/   g  s     ;;+#fll++ru   c                    U " U5      $ ! [         [        4 aL     XR                  5          s $ ! [        [        4 a#  nU R
                   SU< 3n[        U5      UeSnAff = ff = f)aq  Return enum member from its name or value.

Parameters:
    enumtype: Type of IntEnum.
    arg: Name or value of enum member.

Returns:
    Enum member matching name or value.

Raises:
    ValueError: No enum member matches name or value.

Examples:
    >>> enumarg(PHOTOMETRIC, 2)
    <PHOTOMETRIC.RGB: 2>
    >>> enumarg(PHOTOMETRIC, 'RGB')
    <PHOTOMETRIC.RGB: 2>

z: invalid argument N)r   r   rN  r  r   r  )enumtyperx  r  r   s       rv   r.   r.   g  sr    (+}	" +	+IIK((.) 	+&&'':3'BCS/s*	++s(   
 A&/A&A"AA""A&c                   0 nU H  nX@;   d  M
  U R                  U5      X4'   M     UR                  5        H#  u  pEX@;   a  U R                  U5      X4'   M  XSU'   M%     U$ )a  Extract keys from kwargs into a new dict, removing them from kwargs.

Keys listed in ``keys`` are extracted by name only.
Keys listed in ``keyvalues`` are extracted by name if present
in ``kwargs``, otherwise their default value is used.
Extracted keys are deleted from ``kwargs``.

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

)r  r`  )r   r*	  	keyvaluesr  r   rO  s         rv   r>   r>   +g  s^    & F= **S/FK   oo'
= **S/FK3K	 (
 Mru   c               X    UR                  5        H  u  p#U R                  X#5        M     g)zUpdate 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}

N)r`  rP  )r   r  r   rO  s       rv   rM   rM   Jg  s%      oo'
#% (ru   c                 b    U R                  5        VVs0 s H  u  pUc  M
  X_M     snn$ s  snnf )zkReturn kwargs as dict, excluding items with None values.

>>> kwargs_notnone(one=1, none=None)
{'one': 1}

)r`  )r   r   r  s      rv   r   r   Wg  s*     $\\^=^TQqDAD^===s   	++c                 .    [         R                  " S5      $ )z"Return logger for tifffile module.tifffile)logging	getLoggerrt   ru   rv   r7   r7   ag  s    Z((ru   c                 ^	 SSK nUc  [        SS15      nUc  Sn UR                  XSS/UR                  S9nS
nUR                  5        Hl  nUR                  5       nUR                  U5      (       d  M+  U[        U5      S R                  5       m	[        U	4S jU 5       5      (       a  Mc  [        T	5      e   g! [         a  nS	U< 3n[	        U5      UeSnAff = f)a  Validate TIFF file with ``jhove -m TIFF-hul``.

JHOVE does not support the BigTIFF format, more than 50 IFDs, and
many TIFF extensions.

Parameters:
    filename:
        Name of TIFF file to validate.
    jhove:
        Path of jhove app. The default is 'jhove'.
    ignore:
        Jhove error message to ignore.

Raises:
    ValueError:
        Jhove printed error message and did not contain one of strings
        in ``ignore``.

References:
    - `JHOVE TIFF-hul Module <http://jhove.sourceforge.net/tiff-hul.html>`_

r   NzMore than 50 IFDszPredictor value out of rangejhovez-mzTIFF-hul)stderrzjhove executable not found: s   ErrorMessage: c              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   )r   r  r  s     rv   r   !validate_jhove.<locals>.<genexpr>g  s     26aEz6r  )
subprocessr]  check_outputSTDOUTr^  r  rc  r  r   r  r;  r   )
r  r  r  r  r   r  r   ro  r	  r  s
            @rv   rN   rN   fg  s    8 ~ "@A
 }.%%dJ/$$ & 
 F zz|??6""V'..0E26222 '' !	  .,UI6$#-.s   B< <
CCCc                  Uc  SnUc  SnUb  SOSn[        XS9 nUR                  U   n[        U[        5      (       d  SU S3n[	        U5      eUR
                  R                  U5      nUcP  [        U[        5      (       a)  [        R                  R                  US5      =(       d    UnSU< S	3n[        U5      eUc  UR                  sSSS5        $ UR                  U5         SSS5        g! , (       d  f       g= f)
a  Return or replace ImageDescription value in first page of TIFF file.

Parameters:
    arg:
        Specifies TIFF file to open.
    comment:
        7-bit ASCII string or bytes to replace existing tag value.
        The existing value is zeroed.
    pageindex:
        Index of page which ImageDescription tag value to
        read or replace. The default is 0.
    tagcode:
        Code of tag which value to read or replace.
        The default is 270 (ImageDescription).

Returns:
    ``None``, if ``comment`` is specified. Else, the current value of the
    specified tag in the specified page.

Raises:
    IndexError: If ``pageindex`` is not found.
    ValueError: If the specified tag is not found in the page.

Nr   r  r  )r   rk  z
 not foundzno z
 tag found)r   r  r   r   r4  r  rS  r   r   r  r   rO  r  )	rx  r   r  tagcoder   r   r  r   r  s	            rv   rK   rK   g  s    > 	+D	#	!Syy#$))i[
3CS/!iimmG$;'3''))--6A'{*-CS/!?99 
"	! 	g 
"	!	!s   B2C2C22
D )r   r   r   r   r   r   r   r   	groupnamern  zarr_formatc                 Uc  [         R                  " U 5      S-   n[        U 5       nUR                  UUUUUUU	S9 nUR	                  UUU
UUS9  SSS5        SSS5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)ax  Write fsspec ReferenceFileSystem in JSON format for data in TIFF file.

By default, the first series, including all levels, is exported.

Parameters:
    filename:
        Name of TIFF file to reference.
    url:
        Base URL of the remote TIFF file, without filename.
    out:
        Name of output JSON file.
        The default is ``filename`` with a '.json' extension appended.
    key, series, level, chunkmode, fillvalue, zattrs, squeeze:
        Passed to :py:meth:`TiffFile.aszarr`.
    groupname, version, zarr_format:
        Passed to :py:meth:`ZarrTiffStore.write_fsspec`.

Returns:
    Path of written JSON file.

Nz.json)r   r   r   r   r   r   r   )r  rn  r  )r  r	  r   r   write_fsspec)r  urlr   r   r   r   r   r   r   r   r  rn  r  r   r   s                  rv   rJ   rJ   g  s    L {ii!G+c

 	 	
 # 	 	
	
 	$ J#	
 	
 	$ Js"   A5A$A5$
A2	.A55
B)r   verbosec              v   U(       a  [         O[        nUc  SnUc  U nOUR                  5       S:X  a  SnU(       a  UR                  SS5      nUS-  nU" SSS	S
9  [	        5       n[        U 5       nUR                  (       d  U" SUS	S9  Sn[        U5      eUR                  S   nUR                  n	UR                  n
UR                  n[        U	5      UR                  -  nU" U5        U" [        SSU
 3SU	 3SU 3S[        U5       35      S	S9  U
S:X  a  SS/U	Q7n	O^U
S:X  a  S/U	Q7n	OQU
S:X  a  / U	SS QSPSPU	SS Q7n	O9U
S:X  a  / U	SS QSPU	SS Q7n	O#U
R!                  S5      (       d  Sn[        U5      eU" SSS	S
9  UR#                  5         U	S   US   -  U	S   US   -  4nU(       a  XS   U	S    US   US   4-  nS!S"[%        U	5      -
  -  U	-   n	[&        R(                  " U	S#S US$9n[&        R(                  " U	S   U	S    US   US   4US$9n[+        U5      n[-        U	S   5       H  n[-        U	S   5       H  n[-        U	S   5       H  n[-        U	S#   5       H&  n[/        U5      nUc   eUR1                  5       UU'   M(     [-        US   5       Hm  n[-        US   5       HX  nUS%UUS   -  US-   US   -  2UUS   -  US-   US   -  24   USS& U(       a  UR3                  UUUUUU4-  5        U" S&SS	S
9  MZ     Mo     M     M     M     U" US	S9  SSS5        g! , (       d  f       g= f)'a  Convert [MP]TZCYX LSM file to series of BIN files.

One BIN file containing 'ZCYX' data is created for each position, time,
and tile. The position, time, and tile indices are encoded at the end
of the filenames.

Parameters:
    lsmfile:
        Name of LSM file to convert.
    binfile:
        Common name of output BIN files.
        The default is the name of the LSM file.
    tile:
        Y and X dimension sizes of BIN files.
        The default is (256, 256).
    verbose:
        Print status of conversion.

N)r  r  r   r  z%%%%z*_(z%ic%iy%ix%i)_m%%ip%%it%%03iy%%ix%%i.binz
Opening LSM file... r=  Tri  r  )r  znot a LSM filer   r  zaxes:  zshape: zdtype: zsize:  r  rY   r  MPCYXrT  MPZCYXr  znot a *TZCYX LSM filez#Copying image from LSM to BIN filesry  rK  r  r  r  r  r   rz  .r}  )rl  r<   r  r  r)   r   rg  r   r   r   r  r   r@   r   r%  r0   rZ  r  r   r   rB  r  r  r  r   r
  )lsmfilebinfiler   r  printstimerr  r   r   r   r  r   r   r  r  r   r  r-  r  r.  rQ  r  r  r  s                           rv   r8   r8   h  s   6 ,3%F|	F	"//#v.??
#48GE	'	czz4D)"CS/!A{{u~.u$ %!%!+d+,- 		
 5=NENEV^KKEW_2eBQi22A2ab	2EX/eBQi//U12Y/Ew'')CS/!4"DIb	T"X%uRyDH'<<rE"ItAwQ HHGCJ'%/{{59E2kk2Yb	47DG4E
 VuQxA58_uQxA"58_#E{#///"&,,.Q - #58_!&uQxA%) # !DGq1uQ.? ? !DGq1uQ.? ?!A&CF
  ' #

7aAq!_+D E"3Bd; "1 - ) % !" 	uD!A 
		s   0J1L**
L8`   )r   r   r   rZ  interpolationr  vminvmaxfiguresubplotr  window_titledpimaxdim
backgroundshowc              f  ^ ^	^$^%^&^'^(^) Uc  SnUc  SnUS;   nT R                   S:X  a  T R                  [        R                  5      m T R                   R                  S:X  a  SnU(       a:  T R
                  S   S	;   d'  T R                  S
:  a  T R
                  S   S	;   d  SnSnT R                  5       m US;   a  [        T S
5      m O[        T S5      m T R                  m&T&S
:  a  Sn[        U5      eT&S
:X  a  Sm&SnGOU(       aW  T R
                  S   S	;   aD  T R
                  S   S	;  a1  [        R                  " T SS5      m [        R                  " T SS5      m O}U(       dv  T R
                  S   T R
                  S   S-  :  aS  T R
                  S   T R
                  S   S-  :  a0  [        R                  " T SS5      m [        R                  " T SS5      m U=(       a    T R
                  S   S	;   nT&U(       a  SOS
-  m&Uc  SnO[        U[        5      (       a  UnOSnU(       aB  T SSU2SU2SU24   m U(       a+  T R
                  S   U:  d  T R
                  S   U:  a  SnOASnO>T SSU2SU24   m U(       a+  T R
                  S   U:  d  T R
                  S   U:  a  SnOSnUS:X  a;  U(       a4   [        R                  " T 5      nUS:  a  T S-	  m T R                  SSS9m GOT R                   R                  S;   a  U(       a  T R                   R                  S::  a  Uc:   [        R                   " [        R"                  " T R                  5       5      5      nO>[        U[        [        R&                  45      (       d  T R                   R                  S-  nUc   eS
U-  nU(       a-  US:  a	  T SU-
  -  m OUS:  a  T US-
  -	  m T R                  SSS9m GO	T R                   R                  S:X  a  U(       a&  T R)                  5       m [        R*                  T T U:H  '    [        R,                  " T 5      nU(       a<  US:  a6  T R                   R.                  S:X  a  T R                  S5      m T U-  m OmT U-  m OgT R                   R                  S:X  a  SnOJT R                   R                  S :X  a.  [        R0                  " T 5      m  [        R,                  " T 5      nOSnU(       a  SnGOUc  UnUGc  T R                   R                  S!:X  ad  [        R2                  " T R                   5      R4                  n [        R4                  " T 5      nUU:X  a  [        R4                  " T T U:     5      nOT R                   R                  S:X  am  [7        [        R8                  " T R                   5      R4                  5      n [        R:                  " T 5      nUU:X  a  [        R:                  " T T U:     5      nOSnSS#KJn  SS$K J!n  T	c  URE                  S%S&S'SS(9  URG                  US)S*S+S,S-9m	UbR  [H        RJ                  " [L        5         T	RN                  RP                  RR                  RU                  U5        SSS5        U(       a  [W        URY                  5       5      OSn[[        U 4S. j[]        T&5       5       5      nUR_                  S/US
-   -  S0US/-  -
  S1S2S3S"S49  U
c  S5n
URa                  U
5      n
Uc  S6nU
Rc                  U5        U(       a6  [        U[d        5      (       a  URg                  S75      nURU                  US8S99  UcM  T R                   R.                  S::X  a  S;nO%T R                   R                  S<;   d  US:X  a  S=nOS>nUS?:X  a  US@-  nURh                  " [        Rj                  " T SAT&-     R                  5       5      4UUUUSB.UD6m'U(       d  URm                  5         SQU$U%U U&4SC jjnSRSD jnUU
l7        UT'l8        UT'l9        T&(       GaA  [u        SAT&-  5      m%ST [w        T%5         R                  5       /m$[]        T&5       Vs/ s H  nT R
                  U   S:  d  M  UPM     nn[y        U5       V Vs/ s HN  u  n nU" UR{                  SES/U S-   -  SFSG45      SHU 3ST R
                  U   S-
  SSIT R
                  U    SJ3SK9PMP     n!n nU! H
  n"SU"l>        M     U!UT 4U$U	U'4SL jjm)T T%4U$U)4SM jjm(T T%4U$U(4SN jjn#T	RN                  R                  SOU#5        [y        U5       H!  u  n nU!U    R                  U4U(4SP jj5        M#     U(       a  UR                  5         T	U
T'4$ ! [         a    Sn GNf = f! [        [$        4 a    T R                   R                  S-  n GN&f = f! [         a    Sn GNf = f! [         a    Sn GNf = f! [         a    Sn GNf = f! [         a    S"n GN3f = f! , (       d  f       GN= fs  snf s  snn f )Sa`  Plot n-dimensional images with ``matplotlib.pyplot``.

Parameters:
    data:
        Image array to display.
    photometric:
        Color space of image.
    planarconfig:
        How components of each pixel are stored.
    bitspersample:
        Number of bits per channel in integer RGB images.
    interpolation:
       Image interpolation method used in ``matplotlib.imshow``.
       The default is 'bilinear' for image dimensions > 512,
       else 'nearest'.
    cmap:
        Colormap mapping non-RGBA scalar data to colors.
        See ``matplotlib.colors.Colormap``.
    vmin:
        Minimum of data range covered by colormap.
        By default, the complete range of the data is covered.
    vmax:
        Maximum of data range covered by colormap.
        By default, the complete range of the data is covered.
    figure:
        Matplotlib figure to use for plotting.
        See ``matplotlib.figure.Figure``.
    subplot:
        A ``matplotlib.pyplot.subplot`` axis.
    title:
        Subplot title.
    window_title:
        Window title.
    dpi:
        Resolution of figure.
    maxdim:
        Maximum image width and length.
    background:
        Background color.
    show:
        Display figure.
    **kwargs:
        Additional arguments passed to :py:func:`matplotlib.pyplot.imshow`.

Returns:
    Matplotlib figure, subplot, and plot axis.

NrH  r  >   rH  rI  float16r
  FrK  r  rT  r  rF  >	   r]  rh  r^  ri  rJ  rk  rF  rG  rl  r   znot an imager   ry  rP  r	  .bilinearnearestrJ  rY   r  r  r  uir  r  r  r  r  rj  pyplot)Sliderfontz
sans-serifnormal)familyweightr   )g$@g333333@Tz1.0rG  )r  figsizeframeon	facecolor	edgecolorc              3  R   >#    U  H  nTR                   U   S :  d  M  S v   M     g7fr  r  )r   r  r  s     rv   r   imshow.<locals>.<genexpr>li  s#     I[TDJJt4Dq4Hqq[s   '	'gQ?g\(\?r	  gffffff?r	  )bottomtopleftrighthspacewspaceo   )禛 r?r  r  zWindows-1252r>  r  r   graybufviridiscoolwarmrG  r  r  )r  r  r  r  c                  > [        U S-   5      n [        US-   5      n T(       a  TS   X4    ST SUS SU S S3$ TX4    SUS SU S S3$ ! [         a     g	f = f)
Nr  rY   z @ z [4r   r	  z @ [r=  )r   r4  )r  r  curaxdatcurrentr  r  s     rv   format_coordimshow.<locals>.format_coordi  s    CLCL	"1+ad+,Cy1Q%r!AaHH14j\aU"QqE33 		s   A A 
AAc                    g)Nr=  rt   )r(  s    rv   	_nocursorimshow.<locals>._nocursori  s    ru   g      ?g333333?g?z
Dimension z%.0f [r	  )r  r  valminvalmaxvalinitvalfmtc                  > U[        U 5         R                  5       TS'   TR                  TS   5        [        XSS9 H&  u  pESUl        UR                  X   5        SUl        M(     TR                  R                  5         g )NrY   Tr4  F)r~   r   set_datar  eventsonset_valcanvasdraw)	r  slidersslider_axesr  ctrlr  r  r  r  s	         rv   	set_imageimshow.<locals>.set_imagei  sr     uW~.668HQKNN8A;'!'tD
 %W]+ $ E MM ru   c                   > [        U 5      n UTS'   XU   :X  a  g XR                  U   :  a  Sn OU S:  a  UR                  U   S-
  n XU'   T" U5        g )Nr   rY   )r  r   )r  r  r  r  r  r  s       rv   
on_changedimshow.<locals>.on_changedi  s_    %LEHQK%

4((

4(1,!DMgru   c                  > U R                   nTS   n[        U5      S;   a	  T" X45        g US:X  a  T" X$   S-   U5        g US:X  a  T" X$   S-
  U5        g US:X  a'  U[        UR                  5      S-
  :X  a  SOUS-   TS'   g US:X  a'  US:X  a  [        UR                  5      S-
  OUS-
  TS'   g US:X  a  T" UR                  U   S-
  U5        g US	:X  a
  T" SU5        g g )
Nr   rD  r  rY   r  updownrg  home)r   rz   r   r   )r(  r  r  r   r  r  r  s        rv   on_keypressedimshow.<locals>.on_keypressedi  s    ))CA;D3x<'3%7=1,d37=1,d3#'3tzz?Q+>#>aD1H59QYc$**o1D1H4::d+a/61d# ru   key_press_eventc                   > T" X5      $ ry   rt   )r   r  r  s     rv   r  imshow.<locals>.<lambda>i  s
    Jq4Dru   )r  rY  r  rY  r6  rz   )r(  rg   r6  rz   )Br   r,   r   r  r   r   r  r   rH   r   r  r   r   rk  r   ro  rp  log2r5  r  rd  r<  nanmaxr  absoluteiinfor  rY  finfonanmin
matplotlibr  matplotlib.widgetsr  rcr  r  r  r  r  managerwindowr  r   r  r  r  subplots_adjustr  set_facecolorr{   r  r5   
atleast_2dcolorbarr  get_cursor_dataformat_cursor_datarM  r~   r  r  drawonmpl_connectr  r  )*r  r   r   r   rZ  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r   r-  datamaximinfminr  r  r   nslidersr  r  r  r  r  r  sliderr  r  r  r  r  r  r  s*   `        `                          @@@@@@rv   r5   r5   |h  sX	   P ~++EzzY{{5==)zz#

2& IIMdjjn6"<<>D 
 
 $"$"99DaxoqyTZZ^v-$**R.2N>>$B/D>>$B/DJJrNTZZ^q00

2B1!44>>$B/D>>$B/D2$**R.F2U!		M3	'	'!		C&'6'7F723zz"~	)TZZ^i-G * )C&'6')*zz"~	)TZZ^i-G * )iE	iioG S=19D{{3U{+	D	 $**--2}7L8 $		$))DHHJ*? @ MC+?@@ JJ//!3M(((]"q M 12" 12;;s;/D	C	99;D#(99D 	ll4(G Ws]zz#%{{3'g~	C		C	~~d#	ll4(G <D<zz#%{{4::.22 99T?D 4< 99T$+%67DC'U[[4889 <<-D 4< <<TD[(9:D!)~		&hQ	G  
 #$$Y/%%,,22<@ 0*/s5##%&QIU4[II8a<(td{" 	 	
 nnW%G*
*%eU##LL0EU$|::??c!DZZ__%DD,&DLDMMdTk*2245# E 	 	 (G%E(Etd{#tE'N+3356(-dLtzz$7G!7KtL %[1

 24 ;;tq1u~ueDE"4&)zz$'!+

4 013 2 	 

 F!FM  %+D
	! 
	! *.w 	 	 '+G 	$ 	$& 	!!"3]C -GAtAJ!!d"DE . 7E!!u  	G	 . 8 $

 3 3a 78&  	G	  	G	 " D " D( 0/F M

s   7f )8f (g
 g g0 	h 0h#h(>h(Ah-ff)gg
ggg-,g-0h ?h hh
h%c                     SSK JnJn  U" 5       nUR                  5         UR	                  5          UR
                  " S0 U D6nUR                  5         U$ ! UR                  5         f = f)zEReturn file name from Tkinter's file open dialog, or '' if cancelled.r   )Tk
filedialogrt   )tkinterr/  r0  withdrawr  r+   destroy)r   r/  r0  ry  rp  s        rv   r+   r+   i  sR    &4DMMOKKM..88	 	s   A A'c                .  ^ SSK nScS jnSdS jn[        R                  " 5         UR                  SSS9nUR	                  SS	S
[
         3S9  UR                  nU" SS[        SSS9  U" SS[        SSS9  U" SS[        SSS9  U" SSSS9  U" S[        SSS9  U" SSS S!9  U" S"[        S#S$S9  U" S%[        S&S'9  U" S([        S)S'9  U" S*S+S,9  U" S-[        S.S'9  U" S/SS0S9  U" S1[        S2S3S9  U" S4S5SS6S9  U" S7S8S9S:9  UR                  U c  SOU S;S 5      nUR                  =(       d    S<mT(       d0  [        S=[        R                  S>9mT(       d  UR                  S?5        [        U4S@ jSA 5       5      (       a:  [        R                  " TSBSC9nU(       d  [!        SD["        R$                  SE9  g;US   mUR&                  (       d  [!        SFSGSBSH9  [)        5       n [+        TUR,                  (       + SI9n	UR&                  (       d  [!        U5        U	   / nUR6                  S:  Ga  UR&                  (       d  [!        SLSMSBSH9  UR9                  5          UR:                  S:  aA  U	R=                  UR:                  UR>                  SN9U	R@                  UR:                     S4/nGO+URB                  S:  a  U" U	RB                  URB                     URD                  5      nU	R=                  URB                  UUR>                  SO9U" U	RB                  URB                     RF                  5      U	RB                  URB                     4/nO[I        U	RB                  SUR6                   5       Hb  u  pU" XRD                  5      n URK                  U	R=                  UUUR>                  SO9U" URF                  5      U	RB                  U   45        Md      UR&                  (       d  [!        U5        UR&                  (       d{  [!        SUSVSBSH9  UR9                  5          [L        RN                  " 5       S   nU	RS                  URT                  US;-
  SX9n[!        U5        [!        5         [!        U5        [!        5         U(       Ga   SSYK+J,n  U GH  u  nnnUc  M  URZ                  nUR\                  UR^                  nnUR`                  (       ay   URb                  Rd                  SZ:X  a7  [f        Rh                  UUUR`                  :H  '   [f        Rj                  " U5      nO'[f        Rl                  " UUUR`                  :     5      n U	Rp                  (       a=   U	Rr                  S[   nU	Rr                  S\   nUU::  a  UR\                  UR^                  nnU(       a&  U	 SJU SJU 3nU	Rv                   S]URx                   3nO"U	 SJU 3nU	Rv                   S^URx                   3nS_nURz                  [|        R~                  :w  a  [}        URz                  5      R                  n[        UUUUUUR                  UR                  UR`                  UUR                  UR                  S`Sa9  GM     UR                  5         SSS5        g! [.         aN  n
UR0                  (       a  e [!        SJU
R2                  R4                   SKU
 3["        R$                  SE9   Sn
A
g;Sn
A
ff = f! [.         aU  n
URK                  SU" UR@                  5      S45        UR0                  (       a  e [!        SPU SQU
<SR SS3S<ST9   Sn
A
GM  Sn
A
ff = f! [.         aN  n
UR0                  (       a  e [!        U
R2                  R4                   SKU
 3["        R$                  SE9   Sn
A
GNSn
A
ff = f! [P         a    SWn GNzf = f! [n         a     GNxf = f! [t         a     GN;f = f! [         a&  n
[!        SbU
 3["        R$                  SE9   Sn
A
GNSn
A
ff = f! , (       d  f       g= f)ez*Tifffile command line usage main function.r   Nc                   US:  a  U$ U R                   (       d  g[        U R                  5       H"  u  p#[        UR                  5      S:  d  M   Us  $    g)z6Return first pyramid level fitting under 2**31 pixels.r   r  )r	  r  r  r@   r   )r  	requestedlvlrW  s       rv   _best_levelmain.<locals>._best_levelj  sI    >~~)FCqww%'
 * ru   c               &    [        S U  5       5      $ )z)Return first non-None item from iterable.c              3  .   #    U  H  oc  M  Uv   M     g 7fry   rt   r  s     rv   r   (main.<locals>.notnone.<locals>.<genexpr>j  s     2q!AAqr  r8  r  s    rv   notnonemain.<locals>.notnonej  s    2q222ru   z(Display image and metadata in TIFF file.r  )r   progz	--versionrn  z	%(prog)s )actionrn  z-pz--pagerK  zdisplay single page)rw  r  helpz-sz--serieszdisplay select seriesz-lz--levelzdisplay pyramid level of seriesz--no-multifile
store_truez*do not read OME series from multiple files)r@  rA  z
--maxplotsr  zmaximum number of plot windowsz--interpolationMETHODzimage interpolation method)metavarrA  z--dpir  zplot resolutionz--vminzminimum value for colormapping)rw  rA  z--vmaxzmaximum value for colormappingz--cmapz(colormap name used to map data to colors)rA  z--maxworkersz)maximum number of threads (default: auto)z--debugzraise exception on failuresz--detailrT  z#detail level of report (default: 2)z-qz--quietzsuppress outputrE  r   z)path or glob pattern of TIFF file to open)nargsrA  rY   r=  zSelect a TIFF file)r  	filetypeszNo file specifiedc              3  ,   >#    U  H	  oT;   v   M     g 7fry   rt   )r   r  rE  s     rv   r   main.<locals>.<genexpr>mj  s     
#d9dr  z?*T)	recursivezNo files match the pattern)r   z
Reading TIFF header:r  ri  )r   r  rD  zReading image data:r  )r   r   )r   r   r   z
Series r  r_  z... rq  zGenerating report:z   P   r  r  r  r  r  z series z page rF  F)r  r  r  r  r  r   rZ  r   r  r  r  zImportError: )r  rg   r6  r   r6  r   )r  rg   r6  rg   )Hargparser  basicConfigArgumentParseradd_argumentr*   r   rY  
parse_argsrE  r+   r   r]  r  r;  r   rl  r_  r  quietr)   r   no_multifiler  r$  r  r  maxplotsr  r  r   r   r  r   r   r	  r  r   r  get_terminal_sizer]  r  r  r  r  r  r  r  rZ  r   r   r   r<  r  r  r   r:  r  r  r  r  r   r   rJ  r   r5   r  r   r  r  r  r  )argvrK  r8  r=  r  optrn  	path_listr  r   r  re  r   r  r  rX  r  r  imgr  r   r  r  r  r  r  r   rE  s                              @rv   mainrX  i  s   	3 $$> % F I;-/H   

C" $ . 9
 -	 )
 c2,=>-
 -
 7 8
 *
 2	 i3DEc KL  48DH#D&$2F2F
 LL,-

#d
###IIdd3	.SZZ@|>>&Ct<GEtH,A,A(AB >>e	-/q >>+TBKKM5K==A%  KK$,MM+3+>+> (   IIhmm4 	F __)'

8??3X^^E
  KK'/&++3+>+> ( 
 $CJJx$?$F$FGJJx7
F !*#**5Hx7H7H*I J +A~~ >"MM$'KK/0.33;3F3F %0 %&
 %,AHH$5$'JJqM!"
 !K6 >>e~~&E>KKM,,.q1 888??%!)8DD%LG$KG3- *0%Cv{ #}}H!)$D!"yy~~4>CiiC8??$: ;',||C'8',yyS8??5J1K'L zzJ#&#3#3J#?D#&#3#3J#?D  $t|-5]]HMMd#&%r$r& :*-,,x~'N#&%r$ 0*-,,vdjj\'J".K++{/B/BB&1(2F2F&G&L&L#%1!!%]]&.&<&<'$/&.&<&<$LL"A *0\ E 
H [  >>3==))*"SE2D	t  ) "MM41A4*HI'~~ %!"+A3hslTl$ G$& 	  K>>//03%8szzJJK  4  * ! !  ( ! !+  >cU+#**==>c 
H s>  Z A `A]%`'B!]`	9]A
[!]A	`^3A`_	A`A^1`&^1`_6D`
[A[[!
] +A	\;4];]  ]
^A^`^`^.*`-^..`1
^?;`>^??`
_`_`
`_>8`>``
`)rN
  	ZarrStorer  __main__ry   )Jr   Ystr | os.PathLike[Any] | FileHandle | IO[bytes] | Sequence[str | os.PathLike[Any]] | Noner   
Any | Noner   zLiteral['xarray']r   r  r   r3  r   rQ  r   r3  r   r%  r   r3  r   r3  r   r  r   rQ  r   r3  r   r3  r   rQ  r   r2  r    dict[str, dict[str, int]] | Noner4   "Callable[..., NDArray[Any]] | Noner   r*  r   rn
  r   rm
  r   r/  r   r3  r   ro
  r   r3  r   CHUNKMODE | int | str | Noner   r  r   r*  r   r%  r   rQ  r   r3  r   rw   r   r%  r   r%  r   r%  r   rg   r6  rn   )Jr   r[  r   r\  r   zLiteral['zarr']r   r  r   r3  r   rQ  r   r3  r   r%  r   r3  r   r3  r   r  r   rQ  r   r3  r   r3  r   rQ  r   r2  r   r]  r4   r^  r   r*  r   rn
  r   rm
  r   r/  r   r3  r   ro
  r   r3  r   r_  r   r  r   r*  r   r%  r   rQ  r   r3  r   rw   r   r%  r   r%  r   r%  r   rg   r6  z%ZarrTiffStore | ZarrFileSequenceStore)Jr   r[  r   r\  r   zLiteral['numpy'] | Noner   r  r   r3  r   rQ  r   r3  r   r%  r   r3  r   r3  r   r  r   rQ  r   r3  r   r3  r   rQ  r   r2  r   r]  r4   r^  r   r*  r   rn
  r   rm
  r   r/  r   r3  r   ro
  r   r3  r   r_  r   r  r   r*  r   r%  r   rQ  r   r3  r   rw   r   r%  r   r%  r   r%  r   rg   r6  r  )Lr   r[  r   r\  r   z)Literal['numpy', 'xarray', 'zarr'] | Noner   r   r   r  r   r3  r   rQ  r   r3  r   r%  r   r3  r   r3  r   r  r   rQ  r   r3  r   r3  r   rQ  r   r2  r   r]  r4   r^  r   r*  r   rn
  r   rm
  r   r/  r   r3  r   ro
  r   r3  r   r_  r   r  r   r*  r   r%  r   rQ  r   r3  r   rw   r   r%  r   r%  r   r%  r   rg   r6  z@NDArray[Any] | ZarrTiffStore | ZarrFileSequenceStore | DataArray)Rr  r1  r   r-  r   r.  r   r%  r   r/  r   r0  r   r   r   r%  r   r%  r   r   r   r2  r   r3  r   r4  r   r5  r   r6  r   r   r   r2  r   r3  r   r3  r   zCOMPRESSION | int | str | Noner   r*  r   r7  r   r8  r   r9  r   r9  r   r:  r   r;  rU   r<  r   r=  r   r>  r   r?  r   r@  r   r*  r   rA  r   r   r   r   r   r3  r   r3  r   r3  r   r   r6  r8  )r  str | os.PathLike[Any]r   r2  r   r3  r  r3  r   r3  r   rQ  r   r3  r   r%  r   zLiteral['r+', 'r', 'c']r   rg   r6  znumpy.memmap[Any, Any])r   r   r6  rF  )r   ro   rD  r   r	  r%   rl  r   r  r3  r  zGdict[int, Callable[[FileHandle, ByteOrder, int, int, int], Any]] | Noner6  list[dict[str, Any]])rl  r   r   ro   r   r   r  r   rD  r   r6  r   )rl  r   r   ro   r   r   r  r   rD  r   r6  r{   )rl  r   r   ro   r   r   r  r   rD  r   r6  rz   )rl  r   r   ro   r   r   r  r   rD  r   r6  r  )rl  r   r   ro   r   r   r  r   rD  r   r6  rg   r  )rh  r   rl  r   r   ro   r   r   r  r   rD  r   r6  r   )rl  r   r   ro   r   r   r  r   rD  r   r6  r  )
rl  r   rM  r   rh  r   r   r   r6  ztuple[str, Any])rl  r   r6  r   )rl  r   r6  r  )rl  r   r6  zlist[tuple[float, int, str]])rl  r   r6  z*tuple[dict[str, Any], dict[str, Any], int])r*	  Container[str] | Nonerl  FileHandle | IO[bytes]r6  r   )r   r`  r6  zRIterator[tuple[dict[str, int | str], str, int, int, int, int, int, int, int, int]])rl  rc  r6  zdict[str, str] | None)rl  rc  r6  r   )r   r   r   ro   r6  zKtuple[tuple[int, int, int, bytes, bool], tuple[int, int, int, bytes, bool]])r  r{   r  rE  r   ro   r6  r   )r   rz   r6  r   )r  rQ  r   rE  r  r%  r  r   r   rg   r6  rz   )r   rE  r  r%  r  rQ  r6  rM  )
r   r   r   r   r   rM  r?  r   r6  z#tuple[int | None, int | str | None])r  r{   r6  r   )r  r{   r6  ztuple[int, int, bytes])r   rE  r   rg   r6  rz   )r  rb  r   rz   r6  r   )r   rz   r6  ra  )r   rz   r6  rg   )r@  rz   r6  r*  )rN  rz   r6  r   )r  )r_  rz   r   rz   r6  r   )r   rz   rl  r   r6  r   )rs  rz   r6  r   r  )
r   r3  r   r/  r  r{   rt  r   r6  r  )r  r  r   r  r  r   r6  r  r	  )r   rQ  r   r2  r   r]  r   Sequence[str]r  r2  r6  zMtuple[tuple[str, ...], tuple[int, ...], list[tuple[int, ...]], Sequence[str]])r  r  r6  Iterator[NDArray[Any]])
r  r  r   rM  r   r	  r   r   r6  re  )r  r  r   rM  r  rM  r6  re  )r  r   r  r  rg  zCallable[[NDArray[Any]], bytes]r   rE  r   r	  r   r3  r   r3  rK
  r   r6  r7  )r  r  r  zORIENTATION | int | strr6  r  )r  rj   r  rE  r6  r  )r  rM  r  r   r6  rM  )r  r  r  r   r6  r  )r  tuple[int, ...] | NDArray[Any]r  r   r6  rf  )r  rQ  r   rE  r  rz   r6  z-tuple[tuple[int, ...], str, tuple[bool, ...]])r  Sequence[str] | Noner   rE  r  rd  r6  z7tuple[tuple[int, ...], Sequence[str], tuple[bool, ...]])r  r
  r   rE  r  str | Sequence[str]r6  z=tuple[tuple[int, ...], str | Sequence[str], tuple[bool, ...]])r  rQ  r  r  r  rz   r6  r  )
r  rQ  r  rz   r   rE  r  rE  r6  rz   )
r  rQ  r  rd  r   rE  r  rE  r6  rd  )
r  rQ  r  rh  r   rE  r  rE  r6  rh  )r  rj   r   r   r6  rM  )r|  rE  r  rE  r6  r   r  )
r  r   r  r   r  r   r
  r   r6  r3  )
r  r   r  r   r  r   r
  r   r6  r3  )
r  r   r  r   r  TiffPage | TiffPageSeriesr
  ri  r6  r3  )r   r  rA  r   r  r2  r6  r   )r  r 
  rK
  zTiledSequence | Noner*  r  r   r3  r   rw   r   rg   r6  r  )r   rE  r   r3  r   rw   r   zLiteral['r+', 'w+', 'r', 'c']r  rQ  r   r  r6  z%NDArray[Any] | numpy.memmap[Any, Any])r  rz   r6  rg   )r  rz   r  rQ  r6  rh  )r  rg  r  rg  rO  rz   r6  r   )r  Sequence[bytes] | Noner  rj  rO  r{   r6  r   )r  Sequence[str | bytes] | Noner  rk  rO  str | bytesr6  r   )r:  z#Sequence[Callable[..., Any]] | NonerO  rg   r6  rg   )rx  zfloat | tuple[int, int]r6  r:  )r$  Iterable[str]r6  rp
  )i   )r-  rY  r   rY  r6  rz   )rx  rg   r  rg   r   rg   r6  rg   )r  rg   r   rg   r6  r   )r1  zIterable[int | numpy.integer]r6  r   )r5  r  r6  ztuple[Any, Iterator[Any]])r1  rm  r6  r	  )rA  r   rB  r   r6  rh  )iZ
 )rq  rY  rG  r   r6  rh  )rK  r   r  r   r6  rh  )r   rz   r6  r   )r   rz   r3  rz   r6  r   )Nr5  )r
  rQ  r  rz   r
  r{   r6  rz   )rV  r  r6  r   )
r  rz   rW  r   ro  ztuple[str, str] | Noner_  rz   r6  r   )r  r{   rX  r   r  r   ri  r  r  r   rj  rQ  r6  rz   )r>  rl  r6  r   )r>  rz   r  r   r6  rz   )r  rg   r6  rz   )r  rl  r6  rz   )rx  rg   r  r3  rX  r3  r  r3  r  r   r6  rz   )r  )
rX  r   r>  rz   ri  r  rj  rQ  r6  rz   )r  z	enum.Enumr6  rz   )r  r  rx  rg   r6  zenum.IntEnum)r   r   r*	  rz   r  rg   r6  r   )r   r   r  rg   r6  r   )r   rg   r6  r   )r6  zlogging.Logger)r  rQ  r  zCollection[str] | Noner  rz   r6  r   )
r   r;  r  r3  r  zint | str | Nonerx  r-  r6  r;  )r  rz   r  r`  r   rQ  r   r3  r   r3  r   r3  r   r_  r   r  r   r*  r   r%  r  rQ  rn  r3  r  r3  r6  rz   )
r  rQ  r  rz   r   r8  r  r   r6  r   )&r  r  r   r4  r   r5  r   r3  rZ  rY  r  rQ  r  rg   r  r  r  r  r  rg   r  rg   r  r;  r  rQ  r  r   r  r3  r  z'tuple[float, float, float] | str | Noner  r   r   rg   r6  ztuple[Any, Any, Any])r   rg   r6  rz   )rT  r   r6  r   (  r  
__future__r   r*   __all__ra  r  r9  r   r}  r  r  r  ro  r  ri  re  r_  r  rm  rh  collections.abcrP   rQ   rR   rS   concurrent.futuresrT   rU   rh  rV   r~  	fractionsrW   	functoolsrX   r   r(  r  r=  r[   typingr\   r]   r^   r_   r`   ra   rb   rc   rd   re   r:  rf   rg   rh   ri   numpy.typingrj   rk   rl   r   rn   ro   rw   r|   r   r   rL  r4   r6   r:   r   r   r'   r   r   r   r   r    r$   r&   r%   r   r#   rz   r   r"   r(   r   r   r   r   r   r)   r  r   r   rJ  r  r  r:  r   r   r   r   IntFlagr   r
   r	   r   r   r   r   r   r   r   r   r*  r   r  r
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rW  rX  rY  rI  r  r  rH  rT  rN  rO  r  rJ  rK  rL  r)  r  rP  r  r  r  r  r  r  r  r  rV  rU  rR  rQ  rM  rS  rE   rC   rD   rB   r  r3   r  r  r2   rT  r%  r  r  rf  rf  r!  r  r  r0  r  r>  rA  r  r  r	  r  r  rU  r=   rs  r{  rr  rz  r  rF   rH   r  rL   rG   r  r:  r  r6  r  r-   r9   rI   r4  r,   rA   rw  r0   r  r<   r@   rv  r;   rC  rH  r  r   rL  r  rO  r  r"  rO   r1   r  r  r%  r  r?   r*  r/   r.   r>   rM   r   r7   rN   rK   rJ   r8   r5   r+   rX  r!   r   rN
  rY  r  r  exitrt   ru   rv   <module>rx     s%  @yv #M^     	     	 	  
    A A 1 ) +  % + P O O??#))::  " 7 B $& . % 
 	- !.2!!&*&*3715(,-1/3)-#'CG.2"$(##""W-	- - !- 
,- - - -  !-" #-$ %-& $'-( )-* +-, --. /-0 $1-2 13-4 /5-6 &7-8 +9-: -;-< '=-> !?-@ AA-B C-D ,E-F G-H "I-J K-L M-N O-P 
Q-R S-T U-V W-X Y-Z [- 
-` 
 	-0 !.2!!&*&*3715(,-1/3)-#'CG.2"$(##""W-0	-0 -0 -0 
,-0 -0 -0 -0  !-0" #-0$ %-0& $'-0( )-0* +-0, --0. /-00 $1-02 13-04 /5-06 &7-08 +9-0: -;-0< '=-0> !?-0@ AA-0B C-0D ,E-0F G-0H "I-0J K-0L M-0N O-0P 
Q-0R S-0T U-0V W-0X Y-0Z +[-0 
-0` 
 	- !)-.2!!&*&*3715(,-1/3)-#'CG.2"$(##""W-	- - '- 
,- - - -  !-" #-$ %-& $'-( )-* +-, --. /-0 $1-2 13-4 /5-6 &7-8 +9-: -;-< '=-> !?-@ AA-B C-D ,E-F G-H "I-J K-L M-N O-P 
Q-R S-T U-V W-X Y-Z [- 
-p 	X
 !;?.2!!&*&*3715(,-1/3)-#'CG.2"$(##""YX
	X
 X
 9X
 X
 
,X
 X
 X
  !X
" #X
$ %X
& 'X
( $)X
* +X
, -X
. /X
0 1X
2 $3X
4 15X
6 /7X
8 &9X
: +;X
< -=X
> '?X
@ !AX
B ACX
D EX
F ,GX
H IX
J "KX
L MX
N OX
P QX
R 
SX
T UX
V WX
X YX
Z [X
\ F]X
H	 	h
 ,0"&AE"&"2648=A!%# $26-159*.##!%&*-1 	15)-*.&6+/!!gh
		h

9h
 )h
 h
  h
 ?h
 h
  
!h
" #h
$ %h
&  'h
( )h
* 0+h
, 2-h
. ;/h
0 1h
2 3h
4 5h
6 7h
8 09h
: +;h
< 3=h
> (?h
@ Ah
B Ch
D Eh
F $Gh
H +Ih
L 	GMh
P /Qh
R 'Sh
T (Uh
X $Yh
Z )[h
\ ]h
^ _h
` ah
b ch
d eh
f gh
h ih
^ #'"$(CC$CC  	CC
 CC CC CC CC CC CC "CC CC CCL8J 8 ~*N ~*N ~*NBV |? |? |?~/ s
 s
 s
l g-: g-: g-:T[ }; }; };@ |	7I-. |	7 |	7~ i
 i
 i
X t t tn {
 {
 {
|[	4Xh2T9: [	4| s1.) s1 s1ls
8C= s
l =< = =2 b
 b
 b
J c c cL o: o: o:d R
(3- R
 R
j ) ) )X r r rjF) F F+ F+ F+R  B!wsHS&[$99: B! B!J ~!WS(3;"778 ~! ~!B&0t|| &0Rb$,, bJ .$,, @t|| , 
@ 
@$,, "
B4<< 
Bdll ,#$,, #"4<< "*" "Pz$J z$JzI w$ $ 
3	
 	# c s # 3 	# # 3 	# # 3  !" S#$ c% ( GL 6rYxvrQ
h~BK\:z]@*Z7tSltnOdTnWt3lYxNbXvQhcL|~u~  	{ { 	{
 {{ { 	P{ {|  	
  <	M	M	M 	M 		M
 	M 	M	M	M	M 	M 		M
 	M 	M  	
  0""" " 	"
 " 	""  	
    	
  (  	
  	"  	
  6	.	.	. 	. 		.
 	. 	.& % %%% % 	%
 % %P  	
  ,888 8 	8
 8 8   	
  ,~~~ ~ 	~
 ~B:--- - 	-
 - -`,--	-	>4n3l=== = 	=
 = =@  	
  $((( ( 	(
 ( (V  	
  4333 3 	3
 3 3l  	
  "+)+)/+)^ BFE)>EEEPD
 DDN   Fjj)2jjZc
c*c7@ccL!N p-
 p- p-p-
 
p- p- p- 	p-n 9,9, 
	9,
 9, 9,x'%'%'% "'% 	'% )'%T+\P-f:6 -1F *FF 	FR.b2'T/d%
hX %([![[[|99$99x L #,0	= = = *	=
= = =B GK#/?CF &*37d' $(d' d' $	d'
 1d'd' !d'd'N
%K+%K%K %K 	%K %KPC@
C@
C@ C@
 C@LY6Y6,Y6 ,Y6 	Y6
 Y6 Y6 Y6 Y6 Y6x""&=""J"J 
"*- 

 
 N 
 N*(1*(9<*(#*(Z 

 	8 	88
8
 38 
8 

 "&	B 	BB
B
 =B 
B (,	;6 %	;6;6
;6
 C;6D 	/C 	/C/C
/C
 /Cd 
 
 
  	 
 
 
 
   
 H
 H
HH H H^ 	"" 	"
 "J**-:*	*Z 
68$'03 

 
BD03<?( 
 / 	/
 / / / /l ,09 9 	9
 *9 
9@ #'15!Y0Y  	Y
 /Y Y 
Y Y YD +/"V V 	V	V (V V V +Vr_D* *Z 
 "&"&	   	
 
 
 
 $($(	 ! "	
 
 
 *.*.	  '  (	  
 
 L 26  /   		 F&.2 *$0)&@ CCC 	C,$G $GN  #}}53 # >A 4 =E%*%%*69%*%*%*PF %)K3	K3 	K3
 #K3 
K3 K3d v.
v. 	v.
 v. v. v. v. 	v.r* 9>  &0$V Y	Y 	Y
 Y Y Y 	Y~ D
  D DD
 D D 	D DN,+<&)8;>
&>) %)	2( 2( #	2(2(
 
2(p #'  $2  2 	2
 2	82 2 2t .2"$( "; 
;$;
 
; 
; ; ; ,; ; "; ; ; ; ;  	!; ;B k"
 $(k" k"k"
 !k" k" 
k" k"d 3748 $ $ $#:>'r"
r" 0	r"
 2r" r" r" r" r" r" r" r" r" r" r"  
!r"" #r"$ 8%r"& 'r"( )r"* +r" r"jH HX 
EEEzHHTV O|  ++11 +*+	+s*   ?z) ){0z99
{{{{