Ë
    Eü´jª}  ã                   ó$  — d Z ddlmZ ddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZmZmZ ddlZddlZddlmZmZmZ ddlmZmZ  ej2                  e«      Z G d„ d	«      Z G d
„ d«      Z G d„ de«      Zdej>                  de	ee e	e!   f      fd„Z"y)a…  Read SPE files.

This plugin supports reading files saved in the Princeton Instruments
SPE file format.

Parameters
----------
check_filesize : bool
    The number of frames in the file is stored in the file header. However,
    this number may be wrong for certain software. If this is `True`
    (default), derive the number of frames also from the file size and
    raise a warning if the two values do not match.
char_encoding : str
    Deprecated. Exists for backwards compatibility; use ``char_encoding`` of
    ``metadata`` instead.
sdt_meta : bool
    Deprecated. Exists for backwards compatibility; use ``sdt_control`` of
    ``metadata`` instead.

Methods
-------
.. note::
    Check the respective function for a list of supported kwargs and detailed
    documentation.

.. autosummary::
    :toctree:

    SpePlugin.read
    SpePlugin.iter
    SpePlugin.properties
    SpePlugin.metadata

é    )ÚdatetimeN)
ÚAnyÚCallableÚDictÚIteratorÚListÚMappingÚOptionalÚSequenceÚTupleÚUnioné   )ÚRequestÚIOModeÚInitializationError)ÚPluginV3ÚImagePropertiesc                   ón  — e Zd ZdZdddddddœZi d	d
“dd ej                  g d¢«      df“dd“dd“dd“dd“dd“dd“dd“dd“dd “d!d"“d#d$“d%d&“d'd(“d)d*“d+d,“i d-d.“d/d0“d1d2“d3d4“d5d6“d7d8“d9d:“d;d<“d=d>“d?d@“dAdB“dCdD“dEdF“dGdH“dIdJ“dKdL“dMdN“¥dOdPdQdRdSdTdUddVdWdXdYddZœ¥Zd[Z ej                  ej                  «       ej                  ej                  «       ej                  ej                  «       ej                  ej                  «       ej                  ej                  «      d\œZg d]¢Zg d^¢Zd_gZy`)aÚSpecaW  SPE file specification data

    Tuples of (offset, datatype, count), where offset is the offset in the SPE
    file and datatype is the datatype as used in `numpy.fromfile`()

    `data_start` is the offset of actual image data.

    `dtypes` translates SPE datatypes (0...4) to numpy ones, e. g. dtypes[0]
    is dtype("<f") (which is np.float32).

    `controllers` maps the `type` metadata to a human readable name

    `readout_modes` maps the `readoutMode` metadata to something human readable
    although this may not be accurate since there is next to no documentation
    to be found.
    )él   ú<h)é*   ú<H)i�  r   )i¦  z<Q)i¦  z<i)iÈ  ú<f)ÚdatatypeÚxdimÚydimÚxml_footer_offsetÚ	NumFramesÚfile_header_verÚNumROI)iæ  r   ÚROIsiè  ))Ústartxr   )Úendxr   )Úgroupxr   )Ústartyr   )Úendyr   )Úgroupyr   é
   ÚxDimDet)é   r   ÚyDimDet)é   r   Ú	VChipXdim)é   r   Ú	VChipYdim)é   r   Úcontroller_version)r   r   Úlogic_output)r   r   Úamp_high_cap_low_noise)é   r   Úmode)é   r   Úexposure_sec)r)   r   Údate)é   z<10SÚdetector_temp)é$   r   Údetector_type)é(   r   Úst_diode)é,   r   Ú
delay_time)é.   r   Úshutter_control)é2   r   Úabsorb_live)é4   r   Úabsorb_mode)é6   r   Úcan_do_virtual_chip)é8   r   Úthreshold_min_live)é:   r   Úthreshold_min_val)é<   r   Úthreshold_max_live)é@   r   Úthreshold_max_val)éB   r   Ú
time_local)é¬   ú<7SÚtime_utc)é³   rU   Ú
adc_offset)é¼   r   Úadc_rate)é¾   r   Úadc_type)éÀ   r   Úadc_resolution)éÂ   r   Úadc_bit_adjust)éÄ   r   Úgain)éÆ   r   Úcomments)éÈ   z<80Sé   Ú	geometric)iX  r   )i°  z<16S)iæ  z<436S)éb   r   )éd   r   )éf   r   )éh   r   )i   r   )iÀ  r   )i”  r   )iÈ  r   )iÊ  r   )Ú
sw_versionÚspare_4Ú
XPrePixelsÚXPostPixelsÚ
YPrePixelsÚYPostPixelsÚreadout_timer   ÚtypeÚclockspeed_usÚreadout_modeÚwindow_sizer    i  )r   é   r   é   r7   )znew120 (Type II)zold120 (Type I)ÚST130ÚST121ÚST138zDC131 (PentaMax)zST133 (MicroMax/Roper)zST135 (GPIB)ÚVTCCDzST116 (GPIB)zOMA3 (GPIB)ÚOMA4)z
full framezframe transferÚkineticsrm   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚbasicÚnpÚdtypeÚmetadataÚ
data_startÚfloat32Úint32Úint16Úuint16Úuint32ÚdtypesÚcontrollersÚreadout_modesÚ	no_decode© ó    úQ/root/workspace/ytshorts/venv/lib/python3.12/site-packages/imageio/plugins/spe.pyr   r   @   sÛ  „ ñð$  ØØØ(Ø!Ø'ñ€EðBà�,ðBð 	ØØˆB�H‰Hòó	ð ð
ðBð$ 	�9ð%Bð& 	�:ð'Bð( 	�Zð)Bð* 	�Zð+Bð. 	˜ið/Bð0 	˜	ð1Bð2 	! )ð3Bð4 	�	ð5Bð6 	˜
ð7Bð8 	�ð9Bð: 	˜ð;Bð< 	˜ð=Bð> 	�Jð?Bð@ 	�jðABðF 	˜:ñGBðH 	�zðIBðJ 	�zðKBðL 	˜zðMBðN 	˜jðOBðP 	˜ZðQBðR 	˜jðSBðT 	˜ZðUBðV 	�lðWBðX 	�LðYBðZ 	�kð[Bð\ 	�Kð]Bð^ 	�Kð_Bð` 	˜+ðaBðb 	˜+ðcBðd 	�ðeBðf 	Ð$ðgBðh 	�[ñiBðj $Ø!Ø Ø"Ø!Ø"Ø#Ø(ØØ%Ø$Ø#Ø'òCB€HðH €Jð ˆ2�8‰8�B—J‘JÓØˆ2�8‰8�B—H‘HÓØˆ2�8‰8�B—H‘HÓØˆ2�8‰8�B—I‘IÓØˆ2�8‰8�B—I‘IÓñ€Fò€Kò" A€Mð ��Ir’   r   c                   óÄ  ‡ — e Zd ZdZi dd“dd“dd“dd“d	d“d
d“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“Zdd d!d"d#œZ G d$„ d%«      Zi d& ed ed'd(«      e«      “d) ed ed(d*«      e«      “d+ ed ed,d«      e	«      “d- ed ed.d/«      e
d0«      “d1 ed edd2«      e	«      “d3 ed ed4d5«      e«      “d6 edd2d7„ «      “d8 edd9d:„ «      “d; ed ed<d9«      e«      “d= edd>d?„ «      “d@ ed edAd<«      e
dB«      “dC ed edd«      ˆ fdD„«      “dE ed ed5dA«      e
d0«      “dF ed ed,d«      e«      “dG ed eddH«      e
dI«      “dJ ed edd«      e«      “dK ed edHd<«      e
d0«      “ ed edd«      e«       ed ed<dL«      e
d0«       ed edd«      e«       ed ed/dM«      e
d0«       ed edLdN«      e
d0«       ed edNdO«      e
d0«       ed edOd.«      e
d0«      dPœ¥dQ ed edRdS«      dT„ «      idUœZedVee	   dWeeef   fdX„«       ZedVee	   dYeeef   dWee	ef   fˆ fdZ„«       Zed[e	d\e	dWeed]f   fˆ fd^„«       Zedbd_ed`e	fˆ fda„«       Zˆ xZS )cÚSDTControlSpeca&  Extract metadata written by the SDT-control software

    Some of it is encoded in the comment strings
    (see :py:meth:`parse_comments`). Also, date and time are encoded in a
    peculiar way (see :py:meth:`get_datetime`). Use :py:meth:`extract_metadata`
    to update the metadata dict.
    u   JÃ¤nrw   ÚJanÚFebr   u   MÃ¤rrx   ÚMarÚAprr5   ÚMairf   ÚMayÚJunr+   ÚJulé   ÚAugr7   ÚSepé	   ÚOktr)   ÚOctÚNové   ÚDezé   ÚDecÚstandardÚTOCCSLr~   Ú	arbitrary)ÚSEQUÚSETOÚKINEÚSEARc            
       óˆ   — e Zd ZU dZeed<   	 eed<   	 eege	f   ed<   	 e
def   ed<   	 edfdededeege	f   dee   fd„Zy)úSDTControlSpec.CommentDescz>Describe how to extract a metadata entry from a comment stringÚnÚsliceÚcvtNÚscalec                 ó<   — || _         || _        || _        || _        y ©N)r²   r³   r´   rµ   )Úselfr²   r³   r´   rµ   s        r“   Ú__init__z#SDTControlSpec.CommentDesc.__init__ó   s    € ð ˆDŒFØˆDŒJØˆDŒHØˆD�Jr’   )r   r€   r�   r‚   ÚintÚ__annotations__r³   r   Ústrr   r   Úfloatr
   r¹   r‘   r’   r“   ÚCommentDescr±   ç   s}   … ÙLà‹Ø7Ø‹Ø>Ø�s�e˜S�jÑ!Ó!Ø<Ø�T˜5�[Ñ!Ó!Ø1ð ),Ø%)ñ
	àð
	ð ð
	ð ˜3˜% ˜*Ñ%ð	
	ð
 ˜E‘?ô
	r’   r¾   Úsdt_major_versionrR   éD   Úsdt_minor_versionéF   Úsdt_controller_namer   Úexposure_timerP   éI   g�íµ ÷Æ°>Ú
color_coder/   Údetection_channelsé   r1   Úbackground_subtractionc                 ó   — | dk(  S )NÚBr‘   ©Úxs    r“   ú<lambda>zSDTControlSpec.<lambda>  s
   € À1ÈÁ8€ r’   Ú	em_activeé    c                 ó   — | dk(  S )NÚEr‘   rÌ   s    r“   rÎ   zSDTControlSpec.<lambda>  s
   € °a¸3±h€ r’   Úem_gainé   Úmodulation_activeé!   c                 ó   — | dk(  S )NÚAr‘   rÌ   s    r“   rÎ   zSDTControlSpec.<lambda>
  s
   € ¸aÀ3¹h€ r’   Ú
pixel_sizeé   gš™™™™™¹?Úsequence_typec                 ó"   •— ‰j                   |    S r·   )Úsequence_types)rÍ   Ú	__class__s    €r“   rÎ   zSDTControlSpec.<lambda>  s   ø€ ¨9×+CÑ+CÀAÑ+F€ r’   ÚgridÚn_macroÚdelay_macroé   gü©ñÒMbP?Ún_miniÚ
delay_minié%   éO   rB   é7   )Ún_microÚdelay_microÚ	n_subpicsÚdelay_shutterÚdelay_prebleachÚbleach_timeÚrecovery_timeÚbleach_piezo_activeé"   é#   c                 ó   — | dk(  S )NÚzr‘   rÌ   s    r“   rÎ   zSDTControlSpec.<lambda>  s   € È1ÐPSÉ8€ r’   ))rf   r   )rf   rw   rd   Úreturnc                 ó~   — | d   dd dk7  ry	 t        | d   dd «      t        | d   dd «      fS # t        $ r Y yw xY w)a-  Get the version of SDT-control metadata encoded in the comments

        Parameters
        ----------
        comments
            List of SPE file comments, typically ``metadata["comments"]``.

        Returns
        -------
        Major and minor version. ``-1, -1`` if detection failed.
        r5   rÂ   éL   ÚCOMVER)éÿÿÿÿrø   éN   éP   )rº   Ú
ValueError)rd   s    r“   Úget_comment_versionz"SDTControlSpec.get_comment_version!  s\   € ð �A‰;�r˜"Ð Ò)Øð	Ü�x ‘{ 2 bÐ)Ó*¬C°¸±¸B¸rÐ0BÓ,CÐCÐCøÜò 	Ùð	ús   Ž!0 °	<»<Úversionc           	      ó¨  •— i }t        |d   dz   «      D ]{  }	 ‰j                  |d   |f   }|j                  «       D ]Q  \  }}	 |j	                  | |j
                     |j                     «      }|j                  �||j                  z  }|||<   ŒS Œ} |‰j                  vrLdj                  t        d„ ‰j                  «      «      }	t        j                  d|d   › d	|d   d
›d|	› d�«       | d   | d   z   }
|
j                  «       |d<   |S # t        $ r Y �Œw xY w# t        $ r+}t        j                  d|› d|› �«       d||<   Y d}~�Œd}~ww xY w)aC  Extract SDT-control metadata from comments

        Parameters
        ----------
        comments
            List of SPE file comments, typically ``metadata["comments"]``.
        version
            Major and minor version of SDT-control metadata format

        Returns
        -------
        Dict of metadata
        rw   r   Nz-Failed to decode SDT-control metadata field `z`: z, c                 ó   — | d   › d| d   d›�S )Nr   ú.rw   Ú02r‘   rÌ   s    r“   rÎ   z/SDTControlSpec.parse_comments.<locals>.<lambda>]  s   €   1¡  a¨¨!©¨R yÐ1€ r’   z)Unsupported SDT-control metadata version r   r  z. Only versions z@ are supported. Some or all SDT-control metadata may be missing.r   Úcomment)ÚrangeÚcomment_fieldsÚKeyErrorÚitemsr´   r²   r³   rµ   Ú	ExceptionÚwarningsÚwarnÚjoinÚmapÚstrip)rd   rý   Úsdt_mdÚminorÚcmtÚnameÚspecÚvÚeÚsupported_verr  rÞ   s              €r“   Úparse_commentszSDTControlSpec.parse_comments5  sˆ  ø€ ð" ˆÜ˜7 1™:¨™>Ó*ò 	(ˆEð
Ø×.Ñ.¨w°q©z¸5Ð/@ÑA�ð "Ÿi™i›kò 
(‘
��dð	(ØŸ™ ¨$¯&©&Ñ!1°$·*±*Ñ!=Ó>�AØ—z‘zÐ-Ø˜TŸZ™Z™˜Ø#$�F˜4’Lñ
(ð	(ð( ˜)×2Ñ2Ñ2Ø ŸI™IÜÑ1°9×3KÑ3KÓLóˆMô �M‰MØ;¸GÀA¹J¸<ÀqÈÐQRÉÐTVÈð X!Ø!. ð 0CðCôð
 ˜1‘+ ¨¡Ñ+ˆØ#ŸM™M›OˆˆyÑØˆøô1 ò Úðûô !ò (Ü—M‘MØGÈÀvÈSÐQRÐPSÐTôð $(�F˜4—Lûð	(ús*   ™DÁADÄ	DÄDÄ	EÄ& EÅEr9   ÚtimeNc                 ó   •— 	 ‰j                   | dd    }t        t        | dd «      |t        | dd «      t        |dd «      t        |dd «      t        |dd «      «      S # t        $ r#}t        j                  d|› d�«       Y d	}~y	d	}~ww xY w)
ai  Turn date and time saved by SDT-control into proper datetime object

        Parameters
        ----------
        date
            SPE file date, typically ``metadata["date"]``.
        time
            SPE file date, typically ``metadata["time_local"]``.

        Returns
        -------
        File's datetime if parsing was succsessful, else None.
        r   rf   r¡   r   r5   r+   z1Failed to decode date from SDT-control metadata: r   N)Úmonthsr   rº   r  ÚloggerÚinfo)r9   r  Úmonthr  rÞ   s       €r“   Úget_datetimezSDTControlSpec.get_datetimeh  s�   ø€ ð	RØ×$Ñ$ T¨!¨A YÑ/ˆEÜÜ�D˜˜1�I“ØÜ�D˜˜1�I“Ü�D˜˜1�I“Ü�D˜˜1�I“Ü�D˜˜1�I“óð øô ò 	RÜ�K‰KÐKÈAÈ3ÈaÐP×QÑQûð	Rús   ƒAA! Á!	BÁ*BÂBÚmetaÚchar_encodingc                 óP  •— ‰j                  | d   «      }t        d„ |D «       «      rt        j                  d«       y‰j	                  | d   |«      }| j                  d«       | j                  |«       ‰j                  | d   | d   «      }|r'|| d<   | j                  d«       | j                  d«       | d   }	 |j                  |«      | d	<   | j                  d«       | j                  d«       | j                  d«       y# t        $ r t        j                  d
«       Y ŒCw xY w)ar  Extract SDT-control metadata from SPE metadata

        SDT-control stores some metadata in comments and other fields.
        Extract them and remove unused entries.

        Parameters
        ----------
        meta
            SPE file metadata. Modified in place.
        char_encoding
            Character encoding used to decode strings in the metadata.
        rd   c              3   ó&   K  — | ]	  }|d k  –— Œ y­w)r   Nr‘   )Ú.0Úcs     r“   ú	<genexpr>z2SDTControlSpec.extract_metadata.<locals>.<genexpr>“  s   è ø€ Ò%˜ˆq�1�uÑ%ùs   ‚zSDT-control comments not found.Nr9   rS   r   rm   Úmodulation_scriptzHFailed to decode SDT-control laser modulation script. Bad char_encoding?rV   r8   )rü   Úanyr  Údebugr  ÚpopÚupdater  ÚdecodeÚUnicodeDecodeErrorr  r	  )r  r  ÚcomverÚsdt_metaÚdtÚsp4rÞ   s         €r“   Úextract_metadatazSDTControlSpec.extract_metadata„  s  ø€ ð ×.Ñ.¨t°JÑ/?Ó@ˆÜÑ%˜fÔ%Ô%ä�L‰LÐ:Ô;Øà×+Ñ+¨D°Ñ,<¸fÓEˆØ�‰�ÔØ�‰�HÔð ×#Ñ# D¨¡L°$°|Ñ2DÓEˆÙØ!ˆD�ÑØ�H‰H�VÔØ�H‰H�\Ô"à�9‰oˆð	Ø(+¯
©
°=Ó(AˆDÐ$Ñ%Ø�H‰H�YÔð 	�‰�ÔØ�‰�Õ øô "ò 	Ü�M‰Mð8öð	ús   Â<%D ÄD%Ä$D%)Úlatin1)r   r€   r�   r‚   r  rÝ   r¾   r³   rº   r¼   r½   r  Ústaticmethodr   r   rü   r   r   r  r   r   r  r	   r/  Ú__classcell__©rÞ   s   @r“   r•   r•   Á   s>  ø„ ñðà�ðð 	ˆqðð 	ˆqð	ð
 	�ðð 	ˆqðð 	ˆqðð 	ˆqðð 	ˆqðð 	ˆqðð 	ˆqðð 	ˆqðð 	ˆqðð 	ˆrðð 	ˆrðð  	ˆrð!ð" 	ˆrð#ð$ 	ˆrð%€Fð. ØØØñ€N÷ñ ð2
Ø¡¨Q±°b¸"³¸sÓ!Cð
à¡¨Q±°b¸"³¸sÓ!Cð
ð "¡;¨q±%¸¸1³+¸sÓ#Cð
ð ™[¨©E°"°b«M¸5À&ÓIð	
ð
 ™+ a©¨r°2«¸Ó<ð
ð !¡+¨a±°r¸2³ÀÓ"Dð
ð %¡k°!°RÑ9KÓ&Lð
ð ™ Q¨Ñ,>Ó?ð
ð ‘{ 1¡e¨B°£m°SÓ9ð
ð  ¡¨Q°Ñ4FÓ!Gð
ð ™+ a©¨r°2«¸¸sÓCð
ð ™[Ø‘5˜˜B“<Ó!Fóð
ð ‘K ¡5¨¨R£=°%¸Ó@ð
ð  ‘{ 1¡e¨A¨q£k°3Ó7ð!
ð" ™; q©%°°B«-¸ÀÓGð#
ð$ ‘k !¡U¨1¨a£[°#Ó6ð%
ð& ™+ a©¨r°2«¸¸vÓFð'
ñ( # 1¡e¨A¨r£l°CÓ8Ù& q©%°°B«-¸ÀÓGÙ$ Q©¨a°«°cÓ:Ù(¨©E°"°b«M¸5À&ÓIÙ*¨1©e°B¸«m¸UÀFÓKÙ& q©%°°B«-¸ÀÓGÙ(¨©E°"°b«M¸5À&ÓIò5
ð: "¡;¨q±%¸¸B³-ÑASÓ#Tð
ñ; €NðD ð h¨s¡mð ¸¸cÀ3¸h¹ò ó ðð& ð0Ø˜3‘-ð0Ø*/°°S°©/ð0à	ˆc�3ˆh‰ô0ó ð0ðd ðR˜3ð R cð R¨e°H¸d°NÑ.Cô Ró ðRð6 ñ*!˜wð *!°sô *!ó ô*!r’   r•   c                   ó6  ‡ — e Zd Z	 	 	 ddededee   dee   ddf
ˆ fd„Zdd	œd
ede	j                  fd„Zdee	j                     fd„Z	 	 	 	 dd
ededededeeef   f
d„Zdededeeef   fd„Zdeeef   fd„Zdd
edefd„Zdeeef   dedeeef   fd„Zˆ xZS )Ú	SpePluginNÚrequestÚcheck_filesizer  r,  rô   c           	      ó¢  •— t         ‰| �  |«       |j                  j                  t        j
                  k(  rt        d«      ‚|�t        j                  dt        «       || _
        |�t        j                  dt        «       || _        | j                  j                  «       | _        	 | j                  t         j"                  d«      }|d   | _        t         j&                  |d      | _        |d   |d	   f| _        |d
   | _        |�r|d   dk\  r|d   }nD| j                  j/                  dt0        j2                  «       | j                  j5                  «       }|t         j6                  z
  }|| j*                  d   | j*                  d   z  | j(                  j8                  z  z  }|| j,                  k7  rXt        j                  d| j                  j:                  › d| j,                  › d|› d�«       t=        || j,                  «      | _        | j                  j/                  t         j6                  «       y# t>        $ r t        d«      ‚w xY w)aá  Instantiate a new SPE file plugin object

        Parameters
        ----------
        request : Request
            A request object representing the resource to be operated on.
        check_filesize : bool
            If True, compute the number of frames from the filesize, compare it
            to the frame count in the file header, and raise a warning if the
            counts don't match. (Certain software may create files with
        char_encoding : str
            Deprecated. Exists for backwards compatibility; use ``char_encoding`` of
            ``metadata`` instead.
        sdt_meta : bool
            Deprecated. Exists for backwards compatibility; use ``sdt_control`` of
            ``metadata`` instead.

        zcannot write SPE filesNz{Passing `char_encoding` to the constructor is deprecated. Use `char_encoding` parameter of the `metadata()` method instead.ztPassing `sdt_meta` to the constructor is deprecated. Use `sdt_control` parameter of the `metadata()` method instead.r0  r    r   r   r   r   rx   r   r   rw   zThe file header of z claims there are z  frames, but there are actually z frames.z)SPE plugin cannot read the provided file.) Úsuperr¹   r6   Úio_moder   Úwriter   r  r	  ÚDeprecationWarningÚ_char_encodingÚ	_sdt_metar6  Úget_fileÚ_fileÚ_parse_headerr   rƒ   Ú_file_header_verr�   Ú_dtypeÚ_shapeÚ_lenÚseekÚosÚSEEK_ENDÚtellr‡   ÚitemsizeÚfilenameÚminr  )	r¸   r6  r7  r  r,  r  Údata_endÚlinerÞ   s	           €r“   r¹   zSpePlugin.__init__³  sþ  ø€ ô4 	‰Ñ˜Ô!Ø�<‰<×Ñ¤6§<¡<Ò/Ü%Ð&>Ó?Ð?àÐ$Ü�M‰Mðô #ô	ð ,ˆÔØÐÜ�M‰Mðô #ô	ð "ˆŒà—\‘\×*Ñ*Ó,ˆŒ
ð	Sð ×%Ñ%¤d§j¡j°(Ó;ˆDØ$(Ð):Ñ$;ˆDÔ!ÜŸ+™+ d¨:Ñ&6Ñ7ˆDŒKØ ™<¨¨f©Ð6ˆDŒKØ˜[Ñ)ˆDŒIâð
 Ð)Ñ*¨aÒ/Ø#Ð$7Ñ8‘Hà—J‘J—O‘O A¤r§{¡{Ô3Ø#Ÿz™zŸ™Ó0�HØ¤$§/¡/Ñ1�Ø˜Ÿ™ Q™¨$¯+©+°a©.Ñ8¸4¿;¹;×;OÑ;OÑOÑO�Ø˜4Ÿ9™9Ò$Ü—M‘MØ-¨d¯l©l×.CÑ.CÐ-DÐDVØŸ9™9˜+Ð%EÀdÀVÈ8ðUôô !$ D¨$¯)©)Ó 4�D”IØ�J‰J�O‰OœDŸO™OÕ,øÜò 	SÜ%Ð&QÓRÐRð	Sús   Â)FH9 È9I.©ÚindexrP  c                óØ  — |t         u rWt        j                  }| j                  d   | j                  d   z  | j                  z  }| j                  g| j                  ¢­}n´|dk  rt        d|› d�«      ‚|| j                  k\  rt        d|› d| j                  › d�«      ‚t        j                  || j                  d   z  | j                  d   z  | j                  j                  z  z   }| j                  d   | j                  d   z  }| j                  }| j                  j                  |«       t        j                  | j                  | j                  |¬«      }|j                  |«      S )a<  Read a frame or all frames from the file

        Parameters
        ----------
        index : int
            Select the index-th frame from the file. If index is `...`,
            select all frames and stack them along a new axis.

        Returns
        -------
        A Numpy array of pixel values.

        r   rw   zIndex `z` is smaller than 0.z5` exceeds the number of frames stored in this file (`z`).©r…   Úcount)ÚEllipsisr   r‡   rD  rE  Ú
IndexErrorrC  rJ  r@  rF  r„   ÚfromfileÚreshape)r¸   rP  Úread_offsetrS  Ú	out_shapeÚdatas         r“   ÚreadzSpePlugin.read  s<  € ð ”HÑÜŸ/™/ˆKØ—K‘K ‘N T§[¡[°¡^Ñ3°d·i±iÑ?ˆEØŸ™Ð1 T§[¡[Ñ1‰IØ�QŠYÜ˜w u gÐ-AÐBÓCÐCØ�d—i‘iÒÜØ˜%˜Ð UÐVZ×V_ÑV_ÐU`Ð`cÐdóð ô
 —‘Ø˜$Ÿ+™+ a™.Ñ(¨4¯;©;°q©>Ñ9¸D¿K¹K×<PÑ<PÑPñQð ð —K‘K ‘N T§[¡[°¡^Ñ3ˆEØŸ™ˆIà�
‰
�‰˜Ô$Ü�{‰{˜4Ÿ:™:¨T¯[©[ÀÔFˆØ�|‰|˜IÓ&Ð&r’   c                 ó@   ‡ — ˆ fd„t        ‰ j                  «      D «       S )zrIterate over the frames in the file

        Yields
        ------
        A Numpy array of pixel values.
        c              3   óB   •K  — | ]  }‰j                  |¬ «      –— Œ y­w)rO  N)r[  )r!  Úir¸   s     €r“   r#  z!SpePlugin.iter.<locals>.<genexpr>0  s   øè ø€ Ò= q�—	‘	 �	×"Ñ=ùs   ƒ)r  rE  )r¸   s   `r“   ÚiterzSpePlugin.iter(  s   ø€ ó >¬E°$·)±)Ó,<Ô=Ð=r’   Úexclude_appliedÚsdt_controlc                 óÄ   — | j                   dk  rB| j                  �| j                  }| j                  �| j                  }| j                  ||«      S | j	                  «       S )ua  SPE specific metadata.

        Parameters
        ----------
        index : int
            Ignored as SPE files only store global metadata.
        exclude_applied : bool
            Ignored. Exists for API compatibility.
        char_encoding : str
            The encoding to use when parsing strings.
        sdt_control : bool
            If `True`, decode special metadata written by the
            SDT-control software if present.

        Returns
        -------
        metadata : dict
            Key-value pairs of metadata.

        Notes
        -----
        SPE v3 stores metadata as XML, whereas SPE v2 uses a binary format.

        .. rubric:: Supported SPE v2 Metadata fields

        ROIs : list of dict
            Regions of interest used for recording images. Each dict has the
            "top_left" key containing x and y coordinates of the top left corner,
            the "bottom_right" key with x and y coordinates of the bottom right
            corner, and the "bin" key with number of binned pixels in x and y
            directions.
        comments : list of str
            The SPE format allows for 5 comment strings of 80 characters each.
        controller_version : int
            Hardware version
        logic_output : int
            Definition of output BNC
        amp_hi_cap_low_noise : int
            Amp switching mode
        mode : int
            Timing mode
        exp_sec : float
            Alternative exposure in seconds
        date : str
            Date string
        detector_temp : float
            Detector temperature
        detector_type : int
            CCD / diode array type
        st_diode : int
            Trigger diode
        delay_time : float
            Used with async mode
        shutter_control : int
            Normal, disabled open, or disabled closed
        absorb_live : bool
            on / off
        absorb_mode : int
            Reference strip or file
        can_do_virtual_chip : bool
            True or False whether chip can do virtual chip
        threshold_min_live : bool
            on / off
        threshold_min_val : float
            Threshold minimum value
        threshold_max_live : bool
            on / off
        threshold_max_val : float
            Threshold maximum value
        time_local : str
            Experiment local time
        time_utc : str
            Experiment UTC time
        adc_offset : int
            ADC offset
        adc_rate : int
            ADC rate
        adc_type : int
            ADC type
        adc_resolution : int
            ADC resolution
        adc_bit_adjust : int
            ADC bit adjust
        gain : int
            gain
        sw_version : str
            Version of software which created this file
        spare_4 : bytes
            Reserved space
        readout_time : float
            Experiment readout time
        type : str
            Controller type
        clockspeed_us : float
            Vertical clock speed in microseconds
        readout_mode : ["full frame", "frame transfer", "kinetics", ""]
            Readout mode. Empty string means that this was not set by the
            Software.
        window_size : int
            Window size for Kinetics mode
        file_header_ver : float
            File header version
        chip_size : [int, int]
            x and y dimensions of the camera chip
        virt_chip_size : [int, int]
            Virtual chip x and y dimensions
        pre_pixels : [int, int]
            Pre pixels in x and y dimensions
        post_pixels : [int, int],
            Post pixels in x and y dimensions
        geometric : list of {"rotate", "reverse", "flip"}
            Geometric operations
        sdt_major_version : int
            (only for files created by SDT-control)
            Major version of SDT-control software
        sdt_minor_version : int
            (only for files created by SDT-control)
            Minor version of SDT-control software
        sdt_controller_name : str
            (only for files created by SDT-control)
            Controller name
        exposure_time : float
            (only for files created by SDT-control)
            Exposure time in seconds
        color_code : str
            (only for files created by SDT-control)
            Color channels used
        detection_channels : int
            (only for files created by SDT-control)
            Number of channels
        background_subtraction : bool
            (only for files created by SDT-control)
            Whether background subtraction war turned on
        em_active : bool
            (only for files created by SDT-control)
            Whether EM was turned on
        em_gain : int
            (only for files created by SDT-control)
            EM gain
        modulation_active : bool
            (only for files created by SDT-control)
            Whether laser modulation (â€œattenuateâ€�) was turned on
        pixel_size : float
            (only for files created by SDT-control)
            Camera pixel size
        sequence_type : str
            (only for files created by SDT-control)
            Type of sequnce (standard, TOCCSL, arbitrary, â€¦)
        grid : float
            (only for files created by SDT-control)
            Sequence time unit (â€œgrid sizeâ€�) in seconds
        n_macro : int
            (only for files created by SDT-control)
            Number of macro loops
        delay_macro : float
            (only for files created by SDT-control)
            Time between macro loops in seconds
        n_mini : int
            (only for files created by SDT-control)
            Number of mini loops
        delay_mini : float
            (only for files created by SDT-control)
            Time between mini loops in seconds
        n_micro : int (only for files created by SDT-control)
            Number of micro loops
        delay_micro : float (only for files created by SDT-control)
            Time between micro loops in seconds
        n_subpics : int
            (only for files created by SDT-control)
            Number of sub-pictures
        delay_shutter : float
            (only for files created by SDT-control)
            Camera shutter delay in seconds
        delay_prebleach : float
            (only for files created by SDT-control)
            Pre-bleach delay in seconds
        bleach_time : float
            (only for files created by SDT-control)
            Bleaching time in seconds
        recovery_time : float
            (only for files created by SDT-control)
            Recovery time in seconds
        comment : str
            (only for files created by SDT-control)
            User-entered comment. This replaces the "comments" field.
        datetime : datetime.datetime
            (only for files created by SDT-control)
            Combines the "date" and "time_local" keys. The latter two plus
            "time_utc" are removed.
        modulation_script : str
            (only for files created by SDT-control)
            Laser modulation script. Replaces the "spare_4" key.
        bleach_piezo_active : bool
            (only for files created by SDT-control)
            Whether piezo for bleaching was enabled
        rx   )rB  r=  r>  Ú_metadata_pre_v3Ú_metadata_post_v3)r¸   rP  r`  r  ra  s        r“   r†   zSpePlugin.metadata2  s_   € ðX × Ñ  1Ò$Ø×"Ñ"Ð.Ø $× 3Ñ 3�Ø�~‰~Ð)Ø"Ÿn™n�Ø×(Ñ(¨¸ÓDÐDØ×%Ñ%Ó'Ð'r’   c                 óf  — | j                  t        j                  |«      }|j                  dd«      }|dk  rdn|}t	        |d   d| «      |d<   dD �cg c]  }|j                  |d«      ‘Œ c}|d<   dD �cg c]  }|j                  |d«      ‘Œ c}|d<   d	D �cg c]  }|j                  |d«      ‘Œ c}|d
<   dD �cg c]  }|j                  |d«      ‘Œ c}|d<   |d   D �cg c]  }t        |«      ‘Œ c}|d<   g }|j                  dd«      }|dz  r|j                  d«       |dz  r|j                  d«       |dz  r|j                  d«       ||d<   |d   }	d|	cxk  rt        t        j                  «      k  rn nt        j                  |	dz
     |d<   nd|d<   |d   }
d|
cxk  rt        t        j                  «      k  rn nt        j                  |
dz
     |d<   nd|d<   dD ]  }t        ||   «      ||<   Œ |rt        j                  ||«       |S c c}w c c}w c c}w c c}w c c}w )aZ  Extract metadata from SPE v2 files

        Parameters
        ----------
        char_encoding
            String character encoding
        sdt_control
            If `True`, try to decode special metadata written by the
            SDT-control software.

        Returns
        -------
        dict mapping metadata names to values.

        r!   Nrw   r"   )r*   r,   Ú	chip_size)r.   r0   Úvirt_chip_size)rn   rp   Ú
pre_pixels)ro   rq   Úpost_pixelsrd   rg   r   Úrotater   Úreverser5   Úfliprs   ru   )rE   rI   rK   rO   )rA  r   r†   r'  Úroi_array_to_dictr¼   ÚappendÚlenrŽ   r�   Úboolr•   r/  )r¸   r  ra  ÚmÚnrÚkr"  ÚgÚfÚtÚrs              r“   rc  zSpePlugin._metadata_pre_v3  s   € ð" ×ÑœtŸ}™}¨mÓ<ˆà�U‰U�8˜TÓ"ˆØ�q’&‰Q˜bˆÜ% a¨¡i°° nÓ5ˆˆ&‰	ð 3IÖI¨Q˜!Ÿ%™%  4�.ÒIˆˆ+‰Ø7QÖR°!˜qŸu™u Q¨�~ÒRˆÐ
ÑØ3OÖP¨a˜1Ÿ5™5  D�>ÒPˆˆ,‰Ø4RÖS¨q˜AŸE™E ! T�NÒSˆˆ-Ñð *+¨:©Ö7 Aœ˜Q�Ò7ˆˆ*‰ð ˆØ�E‰E�+˜qÓ!ˆØˆqŠ5Ø�H‰H�XÔØˆqŠ5Ø�H‰H�YÔØˆqŠ5Ø�H‰H�VÔØˆˆ+‰ð ˆf‰IˆØ�Ô*”Sœ×)Ñ)Ó*Õ*Ü×(Ñ(¨¨Q©Ñ/ˆAˆfŠIàˆAˆf‰IØˆnÑˆØ�Ô,”Sœ×+Ñ+Ó,Õ,Ü $× 2Ñ 2°1°q±5Ñ 9ˆAˆnÒà $ˆAˆnÑð
ò 	ˆAô ˜˜!™“:ˆAˆaŠDð	ñ Ü×+Ñ+¨A¨}Ô=àˆùòY JùÚRùÚPùÚSùò 8s   ÁHÁ7HÂH$Â=H)Ã#H.c                 óº   — | j                  t        j                  d«      }| j                  j	                  |d   «       | j                  j                  «       }d|iS )z‘Extract XML metadata from SPE v3 files

        Returns
        -------
        dict with key `"__xml"`, whose value is the XML metadata
        r0  r   Ú__xml)rA  r   rƒ   r@  rF  r[  )r¸   r  Úxmls      r“   rd  zSpePlugin._metadata_post_v3L  sJ   € ð ×!Ñ!¤$§*¡*¨hÓ7ˆØ�
‰
�‰˜Ð0Ñ1Ô2Ø�j‰j�o‰oÓˆØ˜ˆ~Ðr’   c                 óÌ   — |t         u r;t        | j                  g| j                  ¢­| j                  | j                  d¬«      S t        | j                  | j                  d¬«      S )aÞ  Standardized ndimage metadata.

        Parameters
        ----------
        index : int
            If the index is an integer, select the index-th frame and return
            its properties. If index is an Ellipsis (...), return the
            properties of all frames in the file stacked along a new batch
            dimension.

        Returns
        -------
        properties : ImageProperties
            A dataclass filled with standardized image metadata.
        T)Úshaper…   Ún_imagesÚis_batchF)r|  r…   r~  )rT  r   rE  rD  rC  )r¸   rP  s     r“   Ú
propertieszSpePlugin.propertiesY  sV   € ð" ”HÑÜ"Ø—y‘yÐ/ 4§;¡;Ñ/Ø—k‘kØŸ™Øô	ð ô  T§[¡[¸¿¹ÈeÔTÐTr’   r  c                 óH  ‡— i }t        j                  ˆfd„«      }|j                  «       D ]§  \  }}| j                  j	                  |d   «       t        |«      dk  rdn|d   }t        j                  | j                  |d   |¬«      }|j                  j                  dk(  r|t        j                  vr		  ||«      }	 |j                  «       }|||<   Œ© |S # t        $ r t        j                  d|› d	�«       Y Œ>w xY w# t        $ r t        j                   |«      }Y ŒQw xY w)
a®  Get information from SPE file header

        Parameters
        ----------
        spec
            Maps header entry name to its location, data type description and
            optionally number of entries. See :py:attr:`Spec.basic` and
            :py:attr:`Spec.metadata`.
        char_encoding
            String character encoding

        Returns
        -------
        Dict mapping header entry name to its value
        c                 ó&   •— | j                  ‰«      S r·   )r)  )rÍ   r  s    €r“   rÎ   z)SpePlugin._parse_header.<locals>.<lambda>ˆ  s   ø€ ¨¯©°Ó(?€ r’   r   rx   rw   r   rR  ÚSzFailed to decode "z3" metadata string. Check `char_encoding` parameter.)r„   Ú	vectorizer  r@  rF  ro  rV  r…   Úkindr   r�   r  r  r	  Úitemrû   Úsqueeze)	r¸   r  r  Úretr)  r  ÚspÚcntr  s	     `      r“   rA  zSpePlugin._parse_headers  s  ø€ ð& ˆä—‘Ó?Ó@ˆàŸ
™
›ò 	‰HˆD�"Ø�J‰J�O‰O˜B˜q™EÔ"Ü˜2“w ’{‘!¨¨1©ˆCÜ—‘˜DŸJ™J¨b°©e¸3Ô?ˆAØ�w‰w�|‰|˜sÒ" t´4·>±>Ñ'AðÙ˜q›	�Að"ð —F‘F“H�ð ˆC�ŠIð)	ð* ˆ
øô !ò Ü—M‘MØ,¨T¨Fð 3Cð Cöðûô ò "Ü—J‘J˜q“M’ð"ús$   Â6CÂ?D Ã"C=Ã<C=Ä D!Ä D!)TNN).Tr0  T).)r   r€   r�   r   rp  r
   r¼   r¹   rº   r„   Úndarrayr[  r   r_  r   r   r†   rc  rd  r   r  r	   r   rA  r2  r3  s   @r“   r5  r5  ²  s\  ø„ ð  $Ø'+Ø#'ñNSàðNSð ðNSð   ‘}ð	NSð
 ˜4‘.ðNSð 
õNSð` $'ò #'˜Sð #'¨2¯:©:ó #'ðJ>�h˜rŸz™zÑ*ó >ð Ø $Ø%Ø ñR(àðR(ð ðR(ð ð	R(ð
 ðR(ð 
ˆc�3ˆh‰óR(ðhD¨cð DÀð DÈÈcÐSVÈhÉó DðL 4¨¨S¨¡>ó ñU ð U¨oó Uð4,Ø˜C ˜JÑ'ð,Ø8;ð,à	ˆc�3ˆh‰÷,r’   r5  Úarô   c                 óÚ   — g }| g d¢   } | D ]\  \  }}}}}}t        |«      t        |«      gt        |«      t        |«      gt        |«      t        |«      gdœ}|j                  |«       Œ^ |S )a\  Convert the `ROIs` structured arrays to :py:class:`dict`

    Parameters
    ----------
    a
        Structured array containing ROI data

    Returns
    -------
    One dict per ROI. Keys are "top_left", "bottom_right", and "bin",
    values are tuples whose first element is the x axis value and the
    second element is the y axis value.
    )r#   r&   r$   r'   r%   r(   )Útop_leftÚbottom_rightÚbin)rº   rn  )	r‹  Ú	dict_listÚsxÚsyÚexÚeyÚgxÚgyÚroi_dicts	            r“   rm  rm  ¢  s   € ð €IØ	Ò
BÑC€AØ"#ò #ÑˆˆB��B˜˜Bä˜R›¤# b£'Ð*Ü  ›W¤c¨"£gÐ.Ü˜“GœS ›WÐ%ñ
ˆð
 	×Ñ˜Õ"ð#ð Ðr’   )#r‚   r   ÚloggingrG  Útypingr   r   r   r   r   r	   r
   r   r   r   r  Únumpyr„   Úcore.requestr   r   r   Úcore.v3_plugin_apir   r   Ú	getLoggerr   r  r   r•   r5  rŠ  r¼   rº   rm  r‘   r’   r“   ú<module>rž     sš   ðñ!õF Û Û 	÷÷ ÷ ó ã ç ?Ñ ?ß :à	ˆ×	Ñ	˜8Ó	$€÷~ñ ~÷Bn!ñ n!ôbm�ô mð`˜Ÿ™ð ¨¨T°#°t¸C±y°.Ñ-AÑ(Bô r’   