Exemplo n.º 1
0
 def test(self):
     p1 = gpstk.Position(1.5, 6.2, 3.5)
     p2 = gpstk.Position(1.0, 1.8, 0.5)
     self.assertAlmostEqual(5.348831648126533, gpstk.range(p1, p2))
Exemplo n.º 2
0
 def test(self):
     p1 = gpstk.Position(1.5, 6.2, 3.5)
     p2 = gpstk.Position(1.0, 1.8, 0.5)
     self.assertAlmostEqual(5.348831648126533, gpstk.range(p1, p2))
Exemplo n.º 3
0
def main(args=sys.argv[1:]):
    program_description = ('This program takes 2 nav files and '
                            'provides a plot of the magnitude of '
                            'the difference of a given PRN ID.'
                            'Valid file types are ' + str(valid_types) + '.')

    parser = argparse.ArgumentParser(description=program_description)
    parser.add_argument('prn_id', type=int,
                        help='The integer PRN ID you are interested in.')
    parser.add_argument('filetype1', help='Type for the first file.')
    parser.add_argument('filename1', help='File name for the first file.')
    parser.add_argument('filetype2', help='Type for the second file.')
    parser.add_argument('filename2', help='File name for the second file.')
    parser.add_argument('-v', '--verbose', action="store_true",
                        help='Print output locations and error.')
    parser.add_argument('-n', '--noplot', action="store_true",
                        help='Don\'t plot the file.')
    parser.add_argument('-d', '--drawdots', action="store_true",
                        help='Matplotlib will not connect calculated data '
                        'points in the plot')
    parser.add_argument('-t', '--timestep', type=int, default=300,
                        help='Timestep, in seconds, between plot points.')
    parser.add_argument('-s', '--save', help='Save the image to <file>.')
    parser.add_argument('-f', '--format', default='%02H:%02M',
                        help='Format for x time ticks.')

    args = parser.parse_args(args)


    def timestr(t):
        return str(gpstk.CivilTime(t))

    def check(filetype, filename):
        if not filetype in valid_types:
            print 'Invalid filetype:', filetype
            print 'Valid choices are:' + str(valid_types)
            print 'Use the -h or --help flags for more information.\n'
            sys.exit()
            try:
                with open('filename'): pass
            except IOError as e:
                print e
                sys.exit(filename, 'cannot be read.\n')

    check(args.filetype1, args.filename1)
    check(args.filetype2, args.filename2)

    pos1 = read_data(args.filetype1, args.filename1, args.prn_id)
    pos2 = read_data(args.filetype2, args.filename2, args.prn_id)

    X = []  # list of x plot values
    Y = []  # list of y plot values

    starttime = max(pos1.first_time(), pos2.first_time())
    endtime = min(pos1.last_time(), pos2.last_time())

    if args.verbose:
        print (args.filename1 + ' ranges from ' + timestr(pos1.first_time())
              + ' to ' + timestr(pos1.last_time()))
        print (args.filename2 + ' ranges from ' + timestr(pos2.first_time())
              + ' to ' + timestr(pos2.last_time()))
        print 'Earliest time computable:', timestr(starttime)
        print 'Latest time computable:', timestr(endtime), '\n'

    sumErr = 0.0
    sumErrSq = 0.0
    n = 0
    maxErr = 0.0

    for t in gpstk.times(starttime, endtime, seconds=args.timestep):
        try:
            p1 = pos1.position(t)
            p2 = pos2.position(t)
            error = gpstk.range(p1, p2)
            maxErr = max(maxErr, error)
            X.append(t.getDays())
            Y.append(error)
            if args.verbose:
                sumErr += error
                sumErrSq += error*error
                n += 1
                print 'Time:', timestr(t)
                print '\tPosition 1:', p1
                print '\tPosition 2:', p2
                print '\tError:', error
        except gpstk.exceptions.InvalidRequest:
            if args.verbose:
                print 'Can\'t use data at:', timestr(t)

    if args.verbose and n > 0:
        print 'Arithmetic mean of error values: ', sumErr / n, 'm'
        print 'Root mean square of error values:', np.sqrt(sumErrSq / n), 'm'

    fig = plt.figure()
    title = ('Error for PRN ' + str(args.prn_id) + ' starting '
        + gpstk.CivilTime(starttime).printf('%02m/%02d/%04Y %02H:%02M:%02S'))

    fig.suptitle(title, fontsize=14, fontweight='bold')
    ax = fig.add_subplot(111)
    ax.text(0.90, 0.90, args.filetype1 + ': ' + args.filename1
        + '\n' + args.filetype2 + ': ' + args.filename2,
        verticalalignment='bottom', horizontalalignment='right',
        transform=ax.transAxes)
    ax.set_xlabel('Time')
    ax.set_ylabel('Error (meters)')
    if args.drawdots:
        plt.plot(X, Y, 'ro')
    else:
        plt.plot(X, Y, 'r')

    # sets the y scale
    plt.ylim([0, 2.0 * maxErr])

    # converts common time day (float) -> string
    def daytostring(x):
        t = gpstk.CommonTime()
        t.set(x)
        return gpstk.CivilTime(t).printf(args.format)

    # sets the text shown per-pixel when viewed interactively
    def format_coord(x, y):
        return 'x=' + daytostring(x) + ', y=%1.4f'%(y)
    ax.format_coord = format_coord

    # sets x ticks to use the daytostring text
    locs, labels = plt.xticks()
    for i in range(len(locs)):
        labels[i] = daytostring(locs[i])
    ax.set_xticklabels(labels)

    if not args.noplot:
        plt.show()

    if args.save is not None:
        fig.savefig(args.save)