ó
ù™xTc           @   s  d  d l  m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d e	 f d „  ƒ  YZ
 d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   divisiont
   ReaderBasec           B   s°   e  Z d  Z d „  Z d „  Z d d „ Z d d „ Z d d „ Z d d „ Z	 d d „ Z
 d d	 „ Z d d
 „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z RS(   s   The imageset reader base class.c         C   s   d  S(   N(    (   t   self(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __init__   s    c         C   s   d  S(   N(    (   R   t   other(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __cmp__   s    c         C   s   d  S(   N(    (   R   t   indices(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_image_paths   s    i    c         C   s   d  S(   N(    (   R   t   panel(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_image_size   s    c         C   s   d  S(   N(    (   R   t   index(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt
   get_format   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_format_class    s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_path#   s    c         C   s   d  S(   N(    (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   is_valid&   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   read)   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_detectorbase,   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_detector/   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_goniometer2   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_beam5   s    c         C   s   d  S(   N(    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_scan8   s    N(   t   __name__t
   __module__t   __doc__R   R   t   NoneR   R	   R   R   R   R   R   R   R   R   R   R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR      s   		t
   NullReaderc           B   s•   e  Z d  Z d „  Z d „  Z d d „ Z d d „ Z d d „ Z d d „ Z	 d d „ Z
 d „  Z d d	 „ Z d d
 „ Z d d „ Z d d „ Z RS(   s    A placeholder reader. c         C   s   t  j |  ƒ | |  _ d  S(   N(   R   R   t
   _filenames(   R   t	   filenames(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ?   s    c         C   s   t  | t ƒ S(   s    Compare with another reader. (   t
   isinstanceR   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   C   s    c         C   s&   | d k r t |  j ƒ S|  j | ƒ S(   s    Get the image paths. N(   R   t   listR   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   G   s    c         C   s   d S(   s    Get the format. N(   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   M   s    c         C   s   d S(   s    Get the format class. N(   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   Q   s    c         C   s"   | d k r |  j d S|  j | S(   s    Get an image path. i    N(   R   t   _pathR   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   U   s    c         C   s   t  S(   s%    Return whether the reader is valid. (   t   True(   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   [   s    c         C   s   t  d ƒ ‚ d  S(   Ns"   NullReader doesn't have image data(   t   RuntimeError(   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   _   s    c         C   s   t  d ƒ ‚ d S(   s   Get the detector instance.s%   NullReader doesn't have detector dataN(   R    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   b   s    c         C   s   t  d ƒ ‚ d S(   s   Get the beam instance.s!   NullReader doesn't have beam dataN(   R    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   f   s    c         C   s   t  d ƒ ‚ d S(   s   Get the goniometer instance.s'   NullReader doesn't have goniometer dataN(   R    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   j   s    c         C   s   t  d ƒ ‚ d S(   s   Get the scan instance.s!   NullReader doesn't have scan dataN(   R    (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   n   s    N(   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   <   s   			t   SingleFileReaderc           B   s¹   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d d „ Z	 d d „ Z
 d d „ Z d d	 „ Z d d
 „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z RS(   s   The single file reader class.c         C   s   t  j |  ƒ | |  _ d S(   s   Initialise the reader class.N(   R   R   t   _format(   R   t   format_instance(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   v   s    c         C   s   |  j  | j  k S(   s%   Compare the reader to another reader.(   R"   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   }   s    c         C   s   |  j  j |  j  j ƒ  f S(   N(   R"   t	   __class__t   get_image_file(   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __getstate__�   s    c         C   s   | d | d ƒ |  _  d  S(   Ni    i   (   R"   (   R   t   state(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __setstate__„   s    c         C   sc   g  t  |  j j ƒ  ƒ D] } |  j j | ƒ ^ q } | d k rD | Sg  | D] } | | ^ qK Sd S(   s$   Get the image paths within the file.N(   t   rangeR"   t   get_num_imagesR%   R   (   R   R   t   iR   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ‡   s
    1c         C   s   |  j  S(   s   Get the format instance(   R"   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ”   s    c         C   s
   |  j  j S(   s   Get the format class(   R"   R$   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ˜   s    c         C   s   |  j  j | ƒ S(   s'   Get the image file for the given index.(   R"   R%   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   œ   s    c         C   s   t  S(   s   Ensure the reader is valid.(   R   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR       s    c         C   s   |  j  j | ƒ S(   s   Get the image data.(   R"   t   get_raw_data(   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ¤   s    c         C   s   |  j  j | ƒ S(   s   Get the detector base instance.(   R"   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ¨   s    c         C   s   |  j  j | ƒ S(   s   Get the detector instance.(   R"   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ¬   s    c         C   s   |  j  j | ƒ S(   s   Get the beam instance.(   R"   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   °   s    c         C   s   |  j  j | ƒ S(   s   Get the goniometer instance.(   R"   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ´   s    c         C   s   |  j  j | ƒ S(   s   Get the scan instance.(   R"   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ¸   s    N(   R   R   R   R   R   R   R&   R(   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR!   s   s    			t   MultiFileStatec           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s1   A class to keep track of multi file reader state.c         C   s   | |  _  d |  _ d S(   s   Initialise with format class.N(   t   _format_classR   t   _current_format_instance(   R   t   format_class(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   À   s    	c         C   s   |  j  S(   s   Get the format class.(   R.   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR0   Å   s    c         C   se   |  j  ƒ  d k s* | |  j  ƒ  j ƒ  k ra |  j | ƒ } |  j | ƒ sU t d ƒ n  | |  _ n  d S(   s&   Load the file with the given filename.s   Format is invalid.N(   R   R   R%   R.   t   _is_format_validR    R/   (   R   t   filenameR#   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt	   load_fileÉ   s    c         C   s   |  j  S(   s    Get the current format instance.(   R/   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   Ú   s    c         C   s   | j  | j ƒ  ƒ S(   s$   Check if the format object is valid.(   t
   understandR%   (   R   R#   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR1   Þ   s    c         C   s<   |  j  d k	 r! |  j  j ƒ  } n d } i |  j d 6| d 6S(   s7    Save the current image and format class for pickling. R0   t   current_filenameN(   R/   R   R%   R.   (   R   R5   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR&   â   s
    c         C   s>   | d |  _  d |  _ | d d k	 r: |  j | d ƒ n  d S(   s*    Set the format class and load the image. R0   R5   N(   R.   R   R/   R3   (   R   R'   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR(   ë   s    	(
   R   R   R   R   R0   R3   R   R1   R&   R(   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR-   ½   s   							t   NullFormatCheckerc           B   s   e  Z d  „  Z RS(   c         C   s   t  S(   N(   R   (   R   t   fmt(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __call__ô   s    (   R   R   R8   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR6   ó   s   t   MultiFileReaderc           B   s¼   e  Z d  Z d d „ Z d „  Z d d „ Z d „  Z d d „ Z d d „ Z	 d d „ Z
 d d	 „ Z d d
 „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z RS(   s@   A multi file reader class implementing the ReaderBase interface.c         C   sƒ   t  j |  ƒ d d l } | d k s+ t ‚ t | ƒ d k sC t ‚ | |  _ t | ƒ |  _ | d k rs | |  _	 n t
 ƒ  |  _	 d S(   s<   Initialise the reader with the format and list of filenames.iÿÿÿÿNi    (   R   R   t   osR   t   AssertionErrort   lenR   R-   t   _stateR1   R6   (   R   R0   R   t   formatcheckerR:   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   û   s    	c         C   s.   |  j  ƒ  | j  ƒ  k o- |  j ƒ  | j ƒ  k S(   s5   Compare the reader by format class and filename list.(   R   R   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR     s    c         C   s;   | d k r t |  j ƒ Sg  | D] } |  j | ^ q  Sd S(   s   Get the list of image paths.N(   R   R   R   (   R   R   R+   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR     s    c         C   s   |  j  j ƒ  S(   s   Get the format class.(   R=   R0   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR     s    i    c         C   s   |  j  ƒ  j ƒ  | j ƒ  S(   s   Get the image size.(   R   R   R	   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR	   !  s    c         C   s+   | d k r |  j ƒ  j ƒ  S|  j | Sd S(   s   Get the path the given index.N(   R   R   R%   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   %  s    c         C   s   |  j  | ƒ j ƒ  S(   s.   Get the detector base instance at given index.(   R   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ,  s    c         C   s   |  j  | ƒ j ƒ  S(   s)   Get the detector instance at given index.(   R   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   0  s    c         C   s   |  j  | ƒ j ƒ  S(   s%   Get the beam instance at given index.(   R   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   4  s    c         C   s   |  j  | ƒ j ƒ  S(   s+   Get the goniometer instance at given index.(   R   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   8  s    c         C   s   |  j  | ƒ j ƒ  S(   s%   Get the scan instance at given index.(   R   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   <  s    c         C   sy   |  j  | ƒ } t | j ƒ  ƒ } | d k s3 t ‚ | d k rI | j ƒ  St g  t | ƒ D] } | j | ƒ ^ qY ƒ Sd S(   s(   Read the image frame at the given index.i    i   N(   R   R<   R   R;   R,   t   tupleR)   (   R   R
   R#   t   npanelsR+   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   @  s    
c         C   s   |  j  | ƒ j ƒ  S(   s"   Get the format at the given index.(   t   _update_stateR   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   O  s    c         C   s`   | d k	 r( |  j j |  j | ƒ ƒ n1 |  j j ƒ  d k rY |  j j |  j d ƒ ƒ n  |  j S(   s.   Update the state and load file at given index.i    N(   R   R=   R3   R   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRA   S  s
    c         C   s‚   d d l  } | d k r0 t t |  j ƒ ƒ } n  xK | D]C } y |  j | ƒ } Wn t k
 rf } t SX|  j | ƒ s7 t Sq7 Wt	 S(   s   Ensure imageset is valid.iÿÿÿÿN(
   R:   R   R)   R<   R   R   t
   IndexErrort   FalseR1   R   (   R   R   R:   R
   R#   R    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   \  s    N(   R   R   R   R   R   R   R   R   R	   R   R   R   R   R   R   R   R   RA   R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR9   ø   s    			t   ImageSetc           B   s  e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d e d
 „ Z d d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   s4    A class exposing the external image set interface. c         C   sy   | s t  d ƒ ‚ n  | |  _ | r0 | |  _ n! t t |  j ƒ  j ƒ  ƒ ƒ |  _ | d k rl t ƒ  |  _	 n	 | |  _	 d S(   s†    Initialise the ImageSet object.

    Params:
        reader The reader object
        array_range The image range (first, last)

    s   ImageSet needs a reader!N(
   t
   ValueErrort   _readert   _indicesR)   R<   t   readerR   R   t   dictt   _models(   R   RH   R   t   models(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   y  s    		!c         C   sS   t  | t ƒ r5 |  j | } t |  j ƒ  | |  j ƒ S|  j ƒ  j |  j | ƒ Sd S(   s`   Get an item from the image set stream.

    If the item is an index, read and return the image at the given index.
    Otherwise, if the item is a slice, then create a new ImageSet object
    with the given number of array indices from the slice.

    Params:
        item The index or slice

    Returns:
        An image or new ImageSet object

    N(   R   t   sliceRG   RD   RH   RJ   R   (   R   t   itemR   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __getitem__”  s    c         C   s   t  |  j ƒ S(   s0    Return the number of images in this image set. (   R<   RG   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __len__¨  s    c         C   s   t  |  j ƒ  ƒ S(   s8    Return the array indices of the image set as a string. (   t   strt   paths(   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __str__¬  s    c         c   s,   x% |  j  D] } |  j ƒ  j | ƒ Vq
 Wd S(   s=    Iterate over the array indices and read each image in turn. N(   RG   RH   R   (   R   t   f(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __iter__°  s    c         C   s   |  j  ƒ  | j  ƒ  k S(   s$    Compare this image set to another. (   RH   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   µ  s    c         C   s   t  |  j ƒ S(   s&    Return the indices in the image set. (   R   RG   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ¹  s    c         C   s0   |  j  ƒ  j ƒ  } g  |  j D] } | | ^ q S(   s4    Return a list of filenames referenced by this set. (   RH   R   RG   (   R   R   R+   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRQ   ½  s    c         C   s   |  j  ƒ  j |  j ƒ S(   sA    Validate all the images in the image set. Can take a long time. (   RH   R   RG   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   Â  s    c         C   sk  |  j  | ƒ } | |  j k r`i  } | s(|  j | ƒ } y |  j ƒ  j | ƒ | d <Wn t k
 rs d | d <n Xy |  j ƒ  j | ƒ | d <Wn t k
 r® d | d <n Xy |  j ƒ  j | ƒ | d <Wn t k
 ré d | d <n Xy |  j ƒ  j	 | ƒ | d <WqPt k
 r$d | d <qPXn( d | d <d | d <d | d <d | d <| |  j | <n  |  j | S(   s    Get the models for the image.t   detectort
   goniometert   beamt   scanN(
   R   RJ   t   _image_indexRH   R   t	   ExceptionR   R   R   R   (   R   R
   t   no_readt   pathRK   t   image_index(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_image_modelsÆ  s6    



i    c         C   s   |  j  ƒ  | j ƒ  S(   s    Get the image size. (   R   R	   (   R   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR	   å  s    c         C   s   |  j  | ƒ d S(   s    Get the detector. RU   (   R^   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   é  s    c         C   s   | |  j  | ƒ d <d S(   s    Set the detector model.RU   N(   R^   (   R   RU   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   set_detectorí  s    c         C   s   |  j  | ƒ d S(   s    Get the beam. RW   (   R^   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ñ  s    c         C   s   | |  j  | ƒ d <d S(   s    Set the beam model.RW   N(   R^   (   R   RW   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   set_beamõ  s    c         C   s   |  j  | ƒ d S(   s    Get the goniometer model. RV   (   R^   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ù  s    c         C   s   | |  j  | ƒ d <d S(   s    Set the goniometer model. RV   N(   R^   (   R   RV   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   set_goniometerý  s    c         C   s   |  j  | ƒ d S(   s    Get the scan model. RX   (   R^   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR     s    c         C   s   | |  j  | ƒ d <d S(   s    Set the scan model. RX   N(   R^   (   R   RX   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   set_scan  s    c         C   s   |  j  ƒ  j |  j | ƒ ƒ S(   s5    Get the detector base instance for the given index. (   RH   R   RY   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   	  s    c         C   s   |  j  S(   s    Return the image set reader. (   RF   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRH     s    c         C   s   |  j  ƒ  j |  j | ƒ ƒ S(   s    Get the path for the index (   RH   R   RY   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR     s    c         C   sR   | d k r |  j d S| d k  s8 | t |  j ƒ k rG t d ƒ ‚ n  |  j | S(   s(    Convert image set index to image index.i    s   Index out of rangeN(   R   RG   R<   RB   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRY     s
    !c         C   s   t  |  j ƒ  d |  j ƒS(   s:    Return the set of all images (i.e. not just the subset). RK   (   RD   RH   RJ   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   complete_set  s    N(   R   R   R   R   R   RN   RO   RR   RT   R   R   RQ   R   RC   R^   R	   R   R_   R   R`   R   Ra   R   Rb   R   RH   R   RY   Rc   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRD   v  s2   											t   MemImageSetc           B   sé   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d d
 „ Z d „  Z d d „ Z d „  Z d d „ Z d d „ Z d d „ Z d d „ Z d „  Z d d „ Z d e d „ Z d „  Z RS(   sï    A class exposing the external image set interface, but instead of a file list, uses
  an already instantiated list of Format objects. Derives from ImageSet for clarity and for
  the dials importer, but overrides all of ImageSet's methods c         C   sU   | d k r t d ƒ ‚ n  | |  _ | d k	 r< | |  _ n t t | ƒ ƒ |  _ d S(   s“    Initialise the MemImageSet object.

    Params:
        images: list of Format objects
        indices: list of indices into the images list

    s#   MemImageSet needs a list of images!N(   R   RE   t   _imagesRG   R)   R<   (   R   t   imagesR   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   '  s    		c         C   s|   t  | t ƒ r, |  j | } t |  j | ƒ S|  j |  j | } t g  t t |  j ƒ  ƒ ƒ D] } | j	 | ƒ ^ q\ ƒ Sd S(   s\   Get an item from the image set.

    If the item is an index, read and return the image at the given index.
    Otherwise, if the item is a slice, then create a new MemImageSet object
    with the given number of array indices from the slice.

    Params:
        item The index or slice

    Returns:
        An image or new ImageSet object

    N(
   R   RL   RG   Rd   Re   R?   t   xrangeR<   R   R,   (   R   RM   R   t   imgR+   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRN   <  s
    c         C   s   t  |  j ƒ S(   s0    Return the number of images in this image set. (   R<   RG   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRO   Q  s    c         C   s   t  |  j ƒ S(   s8    Return the array indices of the image set as a string. (   RP   RG   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRR   U  s    c         c   s^   xW |  j  D]L } |  j | } t g  t t |  j ƒ  ƒ ƒ D] } | j | ƒ ^ q9 ƒ Vq
 Wd S(   s=    Iterate over the array indices and read each image in turn. N(   RG   Re   R?   Rg   R<   R   R,   (   R   t   jRh   R+   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRT   Y  s    c         C   s   |  j  | j  k S(   s$    Compare this image set to another. (   Re   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   _  s    c         C   s   t  |  j ƒ S(   s&    Return the indices in the image set. (   R   RG   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   c  s    c         C   s   t  d ƒ ‚ d S(   s4    Return a list of filenames referenced by this set. s'   No path list for an in-memory image setN(   t   NotImplementedError(   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRQ   g  s    c         C   s   t  S(   sA    Validate all the images in the image set. Can take a long time. (   R   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   k  s    c         C   s-   | d k r |  j d } n  |  j | j ƒ  S(   s    Get the detector. i    N(   R   RG   Re   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   p  s    c         C   s!   x |  j  D] } | | _ q
 Wd S(   s    Set the detector model.N(   Re   t	   _detector(   R   RU   Rh   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR_   v  s    c         C   s-   | d k r |  j d } n  |  j | j ƒ  S(   s    Get the beam. i    N(   R   RG   Re   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   {  s    c         C   s!   x |  j  D] } | | _ q
 Wd S(   s    Set the beam model.N(   Re   t   _beam(   R   RW   Rh   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR`   �  s    c         C   s-   | d  k r |  j d } n  |  j | j ƒ  S(   Ni    (   R   RG   Re   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   †  s    c         C   s-   | d  k r |  j d } n  |  j | j ƒ  S(   Ni    (   R   RG   Re   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ‹  s    i    c         C   s-   | d k r |  j d } n  |  j | j ƒ  S(   s    Get the image size. i    N(   R   RG   Re   R	   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR	   �  s    c         C   s-   | d k r |  j d } n  |  j | j ƒ  S(   s5    Get the detector base instance for the given index. i    N(   R   RG   Re   t   get_detector_base(   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   –  s    c         C   s   d S(   s    Return the image set reader. N(   R   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRH   œ  s    c         C   sK   | d k r d S| d k  s1 | t |  j ƒ k r@ t d ƒ ‚ n  |  j | S(   s(    Convert image set index to image index.i    s   Index out of rangeN(   R   R<   RG   RB   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRY      s
    !c         C   s  |  j  | ƒ } i  } | sò y |  j | ƒ | d <Wn t k
 rO d | d <n Xy |  j | ƒ | d <Wn t k
 r„ d | d <n Xy |  j | ƒ | d <Wn t k
 r¹ d | d <n Xy |  j | ƒ | d <Wqt k
 rî d | d <qXn( d | d <d | d <d | d <d | d <| S(   s    Get the models for the image.RU   RV   RW   RX   N(   RY   R   RZ   R   R   R   R   (   R   R
   R[   R]   RK   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR^   ¨  s0    



c         C   s   t  |  j ƒ S(   s:    Return the set of all images (i.e. not just the subset). (   Rd   Re   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRc   Ä  s    N(   R   R   R   R   R   RN   RO   RR   RT   R   R   RQ   R   R   R_   R   R`   R   R   R	   R   RH   RY   RC   R^   Rc   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRd   "  s,   											t   SweepFileListc           B   sq   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s=   Class implementing a file list interface for sweep templates.c         C   s0   | d | d k s t  ‚ | |  _ | |  _ d S(   s7   Initialise the class with the template and array range.i    i   N(   R;   t	   _templatet   _array_range(   R   t   templatet   array_range(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   Ë  s    	c         C   s   |  j  |  j d | ƒ S(   s%   Get the filename at that array index.i    (   t   get_filenameRp   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRN   Ó  s    c         c   s/   x( t  t |  ƒ ƒ D] } |  j | ƒ Vq Wd S(   s   Iterate through the filenames.N(   R)   R<   RN   (   R   R+   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRT   ×  s    c         C   s   t  g  |  D] } | ^ q
 ƒ S(   s/   Get the string representation of the file list.(   RP   (   R   R2   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRR   Ü  s    c         C   s   |  j  d |  j  d S(   s    Get the length of the file list.i   i    (   Rp   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRO   à  s    c         C   s.   |  j  ƒ  | j  ƒ  k o- |  j ƒ  | j ƒ  k S(   s-   Compare filelist by template and array range.(   Rq   Rr   (   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   __eq__ä  s    c         C   s   |  j  S(   s   Get the template.(   Ro   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRq   é  s    c         C   s   |  j  S(   s   Get the array range.(   Rp   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRr   í  s    c         C   s   t  |  j Œ  S(   s   Get the image indices.(   R)   Rp   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ñ  s    c         C   s-   |  j  | ƒ s t d ƒ ‚ n  |  j | d S(   s$   Get the filename at the given index.s   Image file index out of rangei   (   t   is_index_in_rangeRB   Ro   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRs   õ  s    c         C   s&   |  j  d | k o# |  j  d k  SS(   s0   Ensure that the index is within the array range.i    i   (   Rp   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRu   ü  s    (   R   R   R   R   RN   RT   RR   RO   Rt   Rq   Rr   R   Rs   Ru   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRn   È  s   										t
   ImageSweepc           B   sì   e  Z d  Z d d d d d d „ Z d „  Z d „  Z d „  Z d d d „ Z d d „ Z	 d d „ Z
 d d	 „ Z d d
 „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z RS(   s0    A class exposing the external sweep interface. c         C   sŠ   t  j |  | | ƒ | d k	 rb |  j d g k rb | j ƒ  |  j d |  j d d k sb t ‚ n  | |  _ | |  _ | |  _ | |  _	 d S(   s,   Create the sweep.

    If the models are given here. They are used, otherwise the models
    are read from the files themselves, with the beam, detector and
    goniometer taken from the first image and the scan read from the
    whole range of images. The scan must be consistent with the indices
    given if both are specified.

    Params:
        reader The reader class
        indices The list of image indices
        beam The beam model
        goniometer The goniometer model
        detector The detector model
        scan The scan model

    i    iÿÿÿÿi   N(
   RD   R   R   RG   R*   R;   Rl   t   _goniometerRk   t   _scan(   R   RH   R   RW   RV   RU   RX   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR     s    1			c         C   sŸ   t  | t ƒ r� | j d k r- t d ƒ ‚ n  |  j d k rE d } n |  j | } t |  j ƒ  |  j | |  j	 |  j
 |  j | ƒ S|  j ƒ  j |  j | ƒ Sd S(   sV   Get an item from the sweep stream.

    If the item is an index, read and return the image at the given index.
    Otherwise, if the item is a slice, then create a new Sweep object
    with the given number of array indices from the slice.

    Params:
        item The index or slice

    Returns:
        An image or new Sweep object

    s   Sweeps must be sequentialN(   R   RL   t   stepR   RB   Rx   Rv   RH   RG   Rl   Rw   Rk   R   (   R   RM   RX   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRN   !  s    	c         C   s)   d d l  m } | |  j ƒ  j j ƒ  ƒ S(   s    Get the template. iÿÿÿÿ(   t   template_format_to_string(   t   dxtbx.sweep_filenamesRz   RH   R   Rq   (   R   Rz   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   get_template;  s    c         C   s   |  j  ƒ  j ƒ  S(   s    Get the array range. (   R   t   get_array_range(   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR}   @  s    i    c         C   s   |  j  ƒ  | j ƒ  S(   s    Get the image size. (   R   R	   (   R   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR	   D  s    c         C   s.   |  j  d k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   s    Get the beam. N(   Rl   R   RH   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   H  s    c         C   s.   |  j  d k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   s    Get the detector. N(   Rk   R   RH   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   N  s    c         C   s.   |  j  d k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   s    Get goniometer, N(   Rw   R   RH   R   (   R   R
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   T  s    c            sŸ   ˆ  j  d k rQ t ‡  f d †  ˆ  j d Dƒ ˆ  j ƒ  j ˆ  j d ƒ ƒ ˆ  _  n  | d k	 r˜ | d k  s~ | ˆ  j  j ƒ  k r� t d ƒ ‚ n  ˆ  j  | Sˆ  j  S(   s    Get the scan.c         3   s$   |  ] } ˆ  j  ƒ  j | ƒ Vq d  S(   N(   RH   R   (   t   .0R+   (   R   (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pys	   <genexpr>^  s    i   i    s   index out of rangeN(   Rx   R   t   sumRG   RH   R   R*   RB   (   R   R
   (    (   R   s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   Z  s    %!c         C   s   | |  _  d S(   s    Set the beam. N(   Rl   (   R   RW   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR`   f  s    c         C   s   | |  _  d S(   s    Set the goniometer model N(   Rw   (   R   RV   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRa   j  s    c         C   s   | |  _  d S(   s    Set the detector model. N(   Rk   (   R   RU   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR_   n  s    c         C   sP   |  j  d g k rC | j ƒ  |  j  d |  j  d d k sC t ‚ n  | |  _ d S(   s    Set the scan model. i    iÿÿÿÿi   N(   RG   R*   R;   Rx   (   R   RX   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRb   r  s    1c      
   C   s4   t  |  j ƒ  d |  j d |  j d |  j d |  j ƒS(   s:    Return the set of all images (i.e. not just the subset). RW   RU   RV   RX   (   Rv   RH   Rl   Rk   Rw   Rx   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRc   y  s    !c         C   s-   | d k r |  j | ƒ S|  j | | ƒ Sd S(   so   Read all the files in the sweep and convert them into an array
    of the appropriate dimensions.

    The required array is allocated first, this has he useful property
    that if you've been lazy and just got a sweep and extracted the
    array without consideration for the amount of memory available on
    your machine, you'll get an exception straight away.

    TODO:
        Currently uses numpy for fast copying of arrays, try to do
        this using flex arrays.

    Params:
        item The index item (frame 0, frame n), (z0, z1, y0, y1, x0, x1)

    Returns:
        The sweep image data as an array.

    N(   R   t   _to_array_allt   _to_array_w_range(   R   RM   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   to_array~  s    c   
      C   s-  d d l  m } t |  ƒ } |  j ƒ  j | ƒ d } |  j ƒ  j | ƒ d } | d k sr | d k sr | d k r� t d ƒ ‚ n  | j | j | | | ƒ ƒ } x‡ t |  ƒ D]y \ } } t	 | t
 ƒ sÓ | f } n  | | }	 |	 j | j d |	 j ƒ  Œ ƒ |	 | | | d … d d … d d … f <q¬ W| S(   s,    Get the array from all the sweep elements. iÿÿÿÿ(   t   flexi   i    s   Invalid dimensionsN(   t   scitbx.array_familyRƒ   R<   RH   R	   R    t   intt   gridt	   enumerateR   R?   t   reshapet   all(
   R   R   Rƒ   t   size_zt   size_yt   size_xt   arrayt   kt   imaget   im(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR€   —  s    $
-c         C   sr  d d l  m } |  j | | ƒ \ } } } } } }	 | | }
 | | } |	 | } |
 d k sv | d k sv | d k r… t d ƒ ‚ n  | j | j |
 | | ƒ ƒ } xÈ t |  j ƒ  | | !ƒ D]­ \ } } |  j ƒ  j	 | ƒ } t
 | t ƒ sù | f } n  | | } | j | j d | j ƒ  Œ ƒ | d d … | | … | |	 … f | | | d … d d … d d … f <q½ W| S(   s.    Get the array from the user specified range. iÿÿÿÿ(   Rƒ   i    s   Invalid dimensionsi   N(   R„   Rƒ   t   _get_data_rangeR    R…   R†   R‡   R   RH   R   R   R?   Rˆ   R‰   (   R   RM   R   Rƒ   t   z0t   z1t   y0t   y1t   x0t   x1RŠ   R‹   RŒ   R�   RŽ   R
   R�   R�   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR�   ³  s     $


$&
Lc   	      C   sÁ   t  | t ƒ r± t | ƒ d k rŒ | \ } } d |  j ƒ  j | ƒ d } } d |  j ƒ  j | ƒ d } } |  j | | | | | | f ƒ St | ƒ d k r± |  j | | ƒ Sn  t d ƒ ‚ d S(   s3    Get the range from the user specified index item. i   i    i   i   s	   bad indexN(   R   R?   R<   RH   R	   t   _truncate_rangeRB   (	   R   RM   R   R’   R“   R”   R•   R–   R—   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR‘   Ò  s      c         C   sÓ   | \ } } } } } } t  |  ƒ }	 |  j ƒ  j | ƒ \ }
 } | d k  rT d } n  | d k  ri d } n  | d k  r~ d } n  | |	 k r“ |	 } n  | | k r¨ | } n  | |
 k r½ |
 } n  | | | | | | f S(   s3    Truncate the range to the size of available data. i    (   R<   RH   R	   (   R   t
   data_rangeR   R’   R“   R”   R•   R–   R—   RŠ   RŒ   R‹   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR˜   æ  s      	 	 	 	 	 	N(   R   R   R   R   R   RN   R|   R}   R	   R   R   R   R   R`   Ra   R_   Rb   Rc   R‚   R€   R�   R‘   R˜   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRv     s,   								t   FilenameAnalyserc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s)   Group images by filename into image sets.c         C   s   d S(   s   Initialise the class.N(    (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR   ÿ  s    c         C   sk   d d l  m } | | ƒ } g  } xB | j ƒ  D]4 \ } } |  j | | ƒ } | j | | | f ƒ q/ W| S(   s›   Group the filenames by imageset.

    Params:
        filenames The list of filenames

    Returns:
        A list of (template, [indices], is_sweep)

    iÿÿÿÿ(   t   group_files_by_imageset(   t   sweep_filenamesR›   t	   iteritemst   _is_imageset_a_sweept   append(   R   R   R›   t   filelist_per_imagesett   file_groupsRq   R   t   is_sweep(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR8     s    
c         C   s=   t  | ƒ d k r t St | ƒ } |  j | ƒ r5 t St Sd S(   sä    Return True/False if the imageset is a sweep or not.

    Where more than 1 image that follow sequential numbers are given
    the images are catagorised as belonging to a sweep, otherwise they
    belong to an image set.

    i   N(   R<   RC   t   sortedt   _indices_sequential_ge_zeroR   (   R   Rq   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRž     s    c         C   sM   | d } | d k  r t  Sx, | d D]  } | | d k r? t  S| } q% Wt S(   s%    Determine if indices are sequential.i    i   (   RC   R   (   R   R   t   prevt   curr(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR¤   0  s    

(   R   R   R   R   R8   Rž   R¤   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRš   ü  s
   			t   ImageSetFactoryc           B   sž   e  Z d  Z e e e d „ ƒ Z e d e e d „ ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d e d „ ƒ Z e d d d d d e d „ ƒ Z RS(	   s)    Factory to create imagesets and sweeps. c         C   sÀ   t  |  t ƒ r* t |  ƒ d k sN t ‚ n$ t  |  t ƒ rE |  g }  n	 t d ‚ t ƒ  } | |  ƒ } g  } xP | D]H } y | j t j	 | | ƒ ƒ Wqp t
 k
 r· } | s¸ | ‚ q¸ qp Xqp W| S(   sô    Create an imageset or sweep

    Params:
        filenames A list of filenames
        check_headers Check the headers to ensure all images are valid
        ignore_unknown Ignore unknown formats

    Returns:
        A list of imagesets

    i    s*   unknown argument passed to ImageSetFactory(   R   R   R<   R;   RP   R    Rš   RŸ   R§   t   _create_imageset_or_sweepRZ   (   R   t   check_headerst   ignore_unknownt   analyse_filesR    t   imagesetlistt   filelistt   e(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   new@  s     		c         C   s¬  d d l  } d d l m } d d l m } | sB | sB t ‚ n  |  j d ƒ d k  rf t d ƒ ‚ n  |  j d ƒ d } |  j d ƒ d } d	 | |  j d ƒ | f }	 | d k rÃ | |  ƒ } n  | d d | d f }
 t
 |	 |
 ƒ } | rk| j | d ƒ } d d
 l m } t | | ƒ rYt | ƒ d k s:t ‚ | | d ƒ } t | ƒ } qwt | | ƒ } n t | ƒ } t | ƒ } | r¥| j ƒ  r¥t d ƒ ‚ n  | g S(   sï   Create a new sweep from a template.

    Params:
        template The template argument
        image_range The image range
        check_headers Check the headers to ensure all images are valid

    Returns:
        A list of sweeps

    iÿÿÿÿN(   t   Registry(   t   template_image_ranget   #i   s   Invalid templatei    s
   %s%%0%dd%s(   t   FormatMultiImages   Invalid sweep of images(   R:   t   dxtbx.format.RegistryR°   R{   R±   R;   t   countRE   t   splitR   Rn   t   findt   format.FormatMultiImageR³   t
   issubclassR<   R!   R9   R   Rv   R   R    (   Rq   t   image_rangeR©   t   check_formatR:   R°   R±   t   pfxt   sfxt   template_formatRr   R   R0   R³   R#   RH   t   sweep(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   from_templateh  s6     c         C   s4   |  d t  k r  t j |  | ƒ St j |  | ƒ Sd S(   s#   Create either an imageset of sweep.i   N(   R   R§   t   _create_sweept   _create_imageset(   R­   R©   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR¨   ¦  s    c         C   s[  d d l  m } |  \ } } } | j d ƒ } | d k rœ | j d ƒ d } | j d ƒ d } d | | j d ƒ | f }	 g  | D] }
 |	 |
 ^ qƒ } n	 | g } t | ƒ } | j | d ƒ } d d l m } t | | ƒ r t	 | ƒ d k sû t
 ‚ | | d ƒ } t t | ƒ ƒ } n t t | | ƒ ƒ } | rW| j ƒ  rWt d ƒ ‚ n  | S(	   s   Create an image setiÿÿÿÿ(   R°   R²   i    s
   %s%%0%dd%s(   R³   i   s   Invalid ImageSet(   R´   R°   Rµ   R¶   R£   R·   R¸   R³   R¹   R<   R;   RD   R!   R9   R   R    (   R­   R©   R°   Rq   R   R¢   Rµ   R¼   R½   R¾   R
   R   R0   R³   R#   t	   image_set(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRÂ   ®  s(     	c         C   s¤  d d l  } d d l m } |  \ } } } | j d ƒ } | d k r¨ | j d ƒ d } | j d ƒ d }	 d | | j d ƒ |	 f }
 g  | D] } |
 | ^ q� } n	 | g } t | ƒ } | j | d ƒ } | d } | j j | ƒ \ } } | d } | j d ƒ d } | j d ƒ d }	 d | | j d ƒ |	 f }
 t | ƒ d t	 | ƒ f } t
 |
 | ƒ } t t | | ƒ ƒ } | r | j ƒ  r t d ƒ ‚ n  | S(	   s   Create a sweepiÿÿÿÿN(   R°   R²   i    s
   %s%%0%dd%si   s   Invalid sweep of images(   R:   R´   R°   Rµ   R¶   R£   R·   R\   t   mint   maxRn   Rv   R9   R   R    (   R­   R©   R:   R°   Rq   R   R¢   Rµ   R¼   R½   R¾   R
   R   R0   t   first_imaget	   directoryt   first_image_namet   first_image_numberRr   R¿   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyRÁ   Ö  s0     	

c         C   sÂ   d d l  m } d d l m } | d k rH | rH | j |  d ƒ } n  | d k rc t |  ƒ } nU t | | ƒ r© t |  ƒ d k sŠ t	 ‚ | |  d ƒ } t
 | ƒ } n t | |  ƒ } t | ƒ S(   s   Create an image setiÿÿÿÿ(   R°   (   R³   i    i   N(   R´   R°   R¸   R³   R   R·   R   R¹   R<   R;   R!   R9   RD   (   R   R0   R»   R°   R³   RH   R#   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   make_imageset  s    c      
   C   s>  d d l  } d d l m }	 d d l m }
 t | ƒ } |  j d ƒ } | d k rµ |  j d ƒ d } |  j d ƒ d } d | |  j d ƒ | f } g  | D] } | | ^ qœ } n d } |  g } t | ƒ } | d } | j	 j | ƒ \ } } | d } t
 | ƒ d t | ƒ f } | d k	 r?| | j ƒ  k s?t ‚ n  | d k rg| rg|	 j | d ƒ } n  | d k r | d k	 r‘t | | ƒ } n  t | ƒ } nv t | |
 ƒ ræt | ƒ d k sÇt ‚ | | d ƒ } t | ƒ } n0 | d k	 søt ‚ t | | ƒ } t | | ƒ } t | d	 | d
 | d | d | ƒ} | S(   s   Create a sweepiÿÿÿÿN(   R°   (   R³   R²   i    s
   %s%%0%dd%si   RW   RU   RV   RX   (   R:   R´   R°   R¸   R³   R£   Rµ   R¶   R   R\   RÄ   RÅ   R}   R;   R·   Rn   R   R¹   R<   R!   R9   Rv   (   Rq   R   R0   RW   RU   RV   RX   R»   R:   R°   R³   Rµ   R¼   R½   R¾   R
   R   RÆ   RÇ   RÈ   RÉ   Rr   RH   R#   R¿   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt
   make_sweep"  sN     	

	N(   R   R   R   t   staticmethodRC   R¯   R   R   RÀ   R¨   RÂ   RÁ   RÊ   RË   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyR§   =  s   '<(6	N(   t
   __future__R    t   objectR   R   R!   R-   R6   R9   RD   Rd   Rn   Rv   Rš   R§   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/imageset.pyt   <module>   s   .7J6~¬¦9ûA