ó
û™xTc           @   s«   d  d l  m Z d  d l m Z d  d l m Z d  d l m 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 ƒ GHqŒ Wn  d	 S(   iÿÿÿÿ(   t   division(   t   FormatCBFMini(   t   get_pilatus_timestamp(   t   determine_pilatus_mask(   t   ParallaxCorrectedPxMmStrategyt   FormatCBFMiniPilatusc           B   sS   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sv   A class for reading mini CBF format Pilatus images, and correctly
  constructing a model for the experiment from this.c         C   s�   t  j |  ƒ } x‡ | j d ƒ D]v } d | k rA d | k rA t Sd | k r] d | k r] t Sd | k ry d | k ry t Sd | k r d | k r t Sq Wt S(   sc   Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.s   
s   _array_data.header_conventiont   PILATUSt   SLSt   ?s
   # Detector(   R   t   get_cbf_headert   splitt   Truet   False(   t
   image_filet   headert   record(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.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   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyR   .   s    c         C   s@   t  j |  ƒ d d l m } | |  j ƒ |  _ |  j j ƒ  d  S(   Niÿÿÿÿ(   t   PilatusImage(   R   t   _startt   iotbx.detectors.pilatus_minicbfR   t   _image_filet   detectorbaset
   readHeader(   R   R   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyR   8   s    c         C   s<   d |  j  k r/ t |  j  d j ƒ  d ƒ } n  |  j j ƒ  S(   s¬   Return a model for a simple single-axis goniometer. This should
    probably be checked against the image header, though for miniCBF
    there are limited options for this.t   Phii    (   t   _cif_header_dictionaryt   floatR
   t   _goniometer_factoryt   single_axis(   R   t	   phi_value(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyt   _goniometer>   s     c         C   s  t  |  j d j ƒ  d ƒ } |  j d j d d ƒ j d d ƒ j d d ƒ j ƒ  d  } t  |  j d	 j ƒ  d ƒ } t t  | ƒ \ } } |  j d
 j d d ƒ j d d ƒ j ƒ  } t t  | ƒ \ } } t  |  j d j ƒ  d ƒ d }	 t |  j d ƒ }
 t |  j d ƒ } t |  j d j ƒ  d ƒ } d } d d l m } | j d ƒ } | j	 | ƒ d } |	 } |  j
 j d | d | | d | | d f d d d | d | f |
 | f | | f g  t | | ƒ ƒ
 } x: t | ƒ D], \ } } } } | d j | | | | ƒ qãW| 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.t   Detector_distancei    t   Beam_xyt   (t    t   )t   ,i   t
   Wavelengtht
   Pixel_sizet   mt   xt   Silicong     @�@s   X-Binary-Size-Fastest-Dimensions   X-Binary-Size-Second-Dimensiont   Count_cutoffiÿÿÿÿ(   t   attenuation_coefficientt   Sig      $@t   PADs   +xs   -yiè  (   R   R   R
   t   replacet   mapt   intt   cctbx.eltbxR-   t	   get_tablet   mu_at_angstromt   _detector_factoryt   simpleR   R   t   add_mask(   R   t   distancet   beam_xyt
   wavelengtht   beam_xt   beam_yt   pixel_xyt   pixel_xt   pixel_yt	   thicknesst   nxt   nyt   overloadt	   underloadR-   t   tablet   mut   t0t   detectort   f0t   s0t   f1t   s1(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyt	   _detectorJ   s@    .	c         C   s-   t  |  j d j ƒ  d ƒ } |  j j | ƒ S(   s#   Return a simple model for the beam.R'   i    (   R   R   R
   t   _beam_factoryR7   (   R   R;   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyt   _beam�   s    c         C   sž   |  j  j d ƒ } t |  j d j ƒ  d ƒ } t |  j d j ƒ  d ƒ } t |  j d j ƒ  d ƒ } t |  j d ƒ } |  j  j |  j | | | | | ƒ S(   s+   Return the scan information for this image.t   CBFt   Exposure_periodi    t   Start_anglet   Angle_incrementt	   timestamp(   t   _scan_factoryt   formatR   R   R
   R   t   singleR   (   R   RW   t   exposure_timet	   osc_startt	   osc_rangeRU   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyt   _scan‰   s    	(   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R    RN   RP   R\   (    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyR      s   	
			7	t   __main__Ni   (   t
   __future__R    t   dxtbx.format.FormatCBFMiniR   t(   dxtbx.format.FormatCBFMiniPilatusHelpersR   t!   dxtbx.format.FormatPilatusHelpersR   t   dxtbx.modelR   R   R]   t   syst   argvt   argR   (    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBFMiniPilatus.pyt   <module>   s   Š