ó
ü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   FormatPYt   FormatPYunspecifiedc           B   sV   e  Z e d     Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   c         C   s|   y1 t  j |  d  } d d l } | j |  } Wn t k
 rG } t SXd d d g } x | D] } | | k r^ t Sq^ Wt S(   s4  Seems like the static method wastes a lot of effort here; it's not possible to
    just read the first few bytes; instead understand() reads the entire first data
    item in the file; an entire binary image.  This data is then read again in the
    _start() method and again in the detectorbase constructor.t   rbi˙˙˙˙Nt   SIZE1t   SIZE2t	   TIMESTAMP(   R   t	   open_filet   cPicklet   loadt   IOErrort   Falset   True(   t
   image_filet   streamt   picklet   datat   et   wanted_header_itemst   header_item(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt
   understand   s    c         C   s)   |  j  |  s t  t j |  |  d S(   s3   Initialise the image structure from the given file.N(   R   t   AssertionErrorR   t   __init__(   t   selfR   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyR      s    c         C   sá   t  j |  j d  } d d  l } | j |  } d | k rp d |  _ d | k r} | d d k r} d |  _ q} n | d |  _ d d l m } | | d	  d
 |  _ d d l m	 } | |  j |  j  } |  j
 d d |  d  S(   NR   i˙˙˙˙t   DETECTOR_ADDRESSs   CxiDs1-0|Cspad-0t   DISTANCEič  s   CxiDsd-0|Cspad-0(   t   reverse_timestampR   i    (   t   detector_format_versiont   version_tokens    distl.detector_format_version=%s(   R   R   t   _image_fileR   R	   t   LCLS_detector_addresst   xfel.detector_formatsR   t   _timesecR   t   start_helper(   R   R   R   R   R   t   detector_format_functiont   version_lookup(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt   _start#   s    	c   
      C   sú   d d l  m } d d l m } d d  l } d d  l } |  j | d d g } | j |  } | j j	 } t
 |  j t  rĄ | j j |  j  rĄ | |  j  }	 n  d GH| |  j d | j j }	 |	 j |  |	 j |  | j |  |	 _ |	 |  _ d  S(   Ni˙˙˙˙(   t   cxi_phil(   t   NpyImages   viewer.powder_arcs.show=Falses   viewer.powder_arcs.code=3n9csH   This is not a file; assume the data are in the defined dictionary formatt   source_data(   t   spotfinder.applications.xfelR%   t   iotbx.detectors.npyR&   t   ost   copyR   t   cxi_versioned_extractt   persistt   commandst
   isinstancet
   basestringt   patht   isfilet   indexingR   t
   readHeadert   translate_tilest   deepcopyt   horizons_phil_cachet   detectorbase(
   R   R   R%   R&   R*   R+   t   argst   paramst   horizons_philt   I(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyR!   7   s"    	'c         C   s   |  j  j   S(   N(   t   _goniometer_factoryt   single_axis(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt   _goniometerO   s    c         C   s   |  j  j d d d |  j j d |  j j |  j j f d d d d d	 |  j j |  j j f d
 |  j j |  j j f d d |  j j	 f d g   	S(   s$   Return a model for a simple detectort   sensort   PADt   distancet   beam_centret   fast_directions   +xt   slow_directions   -yt
   pixel_sizet
   image_sizet   trusted_rangei    t   mask(
   t   _detector_factoryt   simpleR8   RB   t   beamxt   beamyRF   t   size2t   size1t
   saturation(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt	   _detectorS   s    			c         C   s   |  j  j |  j j  S(   s#   Return a simple model for the beam.(   t   _beam_factoryRK   R8   t
   wavelength(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt   _beamd   s    c         C   sÍ   |  j  j d k	 r |  j  j d k	 r |  j  j d k r d } |  j  j j d d  } |  j  j } |  j  j } |  j } |  j j |  j	 | | | | |  S|  j j
 d d d d g d d d
 i |  j d 6 Sd S(   s+   Return the scan information for this image.i    t    t   TIMEi   t   image_ranget   exposure_timesg      đ?t   oscillationg        t   epochsN(   i   i   (   g        g        (   R8   t	   osc_startt   Nonet   deltaphit
   parameterst   getR    t   _scan_factoryt   singleR   t	   make_scan(   R   t   formatt   exposure_timeR[   t	   osc_ranget	   timestamp(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt   _scani   s    $			(   t   __name__t
   __module__t   staticmethodR   R   R$   R!   R?   RQ   RT   Rg   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyR      s   						t   __main__Ni   (
   t
   __future__R    t   dxtbx.format.FormatPYR   R   Rh   t   syst   argvt   argR   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatPYunspecified.pyt   <module>   s   ~