³ò
bÄGJc           @   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 e	 i f d „  ƒ  YZ d S(   s  
Manipulating the Proportional-Integral-Differential Controller logs.

Log format:
# ULT fridge, PID pressure controller
# (1) Time (sec, since 1 January 1904)
# (2) P_proportional (W or nW, calculated)
# (3) P_integration (W or nW, calculated)
# (4) P_derivative (W or nW, calculated)
# (5) P_total (W or nW, dissipated)
# (6) V_DAC (mV)
# (7) DAC amplitude (uint16)
# (8) Gain (W/mbar)
# (9) Integral time const (sec)
# (10) Derivative time const (sec)
# (11) p_set (mbar)
# (12) p_measured (mbar)
# (13) P_max (W)

2 September 2008, Lev
iÿÿÿÿNt   PIDLogc           B   sL  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 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z h  d d <d d <Z h  d d <d d <Z h  d d <d d <Z e d „  ƒ Z e d  d  d „ ƒ Z e d  d  d „ ƒ Z d d d „ Z d d d „ Z RS(!   s>  
    Represents a ULT Proportional-Integral-Differential Controller log over
    a certain time. Two logs can be concatenated with a '&' sign

    'self.device' is the controller name, two logs must belong to the same
    device in order to concatenate them.

    log format:

    ULT fridge, PID pressure controller
    [:,0]  (1) Time (sec, since 1 January 1904)
    [:,1]  (2) P_proportional (W or nW, calculated)
    [:,2]  (3) P_integration (W or nW, calculated)
    [:,3]  (4) P_derivative (W or nW, calculated)
    [:,4]  (5) P_total (W/nW, dissipated)
    [:,5]  (6) V_DAC (mV)
    [:,6]  (7) DAC amplitude (uint16)
    [:,7]  (8) Gain (W/mbar or nW/mK)
    [:,8]  (9) Integral time const (sec)
    [:,9]  (10) Derivative time const (sec)
    [:,10] (11) p_set (mbar or mK)
    [:,11] (12) p_measured (mbar or mK)
    [:,12] (13) P_max (W or nW)
    
    Pressure and Temperature PID Controllers think in different units for heat
    and controller parameter. Their string representations can be obtained
    from self.powerUnits() (W or nW) and self.xUnits() (mbar or mK).
    c           C   s   d S(   s)   return number of columns in the self.datai   (    (    (    (    s   c:\py\lib\pidlog.pyt
   fieldcountC   s    c         C   s   |  i  d d … d f S(   s/   power in proportional channel (calculated) [PU]Ni   (   t   data(   t   self(    (    s   c:\py\lib\pidlog.pyt
   power_propF   s    c         C   s   |  i  d d … d f S(   s*   power in integral channel (calculatd) [PU]Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt	   power_intG   s    c         C   s   |  i  d d … d f S(   s5   power in differential channel power (calculated) [PU]Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt
   power_diffH   s    c         C   s   |  i  d d … d f S(   s   total power (calculated) [PU]Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt   power_totalI   s    c         C   s   |  i  d d … d f S(   s   DAC voltage [mV]Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt   voltageK   s    c         C   s   |  i  d d … d f S(   s   Raw DAC value 0-65535Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt	   DAC_valueL   s    c         C   s   | |  i  ƒ  | | d S(   s^   Calculate dissipated power based on DAC voltage and resistances. Always measured in microwattsi   (   R   (   R   t   R_heatert   R_leads(    (    s   c:\py\lib\pidlog.pyt   powerN   s    c         C   s   |  i  d d … d f S(   s   PID Gain (PU/xu)Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt   gainR   s    c         C   s   |  i  d d … d f S(   s   Integral Time Constant (sec)Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt   T_intS   s    c         C   s   |  i  d d … d f S(   s    Differential Time Constant (sec)Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt   T_diffT   s    c         C   s   |  i  d d … d f S(   s'   set point for controlled parameter [xu]Ni
   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt   x_setV   s    c         C   s   |  i  d d … d f S(   s+   measured value of controlled parameter [xu]Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt
   x_measuredW   s    c         C   s   |  i  d d … d f S(   s   power limit [PU]Ni   (   R   (   R   (    (    s   c:\py\lib\pidlog.pyt	   max_powerY   s    c         C   s   d |  i  |  i ƒ  f S(   Ns	   %s Log %s(   t   devicet   datespan(   R   (    (    s   c:\py\lib\pidlog.pyt   __repr__[   s    c         C   s   t  i |  i S(   s?   string representation of units powers are measured in [W or nW](   R    t   xUnitsDBR   (   R   (    (    s   c:\py\lib\pidlog.pyt
   powerUnits]   s    c         C   s   t  i |  i S(   s?   string representation of units powers are measured in [W or nW](   R    t   powerUnitsDBR   (   R   (    (    s   c:\py\lib\pidlog.pyt   xUnits^   s    s   Pressure PIDs
   _PID_P.dats   Temperature PIDs
   _PID_T.datt   mbart   mKt   Wt   nWc         C   s•   t  i i |  ƒ } | d } t i i | ƒ p d Sn t i |  d t i	 ƒ  ƒ} t
 i | d d … d f ƒ | d d … d f <t | t i | ƒ S(   sU  
        Load a PID log from a given file. Controller is determined from
        filename suffix:
        
        filename suffix         controller name     x units     power units
            
        "_PID_P.dat             "Pressure PID"      "mbar"      "W"
        "_PID_T.dat             "Temperature PID"   "mK"        "nW"
        i   t   colsNi    (   t   ost   patht   basenameR    t   nameDBt   has_keyt   Nonet   ascii2numpyt	   loadasciiR   t   flibt
   labview2tm(   t   filenameR!   t   suffixR   (    (    s   c:\py\lib\pidlog.pyt   loadl   s    
/c         C   s2   t  i t i d |  ƒ d | d | ƒi | | ƒ S(   sa   Return pressure PID log for a given run, withing [start, end] period if boundaries are specified.s   //phpc338/Run%d/PID-pressuret   startt   end(   R    t   loaddirR'   t   smbpatht   period(   t   runR,   R-   (    (    s   c:\py\lib\pidlog.pyt   loadPressurePID‡   s    c         C   s2   t  i t i d |  ƒ d | d | ƒi | | ƒ S(   sd   Return temperature PID log for a given run, withing [start, end] period if boundaries are specified.s   //phpc338/Run%d/PID-temperatureR,   R-   (   R    R.   R'   R/   R0   (   R1   R,   R-   (    (    s   c:\py\lib\pidlog.pyt   loadTemperaturePIDŒ   s    i
   c   	      C   s3  g  } |  i  ƒ  } |  i ƒ  } t |  ƒ d j oõ | d } | d } xŠ t d t | ƒ ƒ D]s } | | | j p | | | | d | j o? | t i | | | d d | ƒg 7} | | } | | } q[ q[ W| t | ƒ d | | j o1 | t i | | t | ƒ d d | ƒg 7} q&n t i | ƒ S(   sE  
        Return an array of flib.Period's with constant set point.
        Stabilisation is considered interrupted if a gap between two points
        is over 10 seconds, then even if x is the same before and after,
        separate periods are returned.
        
        Each Period has the set point stored as '.x'
        i    i   t   x(   t   tR   t   lent   rangeR'   t   Periodt   numpyt   array(	   R   t	   minlengtht   maxgapt   periodsR5   R4   R,   t   lastxt   n(    (    s   c:\py\lib\pidlog.pyt   const_setpoint_periods‘   s    


 .'
5c   	      C   sL  g  } |  i  ƒ  } |  i ƒ  } t |  ƒ d j o| d } | d } x£ t d t | ƒ ƒ D]Œ } | | | j p | | | | d | j oX | | | | j o+ | t i | | | d d | ƒg 7} n | | } | | } q[ q[ W| t | ƒ d | | j o1 | t i | | t | ƒ d d | ƒg 7} q?n t i | ƒ S(   sG  
        Return an array of flib.Period's with constant total power.
        Stabilisation is considered interrupted if a gap between two points
        is over 10 seconds, then even if x is the same before and after,
        separate periods are returned.
        
        Each Period has the set power stored as '.q'
        i    i   t   q(   R5   R   R6   R7   R'   R8   R9   R:   (	   R   R;   R<   R=   R5   RA   R,   t   lastqR?   (    (    s   c:\py\lib\pidlog.pyt   const_power_periods²   s     


 .+
5N(   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R   R   R   R	   R   R   R   R   R   R   R   R   R   R   R"   R   R   R+   R$   R2   R3   R@   RC   (    (    (    s   c:\py\lib\pidlog.pyR    %   sD   																			!(   RF   R   t   os.patht   timet   datetimeR9   t   matplotlib.datest
   matplotlibR'   t   timelogR%   t   TimeLogR    (    (    (    s   c:\py\lib\pidlog.pys   <module>   s   