ó
þ™xTc           @   s:   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   Formatt	   FormatSMVc           B   s>   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z RS(   s†  An image reading class for SMV format images i.e. those from ADSC and
  Rigaku which start with:

  {
  HEADER_BYTES=  512;

  and contain a list of keyword-value pairs thereafter which define the
  header. The keywords etc. for these will depend on the instrument
  manufacturer and will be interpreted by subclasses of this class. Note
  also that every line is finished with a semicolon.c         C   s)   t  j |  d ƒ j d ƒ d k r% t St S(   sV   Check to see if this looks like an SMV format image, i.e. we can
    make sense of it.t   rbi   s   {
HEADER_BYTES=(   R   t	   open_filet   readt   Truet   False(   t
   image_file(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMV.pyt
   understand   s    	c         C   së   t  t j |  d ƒ j d ƒ j d ƒ d j d ƒ d j d d ƒ j ƒ  ƒ } t j |  d ƒ j | ƒ } i  } xp | j d ƒ D]_ } | d k r” Pn  d | k r¦ q~ n  | j d d ƒ j d ƒ \ } } | j ƒ  | | j ƒ  <q~ W| | f S(	   NR   i-   s   
i   t   =t   ;t    t   }(   t   intR   R   R   t   splitt   replacet   strip(   R   t   header_sizet   header_textt   header_dictionaryt   recordt   keyt   value(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMV.pyt   get_smv_header)   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   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMV.pyR   A   s    c         C   s"   t  j |  j ƒ \ |  _ |  _ d S(   sÂ   Open the image file, read the image header, copy the key / value
    pairs into an internal dictionary self._header_dictionary along with
    the length of the header in bytes self._header_size.N(   R   R   t   _image_filet   _header_sizet   _header_dictionary(   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMV.pyt   _startJ   s    (   t   __name__t
   __module__t   __doc__t   staticmethodR	   R   R   R   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMV.pyR      s
   
		N(   t
   __future__R    t   dxtbx.format.FormatR   R   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMV.pyt   <module>   s   