Skip to content

Commit

Permalink
workaround for PYthon 3.12 ncompress bug
Browse files Browse the repository at this point in the history
This allows non-Hatanaka, non-LZW files to be read with Python 3.12

valgur/ncompress#2
  • Loading branch information
scivision committed Jan 28, 2024
1 parent 1b7c18d commit 77343b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/georinex/rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@

import xarray

from hatanaka import crx2rnx
from ncompress import decompress as unlzw
try:
from hatanaka import crx2rnx
except ImportError:
logging.info("hatanaka crx2rnx not available")
crx2rnx = None

try:
from ncompress import decompress as unlzw
except ImportError:
logging.info("ncompress unlzw not available")
unlzw = None


@contextmanager
Expand Down Expand Up @@ -77,6 +86,9 @@ def opener(fn: T.TextIO | Path, header: bool = False) -> T.Iterator[T.TextIO]:
)
yield f
elif suffix == ".z" or magic.startswith(b"\x1f\x9d"):
if unlzw is None:
raise ImportError("ncompress unlzw not available")

with fn.open("rb") as zu:
with io.StringIO(unlzw(zu.read()).decode("ascii")) as f:
_, is_crinex = rinex_version(first_nonblank_line(f))
Expand Down
6 changes: 6 additions & 0 deletions src/georinex/tests/test_hatanaka.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@


def test_obs2():
pytest.importorskip("hatanaka")

fn = R / "york0440.15d"

info = gr.rinexinfo(fn)
Expand All @@ -29,6 +31,8 @@ def test_obs2():

@pytest.mark.timeout(30)
def test_obs3_gz():
pytest.importorskip("hatanaka")

fn = R / "CEBR00ESP_R_20182000000_01D_30S_MO.crx.gz"

info = gr.rinexinfo(fn)
Expand Down Expand Up @@ -90,6 +94,8 @@ def test_obs3_gz():
@pytest.mark.timeout(30)
@pytest.mark.parametrize("suffix", [".crx", ".crx.bz2"])
def test_obs3_crx(suffix):
pytest.importorskip("hatanaka")

fn = R / ("P43300USA_R_20190012056_17M_15S_MO" + suffix)

info = gr.rinexinfo(fn)
Expand Down

0 comments on commit 77343b4

Please sign in to comment.