⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ordplot

📁 一个gps小工具包
💻
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/env python2.5
# $Id: ordPlot 1114 2008-03-11 12:52:53Z ocibu $
#
# A routine to plot the output of the ord apps.
# The above magic line works under osx 10.5 and ubuntu 7.10. Dunno if it is good
# any further...

import sys, string, time, datetime, numpy, matplotlib, pylab, math

def main():
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-d", "--debug", help="Increase the debugLevel",
                      default=0, dest="debugLevel", action="count")

    parser.add_option("-i", help="Input data file, defaults to stdin.",
                      dest="inputFile", type="string", action="store")

    parser.add_option("-t", dest="title", type="string", action="store",
                      help="Specify a title for the plot. \
                      Defaults to the name of the input stream.")

    parser.add_option("-l", "--legend", dest="legend", action="count",
                      help="Include a legend.")

    parser.add_option("-p", "--prn-highlight", dest="prnHighlight", action="append",
                     help="Highlight the indicated prn. Specify all for all prns.")

    parser.add_option("-o", "--ords-only", help="Only plot the ords (types 0 & 1).",
                      dest="ordsOnly", default=0, action="count")

    parser.add_option("-c", "--clocks-only", help="Only plot the clocks.",
                      dest="clocksOnly", default=0, action="count")

    parser.add_option("--clock-delta", help="Plot clock delta instead of clock residual.",
                      dest="clockDelta", default=0, action="count")

    parser.add_option("-s", dest="saveFig", action="store", type="string",
                      help="Save the figure to the indicated file")

    parser.add_option("-y", dest="yRange", action="store", type="string",
                      help="Fix the y range on the ords to be +- this value or include\
                      the percentage data indicated.")
                      
    parser.add_option("--start-time", dest="tStart", action="store",
                      help="Start time. Format as \"YYYY DOY HH:MM:SS.S\" (Note\
                      the trailing decimal place).") 

    parser.add_option("--smoothing", dest="smoothing", action="store", type="float",
                      default=0,
                      help="Smooth hilighted prns and clock data with specified \
                      window length. Window length is specied in seconds.")

    parser.add_option("--end-time", dest="tEnd", action="store",
                      help="End time. Format as \"YYYY DOY HH:MM:SS.S\" (Note\
                      the trailing decimal place).") 

    parser.add_option("-w", "--warts", dest="wartiness", action="count",
                      help="Increase the importants of warts on the plot.\
                      Zero (the default) means don't even plot them. One\
                      means plot them but don't autoscale to show them all\
                      (just show all the ords). Two means autoscale to show\
                      all the warts. Three means only show the warts and\
                      don't show any ords. Only zero and 2 have been\
                      implimented.")                    

    (options, args) = parser.parse_args()

    if (len(args) and options.inputFile == None):
        options.inputFile = args[0]

    inputFile = sys.stdin
    if (options.inputFile):
        inputFile = open(options.inputFile)

    if (options.title == None):
        options.title = inputFile.name

    prns = range(1,33)
    highlightPrns = []
    if options.prnHighlight:
        if options.prnHighlight[0] == 'all':
            highlightPrns = range(1,33)
        else:
            highlightPrns = [int(p) for p in options.prnHighlight]

    if (options.debugLevel):
        print "Processing: %s" % inputFile.name
        print "Debug level: %d" % options.debugLevel
        print "Title: %s" % options.title
        print "Warts: %s"% options.wartiness
        print "Smoothing: %d seconds" % options.smoothing
        print "Y axis:",
        if options.yRange:
            print options.yRange
        else:
            print "auto ranged"
        if options.debugLevel:
            print "highlighting prns:",highlightPrns

    # ------------------------------------------------------------------
    # Here we start reading in the ord file
    ordList=([],[],[],[])      # time, prn, ord, elevation
    wartList=([],[],[],[])     # time, prn, ord, elevation
    clockList=([],[])          # time, offset
    ocdList=([],[])

    rleClockList=[]

    for line in inputFile:
        line = line.strip()
        if options.debugLevel>1:
            print line
        if len(line)==0: continue

        if line[0] == "#": continue
        if line[0] == '>':
            if line[1] == "c":
                words=line.split()
                if len(words) < 9:
                    print "bad rle line"
                else:
                    t0 = parse_time(words[1:4])
                    t1 = parse_time(words[4:7])
                    offset = float(words[7])
                    slope = float(words[9])
                    abdev = float(words[10])
                    rleClockList.append( (t0, t1, offset, slope, abdev) )
            continue

        words=line.split()
        t = parse_time(words[0:3])

        ordType = int(words[3])
        if ordType == 0:
            if len(words) < 7:
                print "bad ord line"
                continue
            
            prn = int(words[4])
            ord = float(words[7])
            elev = float(words[5])
            wart = int(words[8],16)
            if wart==0:
                ordList[0].append(t)
                ordList[1].append(prn)
                ordList[2].append(ord)
                ordList[3].append(elev)
            else:
                wartList[0].append(t)
                wartList[1].append(prn)
                wartList[2].append(ord)
                wartList[3].append(elev)
        elif ordType == 1:
            if len(words) < 2: print "bad clock residual line"
            ocdList[0].append(t)
            ocdList[1].append(float(words[4]))
        elif ordType == 50:
            if len(words) < 5: print "bad clk line"
            clockList[0].append(t)
            clockList[1].append(float(words[4])) #offset

        if options.debugLevel>2 and len(clockList[0]) >= 200: break

    ords = numpy.array(ordList)
    warts = numpy.array(wartList)
    clocks = numpy.array(clockList)
    ocds = numpy.array(ocdList)

    # Since these are now in numpy arrays, delete the source to save some memory
    del ordList, clockList, wartList, ocdList
    # done reading in the ord file
    # ------------------------------------------------------------------
    
    # Now figure out how many axes we need to use
    plotOrds = True
    plotClocks = True

    if clocks.size==0 or options.ordsOnly: plotClocks = False
    if ((clocks.size==0 and options.clockDelta) and ords.size == 0 and warts.size == 0 and ocds.size == 0) or options.clocksOnly: plotOrds = False
    axesCount=0;
    if plotOrds: axesCount+=1
    if plotClocks: axesCount+=1

    if options.debugLevel:
        print "Read %d ords, %d clocks, %d ocds %d warts %d rle" %\
              (len(ords[0]), len(clocks[0]), len(ocds[0]), len(warts[0]),
               len(rleClockList))

    if axesCount == 0:
        print "No data to plot. Exiting"
        sys.exit()

    # A key handler for matplotlib
    def press(event):
        if event.key=='q' or event.key==' ':
            pylab.close()

    # Here we start generating the plots
    fig = pylab.figure()
    pylab.connect('key_press_event', press)
    yprops = dict(rotation=90,
                  horizontalalignment='right',
                  verticalalignment='center',
                  family='monospace',
                  x=-0.01)

    scale_props = dict(horizontalalignment="right",
                       verticalalignment="bottom",
                       size=8, family="sans-serif")

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -