B
    N[Y                 @   sZ   d dl mZmZ ddlmZ ddlmZ G dd deZedd	d
dgddZe	e dS )    )absolute_importunicode_literals   )
TiffFormat   )formatsc               @   s*   e Zd ZdZdd ZG dd dejZdS )FEISEMFormata=  Provide read support for TIFFs produced by an FEI SEM microscope.

    This format is based on TIFF, and supports the same parameters.

    FEI microscopes append metadata as ASCII text at the end of the file,
    which this reader correctly extracts.

    Parameters for get_data
    -----------------------
    discard_watermark : bool
        If True (default), discard the bottom rows of the image, which
        contain no image data, only a watermark with metadata.
    watermark_height : int
        The height in pixels of the FEI watermark. The default is 70.
    c             C   s   dS )NF )selfrequestr	   r	   5lib/python3.7/site-packages/imageio/plugins/feisem.py
_can_write   s    zFEISEMFormat._can_writec                   s(   e Zd Zd	 fdd	Zd
ddZ  ZS )zFEISEMFormat.Readerr   TF   c                s0   t tj| |\}}|r(|d|  }||fS )a"  Get image and metadata from given index.

            FEI images usually (always?) contain a watermark at the
            bottom of the image, 70 pixels high. We discard this by
            default as it does not contain any information not present
            in the metadata.
            N)superr   Reader	_get_data)r
   indexZdiscard_watermarkZwatermark_heightZimmeta)	__class__r	   r   r       s    zFEISEMFormat.Reader._get_dataNc             C   s  di i}d}d}| j  }t|d}x|D ]}|sF|dsBq,nd}|  }|drv|dd}i ||< q,|r,|dkr,|d	\}}	x6tt	fD ]*}
y|
|	}	W n t
k
r   wY qX P qW |	|| |< q,W W d
Q R X |d st|dkrt
d| | j| |S )a  Read the metadata from an FEI SEM TIFF.

            This metadata is included as ASCII text at the end of the file.

            The index, if provided, is ignored.

            Returns
            -------
            metadata : dict
                Dictionary of metadata.
            rootFrbs   Date=T[] =Nr   z'Input file %s contains no FEI metadata.)r   Zget_local_filenameopen
startswithrstripdecodelstripsplitintfloat
ValueErrorlenZ_metaupdate)r
   r   ZmdZcurrent_tagZreading_metadatafilenameZfinlinekeyvalZtag_typer	   r	   r   _get_meta_data-   s6    




z"FEISEMFormat.Reader._get_meta_data)r   Tr   )N)__name__
__module____qualname__r   r*   __classcell__r	   r	   )r   r   r      s   r   N)r+   r,   r-   __doc__r   r   r   r	   r	   r	   r   r      s   r   ZfeizFEI-SEM TIFF formatz.tifz.tiffZiv)
extensionsZmodesN)
Z
__future__r   r   Ztifffiler    r   r   formatZ
add_formatr	   r	   r	   r   <module>   s   O