ó
~xTc           @   s'   d  d l  m Z d d d     YZ d S(   i˙˙˙˙(   t   divisiont   readerc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s9   A class to read the X/Y-CORRECTIONS.CBF files used in XDSc         C   s   d  S(   N(    (   t   self(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/correction.pyt   __init__   s    c         C   sB   d d l  } | j   |  _ |  j j | | j  |  j j   d S(   s   Read the CBF correction filei˙˙˙˙N(   t   pycbft   cbf_handle_structt
   cbf_handlet	   read_filet
   MSG_DIGESTt   rewind_datablock(   R   t   filenameR   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/correction.pyR      s    c         C   sÓ   d d l  } |  j j d  |  j j d  |  j j d  |  j j d  |  j j   } | j d  d k rĂ |  j j   } | j	 | | j
  } |  j j   } | d | d f } | | _ n t d   | S(	   s&   Get the correction array from the filei˙˙˙˙Ni    i   t   bnryi
   i	   s   Can't find image(   t   numpyR   t   select_datablockt   select_categoryt   select_columnt
   select_rowt   get_typeofvaluet   findt   get_integerarray_as_stringt
   fromstringt   int32t    get_integerarrayparameters_wdimst   shapet	   TypeError(   R   R   t   typet   image_stringt   imaget
   parameterst
   image_size(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/correction.pyt   get_correction_array   s    c   	      C   s  d d l  } |  j   } | j d d | d k  sN | j d d | d k  r] t d   n  | j | d | j } | j t | d  g | d d | j } | j t | d  g | d d | j j	   } | j
 | d  } | j
 | d  } | | | f d | | | f <| S(	   s!   Get the correction at each pixel.i˙˙˙˙Ni    i   i   s   Dimensions are incompatiblet   dtypeg      $@(   R   R   R   t
   ValueErrort   zerost   float64t   arrayt   rangeR   t	   transposet   divide(	   R   t   dimR   t	   raw_arrayt
   correctiont   i1t   j1t   i2t   j2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/correction.pyt   get_correction7   s    6-3(   t   __name__t
   __module__t   __doc__R   R   R   R.   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/correction.pyR      s
   			 N(    (   t
   __future__R    R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/correction.pyt   <module>	   s   