³ò
eÁJc           @   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 ULT fridge Platinum Thermometer logs.

Changelog (partial)
25 Jun 2009, Lev
handle empty logs in the "PLMLog.interpolate" method

29 Sep 2009, Lev
add 'trace_filename' method
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 d d d d d „ Z d „  Z d „  Z d „  Z d d „ Z e d „  ƒ Z e d d d „ ƒ Z 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\plmlog.pyt
   fieldcount*   s    c         C   s   |  i  d d … d f S(   t   temperatureNi   (   t   data(   t   self(    (    s   c:\py\lib\plmlog.pyt   T-   s    c         C   s   |  i  d d … d f S(   t   M0Ni   (   R   (   R   (    (    s   c:\py\lib\plmlog.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\plmlog.pyt   xmit/   s    c         C   s   |  i  d d … d f S(   s
   MCTNS TempNi   (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   T_MCTNS0   s    c         C   s   |  i  d d … d f S(   s   MCTNS ratioNi   (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   r_MCTNS1   s    c         C   s   |  i  d d … d f S(   s   raw backgroundNi   (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   bg2   s    c         C   s   |  i  d d … d f S(   s   gain stability indexNi   (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   stabi3   s    c         C   s    |  i  d d … d f i d ƒ S(   s
   PLM-4 gainNi   R   (   R   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   gain4   s    c         C   s   |  i  d d … d f S(   s   integration delayNi	   (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   idelay5   s    c         C   s   |  i  d d … d f S(   s   integration timeNi
   (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   itime6   s    c         C   s   |  i  d d … d f d j S(   s9   True if the measurement overloaded PLM-4, otherwise FalseNi   i    (   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   overload7   s    c         C   s   |  i  ƒ  |  i ƒ  |  i ƒ  S(   s   raw (unstabilised) M0(   R   R   R   (   R   (    (    s   c:\py\lib\plmlog.pyt   rawM08   s    c         C   sè   |  i  ƒ  |  i  ƒ  j } | d j	 o | |  i ƒ  | j M} n | d j	 o | |  i ƒ  | j M} n | d j	 o | |  i ƒ  | j M} n | d j	 o | |  i ƒ  | j M} n | d j	 o | |  i ƒ  | j M} n |  i | ƒ S(   sÚ   
        Return a subset of the log obtained for at given settings. Any of
        the paramameters, xmit, gain, idelay, itime, overload is used for
        filtering points if it is specified (is not 'None').
        N(   R   t   NoneR	   R   R   R   R   t   subset(   R   R	   R   R   R   R   R   (    (    s   c:\py\lib\plmlog.pyt   at:   s    c         C   s   |  i  d | ƒ S(   NR	   (   R   (   R   R	   (    (    s   c:\py\lib\plmlog.pyt   atxmitP   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\plmlog.pyt   xmitsR   s    c         C   s   d |  i  ƒ  |  i ƒ  f S(   Ns   PLMLog %s, xmit=%s(   t   datespanR   (   R   (    (    s   c:\py\lib\plmlog.pyt   __repr__X   s    gìQ¸…ë±?c      	   C   s…   t  |  ƒ d j  o t i | Sn |  i ƒ  d | d } d t i | |  i ƒ  d | d t i d t i ƒ} | d | d } | S(   sM  
        Return interpolated PLM temperature for time(s) in 't'.
        'heatlink' [mK^2] is used to determine nuclear stage temperature
        Tns = (Tsp^2 - heatleak)^0.5
        Then 1/Tns vs time is interpolated linearly and PLM temperature
        is calculated back. 0.07 mK^2 is the value about right for ULT RUN 20
        i   i   g      à?g      ð?t   leftt   right(   t   lent   numpyt   nanR   t   interpt   t(   R   R"   t   heatleakt   Tnst   Tpt(    (    s   c:\py\lib\plmlog.pyt   interpolateZ   s    5c         C   s7  t  i i |  ƒ } | d d j oê t i |  d 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 | ƒ Sn'| d d j ot i |  d 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   colsi   Ni    i
   i   i   i2   i   id   i   s   plm4.datg        i7   i	   i}   i   s	   _plm4.dati   i   i   i   (   t   ost   patht   basenamet   ascii2numpyt	   loadasciit   flibt
   labview2tmR    R   t   zerosR   t   intt   timet   mktimet   datetimet   datet	   timetupleR   (   t   filenameR*   R   t   rawdatat   yeart   montht   day(    (    s   c:\py\lib\plmlog.pyt   loadi   sJ    /&&&&2,/H&&&&&,c         C   sL   t  i |  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   smbpathR    t   loaddirt   period(   t   runR<   R=   t   logdir(    (    s   c:\py\lib\plmlog.pyt   loadrunë   s    'c         C   sZ   t  i i t i |  i ƒ  | ƒ d |  i ƒ  | |  i ƒ  | t i |  i ƒ  | ƒ f ƒ S(   s‰   
        Return a standard filename 'YYYYMMDD/xplm-XMIT-GAIN-TIME.dat'
        containing the FID of the 'i'-th entry of the log
        s   xplm-%d-%d-%.2f.dat(	   R(   R)   t   joinR-   t   dt2filenameR"   R	   R   t
   tm2labview(   R   R   (    (    s   c:\py\lib\plmlog.pyt   trace_filenameó   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   R   R   R&   R;   RC   RG   (    (    (    s   c:\py\lib\plmlog.pyR       s.   															‚(   RJ   R(   t   os.pathR1   R3   R   t   matplotlib.datest
   matplotlibR-   t   timelogR+   t   TimeLogR    (    (    (    s   c:\py\lib\plmlog.pys   <module>
   s   