Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 0f8ae7c

Browse files
Updated unit tests
Updated hanlding of encoding names, added GLONASS tracking test.
1 parent 7af2714 commit 0f8ae7c

File tree

5 files changed

+166
-97
lines changed

5 files changed

+166
-97
lines changed

tests/test_acquisition.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
99

1010
from test_common import generate_sample_file, \
11-
run_peregrine,\
12-
propagate_code_phase, \
13-
get_sampling_freq
11+
run_peregrine,\
12+
propagate_code_phase, \
13+
get_sampling_freq
1414

1515
import os
1616
import peregrine.acquisition as acq
17+
from peregrine import defaults
1718

1819

1920
def get_acq_result_file_name(sample_file):
@@ -37,15 +38,15 @@ def run_acq_test(init_doppler, init_code_phase,
3738

3839
for prn in prns:
3940
samples_filename = generate_sample_file(prn, init_doppler,
40-
init_code_phase,
41-
file_format, freq_profile)
41+
init_code_phase,
42+
file_format, freq_profile)
4243

4344
run_peregrine(samples_filename, file_format, freq_profile,
4445
skip_param, skip_val)
4546

4647
code_phase = propagate_code_phase(init_code_phase,
47-
get_sampling_freq(freq_profile),
48-
skip_param, skip_val)
48+
get_sampling_freq(freq_profile),
49+
skip_param, skip_val)
4950

5051
if skip_val == 0:
5152
check_acq_results(samples_filename, prn, init_doppler, code_phase)
@@ -57,7 +58,7 @@ def run_acq_test(init_doppler, init_code_phase,
5758

5859
def check_acq_results(filename, prn, doppler, code_phase):
5960
acq_results = acq.load_acq_results(
60-
get_acq_result_file_name(filename))
61+
get_acq_result_file_name(filename))
6162

6263
acq_results = sorted(acq_results,
6364
lambda x, y: -1 if x.snr > y.snr else 1)
@@ -79,7 +80,7 @@ def check_acq_results(filename, prn, doppler, code_phase):
7980
assert code_phase_diff < 1.0
8081

8182

82-
#def test_acquisition():
83+
# def test_acquisition():
8384
# """
8485
# Test GPS L1C/A acquisition
8586
# """
@@ -97,21 +98,21 @@ def test_acqusition_prn1_m1000():
9798
"""
9899
Test GPS L1C/A acquisition
99100
"""
100-
run_acq_test(-1000., 0., [1], '2bits')
101+
run_acq_test(-1000., 0., [1], defaults.FORMAT_2BITS_X1_GPS_L1)
101102

102103

103104
def test_acqusition_prn32_0():
104105
"""
105106
Test GPS L1C/A acquisition
106107
"""
107-
run_acq_test(0., 0., [32], '2bits')
108+
run_acq_test(0., 0., [32], defaults.FORMAT_2BITS_X1_GPS_L1)
108109

109110

110111
def test_acqusition_prn5_p1000():
111112
"""
112113
Test GPS L1C/A acquisition
113114
"""
114-
run_acq_test(1000., 0., [5], '2bits')
115+
run_acq_test(1000., 0., [5], defaults.FORMAT_2BITS_X1_GPS_L1)
115116

116117

117118
def test_skip_params():
@@ -122,5 +123,5 @@ def test_skip_params():
122123
--skip_ms
123124
124125
"""
125-
run_acq_test(1000, 0, [1], '1bit', skip_samples=1000)
126-
run_acq_test(1000, 0, [1], '1bit', skip_ms=50)
126+
run_acq_test(1000, 0, [1], defaults.FORMAT_1BIT_X1_GPS_L1, skip_samples=1000)
127+
run_acq_test(1000, 0, [1], defaults.FORMAT_1BIT_X1_GPS_L1, skip_ms=50)

tests/test_common.py

+76-44
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
import peregrine.iqgen.iqgen_main as iqgen
1313
import peregrine.defaults as defaults
1414
import peregrine.gps_constants as gps
15+
import peregrine.glo_constants as glo
1516
import numpy as np
1617

1718
from mock import patch
1819

1920

2021
def fileformat_to_bands(file_format):
21-
if file_format == '1bit':
22-
bands = ['l1ca']
23-
elif file_format == '1bit_x2':
24-
bands = ['l1ca', 'l2c']
25-
elif file_format == '2bits':
26-
bands = ['l1ca']
27-
elif file_format == '2bits_x2':
28-
bands = ['l1ca', 'l2c']
29-
elif file_format == '2bits_x4':
30-
bands = ['l1ca', 'l2c']
22+
profile = defaults.file_encoding_profile[file_format]
23+
bands = []
24+
for p in profile:
25+
if p == defaults.sample_channel_GPS_L1:
26+
bands += [gps.L1CA]
27+
elif p == defaults.sample_channel_GPS_L2:
28+
bands += [gps.L2C]
29+
elif p == defaults.sample_channel_GLO_L1:
30+
bands += [glo.GLO_L1]
31+
elif p == defaults.sample_channel_GLO_L2:
32+
bands += [glo.GLO_L2]
3133
return bands
3234

3335

@@ -67,8 +69,8 @@ def generate_2bits_x4_sample_file(filename):
6769
samples[channel_lookup[rx]][:] = chan
6870
# Store the result back to the same file
6971
packed = np.zeros(num_samples, dtype=np.uint8)
70-
packed = samples[3][::] << 6
71-
packed |= samples[0][::] & 3
72+
packed[:] = samples[3] << 6
73+
packed |= samples[0] & 3
7274
with open(filename, 'wb') as f:
7375
packed.tofile(f)
7476

@@ -77,17 +79,17 @@ def generate_2bits_x4_sample_file(filename):
7779

7880
def generate_piksi_sample_file(filename):
7981
samples_lookup = [
80-
0b11111100,
81-
0b11011000,
82-
0b10110100,
83-
0b10010000,
84-
0b00000000,
85-
0b00100100,
86-
0b01001000,
87-
0b01101100
82+
0b11111100,
83+
0b11011000,
84+
0b10110100,
85+
0b10010000,
86+
0b00000000,
87+
0b00100100,
88+
0b01001000,
89+
0b01101100
8890
]
8991
samples_lookup_values = [
90-
-7, -7, -5, -5, -3, -3, -1, -1, 1, 1, 3, 3, 5, 5, 7, 7
92+
-7, -7, -5, -5, -3, -3, -1, -1, 1, 1, 3, 3, 5, 5, 7, 7
9193
]
9294
num_samples = int(1e6)
9395
packed = np.zeros(num_samples, dtype=np.uint8)
@@ -104,23 +106,53 @@ def generate_sample_file(gps_sv_prn, init_doppler,
104106
freq_profile, generate=.1):
105107
sample_file = 'iqgen-data-samples.bin'
106108
params = ['iqgen_main']
107-
params += ['--gps-sv', str(gps_sv_prn)]
108-
109-
if file_format == '1bit':
110-
encoder = '1bit'
111-
params += ['--bands', 'l1ca']
112-
elif file_format == '1bit_x2':
113-
encoder = '1bit'
114-
params += ['--bands', 'l1ca+l2c']
115-
elif file_format == '2bits':
116-
encoder = '2bits'
117-
params += ['--bands', 'l1ca']
118-
elif file_format == '2bits_x2':
119-
encoder = '2bits'
120-
params += ['--bands', 'l1ca+l2c']
121-
elif file_format == '2bits_x4':
122-
encoder = '2bits'
123-
params += ['--bands', 'l1ca+l2c']
109+
bands = fileformat_to_bands(file_format)
110+
111+
if gps.L1CA in bands or gps.L2C in bands:
112+
params += ['--gps-sv', str(gps_sv_prn)]
113+
114+
if file_format == defaults.FORMAT_1BIT_X1_GPS_L1:
115+
encoder = '1bit'
116+
params += ['--bands', 'l1ca']
117+
elif file_format == defaults.FORMAT_1BIT_X2_GPS_L1L2:
118+
encoder = '1bit'
119+
params += ['--bands', 'l1ca+l2c']
120+
elif file_format == defaults.FORMAT_2BITS_X1_GPS_L1:
121+
encoder = '2bits'
122+
params += ['--bands', 'l1ca']
123+
elif file_format == defaults.FORMAT_2BITS_X2_GPS_L1L2:
124+
encoder = '2bits'
125+
params += ['--bands', 'l1ca+l2c']
126+
elif file_format == defaults.FORMAT_2BITS_X4_GPS_L1L2_GLO_L1L2:
127+
encoder = '2bits'
128+
params += ['--bands', 'l1ca+l2c']
129+
else:
130+
assert False
131+
elif glo.GLO_L1 in bands or glo.GLO_L2 in bands:
132+
params += ['--glo-sv', str(gps_sv_prn)]
133+
134+
if file_format == defaults.FORMAT_1BIT_X1_GLO_L1:
135+
encoder = '1bit'
136+
params += ['--bands', 'l1']
137+
elif file_format == defaults.FORMAT_1BIT_X1_GLO_L2:
138+
encoder = '1bit'
139+
params += ['--bands', 'l2']
140+
elif file_format == defaults.FORMAT_1BIT_X2_GLO_L1L2:
141+
encoder = '1bit'
142+
params += ['--bands', 'l1+l2']
143+
elif file_format == defaults.FORMAT_2BITS_X1_GLO_L1:
144+
encoder = '2bits'
145+
params += ['--bands', 'l1']
146+
elif file_format == defaults.FORMAT_2BITS_X2_GLO_L1L2:
147+
encoder = '2bits'
148+
params += ['--bands', 'l1+l2']
149+
elif file_format == defaults.FORMAT_2BITS_X4_GPS_L1L2_GLO_L1L2:
150+
encoder = '2bits'
151+
params += ['--bands', 'l1+l2']
152+
else:
153+
assert False
154+
else:
155+
assert False
124156

125157
params += ['--encoder', encoder]
126158
params += ['--doppler-type', 'const']
@@ -153,12 +185,12 @@ def run_peregrine(file_name, file_format, freq_profile,
153185
short_long_cycles=None):
154186

155187
parameters = [
156-
'peregrine',
157-
'--file', file_name,
158-
'--file-format', file_format,
159-
'--profile', freq_profile,
160-
skip_param, str(skip_val),
161-
'--progress-bar', 'stdout'
188+
'peregrine',
189+
'--file', file_name,
190+
'--file-format', file_format,
191+
'--profile', freq_profile,
192+
skip_param, str(skip_val),
193+
'--progress-bar', 'stdout'
162194
]
163195
if skip_tracking:
164196
parameters += ['-t']

tests/test_file_format.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ def test_file_format_1bit():
1313
"""
1414
Test different file formats: '1bit'
1515
"""
16-
run_acq_test(1000, 0, [1], '1bit')
16+
run_acq_test(1000, 0, [1], defaults.FORMAT_1BIT_X1_GPS_L1)
1717

1818

1919
def test_file_format_2bits():
2020
"""
2121
Test different file formats: '2bits'
2222
"""
23-
run_acq_test(1000, 0, [1], '2bits')
23+
run_acq_test(1000, 0, [1], defaults.FORMAT_2BITS_X1_GPS_L1)
2424

2525

2626
def test_file_format_1bitx2():
2727
"""
2828
Test different file formats: '1bit_x2'
2929
"""
30-
run_acq_test(1000, 0, [1], '1bit_x2')
30+
run_acq_test(1000, 0, [1], defaults.FORMAT_1BIT_X2_GPS_L1L2)
3131

3232

3333
def test_file_format_2bitsx2():
3434
"""
3535
Test different file formats: '2bits_x2'
3636
"""
37-
run_acq_test(1000, 0, [1], '2bits_x2')
37+
run_acq_test(1000, 0, [1], defaults.FORMAT_2BITS_X2_GPS_L1L2)
3838

3939

4040
def test_file_formats():
@@ -45,9 +45,9 @@ def test_file_formats():
4545
# test 'piksi' format
4646
val = generate_piksi_sample_file(SAMPLE_FILE_NAME)
4747
samples = {
48-
'samples_total': -1,
49-
'sample_index': 0,
50-
L1CA: {}
48+
'samples_total': -1,
49+
'sample_index': 0,
50+
L1CA: {}
5151
}
5252
for num in [-1, defaults.processing_block_size]:
5353
load_samples(samples, SAMPLE_FILE_NAME, num, 'piksi')

tests/test_freq_profiles.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
99

1010
from test_acquisition import run_acq_test
11+
from peregrine import defaults
1112

1213

1314
def test_custom_rate():
14-
run_acq_test(-4000, 0, [1], '2bits', 'custom_rate')
15+
run_acq_test(-4000, 0, [1], defaults.FORMAT_2BITS_X1_GPS_L1, 'custom_rate')
1516

1617

1718
def test_low_rate():
18-
run_acq_test(-2000, 0, [2], '2bits', 'low_rate')
19+
run_acq_test(-2000, 0, [2], defaults.FORMAT_2BITS_X1_GPS_L1, 'low_rate')
1920

2021

2122
def test_normal_rate():
22-
run_acq_test(2000, 0, [3], '2bits', 'normal_rate')
23+
run_acq_test(2000, 0, [3], defaults.FORMAT_2BITS_X1_GPS_L1, 'normal_rate')
2324

2425

2526
# Takes long time to complete in Travis CI test and
2627
# therefore fails
27-
#def test_high_rate():
28-
# run_acq_test(2000, 0, [4], '2bits', 'high_rate')
28+
# def test_high_rate():
29+
# run_acq_test(2000, 0, [4], defaults.FORMAT_2BITS_X1_GPS_L1, 'high_rate')

0 commit comments

Comments
 (0)