ó
û™xTc           @   s‡   d  d l  m Z d  d l Z d  d l m Z d e f d „  ƒ  YZ e d k rƒ d  d l Z x& e j d D] Z	 e j
 e	 ƒ GHqh Wn  d S(   iÿÿÿÿ(   t   divisionN(   t	   FormatSMVt   FormatSMVADSCc           B   s\   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   sn   A class for reading SMV format ADSC images, and correctly constructing
  a model for the experiment from this.c      
   C   sˆ   t  j |  ƒ \ } } d d d d d d d d d	 d
 g
 } x | D] } | | k r@ d Sq@ Wd g } x | D] } | | k rj t Sqj Wt S(   sí   Check to see if this looks like an ADSC SMV 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 and not some we are not (i.e. that belong
    to a Rigaku Saturn.)t   BEAM_CENTER_Xt   BEAM_CENTER_Yt   DISTANCEt
   WAVELENGTHt
   PIXEL_SIZEt	   OSC_STARTt	   OSC_RANGEt   SIZE1t   SIZE2t
   BYTE_ORDERi    t   DTREK_DATE_TIME(   R   t   get_smv_headert   Falset   True(   t
   image_filet   sizet   headert   wanted_header_itemst   header_itemt   unwanted_header_items(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.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   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyR   /   s    c         C   sb   t  j |  ƒ t |  d ƒ s, |  j d  k r^ d d l m } | |  j ƒ |  _ |  j j ƒ  n  d  S(   Nt   detectorbaseiÿÿÿÿ(   t   SMVImage(	   R   t   _startt   hasattrR   t   Nonet   iotbx.detectorsR   t   _image_filet
   readHeader(   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyR   9   s
    c         C   s   |  j  j ƒ  S(   sq   Return a model for a simple single-axis goniometer. This should
    probably be checked against the image header.(   t   _goniometer_factoryt   single_axis(   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyt   _goniometerB   s    c      
   C   s¸   t  |  j d ƒ } t  |  j d ƒ } t  |  j d ƒ } t  |  j d ƒ } t  |  j d ƒ t  |  j d ƒ f } d } d } |  j j d	 | | | f d
 d | | f | | | f g  ƒ	 S(   s­   Return a model for a simple detector, presuming no one has
    one of these on a two-theta stage. Assert that the beam centre is
    provided in the Mosflm coordinate frame.R   R   R   R   R
   R   iÿÿ  i   t   CCDs   +xs   -y(   t   floatt   _header_dictionaryt   _detector_factoryt   simple(   R   t   distancet   beam_xt   beam_yt
   pixel_sizet
   image_sizet   overloadt	   underload(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyt	   _detectorH   s    	c         C   s#   t  |  j d ƒ } |  j j | ƒ S(   s#   Return a simple model for the beam.R   (   R'   R(   t   _beam_factoryR*   (   R   t
   wavelength(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyt   _beamZ   s    c   	      C   s  |  j  j d ƒ } t |  j d ƒ } d } d } y/ |  j d } | j d d ƒ j d d ƒ } Wn t k
 r{ } d } n XxJ d d	 g D]< } y  t j t j	 | | ƒ ƒ } PWq‰ t
 k
 rÄ } q‰ Xq‰ Wt |  j d
 ƒ } t |  j d ƒ } |  j  j |  j | | | | | ƒ S(   s+   Return the scan information for this image.t   SMVt   TIMEi    t   DATEt   PSTt    t   PDTs   %a %b %d %H:%M:%S %Ys   %a %b %d %H:%M:%S %Z %YR   R	   N(   t   _scan_factoryt   formatR'   R(   R   t   replacet   KeyErrort   timet   mktimet   strptimet
   ValueErrort   singleR!   (	   R   R=   t   exposure_timet   epocht   date_strt   et   format_stringt	   osc_startt	   osc_range(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyt   _scana   s(    "
	c         C   sN  d d l  m } d d l m } m } m } d d l m } t |  j	 ƒ  ƒ d k sZ t
 ‚ |  j	 ƒ  d } | j ƒ  } t j |  j d ƒ } | j |  j ƒ |  j d d	 k r· t }	 n t }	 |	 | ƒ  k rö | | | ƒ t | d | d ƒ ƒ }
 n' | | | ƒ t | d | d ƒ ƒ }
 | j ƒ  } |
 j | j | d | d ƒ ƒ |
 S(
   s[   Get the pixel intensities (i.e. read the image and return as a
    flex array of integers.)iÿÿÿÿ(   t	   streambuf(   t   read_uint16t   read_uint16_bst   is_big_endian(   t   flexi   i    t   rbR   t
   big_endian(   t   boost.pythonRM   t   dxtbxRN   RO   RP   t   scitbx.array_familyRQ   t   lent   get_detectorR   t   get_image_sizeR   t	   open_fileR!   t   readt   _header_sizeR(   R   R   t   intt   reshapet   grid(   R   RM   RN   RO   RP   RQ   t   panelR   t   fRS   t   raw_dataR/   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyt   get_raw_data   s"    	*'!(   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R%   R2   R5   RL   Rc   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyR      s   	
						t   __main__i   (   t
   __future__R    R@   t   dxtbx.format.FormatSMVR   R   Rd   t   syst   argvt   argR   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVADSC.pyt   <module>   s   Š