ó
z™xTc           @   s   d  d l  m Z d  d l Z d  d l m Z d „  Z d d d „  ƒ  YZ e d k rü d  d l Z e e j	 d ƒ Z
 e
 j ƒ  e
 j ƒ  d	 j e
 j ƒ GHe
 j GHd
 Z xS e e
 j d ƒ D]; Z x1 e e
 j d ƒ D] Z e
 j e GHe d 7Z qÔ WHqº Wn  d S(   iÿÿÿÿ(   t   divisionN(   t   flexc         C   s   t  |  d ƒ S(   Nt   rb(   t   open(   t   filename(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/edf.pyt   file_object_from_file_name   s    t   EDFImagec           B   s&   e  Z d  „  Z d d „ Z d „  Z RS(   c         C   sF   t  | ƒ |  _ d |  _ d d g |  _ i  |  _ g  |  _ d  |  _ d  S(   Ni    (   R   t   objt
   headersizet   data_dimensiont
   parameterst   headert   Nonet   linearintdata(   t   selfR   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/edf.pyt   __init__	   s    			c         C   s{  d } |  j  j d ƒ xŒ t r¤ |  j  j d ƒ } t | ƒ d k sI t ‚ | d k rw t |  j d ƒ d k sw t ‚ n  |  j j | ƒ | d k r— Pn  | d 7} q W|  j  j d ƒ d k sÃ t ‚ d t |  j ƒ |  _	 |  j	 d d k sò t ‚ d j
 |  j d ƒ } | j d ƒ } xp | D]h } | j ƒ  } | j d	 ƒ d k  rKqn  | j d	 ƒ \ } }	 | j ƒ  |	 j ƒ  } }	 |	 |  j | <qWxL d
 d d d d g D]5 }
 |  j j |
 ƒ r t |  j |
 ƒ |  j |
 <q q Wx@ d g D]5 }
 |  j j |
 ƒ rãt |  j |
 ƒ |  j |
 <qãqãWi d d 6d d 6d d 6|  j d |  _ |  j d |  j d |  j d |  j k swt ‚ d  S(   Ni    i   i{   t   }s   
i   t    t   ;t   =t   runt   Imaget   Sizet   Dim_1t   Dim_2t
   count_timei   t   SignedIntegeri   t   UnsignedShortt   Floatt   DataType(   R   t   seekt   Truet   readt   ordt   AssertionErrorR   t   appendt   lenR   t   joint   splitt   stript   findR
   t   has_keyt   intt   floatt	   type_size(   R   t   external_keyst   ptrt   newchrt
   headertextt   headerpairst   pairt   baret   keyt   valuet	   attribute(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/edf.pyt
   readHeader   s>    	 "  !!)c         C   s-  |  j  j |  j ƒ i d d 6d d 6|  j d } i d d 6d d	 6d
 d 6d d 6|  j d } |  j d d k s~ d s~ t ‚ |  j  j |  j d ƒ } t j | | |  j d |  j d | ƒ } | d k rê t j	 | ƒ j
 ƒ  |  _ n t j | ƒ |  _ |  j j t j |  j d |  j d f ƒ ƒ d  S(   Nt   <t   LowByteFirstt   >t   HighByteFirstt	   ByteOrdert   iR   t   It   UnsignedIntegert   HR   t   fR   R   R   R   R   (   R   R   R   R
   R"   R    t   structt   unpackR   t   doublet   iroundR   R*   t   reshapet   grid(   R   t   endian_codet	   type_codet   rawdatat   uncoded_data(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/edf.pyR    6   s    -,N(   t   __name__t
   __module__R   R   R7   R    (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/edf.pyR      s   	%t   __main__i   R   i    R   R   (    (   t
   __future__R    RB   t   scitbx.array_familyR   R   R   RL   t   syst   argvt   PR7   R    R%   R   R
   t   countt   xranget   iit   jjR   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/edf.pyt   <module>   s"   	?

