ó
ú™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   FormatSMVRigakut   FormatSMVRigakuPilatus200Lc           B   s\   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   s:   A class for reading SMV format Rigaku Pilatus 200L images.c         C   s=   t  j |  ƒ \ } } d | k r% t S| d d k r9 t St S(   s¹   Check to see if this looks like a Rigaku d*TREK SMVRigaku format image,
    i.e. we can make sense of it. Essentially that will be if it contains
    all of the keys we are looking for.t   DETECTOR_TYPEs   Pilatus 200K(   R   t   get_smv_headert   Falset   True(   t
   image_filet   sizet   header(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt
   understand   s    c         C   s)   |  j  | ƒ s t ‚ t j |  | ƒ d S(   sc   Initialise the image structure from the given file, including a
    proper model of the experiment.N(   R
   t   AssertionErrorR   t   __init__(   t   selfR   (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyR   "   s    c         C   s   t  j |  ƒ d  S(   N(   R   t   _start(   R   (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyR   *   s    c         C   s2   t  t t |  j d j ƒ  ƒ ƒ } |  j j | ƒ S(   sE  Initialize the structure for the goniometer - this will need to
    correctly compose the axes given in the image header. In this case
    this is made rather straightforward as the image header has the
    calculated rotation axis stored in it. We could work from the
    rest of the header and construct a goniometer model.t   ROTATION_VECTOR(   t   tuplet   mapt   floatt   _header_dictionaryt   splitt   _goniometer_factoryt
   known_axis(   R   t   axis(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt   _goniometer.   s    c         C   s_  d d l  m } |  j d j ƒ  d j ƒ  } t t |  j d | j ƒ  ƒ } | j t | d  ƒ ƒ } | j t | d ƒ ƒ } t t	 |  j d | j ƒ  ƒ } | d | | d | | d	 | | d | } } t t |  j d
 | j ƒ  d	  ƒ }	 t t |  j d
 | j ƒ  d	 ƒ }
 t t	 |  j d | j ƒ  ƒ } |	 d |
 d | |	 d |
 d | } t t |  j d | j ƒ  ƒ } t t |  j d | j ƒ  ƒ } |  j d | j ƒ  } t	 |  j d | ƒ } g  } g  } xÈ t
 | ƒ D]º \ } } | j | d | d | d !ƒ } | d k ra| j | j | | d t ƒƒ | j | j d ƒ ƒ qî| d k r›| j | j d ƒ ƒ | j | | | ƒ qît d | ‚ qîW| j ƒ  | j ƒ  xL t | ƒ D]> } | | | } | | | } | | | } | | | } qÍWt	 t |  j d ƒ ƒ } d } |  j j d | j | j | j |
 | | | f ƒ S(   s‚   Return a model for the detector, allowing for two-theta offsets
    and the detector position. This will be rather more complex...iÿÿÿÿ(   t   matrixt   DETECTOR_NAMESi    s   %sDETECTOR_VECTORSi   s   %sSPATIAL_DISTORTION_VECTORSi   i   s   %sSPATIAL_DISTORTION_INFOs   %sDETECTOR_DIMENSIONSs   %sGONIO_VECTORSs   %sGONIO_VALUESs   %sGONIO_UNITSs   %sGONIO_NUM_VALUESt   degg        t   mmg      ð?s   unknown axis unit %st   SATURATED_VALUEt   PAD(   g        g        g        (	   g      ð?g        g        g        g      ð?g        g        g        g      ð?(   t   scitbxR   R   R   t   stripR   R   t   colR   t   intt	   enumeratet   appendt$   axis_and_angle_as_r3_rotation_matrixR   t   sqrt   RuntimeErrort   reverset   ranget   _detector_factoryt   complext   elems(   R   R   t   detector_namet   detector_axest   fastt   slowt
   distortiont   detector_fastt   detector_slowt   beam_pixelst
   pixel_sizet
   image_sizet   detector_origint
   gonio_axest   gonio_valuest   gonio_unitst   gonio_num_axest	   rotationst   translationst   jt   unitR   t   overloadt	   underload(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt	   _detector:   sj    	" 


	c         C   s|   t  t |  j d j ƒ  d  ƒ } t  t |  j d j ƒ  ƒ } | d } | d } t |  j d ƒ } |  j j | | | | ƒ S(   s#   Return a simple model for the beam.t   SOURCE_VECTORSi   t   SOURCE_POLARZi    i   t   SCAN_WAVELENGTH(   R   R   R   R   t   _beam_factoryR+   (   R   t   beam_directiont   polarizationt
   p_fractiont   p_planet
   wavelength(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt   _beam…   s    

	c         C   sœ   d d l  } t t |  j d j ƒ  ƒ } |  j j d ƒ } | j | j |  j d d ƒ ƒ } | d } | d } | d	 } |  j j	 |  j
 | | | | | ƒ S(
   s+   Return the scan information for this image.iÿÿÿÿNt   ROTATIONt   SMVt   DTREK_DATE_TIMEs   %d-%b-%Y %H:%M:%Si   i    i   (   t   timeR   R   R   R   t   _scan_factoryt   formatt   mktimet   strptimet   singlet   _image_file(   R   RP   t   rotationRR   t   epocht   exposure_timet	   osc_startt	   osc_range(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt   _scan–   s    


	c         C   sÜ   d d l  m } d d l m } d d l m } t |  j ƒ  ƒ d k sN t ‚ |  j ƒ  d j	 ƒ  } |  j
 |  j ƒ } | j t |  j d ƒ ƒ | | | ƒ t | d | d ƒ ƒ } | j | j | d | d ƒ ƒ | S(   sY   Read the data - assuming it is streaming 4-byte unsigned ints following the
    header...iÿÿÿÿ(   t	   streambuf(   t
   read_int32(   t   flexi   i    t   HEADER_BYTES(   t   boost.pythonR]   t   dxtbxR^   t   scitbx.array_familyR_   t   lent   get_detectorR   t   get_image_sizet	   open_fileRV   t   readR"   R   t   reshapet   grid(   R   R]   R^   R_   R   t   ft   raw_data(    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt   get_raw_dataª   s    '!(   t   __name__t
   __module__t   __doc__t   staticmethodR
   R   R   R   RB   RL   R\   Rm   (    (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyR      s   				K		t   __main__Ni   (
   t
   __future__R    t   dxtbx.format.FormatSMVRigakuR   R   Rn   t   syst   argvt   argR
   (    (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuPilatus200L.pyt   <module>   s   ¬