ó
ÿ™xTc           @   s…   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l	 Z	 d e e f d „  ƒ  YZ
 d e
 f d	 „  ƒ  YZ d S(
   iÿÿÿÿ(   t   division(   t   FormatCBFMultiTileHierarchy(   t   FormatStill(   t   colt   sqrNt   FormatCBFCspadc           B   s)   e  Z d  Z e d „  ƒ Z d d „ Z RS(   s&   An image reading class CSPAD CBF filesc         C   s_   t  j ƒ  } | j |  t  j ƒ | j d ƒ | j ƒ  d k rB t S| j d ƒ | j ƒ  d k S(   s[   Check to see if this looks like an CSPD CBF format image, i.e. we can
    make sense of it.t   diffrn_detectori   t   types   CS PAD(	   t   pycbft   cbf_handle_structt   read_widefilet
   MSG_DIGESTt   find_categoryt
   count_rowst   Falset   find_columnt	   get_value(   t
   image_filet
   cbf_handle(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyt
   understand   s    c            sÛ  t  ‡  f d † ‰  | d k r- |  j ƒ  } n  | j ƒ  } t | ƒ d k sQ t ‚ |  j } | j ƒ  rÇg  t t | ƒ ƒ D] } | j	 | ƒ ^ qy } g  | D] } | j
 ƒ  ^ q› } i  } | j d ƒ x{ t | j ƒ  ƒ D]g } | j d ƒ | j ƒ  }	 |	 | k r6|	 | j ƒ  k r6| j d ƒ |	 | | j ƒ  <n  | j ƒ  qÙ Wi  }
 x+ | D]# } | j d ƒ } | |
 | | <qQWxL | j ƒ  D]; } x2 | D]* } x! | D] } |
 | j
 ƒ  | _ qŸWq’Wq…Wn  ˆ  | | t ƒ d S(   s®    If the dectector object has been changed, due to refinment or manual repositioning
    in a gui, call this function to synchronize these changes to the underlying CBF handlec            s_  y t  | ƒ } Wn t k
 r+ } t } n Xt } | j ƒ  } t | d | d | d f ƒ j ƒ  } t | d | d | d f ƒ j ƒ  } t | d | d | d	 f ƒ }	 | r°|  j ƒ  rË | j }
 n_ |  j	 d
 ƒ |  j
 d ƒ |  j | j ƒ  ƒ |  j
 d ƒ t |  j ƒ  ƒ d } |  j | ƒ }
 |
 j d ƒ } |
 j d ƒ } |  j | ƒ | k sct ‚ |  j | ƒ } t | d | d | d f ƒ } |	 t |  j | ƒ ƒ 8}	 n | j ƒ  } | j | ƒ j ƒ  } | r|	 d } t |	 d |	 d d f ƒ }	 n  |  j	 d ƒ |  j
 d ƒ x6 t rS|  j ƒ  | k rF|  j ƒ  } Pn  |  j ƒ  qW|  j
 d ƒ |  j t |	 d ƒ ƒ |  j
 d ƒ |  j t |	 d ƒ ƒ |  j
 d ƒ |  j t |	 d ƒ ƒ t | d | d | d | d | d | d | d | d | d f	 ƒ } | j ƒ  j d t ƒ \ } } | d k rDt d ƒ } n  | j ƒ  d k s\t ‚ |  j
 d ƒ |  j t | d ƒ ƒ |  j
 d ƒ |  j t | d ƒ ƒ |  j
 d ƒ |  j t | d ƒ ƒ |  j | | d ƒ | r4x d | k r|  j | ƒ } qäW|  j | ƒ d k st ‚ |  j | | d ƒ n  | s[x | D] } ˆ  |  | ƒ qAWn  d S(   sI    Walks the hierarchy and synchronizes the dxtbx matrices to the CBF axes.i    i   i   i   i   i   i   i   i   t   diffrn_data_framet   array_idt	   binary_idt   axist   ids	   offset[1]s	   offset[2]s	   offset[3]t   degs	   vector[1]s	   vector[2]s	   vector[3]t   _Zt   translationN(   i    i    i   (   t   itert	   TypeErrort   TrueR   t   get_local_d_matrixR   t	   normalizet   has_sectionst   _cbf_detectorR   R   t   find_rowt   get_namet   intR   t   construct_detectort   get_detector_surface_axest   get_axis_depends_ont   AssertionErrort   get_axis_offsett   crosst   next_rowt	   set_valuet   strR   t%   r3_rotation_matrix_as_unit_quaterniont!   unit_quaternion_as_axis_and_anglet   lengtht   set_axis_settingt   get_axis_type(   t   cbft   groupt   roott   iteratort   et   is_panelt   d_matt   fastt   slowt   origt   cbf_detectort	   array_numt   axis0t   axis1t   namet   v3t   distancet	   axis_namet   r3t   angleR   t   subgroup(   t   recursive_sync(    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyRI   '   s€    
''!"
 	      i   t   array_structure_listt   array_section_idt   axis_set_idi    N(   R   t   Nonet   get_detectort	   hierarchyt   lenR)   t   _cbf_handleR!   t   xrangeR&   R$   R   R   R   R   t   valuesR,   R'   R"   R   (   t   selft   detectorR6   R4   t   it   all_cbfdetectorst   panelt   all_panelnamest   panel_name_mappingRB   t   mapped_detectorst   cbf_dt	   root_axist   quadt   sensor(    (   RI   sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyt   sync_detector_to_cbf#   s6    Y	."N(   t   __name__t
   __module__t   __doc__t   staticmethodR   RM   R`   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyR      s   t   FormatCBFCspadInMemoryc           B   s&   e  Z d  Z e d „  ƒ Z d „  Z RS(   sÎ    Overrides the Format object's init method to accept a cbf handle instead
      of a file name. Used with XFELs when it is desirable to never write
      a file to disk, but to process it only in memory.
  c         C   s   t  S(   sw    This class shouldn't be found by the dxtbx Registry. Instead it should
        be instantiated directly as needed
    (   R   (   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyR   °   s    c         C   sã   d d l  m } d d l m } d |  _ d |  _ d |  _ | |  _ | |  _	 | |  _
 d |  _ zr yX |  j ƒ  } t | t ƒ s† t ‚ | |  _ |  j ƒ  } t | t ƒ s° t ‚ | |  _ Wn t k
 rÏ } n XWd |  j ƒ  Xd S(   s<    @param cbf_handle In memory cbf_handle, alredy initialized iÿÿÿÿ(   t   detector_factory(   t   beam_factoryN(   t   dxtbx.model.detectorRf   t   dxtbx.model.beamRg   RM   t   _goniometer_instancet   _scan_instancet   _detector_instancet   _detector_factoryt   _beam_factoryRQ   t	   _raw_datat	   _detectort
   isinstancet   DetectorR)   t   _beamt   Beamt   _beam_instancet	   Exceptiont   _end(   RT   R   Rf   Rg   t   detector_instancet   beam_instanceR8   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyt   __init__·   s*    							 	(   Ra   Rb   Rc   Rd   R   Rz   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyRe   ª   s   (   t
   __future__R    t(   dxtbx.format.FormatCBFMultiTileHierarchyR   t   dxtbx.format.FormatStillR   t   scitbx.matrixR   R   R   R   Re   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFCspad.pyt   <module>	   s   š