ó
ô™xTc           @   sº   d  d l  m Z d  d l m Z m Z d  d l m Z d  d l m Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z e d k r¶ e ƒ  n  d S(   iÿÿÿÿ(   t   division(   t   Panelt   Detector(   t   approx_equal(   t   flexc         C   sÆ   d d l  m } d } |  d j d	 ƒ } t | j | ƒ | j |  d j ƒ  ƒ ƒ } | | k  sg t ‚ |  d j d
 ƒ } d d d f } t | j | ƒ | j | ƒ ƒ } | | k  s½ t ‚ d GHd  S(   Niÿÿÿÿ(   t   matrixgH¯¼šò×z>i    i   gj¼t“Æ?iÈ   t   OK(   i    i    (   i   i   gj¼t“V@gj¼t“V@(   t   scitbxR   t   get_pixel_lab_coordt   abst   colt
   get_origint   AssertionError(   t   detectorR   t   epst   origt   dorigt   cornert   corner2t   dcorner(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_get_pixel_lab_coord   s    ,"c         C   so   d d l  m } d } |  d j ƒ  } d d	 f } t | j | ƒ | j | ƒ ƒ } | | k  sf t ‚ d GHd  S(
   Niÿÿÿÿ(   R   gH¯¼šò×z>i    i   gj¼t“Æ?R   gj¼t“V@gj¼t“V@(   R   R   t   get_image_size_mmR	   R
   R   (   R   R   R   t   sizet   size2t   dsize(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_get_image_size_mm   s    "c         C   s…   |  d j  d ƒ t k s t ‚ |  d j  d ƒ t k s> t ‚ |  d j  d ƒ t k s] t ‚ |  d j  d ƒ t k s| t ‚ d GHd S(   s8   Check values are either inside or outside trusted range.i    iÿÿÿÿiç  iè  R   N(   t   is_value_in_trusted_ranget   FalseR   t   True(   R   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_is_value_in_trusted_range   s
    c         C   sÃ   |  d j  d ƒ t k s t ‚ |  d j  d	 ƒ t k s> t ‚ |  d j  d
 ƒ t k s] t ‚ |  d j  d ƒ t k s| t ‚ |  d j  d ƒ t k s› t ‚ |  d j  d ƒ t k sº t ‚ d GHd S(   s9   Check points are either inside or outside detector range.i    iÿÿÿÿi   i   i  R   N(   iÿÿÿÿi   (   i   i   (   i   i   (   i   iÿÿÿÿ(   i   i   (   i   i  (   t   is_coord_validR   R   R   (   R   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_is_coord_valid'   s    c            s%  d d l  m } d d l m ‰ d } |  d j ƒ  \ ‰ ‰  ‡  ‡ ‡ f d †  ‰ t j ‡ f d †  t d ƒ Dƒ ƒ } |  d j | ƒ } |  d j | ƒ } t	 | | d	 | ƒs· t
 ‚ xb | D]Z } |  d j | ƒ } |  d j | ƒ } t | j | ƒ | j | ƒ ƒ | k  s¾ t
 ‚ q¾ Wd
 GHd  S(   Niÿÿÿÿ(   R   (   t   randomgH¯¼šò×z>i    c              s   ˆ ƒ  ˆ ˆ ƒ  ˆ  f S(   N(    (    (   t   hR    t   w(    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   <lambda>9   s    c         3   s   |  ] } ˆ  ƒ  Vq d  S(   N(    (   t   .0t   i(   t   random_pixel(    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pys	   <genexpr>:   s    id   R   R   (   R   R   R    t   get_image_sizeR   t   vec2_doublet   ranget   pixel_to_millimetert   millimeter_to_pixelR   R   R	   R
   (   R   R   R   t   pixelst   xy_mmt   xy_pxt   xy(    (   R!   R    R&   R"   sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt    tst_pixel_to_millimeter_to_pixel1   s    %2c            s¬   d d l  m ‰  d d l m } ‡  f d †  } xq t d ƒ D]c } | ƒ  } |  d j | ƒ } |  d j | ƒ } t | j | ƒ | j | ƒ ƒ d k  s< t	 ‚ q< Wd GHd  S(	   Niÿÿÿÿ(   t   uniform(   R   c              s   ˆ  d d ƒ ˆ  d d ƒ f S(   Niüÿÿiè  (    (    (   R1   (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyR#   I   s    i'  i    gü©ñÒMbP?R   (
   R    R1   R   R   R)   R+   R*   R	   R
   R   (   R   R   t   random_coordR%   t   mmt   pxt   mm2(    (   R1   sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_parallax_correctionF   s    	2c         C   sC   |  j  ƒ  } t | ƒ d k s$ t ‚ | d d k s: t ‚ d GHd  S(   Ni   i    R   R   (   t	   get_namest   lenR   (   R   t   names(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_get_namesT   s    c         C   sz  d d l  m } d d l m } d } |  d } | j | j ƒ  ƒ } | j | j ƒ  ƒ } | j | j ƒ  ƒ } | j ƒ  } d | | d | | d d | | d }	 | |	 j	 ƒ  | ƒ }
 | j | j
 |
 j ƒ  ƒ ƒ } | j d ƒ } | | } t t | ƒ ƒ } d d l m } | |  |
 | ƒ | j | j
 |
 j ƒ  ƒ ƒ | j t t | ƒ ƒ ƒ j ƒ  d	 k  sqt ‚ d
 GHd  S(   Niÿÿÿÿ(   R   (   t   Beami   i    g      ð?g      à?(   t   set_mosflm_beam_centreg�íµ ÷Æ°>R   (   i   g      à?(   R   R   t   dxtbx.modelR;   R
   R   t   get_fast_axist   get_slow_axisR   t	   normalizet   get_beam_centret   get_s0t   tuplet   reversedt   dxtbx.model.detector_helpersR<   t   lengthR   (   R   R   R;   t
   wavelengtht   panelt   origint	   fast_axist	   slow_axist
   image_sizet   s0t   beamt   beam_centret   origin_shiftt   new_beam_centret   new_mosflm_beam_centreR<   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_set_mosflm_beam_centreZ   s(    
'
.c          C   sö   d d l  m }  t t d d d d d d d d ƒ ƒ } t | ƒ t | ƒ t | ƒ t | ƒ t | ƒ t	 | ƒ t
 | ƒ d d l m } | j d ƒ } | j d ƒ d } d } t t d d d d d d d d |  | | ƒ ƒ	 ƒ } t | ƒ d  S(   Niÿÿÿÿ(   t   ParallaxCorrectedPxMmStrategyt    R   i
   i    iÈ   gj¼t“Æ?i   iè  (   t   attenuation_coefficientt   Sii   g{®GázÔ?(   i
   i    i    (   i    i
   i    (   i    i    iÈ   (   gj¼t“Æ?gj¼t“Æ?(   i   i   (   i    iè  (   i
   i    i    (   i    i
   i    (   i    i    iÈ   (   gj¼t“Æ?gj¼t“Æ?(   i   i   (   i    iè  (   R=   RT   R   R   RS   R   R   R   R   R0   R:   t   cctbx.eltbxRV   t	   get_tablet   mu_at_angstromR6   (   RT   R   RV   t   tablet   mut   t0(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   tst_detectorw   s@    






c           C   s   t  ƒ  d  S(   N(   R^   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   run¢   s    t   __main__N(   t
   __future__R    R=   R   R   t   libtbx.test_utilsR   t   scitbx.array_familyR   R   R   R   R   R0   R6   R:   RS   R^   R_   t   __name__(    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/tests/model/tst_detector.pyt   <module>   s   					
					+	