³ò
­>AKc           @   s›   d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Z d e	 i f d „  ƒ  YZ d S(   s÷  
Manipulating the Melting Curve Thermometry logs.

Log format:
[:,0] (1) Time (sec, since 1 January 1970 UTC)
[:,1] (2) Ratio transformer bridge ratio, set point
[:,2] (3) Off-balance voltage (V)
[:,3] (4) Bridge ratio (corrected for off-balance voltage)
[:,4] (5) Absolute pressure (bar, without A-transition correction)
[:,5] (6) Temperature (mK, Greywall scale)
[:,6] (7) Temperature (mK, PLTS2000 high temperature scale)
[:,7] (8) Temperature (mK, PLTS2000 low temperature scale)

07 June 2008, Lev
iÿÿÿÿNt   MCTLogc           B   s[  e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d d d „ Z d „  Z h  d d <d d <d d <d d <Z e d „  ƒ Z d „  Z e d" d" d „ ƒ Z e i d d d d d g ƒ Z e e i d d d d d g ƒ d „ ƒ Z d d „ Z d  e i d d d d d g ƒ d d! „ Z RS(#   së  
    Represents a Melting Curve Thermometry log over a certain time.
    Two logs can be concatenated with a '&' sign

    'self.device' is the thermometer name, two logs must have the same gauge names in order to concatenate them.

    log format:

    [:,0] (1) Time (sec, since 1 January 1970 UTC)
    [:,1] (2) Ratio transformer bridge ratio, set point
    [:,2] (3) Lock-in Off-balance voltage (V)
    [:,3] (4) Bridge ratio (corrected for off-balance voltage)
    [:,4] (5) Absolute pressure (bar, without A-transition correction)
    [:,5] (6) Temperature (mK, Greywall scale)
    [:,6] (7) Temperature (mK, PLTS2000 high temperature scale)
    [:,7] (8) Temperature (mK, PLTS2000 low temperature scale)
    [:,8] (9) Lock-in Range (V)
    c           C   s   d S(   s)   return number of columns in the self.datai	   (    (    (    (    s   c:\py\lib\mctlog.pyt
   fieldcount8   s    c         C   s   |  i  d d … d f S(   s   Ratio Transformer Set PointNi   (   t   data(   t   self(    (    s   c:\py\lib\mctlog.pyt   r_set;   s    c         C   s   |  i  d d … d f S(   s   Off-balance voltage [V]Ni   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   V_off<   s    c         C   s   |  i  d d … d f S(   s   Bridge ratioNi   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   r=   s    c         C   s   |  i  d d … d f S(   s*   Pressure[bar], no A-transition correction Ni   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   P>   s    c         C   s   |  i  d d … d f S(   s   Greywall scale temperature [mK]Ni   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   T_grwl?   s    c         C   s   |  i  d d … d f S(   s$   PLTS2000 high scale temperature [mK]Ni   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   T_pltsH@   s    c         C   s   |  i  d d … d f S(   s#   PLTS2000 low scale temperature [mK]Ni   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   T_pltsLA   s    c         C   s   |  i  d d … d f S(   s   Lock-in range [V]Ni   (   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   rangeB   s    c         C   s   |  i  ƒ  |  i ƒ  d j S(   sR   Return True for points where lock-in overloads. False otherwise or before 13/01/09g×£p=
×÷?(   R   R   (   R   (    (    s   c:\py\lib\mctlog.pyt   overloadD   s    i    i   c         C   s  t  |  ƒ d j  o |  i g  ƒ Sn |  i ƒ  } |  i ƒ  } |  i ƒ  } t i t  |  ƒ g d t ƒ} x‘ t d t  |  ƒ ƒ D]z } | | | | d j p- t i	 | | ƒ oG | | | | d j o. t
 | | | | | j | | | | j @<q| q| W|  i | ƒ S(   Ni   t   dtype(   t   lent   subsett   tR   R   t   numpyt   onest   boolt   xranget   isfinitet   False(   R   t   beforet   afterR   R   R   t   maskt   n(    (    s   c:\py\lib\mctlog.pyt   steady_rH   s     F2c         C   s   d |  i  |  i ƒ  f S(   Ns	   %s Log %s(   t   devicet   datespan(   R   (    (    s   c:\py\lib\mctlog.pyt   __repr__Z   s    t   MCTNSs   _MCT_NuclearStage.dats
   _MCTNS.datt   MCTMCs   _MCT_MixingChamber.dats
   _MCTMC.datc         C   sñ  t  i i |  ƒ } | d } t i i | ƒ p d Sn | i d ƒ d j o t i	 |  d d ƒ} t
 i t | ƒ d g ƒ } | d d … d d … f | d d … d d … f <t
 i | d d … d f <n t i	 |  d t i ƒ  ƒ} t i | d d … d f ƒ | d d … d f <t
 i | | d d … d f d j  d f <t
 i | | d d … d	 f d j  d	 f <t
 i | | d d … d
 f d j  d
 f <| d d … d f t i d ƒ j  } t | ƒ o | | d f c d 9<n t | t i | ƒ S(   sp   
        Load an MCT log from a given file
        The thermometer is infered from the filename suffix.
        i   t   _i   t   colsi	   Ni    i   i   i   s   05 Jan 2009 19:40 UTCg{®Gáz„?(   t   ost   patht   basenameR    t   devNamest   has_keyt   Nonet   countt   ascii2numpyt	   loadasciiR   t   zerosR   t   NaNR   t   flibt
   labview2tmt   tmt   any(   t   filenameR%   t   suffixt   olddataR   t   ii(    (    s   c:\py\lib\mctlog.pyt   load_   s$    
2/)))%c         C   se   |  i  ƒ  } | t i d ƒ j  } t | ƒ p d Sn |  i | d f d d !|  i | d f d )d S(   s±  
        Before 15:30 on 13/01/09 r_set was one step in the future
        Cure this in place by shifting the r_set column of the data.
        The first entry in the log is not cured, so it is best to apply
        this after consequent days are merged into one log.
        This function is called automatically by MCTLog.loadMCTNS().
        
        The log should be sorted chronologically before calling this function.
        s   13 Jan 2009 15:30 UTCNi   i    iÿÿÿÿ(   R   R.   R0   R1   R   (   R   R   R5   (    (    s   c:\py\lib\mctlog.pyt
   cure_r_set›   s
    
 c         C   sB   t  i t i d |  ƒ d | d | ƒi | | ƒ } | i ƒ  | S(   sƒ   
        Return highP paroscientific log for a given run, withing [start, end]
        period if boundaries are specified.
        s    \\phpc338\Run%d\MCT_NuclearStaget   startt   end(   R    t   loaddirR.   t   smbpatht   periodR7   (   t   runR8   R9   t   mctlog(    (    s   c:\py\lib\mctlog.pyt	   loadMCTNS«   s    4
g? <¯ ñ¿g­µù/Y@gÑ È)Àg/¸1A¾Ü#Àg°l¤½ÁÚI@c         C   s   t  i | |  d |  ƒ S(   s3  
        Convert bridge ratio to pressure
        r - bridge ratio or an array of them
        cal - a calibration polynomial that transfers from r/(1-r) to pressure
        from a highest power of the argument a constant, like in numpy.polyval.
        Defaults to MCTNS calibration from 11/02/08.
        i   (   R   t   polyval(   R   t   cal(    (    s   c:\py\lib\mctlog.pyt   r2P¹   s    	g      ð?c         C   s*   |  i  ƒ  |  i ƒ  d |  i ƒ  d | S(   s)   corrected ULT MCTNS (Run 20) bridge ratiog…ÏÖÁÁÀ¿gVñFæ‘Á?(   R   R   R   (   R   t   k(    (    s   c:\py\lib\mctlog.pyt   r_corrÄ   s    gp™Óe1±ß?c         C   s    |  i  d | ƒ |  i d d … d f <|  i |  i ƒ  | ƒ |  i | | ƒ t i ƒ  |  i d d … d f <t i |  i ƒ  t i ƒ  ƒ |  i d d … d f <d S(   sN  
        correct in place the bridge ratio, pressure and Greywall temperature
        NOTE: PLTS temperatures are left uncorrected
        rA - bridge ratio at superfluid transition
        cal - a calibration polynomial that transfers from r/(1-r) to pressure
        rA and cal defaults to MCTNS @ ULT on Run 20 calibration
        RC   Ni   i   i   (   RD   R   RB   R   t   mctscalet   greywall_PAt   greywall_P2TR   (   R   t   rARA   t   k_V2r(    (    s   c:\py\lib\mctlog.pyt   corr_r_P_TgrwlÆ   s    %EN(   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R   R   R   R	   R
   R   R   R   R   R&   R6   R7   R(   R?   R   t   arrayt	   cal_MCTNSRB   RD   RJ   (    (    (    s   c:\py\lib\mctlog.pyR    $   s0   										<	'
(   RM   R#   t   os.patht   timet   datetimeR   t   matplotlib.datest
   matplotlibR.   t   timelogR*   RE   t   TimeLogR    (    (    (    s   c:\py\lib\mctlog.pys   <module>   s   
