ó
űxTc           @   s{   d  d l  m Z d  d l m Z d e f d     YZ e d k rw d  d l Z x& e j d D] Z e j	 e  GHq\ Wn  d S(   i˙˙˙˙(   t   division(   t   FormatPYt   FormatPYmultitilec           B   sY   e  Z e d     Z d   Z d   Z d   Z d   Z d d  Z	 d   Z
 d   Z RS(	   c         C   s¤   y1 d d  l  } t j |  d  } | j |  } Wn t k
 rE t SXd d g } x | D] } | | k rY t SqY Wd d g } x | D] } | | k r t Sq Wt S(   Ni˙˙˙˙t   rbt   TILESt	   METROLOGYt   SIZE1t   SIZE2(   t   cPickleR   t	   open_filet   loadt   IOErrort   Falset   True(   t
   image_filet   picklet   streamt   datat   wanted_header_itemst   header_itemt   unwanted_header_items(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt
   understand   s    c         C   s)   |  j  |  s t  t j |  |  d S(   s3   Initialise the image structure from the given file.N(   R   t   AssertionErrorR   t   __init__(   t   selfR   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyR   !   s    c         C   sQ   d d l  m } | |  j  |  _ |  j j   |  j j |  _ |  j j |  _ d  S(   Ni˙˙˙˙(   t   CSPadDetector(   t"   xfel.cftbx.detector.cspad_detectorR   t   _image_filet   detectorbaset
   readHeadert   _metrology_paramst   _tiles(   R   R   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt   _start)   s    c         C   s   |  j  j   S(   N(   t   _goniometer_factoryt   single_axis(   R   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt   _goniometer=   s    c      
   C   s  d d l  m } d d l m } d d l m } d d l m } m } |  j	 j
 } | | | j  j   | | j  | d d |  j	 j d f   d } g  |  _ |   } xe| j D]Z}	 | | | |	 j  j   | |	 j   d }
 x"|	 j D]} |
 | | | j  j   | | j   d } xß| j D]Ô} | | | | j  j   | | j   d } | | j | j  d } | | | d  } | | | d | j d d f  | } | | | | j d d d f  | } | j |	 j | j | j f } | j   } | j d	  | j d
 |  | j g  | j d d !D] } | d ^ qFg  | j d d !D] } | d ^ qjg  | j d d !D] } | d ^ q | j g  | j D] } | d ^ qľ | j | j  | j d | j f  |  j j |  j  |  q5Wqö Wqˇ W| S(   sä  The _detector() function returns a model for a CSPAD detector as
    used at LCLS's CXI and XPP endstations.  It converts the
    metrology information in the pure Python object extracted from
    the image pickle to DXTBX-style transformation vectors.  Only
    ASIC:s are considered, since DXTBX metrology is not concerned
    with hierarchies.

    Merged from xfel.cftbx.detector.cspad_detector.readHeader() and
    xfel.cftbx.detector.metrology.metrology_as_dxtbx_vectors().
    i˙˙˙˙(   t   SimplePxMmStrategy(   t   HierarchicalDetector(   t   col(   t
   _transformt   get_projection_matrixi    güŠńŇMbP?i   t   PADs   %d:%d:%d:%di   g     @@(   i    i    i   (!   t   dxtbx.modelR$   t   dxtbx.model.detectorR%   t   scitbx.matrixR&   t   xfel.cftbx.detector.metrologyR'   R(   R   t   detectort   orientationt	   normalizet   translationt   distancet	   _raw_datat   panelt   sensort   asict
   pixel_sizet	   dimensiont   serialt	   add_panelt   set_typet   set_namet   set_local_framet   elemst   set_pixel_sizet   set_image_sizet   set_trusted_ranget
   saturationt   appendR   (   R   R$   R%   R&   R'   R(   t   dt   Tb_dR.   t   pt   Tb_pt   st   Tb_st   at   Tb_at   Pbt   origint   fastt   slowt   keyR4   t   t(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt	   _detectorA   sP    (		(($$('#c         C   s"   | d k	 r |  j | S|  j d S(   s   If @p index is @c None, return the flex array for the first ASIC.
    Otherwise return the array for the ASIC at index @p index.
    i    N(   t   NoneR3   (   R   t   index(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt   get_raw_data   s    c         C   s   |  j  j |  j j  S(   s#   Return a simple model for the beam.(   t   _beam_factoryt   simpleR   t
   wavelength(   R   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt   _beam   s    c         C   s   d d l  m } d d l m } |  j j d  d } |  j j d } | | | d   t |  } |  j j d d d
 d |  j j	 g d d d i | d	 6 S(   s+   Return the scan information for this image.i˙˙˙˙(   t   timegm(   t   strptimei   t   UTCi   s   %Y-%m-%dT%H:%M%Zt   image_rangei   t   exposure_timesgVçŻŇ<t   oscillationi    t   epochs(   i   i   (   i    i    (
   t   calendarRZ   t   timeR[   R   t	   timestampt   floatt   _scan_factoryt	   make_scant   pulse_length(   R   RZ   R[   t   str_mint   str_sect   epoch(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt   _scan¤   s    N(   t   __name__t
   __module__t   staticmethodR   R   R    R#   RR   RS   RU   RY   Rk   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyR   	   s   				S
	t   __main__Ni   (
   t
   __future__R    t   dxtbx.format.FormatPYR   R   Rl   t   syst   argvt   argR   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYmultitile.pyt   <module>   s   Ž