labcom.SamplePlot (version 22.0.0, 2020-07-31)

retrieveのサンプル(計測データ)スクリプト
 
データを取り出し、グラフ表示する。
 
 
$ python SamplePlot.py [options] diag shot subshot channel [nsum]
 or 
$ SamplePlot.py [options] diag shot subshot channel [nsum]
 
[ source code ]
 
import sys
import numpy as np
import labcom
from labcom.Retriever import Retriever,RetrieveError 
#
if __name__ == '__main__' :
    import matplotlib.pyplot as plt
    import optparse
    parser = optparse.OptionParser(usage='%prog [options] diag shot subshot channel [nsum]', version=__version__)
    gopt = optparse.OptionGroup(parser,'Range options','(Only one can be used from below.)')
    gopt.add_option('--et', action='store', dest='range_et', metavar='RANGE', help='range by experiment time')
    gopt.add_option('--tt', action='store', dest='range_tt', metavar='RANGE', help='range by relative time from trigger')
    gopt.add_option('--ss', action='store', dest='range_ss', metavar='RANGE', help='range by sample number')
    gopt.add_option('--frame', action='store', dest='range_fr', metavar='RANGE', help='range by frame number for PHA')
    g2opt = optparse.OptionGroup(parser,'Direct options','for direct connection.')
    g2opt.add_option('--host', action='store', dest='host_opt',help='Connection destination host name')
    g2opt.add_option('--path', action='store', dest='path_opt',help='Connection destination path name')
    
    parser.add_option('--raw', action="store_true", dest="raw_mode", default=False, help="don't voltage convert")
    parser.add_option_group(gopt)
    parser.add_option_group(g2opt)
 
    argopt, arg_remainder = parser.parse_args()
    argvs= arg_remainder
    argc = len(argvs)
 
    if( argc < 4 ) :
        parser.print_help()
        sys.exit(0)
 
    if( argc > 4 ) :
        nsum = int(argvs[4])
    else :
        nsum = 0
 
    range_type = Retriever.RANGE_NOSET
    range_str = None
    if None != argopt.range_et :
        if range_type == Retriever.RANGE_NOSET :
            range_str = argopt.range_et
            range_type = Retriever.RANGE_EXP
        else :
            range_type = None
    if None != argopt.range_tt :
        if range_type == Retriever.RANGE_NOSET :
            range_str = argopt.range_tt
            range_type = Retriever.RANGE_TRIG
        else :
            range_type = None
    if None != argopt.range_ss :
        if range_type == Retriever.RANGE_NOSET :
            range_str = argopt.range_ss
            range_type = Retriever.RANGE_SAMPLES
        else :
            range_type = None
    if None != argopt.range_fr :
        if range_type == Retriever.RANGE_NOSET :
            range_str = argopt.range_fr
            range_type = Retriever.RANGE_FRAMES
        else :
            range_type = None
 
    if( range_type == None ) :
        parser.print_help()
        sys.exit(0)
 
    host_opt = argopt.host_opt
    path_opt = argopt.path_opt
    if None != argopt.host_opt :
        if None == argopt.path_opt :
            path_opt = 'ShotDataFS'
 
    print('SamplePlot.py START')
    print(Retriever.version())
    try:
        p = Retriever(0, host_opt, path_opt, 0)
        if( argopt.raw_mode ) :
            p.raw_mode=1
        x = p.get(argvs[0], int(argvs[1]), int(argvs[2]), int(argvs[3]), range_type, range_str)
        arc= x
        py= arc.val()
        ary_len = len(py)
        print(py.dtype)
        print(py.ndim)
        print(py.shape)
        print(arc.parameters)
        
        if arc.num_times() != ary_len :
            print('It's different from the number of sample and times.')
            sys.exit(0)
        
        if 0 == nsum :
            if ( 1000000 < ary_len ) :  
                nsum = 100
            elif ( 100000 < ary_len ) :  
                nsum = 10
            else :  
                nsum = 1
            
        print('nsum : ',nsum)
 
        if 1 == nsum :
            px = arc.time()
        else :
            base = np.ones(nsum)/float(nsum)
            px = np.convolve(arc.time(), base, 'valid')
            py = np.convolve(py, base, 'valid')
        
        plt.plot(px, py)
        plt.show()
    except RetrieveError as e:
        print('Retrieve Error : ', e.msg,' (',e.func,':',e.code,')') 
 
    print('SamplePlot.py END')