ó
x™xTc           @   s]  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d „  Z	 d „  Z
 d e f d	 „  ƒ  YZ e d
 k rYd  d l Z d Z e j d Z e e ƒ Z e j ƒ  e GHe j GHe j Ge e j ƒ Ge j e j GHx3 d d d d d d d g D] Z e Gd e d UqWe
 e e ƒ GHe	 d d e e f ƒ Z d e e f GHe GHn  d S(   iÿÿÿÿ(   t   divisionN(   t	   ADSCImage(   t   flex(   t   image_dividerc         C   së   y d d l  m } Wn! t k
 r7 d d l m } n Xd d l  m  } | |  ƒ } | j d k si t ‚ | j j d ƒ d } | | j k r˜ t | ƒ S| | j j d ƒ d ƒ } t	 | d d ƒ } t | ƒ } | j
 ƒ  t | | ƒ S(	   Niÿÿÿÿ(   t   parse_qs(   t   urlparset   filet   ?i    i   t   slice(   R   R   t	   Exceptiont   cgit   schemet   AssertionErrort   patht   splitR   t   intt
   readHeadert'   ADSC_module_from_object_and_slicenumber(   t   urlR   R   t   parsedR   t   qst
   sliceindext   object(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyt   ADSC_module_from_file_url   s      

c         C   sY   t  ƒ  } | | _ |  | _ | j | j ƒ d | _ | j | j ƒ | _ | j | _ | S(   Ns   ADSC module(	   t
   ADSCModulet   moduleindexR   t+   copy_common_attributes_from_parent_instancet
   vendortypet   module_parameterst
   parameterst   slice_callback_with_object_datat   slice_callback(   R   R   t   P(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyR      s    				R   c           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  |  _ d  S(   N(   t   Falset   already_read_data(   t   self(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyt   __init__#   s    c      	   C   sc  | j  } i  } x@ d d d d d d d d d	 g	 D] } t j | | ƒ | | <q1 Wx5 d
 d d d g D]! } t j | | ƒ | d | <qe W| j ƒ  t | ƒ } t d | j d | ƒ } d G| j |  j ƒ j G| j |  j ƒ j	 GHd G| j
 |  j ƒ j G| j
 |  j ƒ j	 GH| j |  j ƒ j ƒ  | d
 <| j
 |  j ƒ j ƒ  | d <d G| d
 Gd G| d GH| S(   Nt   DISTANCEt   PHIt
   WAVELENGTHt   TWOTHETAt	   OSC_RANGEt   CCD_IMAGE_SATURATIONt	   OSC_STARTt   DETECTOR_SNt
   PIXEL_SIZEt   SIZE1t   SIZE2t   BEAM_CENTER_Xt   BEAM_CENTER_Yt   PARENT_t   datat	   nullvalues   module slow intervals   module fast intervalt   size1t   size2(   R   t   copyt   readt   vendor_specific_null_valueR   t   linearintdatat   tile_slow_intervalR   t   firstt   lastt   tile_fast_intervalt   size(   R#   R   t   paramt   resultt   itemR4   t   ID(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyR   &   s"    	
++c         C   sä   d G| GH|  j  j d k s! t ‚ |  j  j } t d |  j  j d | ƒ } d d l m } | |  j  | |  j | ƒ \ |  j	 d <|  j	 d <d	 |  _ | |  _
 d
 G|  j  j	 d G|  j  j	 d GHd G|  j Gd G|  j	 d G|  j	 d GHd  S(   Nt   CCt
   instrumentR3   R4   iÿÿÿÿ(   t!   convert_beam_instrument_to_moduleR0   R1   t
   imageblocks   old beam centers
   for modules   beam x,y is(   R   t   beam_center_reference_frameR   R9   R   R:   t&   iotbx.detectors.beam_center_conventionRF   R   R   t   beam_center_convention(   R#   RJ   R4   RC   RF   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyt   set_beam_center_conventionF   s    	,		!c         C   s{   |  j  j ƒ  } t j | ƒ } | j ƒ  } | |  j |  j k sF t ‚ d G| GH| j t j	 |  j |  j f ƒ ƒ |  `  | S(   Ns   size assertion OK(
   R   R8   R   t   int_from_byte_strR?   R5   R6   R   t   reshapet   grid(   R#   t   BYUR:   t   provisional_size(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyt.   slice_callback_with_high_performance_http_dataX   s    	"c         C   s¥   |  j  j ƒ  |  j  j } t d |  j  j d | ƒ } d |  j k oT | j ƒ  k  n s_ t ‚ | j |  j ƒ } |  j  j j	 j
 d ƒ t k r› t | _ n  |  `  | S(   NR3   R4   i    t   bin2by2(   R   R8   R9   R   R:   R   t   module_countR   t	   tile_datat   __dict__t   gett   TrueRR   (   R#   R4   RC   t   new_data_array(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyR   b   s    +c         C   s-   |  j  r d  S|  j |  j ƒ  ƒ t |  _  d  S(   N(   R"   t   bin_safe_set_dataR   RW   (   R#   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyR8   m   s    	 (   t   __name__t
   __module__R$   R   RK   RQ   R   R8   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyR   "   s   		 		
	t   __main__i   i   t   bint   filenamet   headert   headerlinesR:   R   R   s
   print a.%sR   s   file://%s?slice=%d(   t
   __future__R    R7   t   iotbx.detectors.adscR   t   scitbx.array_familyR   t   iotbx.detectorsR   R   R   R   RZ   t   syst   sliceidxt   argvt   full_path_to_filet   aR8   R   t   rawdatat   lenR5   R6   t   dataitemR    (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/detectors/adsc_module.pyt   <module>   s.   		
P
#"