³ò
Ú]µHc           @   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 e	 i
 f d „  ƒ  YZ d S(   s8   
Manipulating the ULT fridge Platinum Thermometer logs.
iÿÿÿÿNt   PLMLogc           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 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d d d „ ƒ Z RS(   sa  
    Represents a ULT PLM4 thermometry log over a certain time.
    Two logs can be concatenated with a '&' sign

    log format:
    1  [:,0]  Time (sec, since 00:00 1 January 1970 GMT)
    2  [:,1]  Curie Temperature [mK] T = B / (M0 - A)
    3  [:,2]  Magnetisation M0
    4  [:,3]  Transmitter Pulse Length
    5  [:,4]  NS MCT Temperature (mK, Greywall scale)
    6  [:,5]  NS MCT Bridge Ratio
    7  [:,6]  Background (stabilised)
    8  [:,7]  Gain Stability Index
    9  [:,8]  Gain
    10 [:,9]  Integration delay
    11 [:,10] Integration time
    12 [:,11] 0 if PLM was overloaded, otherwise 1
    c           C   s   d S(   s)   return number of columns in the self.datai   (    (    (    (    s   c:\py\lib\plm.pyt
   fieldcount"   s    c         C   s   |  i  d d … d f S(   t   temperatureNi   (   t   data(   t   self(    (    s   c:\py\lib\plm.pyt   T%   s    c         C   s   |  i  d d … d f S(   t   M0Ni   (   R   (   R   (    (    s   c:\py\lib\plm.pyR   &   s    c         C   s    |  i  d d … d f i d ƒ S(   s   transmitter pulse lengthNi   t   i(   R   t   astype(   R   (    (    s   c:\py\lib\plm.pyt   xmit'   s    c         C   s   |  i  d d … d f S(   s
   MCTNS TempNi   (   R   (   R   (    (    s   c:\py\lib\plm.pyt   T_MCTNS(   s    c         C   s   |  i  d d … d f S(   s   MCTNS ratioNi   (   R   (   R   (    (    s   c:\py\lib\plm.pyt   r_MCTNS)   s    c         C   s   |  i  d d … d f S(   s   raw backgroundNi   (   R   (   R   (    (    s   c:\py\lib\plm.pyt   bg*   s    c         C   s   |  i  d d … d f S(   s   gain stability indexNi   (   R   (   R   (    (    s   c:\py\lib\plm.pyt   stabi+   s    c         C   s    |  i  d d … d f i d ƒ S(   s
   PLM-4 gainNi   R   (   R   R   (   R   (    (    s   c:\py\lib\plm.pyt   gain,   s    c         C   s   |  i  d d … d f S(   s   integration delayNi	   (   R   (   R   (    (    s   c:\py\lib\plm.pyt   idelay-   s    c         C   s   |  i  d d … d f S(   s   integration timeNi
   (   R   (   R   (    (    s   c:\py\lib\plm.pyt   itime.   s    c         C   s   |  i  d d … d f d j S(   s8   True if the measurement overdrove PLM-4, otherwise FalseNi   i    (   t   dat(   R   (    (    s   c:\py\lib\plm.pyt	   overdrive/   s    c         C   s   |  i  ƒ  |  i ƒ  |  i ƒ  S(   s   raw (unstabilised) M0(   R   R   R   (   R   (    (    s   c:\py\lib\plm.pyt   rawM00   s    c         C   s   |  i  |  i ƒ  | j ƒ S(   s\   
        Return a subset of the log obtained for a certain transmitter pulse length
        (   t   subsetR	   (   R   R	   (    (    s   c:\py\lib\plm.pyt   atxmit2   s    c         C   s   t  t |  i ƒ  ƒ ƒ S(   sT   
        Return a list of transmitter pulse lengths used present in the log
        (   t   sortedt   setR	   (   R   (    (    s   c:\py\lib\plm.pyt   xmits8   s    c         C   s   d |  i  ƒ  |  i ƒ  f S(   Ns   PLMLog %s, xmit=%s(   t   datespanR   (   R   (    (    s   c:\py\lib\plm.pyt   __repr__>   s    c         C   sI  t  i i |  ƒ } | d d j oð t i |  d t d ƒ ƒ} t i | d d … d f ƒ | d d … d f <d | | d d … d f d j d f <d | | d d … d f d	 j d f <d
 | | d d … d f d j d f <d | | d d … d f d j d f <t | ƒ Sn3| d d j ot i |  d d d t d ƒ ƒ} d t i	 t
 | ƒ d f ƒ } | d d … d d … f | d d … d d … f <d | d d … d f <d | d d … d f <d | d d … d f <| d d … d f d j | d d … d f <t i | d d … d f ƒ | d d … d f <t | ƒ Sn| d d j oït i |  d d ƒ} d t i	 t
 | ƒ d f ƒ } t | d d !ƒ } t | d d !ƒ } t | d d !ƒ } | d d … d f t i t i | | | ƒ i ƒ  ƒ | d d … d f <| d d … d f | d d … d	 f <| d d … d f | d d … d f <| d d … d f | d d … d f <| d d … d	 f | d d … d f <| d d … d f | d d … d f <d | d d … d f <d | d d … d f <d | d d … d f <| d d … d f d j | d d … d f <t | ƒ Sn d Sd S(   sj  
        Load PLM log from a given file
        The function determines file format from the name:
            3. '????????plm-4.dat' run 20+, since 24 March 2008
            2. '????????plm4.dat'  early on run 20 (before 24 March 2008)
            1. '????????_plm4.dat' prior to run 20
        
        If a file read is in format 1 or 2, the following assumptions are made
        (the corresponding data were not recorded):
            
            variable gain defaults to 10
            integration delay to 55
            integration time to 125
            PLM is considered not to overload if M0 > 0
        i   s	   plm-4.datt   usecolsi   Ni    i
   i   i   i2   i   id   i   s   plm4.datt   skiprowsg        i7   i	   i}   i   s	   _plm4.dati   i   i   i   (   i    i   i   i   i   i   (   t   ost   patht   basenamet   flibt	   loadasciit   ranget
   labview2tmR    t   numpyt   zerost   lent   intt   timet   mktimet   datetimet   datet	   timetuplet   None(   t   filenameR   R   t   rawdatat   yeart   montht   day(    (    s   c:\py\lib\plm.pyt   load@   sJ    /&&&&!2,/H&&&&&,c         C   sC   |  d j o d n d |  } t  i | d | d | ƒi | | ƒ S(   sj   
        Return plm log for a given run, withing [start, end] period if boundaries are specified.
        i   s   \\phpc338\Run20\PLM4s   C:\pub\plm\run%dt   startt   end(   R    t   loaddirt   period(   t   runR4   R5   t   logdir(    (    s   c:\py\lib\plm.pyt   loadrunÁ   s    N(   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R3   R-   R:   (    (    (    s   c:\py\lib\plm.pyR       s(   															(   R=   R   t   os.pathR(   R*   R$   t   matplotlib.datest
   matplotlibR    t   timelogt   TimeLogR    (    (    (    s   c:\py\lib\plm.pys   <module>   s   