Commit 90ebd47a authored by enfo's avatar enfo

Merge branch 'develop' into 'master'

Different delimiter support

See merge request enfo/sentiboard-utils!10
parents 5f55af0d 5e53b637
Pipeline #126 passed with stages
in 1 minute and 1 second
......@@ -2,6 +2,7 @@
import sys
import os
import re
import numpy as np
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
......@@ -11,8 +12,15 @@ def print_usage():
print(' python rtklib2matlab.py [rover.pos]')
sys.exit(1)
def split_line(line):
if '|' in line:
return line.split('|')
if '\t' in line:
return line.split('\t')
return re.sub(' +', ' ', line).split(' ')
def parseline(line, names):
values = line.split()
values = split_line(line)
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))
......@@ -33,13 +41,18 @@ if __name__ == '__main__':
print('')
print_usage()
if len(sys.argv) == 3:
if len(sys.argv) >= 3:
min_quality = int(sys.argv[2])
else:
min_quality = 1
if len(sys.argv) >= 4:
min_sat = int(sys.argv[3])
else:
min_sat = 6
infile = sys.argv[1]
print('Extracting average from %s with Q <= %d' % (infile, min_quality))
print('Extracting average from %s with Q <= %d, n_sat >= %d' % (infile, min_quality, min_sat))
names = ['week', 'tow', 'ecef_x', 'ecef_y', 'ecef_z', 'Q', 'ns', 'sdx', 'sdy',
'sdz', 'sdxy', 'sdyz', 'sdzx', 'age', 'ratio']
......@@ -48,28 +61,30 @@ if __name__ == '__main__':
for line in f:
if line.startswith('%'):
if 'ratio' in line:
names = [fix_name(name) for name in line[1:].split()]
names = [fix_name(name) for name in split_line(line.strip('% '))]
if 'gpst' in names:
names.insert(0, 'week')
continue
n_lines += 1
f.seek(0)
arr = np.zeros((4, n_lines))
arr = np.zeros((5, n_lines))
arr_ix=0
for line in f:
if line.startswith('%'):
continue
data_line = parseline(line, names)
for key, val in data_line.items():
if key in ['x_ecef', 'lat']:
if key in ['x_ecef', 'lat', 'latitude']:
arr[0, arr_ix] = val
elif key in ['y_ecef', 'lon']:
elif key in ['y_ecef', 'lon', 'longitude']:
arr[1, arr_ix] = val
elif key in ['z_ecef', 'alt']:
elif key in ['z_ecef', 'alt', 'height']:
arr[2, arr_ix] = val
elif key == 'q':
arr[3, arr_ix] = val
elif key == 'ns':
arr[4, arr_ix] = val
arr_ix += 1
print('')
......@@ -77,8 +92,17 @@ if __name__ == '__main__':
legal_arr = arr[:, arr[3,:] > 0]
valid_arr = legal_arr[:, legal_arr[3,:] <= min_quality]
valid_arr = valid_arr[:, valid_arr[4,:] >= min_sat]
print('Found %d quality points.' % valid_arr.shape[1])
for ix, key in enumerate(names):
if key in ['x_ecef', 'lat', 'latitude']:
name_start_ix = ix
break
print('')
print('Mean: %s' % np.mean(valid_arr, axis=1)[:3])
print('Std : %s' % np.std(valid_arr, axis=1)[:3])
print('Mean:')
print('\t'.join(names[name_start_ix:name_start_ix+3]))
llh = np.mean(valid_arr, axis=1)[:3]
print('%.12f\t%.12f\t%.12f' % (llh[0], llh[1], llh[2]))
......@@ -2,18 +2,26 @@
import sys
import os
import re
from scipy.io import savemat
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
def print_usage():
print('Usage:')
print(' python rtklib2matlab.py [rover.pos]')
sys.exit(1)
def parseline(line, names):
def split_line(line):
if '|' in line:
return line.split('|')
if '\t' in line:
return line.split('\t')
return re.sub(' +', ' ', line).split(' ')
values = line.split('|')
def parseline(line, names):
values = split_line(line)
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))
......@@ -38,7 +46,7 @@ if __name__ == '__main__':
infile = sys.argv[1]
outfile = os.path.splitext(infile)[0] + '.mat'
print('Converting %s to to %s' % (infile, outfile))
print('Converting %s to %s' % (infile, outfile))
names = ['week', 'tow', 'ecef_x', 'ecef_y', 'ecef_z', 'Q', 'ns', 'sdx', 'sdy',
'sdz', 'sdxy', 'sdyz', 'sdzx', 'age', 'ratio']
......@@ -58,7 +66,7 @@ if __name__ == '__main__':
for line in f:
if line.startswith('%'):
if 'age' in line:
names = [handle_name(name) for name in line.strip('% ').split('|')]
names = [handle_name(name) for name in split_line(line.strip('% '))]
if names[0] == 'gpst':
names.insert(0, 'week')
continue
......
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