Skip to content

Commit

Permalink
sp3: make t0 scalar dataset rather than attribute for netcdf4 write
Browse files Browse the repository at this point in the history
fixes #95

Co-authored-by: linustan <[email protected]>
  • Loading branch information
scivision and linustan committed Oct 18, 2023
1 parent fc50a82 commit fdd0cd3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
experimental: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand Down
7 changes: 6 additions & 1 deletion src/georinex/sp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def load_sp3(fn: Path, outfn: Path) -> xarray.Dataset:
http://epncb.oma.be/ftp/data/format/sp3_docu.txt (sp3a)
"""

dat: dict[T.Hashable, T.Any] = {}

with opener(fn) as f:
ln = first_nonblank_line(f)
assert ln[0] == "#", f"failed to read {fn} line 1"
# sp3_version = ln[1]
dat["t0"] = sp3dt(ln)
t0 = sp3dt(ln)
# Nepoch != number of time steps, at least for some files
dat["Nepoch"] = int(ln[32:39])
dat["coord_sys"] = ln[46:51]
Expand Down Expand Up @@ -105,6 +107,7 @@ def load_sp3(fn: Path, outfn: Path) -> xarray.Dataset:
ecefs.append(ecef)
clocks.append(clock)
vels.append(vel)

aclock = np.asarray(clocks)

# assemble into final xarray.Dataset
Expand All @@ -115,6 +118,8 @@ def load_sp3(fn: Path, outfn: Path) -> xarray.Dataset:
ds["velocity"] = (("time", "sv", "ECEF"), vels)
ds["dclock"] = (("time", "sv"), aclock[:, :, 1])

ds["t0"] = t0

ds.attrs = dat

if outfn:
Expand Down
16 changes: 16 additions & 0 deletions src/georinex/tests/test_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def test_netcdf_write(tmp_path):
assert obs.equals(wobs)


def test_netcdf_write_sp3(tmp_path):
"""
NetCDF4 wants suffix .nc -- arbitrary tempfile.NamedTemporaryFile names do NOT work!
"""
pytest.importorskip("netCDF4")

fn = tmp_path / "sp3.nc"
obs = gr.load(R / "example1.sp3a", out=fn)

wobs = xarray.load_dataset(fn)

assert obs.equals(wobs)

assert obs.attrs == wobs.attrs


def test_locs():
pytest.importorskip("pymap3d") # need to have this
gg = pytest.importorskip("georinex.geo")
Expand Down

0 comments on commit fdd0cd3

Please sign in to comment.