Skip to content

Commit

Permalink
.time: bugfix: work with CRINEX
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 15, 2023
1 parent ab46fc3 commit da3eb3e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/georinex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/georinex/obs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/georinex/rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
17 changes: 16 additions & 1 deletion src/georinex/tests/test_hatanaka.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Hatanaka CRINEX
"""

import pytest
from pathlib import Path
from datetime import datetime
Expand All @@ -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
Expand All @@ -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"))

Expand Down Expand Up @@ -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"))

Expand Down
6 changes: 1 addition & 5 deletions src/georinex/time/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/georinex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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)
Expand Down

0 comments on commit da3eb3e

Please sign in to comment.