ó
w™xTc           @   s~   d  d l  m Z d  d l Z d  d l Z d  d l m Z d e f d „  ƒ  YZ e d k rz d Z e e ƒ Z	 e	 j
 ƒ  GHn  d S(   iÿÿÿÿ(   t   divisionN(   t   DetectorImageBaset   MARImagec           B   sJ   e  Z d  „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   c         C   sr   t  j |  | ƒ d |  _ t t |  j d ƒ j d ƒ ƒ } | d k rR d |  _ n	 d |  _ |  j ƒ  sn t	 ‚ d  S(   Nt   MARCCDt   rbi   t   IIi    i   (
   R   t   __init__t
   vendortypet   strt   opent   filenamet   readt   endiant   isCompressedt   AssertionError(   t   selfR
   t
   byte_order(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyR      s    	!	c   	      C   sÒ  |  j  ƒ  r d } n d } t |  j d ƒ } z�| j d ƒ | j d ƒ } t j | d | ƒ d } xD| r¬| j | ƒ | j d ƒ } t j | d | ƒ d } x¿ t | ƒ D]± } | j | | d	 d ƒ | j d ƒ } t j | d | ƒ d } | d
 k r² | j | | d	 d d ƒ | j d ƒ } t j | d | ƒ d } | d k r\d Sd Sq² q² W| j | | d	 d ƒ | j d ƒ } t j | d | ƒ d } qi WWd  | j ƒ  Xd d k sÎt	 ‚ d  S(   Nt   >t   <R   i   t   ii    i   t   hi   i  i   i   (
   t	   getEndianR	   R
   t   seekR   t   structt   unpackt   ranget   closeR   (	   R   t   formatt   ft   rawdatat   ifdt
   numentriest   xt   tagt   value(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyR      s8     		"c         C   s   |  j  S(   N(   R   (   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyR   A   s    i   c         C   s$  |  j  s |  j ƒ  r d } n d } t |  j d ƒ } zÆ| j d ƒ | j d ƒ } i  } xv d5 g D]k } t j | d d	 d
 ƒ } | j | ƒ } t	 | ƒ d k rÂ t
 | d ƒ | | d <qe d | | d <qe W| j | d ƒ | j d ƒ }	 t j | d |	 ƒ \ }
 } | j | d ƒ | j d ƒ }	 t j | d |	 ƒ \ | d <| d <| d | d k snt ‚ | j | d ƒ | j d ƒ }	 t j | d |	 ƒ d |  _ | j | d ƒ | j d ƒ }	 t j | d |	 ƒ d | d <| j | d ƒ | j d ƒ }	 t j | d |	 ƒ \ } } } | j | d ƒ | j d ƒ }	 t j | d |	 ƒ d d } | j | d ƒ | j d ƒ }	 t j | d |	 ƒ d d } | | d <| j | d ƒ | j d ƒ }	 t j | d |	 ƒ \ } } | | k süt ‚ | d  | d! <| j | d" ƒ | j d ƒ }	 t j | d |	 ƒ \ } } | d | d! | d# <| d | d! | d$ <| j | d% ƒ | j d ƒ }	 t j | d |	 ƒ d d | d& <| j | d' ƒ | j d ƒ }	 t j | d |	 ƒ d d } | j | d( ƒ | j d ƒ }	 t j | d |	 ƒ d d } | | d) <| j | d* ƒ | j d ƒ }	 t j | d |	 ƒ d } | j | d+ ƒ | j d ƒ }	 t j | d |	 ƒ d d | d, <| j | d- ƒ | j d ƒ }	 t j | d |	 ƒ d d | d. <| d k rn | d k r$| d, | d& <n  | j | d/ ƒ | j d ƒ }	 t j | d |	 ƒ d d } | j | d0 ƒ | j d ƒ }	 t j | d |	 ƒ d d } | | k |  _ | | d1 <| j | d2 ƒ | j d ƒ }	 t j | d |	 ƒ d d3 | d4 <Wd  | j ƒ  X| |  _  |  j ƒ  n  d  S(6   NR   R   R   i 	  i   s   Detector Serial Numbert   DETECTOR_SNi    s    = s   (.*)iÿÿÿÿi   i   i   t   iiiP   t   SIZE1t   SIZE2iX   i   R   ih   t   CCD_IMAGE_SATURATIONit   i   t   iiii¸  g     @�@iØ  t   DISTANCEi  g�íµ ÷Æ°>t
   PIXEL_SIZEi„  t   BEAM_CENTER_Xt   BEAM_CENTER_Yi¬  t	   OSC_STARTiÌ  ià  t	   OSC_RANGEiÜ  i   t   OMEGA_STARTiÀ  t	   OMEGA_ENDiœ  i¼  t   TWOTHETAiŒ  gñhãˆµøä>t
   WAVELENGTH(   s   Detector Serial NumberR#   (   t
   parametersR   R	   R
   R   R   t   ret   compilet   findallt   lent   intR   R   R   t   deptht   _assert_matching_twothetasR   t   _read_header_asserts(   R   t   offsetR   R   t   file_commentsR3   t   itemt   patternt   matchesR   t   header_byte_ordert   data_byte_ordert   origint   orientationt   view_directiont   start_xtal_to_detectort   end_xtal_to_detectort   pixelsize_xt   pixelsize_yt   beam_center_xt   beam_center_yt   end_phit   rotation_ranget   rotation_axist   start_twothetat   end_twotheta(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyt
   readHeaderD   sª    	 	$
"
""
&	c         C   s,   |  j  d d k s t ‚ |  j s( t ‚ d S(   sR    move a couple asserts here that aren't always desireable for un-initialized data R)   i    N(   R3   R   R:   (   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyR;   ½   s    c         C   s   d S(   Ni   (    (   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyt
   dataoffsetÂ   s    c         C   s   |  j  S(   N(   R9   (   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyt   integerdepthÅ   s    (	   t   __name__t
   __module__R   R   R   RQ   R;   RR   RS   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyR      s   		/	y		t   __main__s(   /net/racer/scratch1/ttleese/lyso201.0002(   t
   __future__R    R4   R   t   iotbx.detectors.detectorbaseR   R   RT   R   t   mR   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/mar.pyt   <module>   s   Ã