Skip to content

Commit

Permalink
tests nav3: add multi observation tests
Browse files Browse the repository at this point in the history
pep8
  • Loading branch information
scivision committed Sep 3, 2019
1 parent 9396d71 commit 2a7a614
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
12 changes: 6 additions & 6 deletions georinex/nav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def rinexnav3(fn: Union[TextIO, str, Path],
check = np.array([True]*t[svi].size)
duplicate = True
sv_copies = 0
while duplicate: # process until there are no more duplicate times
while duplicate: # process until there are no more duplicate times
tu, iu = np.unique(t[svi][check], return_index=True)
duplicate = tu.size != t[svi][check].size

Expand All @@ -114,8 +114,8 @@ def rinexnav3(fn: Union[TextIO, str, Path],
dsf = {}
for (i, d) in zip(gi, darr.T):
if sv[0] in ('R', 'S') and cf[i] in ('X', 'dX', 'dX2',
'Y', 'dY', 'dY2',
'Z', 'dZ', 'dZ2'):
'Y', 'dY', 'dY2',
'Z', 'dZ', 'dZ2'):
d *= 1000 # km => m

dsf[cf[i]] = (('time', 'sv'), d[:, None])
Expand All @@ -125,11 +125,11 @@ def rinexnav3(fn: Union[TextIO, str, Path],
nav = xarray.Dataset(dsf, coords={'time': tu, 'sv': [svv]})
else:
nav = xarray.merge((nav,
xarray.Dataset(dsf, coords={'time': tu, 'sv': [svv]})))
xarray.Dataset(dsf, coords={'time': tu, 'sv': [svv]})))

sv_copies += 1
check[np.arange(check.size)[check][iu]] = False

# %% patch SV names in case of "G 7" => "G07"
nav = nav.assign_coords(sv=[s.replace(' ', '0') for s in nav.sv.values.tolist()])
# %% other attributes
Expand Down
74 changes: 42 additions & 32 deletions tests/test_nav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,48 @@ def test_tlim_past_eof():
assert times == datetime(2018, 7, 29, 23)


def test_mixed():
fn = R/'ELKO00USA_R_20182100000_01D_MN.rnx.gz'
nav = gr.load(fn,
tlim=(datetime(2018, 7, 28, 21),
datetime(2018, 7, 28, 23)))

E04 = nav.sel(sv='E04').dropna(dim='time', how='all')
E04_1 = nav.sel(sv='E04_1').dropna(dim='time', how='all')

E04tt = E04['TransTime'].values
E04_1tt = E04_1['TransTime'].values

assert E04tt != approx(E04_1tt)

assert isinstance(nav, xarray.Dataset)
assert sorted(nav.svtype) == ['C', 'E', 'G', 'R']

times = gr.to_datetime(nav.time)

assert times.size == 15
# %% full flle test
nav = gr.load(fn)

svin = {'C06', 'C07', 'C08', 'C11', 'C12', 'C14', 'C16', 'C20', 'C21',
'C22', 'C27', 'C29', 'C30', 'E01', 'E02', 'E03', 'E04', 'E05',
'E07', 'E08', 'E09', 'E11', 'E12', 'E14', 'E18', 'E19', 'E21',
'E24', 'E25', 'E26', 'E27', 'E30', 'E31', 'G01', 'G02', 'G03',
'G04', 'G05', 'G06', 'G07', 'G08', 'G09', 'G10', 'G11', 'G12',
'G13', 'G14', 'G15', 'G16', 'G17', 'G18', 'G19', 'G20', 'G21',
'G22', 'G23', 'G24', 'G25', 'G26', 'G27', 'G28', 'G29', 'G30',
'G31', 'G32', 'R01', 'R02', 'R03', 'R04', 'R05', 'R06', 'R07',
'R08', 'R09', 'R10', 'R11', 'R12', 'R13', 'R14', 'R15', 'R16',
'R17', 'R18', 'R19', 'R20', 'R21', 'R22', 'R23', 'R24'}
assert len(svin.intersection(nav.sv.values)) == len(svin)

C05 = nav.sel(sv='C06').dropna(how='all', dim='time')
E05 = nav.sel(sv='E05').dropna(how='all', dim='time')

assert C05.time.size == 3 # from inspection of file
assert E05.time.size == 22 # duplications in file at same time--> take first time


@pytest.mark.parametrize('filename, sv, shape',
[('VILL00ESP_R_20181700000_01D_MN.rnx.gz', 'S36', (542, 16)),
('VILL00ESP_R_20181700000_01D_MN.rnx.gz', 'G05', (7, 29)),
Expand Down Expand Up @@ -55,38 +97,6 @@ def test_large_all(sv, size):
assert dat.shape[0] == size # manually counted from file


def test_mixed():
fn = R/'ELKO00USA_R_20182100000_01D_MN.rnx.gz'
nav = gr.load(fn,
tlim=(datetime(2018, 7, 28, 21),
datetime(2018, 7, 28, 23)))

assert isinstance(nav, xarray.Dataset)
assert sorted(nav.svtype) == ['C', 'E', 'G', 'R']

times = gr.to_datetime(nav.time)

assert times.size == 15
# %% full flle test
nav = gr.load(fn)
assert (nav.sv.values == ['C06', 'C07', 'C08', 'C11', 'C12', 'C14', 'C16', 'C20', 'C21',
'C22', 'C27', 'C29', 'C30', 'E01', 'E02', 'E03', 'E04', 'E05',
'E07', 'E08', 'E09', 'E11', 'E12', 'E14', 'E18', 'E19', 'E21',
'E24', 'E25', 'E26', 'E27', 'E30', 'E31', 'G01', 'G02', 'G03',
'G04', 'G05', 'G06', 'G07', 'G08', 'G09', 'G10', 'G11', 'G12',
'G13', 'G14', 'G15', 'G16', 'G17', 'G18', 'G19', 'G20', 'G21',
'G22', 'G23', 'G24', 'G25', 'G26', 'G27', 'G28', 'G29', 'G30',
'G31', 'G32', 'R01', 'R02', 'R03', 'R04', 'R05', 'R06', 'R07',
'R08', 'R09', 'R10', 'R11', 'R12', 'R13', 'R14', 'R15', 'R16',
'R17', 'R18', 'R19', 'R20', 'R21', 'R22', 'R23', 'R24']).all()

C05 = nav.sel(sv='C06').dropna(how='all', dim='time')
E05 = nav.sel(sv='E05').dropna(how='all', dim='time')

assert C05.time.size == 3 # from inspection of file
assert E05.time.size == 22 # duplications in file at same time--> take first time


@pytest.mark.parametrize('rfn, ncfn',
[('galileo3.15n', 'r3galileo.nc'),
('demo.17n', 'r3gps.nc'),
Expand Down

0 comments on commit 2a7a614

Please sign in to comment.