Skip to content

Commit

Permalink
test large nav3 file
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Aug 2, 2018
1 parent 3965441 commit ec94b50
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 23 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE
10 changes: 6 additions & 4 deletions georinex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def readrinex(rinexfn: Path, outfn: Path=None,
# %% Navigation file


def rinexnav(fn: Path, ofn: Path=None, group: str='NAV',
def rinexnav(fn: Path, ofn: Path=None,
use: Union[str, list, tuple]=None,
group: str='NAV',
tlim: Tuple[datetime, datetime]=None) -> xarray.Dataset:
""" Read RINEX 2 or 3 NAV files"""
fn = Path(fn).expanduser()
Expand All @@ -58,9 +60,9 @@ def rinexnav(fn: Path, ofn: Path=None, group: str='NAV',

info = rinexinfo(fn)
if int(info['version']) == 2:
nav = rinexnav2(fn, tlim)
nav = rinexnav2(fn, tlim=tlim)
elif int(info['version']) == 3:
nav = rinexnav3(fn, tlim)
nav = rinexnav3(fn, use=use, tlim=tlim)
else:
raise ValueError(f'unknown RINEX {info} {fn}')

Expand Down Expand Up @@ -127,7 +129,7 @@ def gettime(fn: Path) -> xarray.DataArray:
fn = Path(fn).expanduser()

info = rinexinfo(fn)
assert int(info['version']) in (2,3)
assert int(info['version']) in (2, 3)

rtype = rinextype(fn)

Expand Down
3 changes: 1 addition & 2 deletions georinex/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ def rinexinfo(f: Union[Path, TextIO]) -> Dict[str, Union[str, float]]:
try:
line = f.readline()


info = {'version': float(line[:9]), # yes :9
'filetype': line[20],
'systems': line[40]}

if info['filetype'] == 'N' and int(info['version'])==2 and info['systems'] == ' ':
if info['filetype'] == 'N' and int(info['version']) == 2 and info['systems'] == ' ':
info['systems'] = 'G'

except (ValueError, UnicodeDecodeError) as e:
Expand Down
2 changes: 1 addition & 1 deletion georinex/nav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ def navtime2(fn: Path) -> xarray.DataArray:
attrs={'filename': fn,
'interval': ''})

return timedat
return timedat
12 changes: 9 additions & 3 deletions georinex/nav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from io import BytesIO
from datetime import datetime
from .io import opener, rinexinfo
from typing import Dict, List, Tuple, Any
from typing import Dict, List, Tuple, Any, Union
from typing.io import TextIO
# constants
STARTCOL3 = 4 # column where numerical data starts for RINEX 3
Nl = {'C': 7, 'E': 7, 'G': 7, 'J': 7, 'R': 3, 'S': 3} # number of additional SV lines


def rinexnav3(fn: Path, tlim: Tuple[datetime, datetime]=None) -> xarray.Dataset:
def rinexnav3(fn: Path,
use: Union[str, list, tuple]=None,
tlim: Tuple[datetime, datetime]=None) -> xarray.Dataset:
"""
Reads RINEX 3.x NAV files
Michael Hirsch, Ph.D.
Expand Down Expand Up @@ -47,9 +49,13 @@ def rinexnav3(fn: Path, tlim: Tuple[datetime, datetime]=None) -> xarray.Dataset:
continue
# not break due to non-monotonic NAV files

sv = line[:3]
if use is not None and not sv[0] in use:
_skip(f, Nl[sv[0]])
continue

times.append(time)
# %% SV types
sv = line[:3]
field = _newnav(line, sv)

if len(svtypes) == 0:
Expand Down
4 changes: 2 additions & 2 deletions georinex/obs3.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def obsheader3(f: TextIO, use: Union[str, list, tuple]= None) -> Dict[str, Any]:
return obsheader3(f)
# %% first line
ln = f.readline()
header = {'version': float(ln[:9]), # yes :9
header = {'version': float(ln[:9]), # yes :9
'systems': ln[40],
}
}
for ln in f:
if "END OF HEADER" in ln:
break
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = georinex
version = 1.5.3
version = 1.5.4
author = Michael Hirsch, Ph.D.
description = Python RINEX 2/3 NAV/OBS reader that is very fast
url = https://github.com/scivision/georinex
Expand Down
6 changes: 3 additions & 3 deletions tests/test_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def test_netcdf_read():
pytest.importorskip('netCDF4')

obs, nav = gr.readrinex(R/'r2all.nc')
assert isinstance(obs, xarray.Dataset)

Expand All @@ -37,7 +37,7 @@ def test_netcdf_write():

def test_obsdata():
pytest.importorskip('netCDF4')

truth = xarray.open_dataset(R/'r2all.nc', group='OBS', autoclose=True)

obs, nav = gr.readrinex(R/'demo.10o')
Expand All @@ -46,7 +46,7 @@ def test_obsdata():

def test_navdata():
pytest.importorskip('netCDF4')

truth = xarray.open_dataset(R/'r2all.nc', group='NAV', autoclose=True)
obs, nav = gr.readrinex(R/'demo.10n')

Expand Down
4 changes: 2 additions & 2 deletions tests/test_nav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
def test_time():
times = gr.gettime(R/'ab422100.18n.Z').values.astype('datetime64[us]').astype(datetime)

assert times[0] == datetime(2018,7,29,1,59,44)
assert times[-1] == datetime(2018,7,30)
assert times[0] == datetime(2018, 7, 29, 1, 59, 44)
assert times[-1] == datetime(2018, 7, 30)


def test_mangled():
Expand Down
93 changes: 89 additions & 4 deletions tests/test_nav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
#
R = Path(__file__).parent


def test_time():
times = gr.gettime(R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz').values.astype('datetime64[us]').astype(datetime)

assert times[0] == datetime(2018,4,24,8)
assert times[-1] == datetime(2018,6,20,22)
assert times[0] == datetime(2018, 4, 24, 8)
assert times[-1] == datetime(2018, 6, 20, 22)


def test_tlim():
Expand All @@ -37,9 +38,93 @@ def test_qzss():
assert nav.equals(truth)


def test_mixed():
pytest.importorskip('netCDF4')
def test_large_galileo():
fn = R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn, use='E')

assert nav.svtype[0] == 'E' and len(nav.svtype) == 1

E05 = nav.sel(sv='E05').dropna(how='all', dim='time').to_dataframe()
assert E05.shape[0] == 45 # manually counted from file
assert E05.shape[1] == 28 # by Galileo NAV3 def'n

assert E05.notnull().all().all()


def test_large_beidou():
fn = R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn, use='C')

assert nav.svtype[0] == 'C' and len(nav.svtype) == 1

C05 = nav.sel(sv='C05').dropna(how='all', dim='time').to_dataframe()
assert C05.shape[0] == 25 # manually counted from file
assert C05.shape[1] == 29 # by Beidou NAV3 def'n

assert C05.notnull().all().all()


def test_large_gps():
fn = R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn, use='G')

assert nav.svtype[0] == 'G' and len(nav.svtype) == 1

G05 = nav.sel(sv='G05').dropna(how='all', dim='time').to_dataframe()
assert G05.shape[0] == 7 # manually counted from file
assert G05.shape[1] == 30 # by GPS NAV3 def'n

assert G05.notnull().all().all()


def test_large_sbas():
fn = R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn, use='S')

assert nav.svtype[0] == 'S' and len(nav.svtype) == 1

S36 = nav.sel(sv='S36').dropna(how='all', dim='time').to_dataframe()
assert S36.shape[0] == 542 # manually counted from file
assert S36.shape[1] == 16 # by SBAS NAV3 def'n

assert S36.notnull().all().all()


def test_large_glonass():
fn = R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn, use='R')

assert nav.svtype[0] == 'R' and len(nav.svtype) == 1

R05 = nav.sel(sv='R05').dropna(how='all', dim='time').to_dataframe()
assert R05.shape[0] == 19 # manually counted from file
assert R05.shape[1] == 16 # by GLONASS NAV3 def'n

assert R05.notnull().all().all()


def test_large():
fn = R/'VILL00ESP_R_20181700000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn)
assert sorted(nav.svtype) == ['C', 'E', 'G', 'R', 'S']

C05 = nav.sel(sv='C05').dropna(how='all', dim='time').to_dataframe()
assert C05.shape[0] == 25 # manually counted from file

E05 = nav.sel(sv='E05').dropna(how='all', dim='time').to_dataframe()
assert E05.shape[0] == 45 # manually counted from file

G05 = nav.sel(sv='G05').dropna(how='all', dim='time').to_dataframe()
assert G05.shape[0] == 7 # manually counted from file

R05 = nav.sel(sv='R05').dropna(how='all', dim='time').to_dataframe()
assert R05.shape[0] == 19

S36 = nav.sel(sv='S36').dropna(how='all', dim='time').to_dataframe()
assert S36.shape[0] == 542 # manually counted from file


def test_mixed():
fn = R/'ELKO00USA_R_20182100000_01D_MN.rnx.gz'
nav = gr.rinexnav(fn,
tlim=(datetime(2018, 7, 28, 21),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_obs3.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_multi_system():
./ReadRinex.py -q tests/demo3.10o -u G R -o r3GR.nc
"""
pytest.importorskip('netCDF4')

use = ('G', 'R')

obs = gr.rinexobs(R/'demo3.10o', use=use)
Expand Down

0 comments on commit ec94b50

Please sign in to comment.