Commit 36bac2d3 authored by Sigurd M. Albrektsen's avatar Sigurd M. Albrektsen

Added tool to calculate average from rtklib.pos

parent 066529fc
#!/usr/bin/env python
import sys
import os
import numpy as np
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
def print_usage():
print(' python [rover.pos]')
def parseline(line, names):
values = line.split()
converters = [int] + [float]*4 + [int]*2 + [float]*8
conv_vals = [c(v) for c, v in zip(converters, values) ]
return dict(zip(names, conv_vals))
def fix_name(name):
name = name.strip().lower()
if '(' in name:
name = name[:name.find('(')]
name = name.replace('-', '_')
return name
if __name__ == '__main__':
import sys
if len(sys.argv) < 2:
print('No file specified.')
if len(sys.argv) == 3:
min_quality = int(sys.argv[2])
min_quality = 1
infile = sys.argv[1]
print('Extracting average from %s with Q <= %d' % (infile, min_quality))
names = ['week', 'tow', 'ecef_x', 'ecef_y', 'ecef_z', 'Q', 'ns', 'sdx', 'sdy',
'sdz', 'sdxy', 'sdyz', 'sdzx', 'age', 'ratio']
n_lines = 0
with open(infile, 'rU') as f:
for line in f:
if line.startswith('%'):
if 'ratio' in line:
names = [fix_name(name) for name in line[1:].split()]
if 'gpst' in names:
names.insert(0, 'week')
n_lines += 1
arr = np.zeros((4, n_lines))
for line in f:
if line.startswith('%'):
data_line = parseline(line, names)
for key, val in data_line.items():
if key in ['x_ecef', 'lat']:
arr[0, arr_ix] = val
elif key in ['y_ecef', 'lon']:
arr[1, arr_ix] = val
elif key in ['z_ecef', 'alt']:
arr[2, arr_ix] = val
elif key == 'q':
arr[3, arr_ix] = val
arr_ix += 1
print('Found %d lines' % arr_ix)
legal_arr = arr[:, arr[3,:] > 0]
valid_arr = legal_arr[:, legal_arr[3,:] <= min_quality]
print('Found %d quality points.' % valid_arr.shape[1])
print('Mean: %s' % np.mean(valid_arr, axis=1)[:3])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment