From da3eb3e5af30d38e1c865854682447800503bfc8 Mon Sep 17 00:00:00 2001 From: scivision Date: Wed, 15 Nov 2023 01:40:03 -0500 Subject: [PATCH] .time: bugfix: work with CRINEX --- src/georinex/base.py | 2 +- src/georinex/obs2.py | 1 + src/georinex/rio.py | 1 + src/georinex/tests/test_hatanaka.py | 17 ++++++++++++++++- src/georinex/time/__main__.py | 6 +----- src/georinex/utils.py | 7 ++++--- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/georinex/base.py b/src/georinex/base.py index 5b1cecc..60f079a 100644 --- a/src/georinex/base.py +++ b/src/georinex/base.py @@ -212,7 +212,7 @@ def rinexobs( # %% version selection info = rinexinfo(fn) - if int(info["version"]) in (1, 2): + if int(info["version"]) in {1, 2}: obs = rinexobs2( fn, use, diff --git a/src/georinex/obs2.py b/src/georinex/obs2.py index 1de0cb8..292db34 100644 --- a/src/georinex/obs2.py +++ b/src/georinex/obs2.py @@ -356,6 +356,7 @@ def obsheader2( """ End users should use rinexheader() """ + if isinstance(f, (str, Path)): with opener(f, header=True) as h: return obsheader2(h, useindicators, meas) diff --git a/src/georinex/rio.py b/src/georinex/rio.py index b1b2929..c036632 100644 --- a/src/georinex/rio.py +++ b/src/georinex/rio.py @@ -17,6 +17,7 @@ @contextmanager def opener(fn: T.TextIO | Path, header: bool = False) -> T.Iterator[T.TextIO]: """provides file handle for regular ASCII or gzip files transparently""" + if isinstance(fn, str): fn = Path(fn).expanduser() diff --git a/src/georinex/tests/test_hatanaka.py b/src/georinex/tests/test_hatanaka.py index fb16b78..fb17f9a 100755 --- a/src/georinex/tests/test_hatanaka.py +++ b/src/georinex/tests/test_hatanaka.py @@ -1,3 +1,7 @@ +""" +Hatanaka CRINEX +""" + import pytest from pathlib import Path from datetime import datetime @@ -13,6 +17,9 @@ def test_obs2(): info = gr.rinexinfo(fn) assert int(info["version"]) == 1 + times = gr.gettime(fn) + assert times.size == 2880 + obs = gr.load(fn, tlim=("2015-02-13T23:00", "2015-02-13T23:01")) assert obs.time.size == 3 @@ -27,6 +34,10 @@ def test_obs3_gz(): info = gr.rinexinfo(fn) assert int(info["version"]) == 3 + # times out--need smaller test file + # times = gr.gettime(fn) + # assert times.size == 2880 + # %% full file obs = gr.load(fn, tlim=("2018-07-19T01", "2018-07-19T01:10")) @@ -78,12 +89,16 @@ def test_obs3_gz(): @pytest.mark.timeout(30) @pytest.mark.parametrize("suffix", [".crx", ".crx.bz2"]) -def test_obs3(suffix): +def test_obs3_crx(suffix): fn = R / ("P43300USA_R_20190012056_17M_15S_MO" + suffix) info = gr.rinexinfo(fn) assert int(info["version"]) == 3 + + times = gr.gettime(fn) + assert times.size == 70 + # %% full file obs = gr.load(fn, tlim=("2019-01-01", "2019-01-01T20:57")) diff --git a/src/georinex/time/__main__.py b/src/georinex/time/__main__.py index d83ac85..b1b1917 100644 --- a/src/georinex/time/__main__.py +++ b/src/georinex/time/__main__.py @@ -10,11 +10,7 @@ def eachfile(fn: Path): - try: - times = gr.gettime(fn) - except ValueError as e: - logging.error(f"{fn.name}: {e}") - return + times = gr.gettime(fn) # %% output Ntimes = times.size diff --git a/src/georinex/utils.py b/src/georinex/utils.py index 662b46a..b958e67 100644 --- a/src/georinex/utils.py +++ b/src/georinex/utils.py @@ -30,7 +30,7 @@ def globber(path: Path, glob: list[str]) -> list[Path]: def gettime(fn: T.TextIO | Path): """ - get times in RINEX 2/3 file + get times in [C]RINEX 2/3 file Note: in header, * TIME OF FIRST OBS is mandatory * TIME OF LAST OBS is optional @@ -47,6 +47,7 @@ def gettime(fn: T.TextIO | Path): times : numpy.ndarray of numpy.datetime64 1-D vector of epochs in file """ + info = rinexinfo(fn) version = info["version"] @@ -55,14 +56,14 @@ def gettime(fn: T.TextIO | Path): # %% select function if rtype == "obs": - if vers == 2: + if vers in {1, 2}: times = obstime2(fn) elif vers == 3: times = obstime3(fn) else: raise ValueError(f"Unknown RINEX version {version} {fn}") elif rtype == "nav": - if vers == 2: + if vers in {1, 2}: times = navtime2(fn) elif vers == 3: times = navtime3(fn)