ó
x™xTc           @   s|   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ e d k rx d  d l Z e e j d ƒ Z e j	 ƒ  e j
 ƒ  n  d S(   iÿÿÿÿ(   t   division(   t   DetectorImageBaset
   EIGERImagec           B   sM   e  Z d  „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 RS(	   c         C   s/   t  j |  | ƒ d |  _ t |  _ d |  _ d  S(   Nt   EIGERi    (   R   t   __init__t
   vendortypet   Truet   supports_multiple_imagest
   img_number(   t   selft   filename(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyR      s    		i 0  c         C   s   |  j  sd d  l } |  j } | j | d ƒ |  _ |  j d d d } |  j d d d d } |  j d d d } |  j d d } i  |  _ |  j d } x£ t | ƒ D]• }	 |	 d	 d
 !d k sÉ qª n  y | |	 }
 Wn t k
 rï } qª n X|
 j d } |
 j d } x2 t	 | | d ƒ D] } |	 | | f |  j | <qWqª Wi d d 6|  _  d d t
 f d d t
 f d d t
 f d d t
 f d d t f d d t f d d t f d d t f d d t f d d  t f d! d" t f d# d$ t f d% d% t f d& d& t f d' d' t f d( d( t f d) d) t f d* d+ t f g } xã | D]Û \ } } } y | | | d	 ƒ |  j  | <Wq8t k
 ry | | | d	 ƒ |  j  | <Wqt k
 ry | | | d	 ƒ |  j  | <Wqt k
 r
y | | | d	 ƒ |  j  | <Wqt k
 rqXqXqXq8Xq8W|  j  j d ƒ r8|  j |  _ n  |  j  j d ƒ rY|  j |  _ n  |  j  j d ƒ rz|  j |  _ n  |  j  j d% ƒ sœd, |  j  d% <n  |  j  j d ƒ s¾d, |  j  d <n  |  j  j d ƒ r|  j  j d! ƒ r|  j |  j  d |  j  d! ƒ \ |  j  d <|  j  d! <qn  d  S(-   Niÿÿÿÿt   rt   entryt
   instrumentt   detectort   detectorSpecifict   monochromatort   samplei    i   t   datat   image_nr_lowt   image_nr_highi   iÿÿ  t   CCD_IMAGE_SATURATIONt   HEADER_BYTESt   SIZE1t   y_pixels_in_detectort   SIZE2t   x_pixels_in_detectort   DETECTOR_SNt   detector_numbert
   PIXEL_SIZEt   x_pixel_sizet	   OSC_STARTt   DISTANCEt   detector_distancet
   WAVELENGTHt
   wavelengtht   BEAM_CENTER_Xt   beam_center_xt   BEAM_CENTER_Yt   beam_center_yt	   OSC_RANGEt   rotation_angle_stept   TWOTHETAt
   BYTE_ORDERt   AXISt   PHIt   OMEGAt   DATEt   data_collection_dateg        (   t
   parameterst   h5pyR
   t   Filet   hdf5Filet   LUTt   listt   KeyErrort   attrst   ranget   intt   strt   floatt   has_keyt   size2t   image_size_fastt   size1t   image_size_slowt
   pixel_sizet   pixel_resolutiont   image_coords_as_detector_coords(   R	   t	   maxlengthR2   t   masterFilenamet   paramst   dparamst   mparamst   sparamsR   t   datalinkR   t	   exceptionR   R   t   imgNrt   libraryt   tagt   searcht   datatype(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt
   readHeader   s†    			 $c   	      C   s  d } y |  j  |  j d \ } } Wn t k
 rE } t d ƒ ‚ n X|  j d | } | | d  d  … d  d  … f } t | ƒ d k sž t | d ƒ d k r­ t d ƒ ‚ n  d d l m } d d  l } | j	 t | ƒ t | d ƒ ƒ } | j
 | j ƒ } | j | ƒ } |  j | ƒ d  S(	   Nt    i   s   imgNr out of rangeR   i    s   an image dimension is zeroiÿÿÿÿ(   t   flex(   R5   R   R7   t   ImageReadExceptionR4   t   lent   scitbx.array_familyRT   t   numpyt   reshapet   astypet   int32R:   t   bin_safe_set_data(	   R	   RK   t   imageNrOffsett   eR   t   imageRT   RX   t   tmp(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt   readb   s    ("c         C   s   t  |  j ƒ S(   N(   RV   R5   (   R	   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt   image_countv   s    c         C   s   d S(   Ni   (    (   R	   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt   integerdepthy   s    c         C   s   d S(   Ni    (    (   R	   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt
   dataoffset|   s    c         C   s9   | d  k r" |  j |  j d d S|  j | d d Sd  S(   Ni   i    (   t   NoneR5   R   (   R	   t   index(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt   get_data_link   s    N(
   t   __name__t
   __module__R   RR   Ra   Rb   Rc   Rd   Re   Rg   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyR      s   	W				t   __main__Ni   (   t
   __future__R    t   iotbx.detectors.detectorbaseR   R   Rh   t   syst   argvt   ERR   t   show_header(    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/eiger.pyt   <module>   s   �
