ó
ý™xTc           @   s¤   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d „  Z d e f d „  ƒ  YZ	 e
 d k r  d  d	 l Z x& e j d
 D] Z e	 j e ƒ GHq… Wn  d	 S(   iÿÿÿÿ(   t   division(   t   FormatCBFMiniPilatus(   t   ParallaxCorrectedPxMmStrategy(   t   determine_pilatus_maskc         C   sw  d d l  m } d d l m } m } d d  l } | j d ƒ } t |  d ƒ j ƒ  } | j	 | ƒ d } | | d  } d }	 d }
 d } x« | j
 d ƒ D]š } d	 | k rÄ t | j
 ƒ  d ƒ }	 q™ d
 | k ré t | j
 ƒ  d ƒ }
 q™ d | k rt | j
 ƒ  d ƒ } q™ d | k r™ t | j
 ƒ  d ƒ } q™ q™ W| |	 |
 k sMt ‚ | d | | | | !d |	 d |
 ƒ } | S(   Niÿÿÿÿ(   t   flex(   t
   uncompresst   compresst   0c1a04d5t   rbi   i    s   
s   X-Binary-Size-Fastest-Dimensions   X-Binary-Size-Second-Dimensions   X-Binary-Number-of-Elementss   X-Binary-Size:t   packedt   fastt   slow(   t   scitbx.array_familyR   t   cbflib_adaptbxR   R   t   binasciit	   unhexlifyt   opent   readt   findt   splitt   intt   AssertionError(   t	   cbf_imageR   R   R   R   t	   start_tagt   datat   data_offsett
   cbf_headerR
   R   t   lengtht   recordt   sizet   pixel_values(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyt   read_cbf_image   s.    t   FormatCBFMiniPilatusDLS12Mc           B   s5   e  Z e d  „  ƒ Z d „  Z d „  Z d d „ Z RS(   c         C   sU   t  j |  ƒ } x? | j d ƒ D]. } d | k r d | k r d | k r t Sq Wt S(   sc   Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.s   
s
   # Detectort   PILATUSs   S/N 120-0100(   R   t   get_cbf_headerR   t   Truet   False(   t
   image_filet   headerR   (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyt
   understand3   s    c         C   s2   |  j  | ƒ s t ‚ t j |  | ƒ d |  _ d S(   sc   Initialise the image structure from the given file, including a
    proper model of the experiment.N(   R'   R   R   t   __init__t   Nonet	   _raw_data(   t   selfR%   (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyR(   A   s    	c         C   s\  d d l  m } d d l m } d d  l } | ƒ  } | j ƒ  } | j d d d ƒ xt d ƒ D]ó } | j d d | d d } | j	 d ƒ } | j	 d | j
 | ƒ | j | ƒ f ƒ }	 | j |	 ƒ }
 d |
 d | d |	 } | j ƒ  } | j d | ƒ | j d ƒ | j d ƒ | j d ƒ | j | j |	 j | j ƒ | j | ƒ qa W| S(   Niÿÿÿÿ(   t   HierarchicalDetector(   t   matrixi   i    iÿÿÿi   gffffff(Àg      à?gé&1¬œ@gÓMbX9Ü?g     €f@g     @o@gš™™™™	h@g…ëQ¸Å0@s   row-%02diŸ	  iÃ   i@B gj¼t“Æ?(   i   i    i    (   i    i   i    (   i    i    iÿÿÿgé&1¬œ@gã¥›Ä ° @(   iÿÿÿÿi    i    (   iŸ	  iÃ   (   iÿÿÿÿi@B (   gj¼t“Æ?gj¼t“Æ?(   t   dxtbx.model.detectorR,   t   scitbxR-   t   matht	   hierarchyt   set_local_framet   ranget   pit   colt   sint   cost   crosst	   add_panelt   set_namet   set_image_sizet   set_trusted_ranget   set_pixel_sizet   elems(   R+   R,   R-   R0   t   detectort   roott   jt   angleR
   R   t   normalt   origint   p(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyt	   _detectorM   s4    	+
c   	      C   s¿   |  j  d  k r� t |  j ƒ } g  |  _  xs t |  j ƒ  ƒ D]\ \ } } d | d d | d d f \ } } } } |  j  j | | | … | | … f ƒ q: Wn  | d  k	 r´ |  j  | S|  j  d S(   Ni    iÃ   i   iŸ	  iÊ   iÊ   (   R*   R)   R   t   _image_filet	   enumeratet   get_detectort   append(	   R+   t   indexR   RA   t   panelt   xmint   ymint   xmaxt   ymax(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyt   get_raw_dataq   s    	*-N(   t   __name__t
   __module__t   staticmethodR'   R(   RF   R)   RQ   (    (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyR    1   s   		$t   __main__Ni   (   t
   __future__R    t!   dxtbx.format.FormatCBFMiniPilatusR   t   dxtbx.modelR   t!   dxtbx.format.FormatPilatusHelpersR   R   R    RR   t   syst   argvt   argR'   (    (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatusDLS12M.pyt   <module>   s   	 N