Skip to content

Commit

Permalink
sp3a add format
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 26, 2021
1 parent cade46c commit d76c33d
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/georinex/rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ def rinexinfo(f: T.TextIO | Path) -> dict[str, T.Any]:
try:
line = first_nonblank_line(f) # don't choke on binary files

if line.startswith("#c"):
return {"version": "c", "rinextype": "sp3"}
elif line.startswith("#d"):
return {"version": "d", "rinextype": "sp3"}
if line.startswith(("#a", "#c", "#d")):
return {"version": line[1], "rinextype": "sp3"}

version = rinex_version(line)[0]
file_type = line[20]
Expand Down Expand Up @@ -201,11 +199,9 @@ def rinex_version(s: str) -> tuple[float | str, bool]:

# %% .sp3 file
if s[0] == "#":
supported_versions = ["c", "d"]
supported_versions = {"a", "c", "d"}
if s[1] not in supported_versions:
raise ValueError(
f"SP3 versions of SP3 files currently handled: {','.join(supported_versions)}"
)
raise ValueError(f"SP3 versions of SP3 files currently handled: {supported_versions}")
return "sp3" + s[1], False

# %% typical RINEX files
Expand Down
8 changes: 6 additions & 2 deletions src/georinex/sp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def load_sp3(fn: Path, outfn: Path) -> xarray.Dataset:
with fn.open("r") 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)
# Nepoch != number of time steps, at least for some files
dat["Nepoch"] = int(ln[32:39])
Expand Down Expand Up @@ -78,11 +79,13 @@ def load_sp3(fn: Path, outfn: Path) -> xarray.Dataset:
elif ln[0] == "V":
vel[i - 1, :] = (float(ln[4:18]), float(ln[18:32]), float(ln[32:46]))
clock[i - 1, 1] = float(ln[46:60])
elif ln[:2] in ("EP", "EV"):
elif ln.startswith(("EP", "EV")):
# let us know if you want these data types
pass
elif len(ln) == 0: # blank line
pass
elif len(ln) >= 4 and ln[3] == "*": # sp3a no data
continue
elif ln.startswith("EOF"):
break
else:
Expand Down Expand Up @@ -157,5 +160,6 @@ def get_sv(ln: str, Nsv: int) -> list[str]:
i0 = 9
svs = []
for i in range(min(Nsv, 17)):
svs.append(ln[i0 + i * 3 : (i0 + 3) + i * 3])
svs.append(ln[i0 + i * 3 : (i0 + 3) + i * 3].replace(" ", ""))

return svs
53 changes: 53 additions & 0 deletions src/georinex/tests/data/example1.sp3a
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#aP1994 12 17 0 0 0.00000000 96 d ITR92 FIT NGS
## 779 518400.00000000 900.00000000 49703 0.0000000000000
+ 25 1 2 4 5 6 7 9 12 14 15 16 17 18 19 20 21 22
+ 23 24 25 26 27 28 29 31 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 7 6 5 5 5 5 5 5 5 6 5 5 5 5 6 5 5
++ 5 5 6 5 5 5 5 5 0 0 0 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc
%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc
%f 0.0000000 0.000000000 0.00000000000 0.000000000000000
%f 0.0000000 0.000000000 0.00000000000 0.000000000000000
%i 0 0 0 0 0 0 0 0 0
%i 0 0 0 0 0 0 0 0 0
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
* 1994 12 17 0 0 0.00000000
P 1 16258.524750 -3529.015750 -20611.427050 -62.540600
P 2 -21998.652100 -8922.093550 -12229.824050 -131.326200
P 4 -26019.547600 4809.810900 -2508.578200 3.544600
P 5 7014.950200 21130.960300 -14387.334650 79.692800
*
*
*
P 28 13204.937750 -20485.533400 10794.787000 55.200800
P 29 -1638.431050 -24391.479200 10455.312650 3.690300
P 31 6265.255800 -25687.986950 -753.359000 70.830800
* 1994 12 17 0 15 0.00000000
P 1 15716.820135 -1169.850490 -21281.578766 -62.542746
P 2 -22813.261065 -9927.616864 -9816.490189 -131.328686
*
*
*
P 28 13416.746195 -22186.753441 6248.864499 55.385492
P 29 -2745.269113 -22169.709690 14469.340453 3.718873
P 31 5629.986510 -25241.323751 -5659.769347 71.118497
* 1994 12 17 23 45 0.00000000
P 1 16708.907949 -5150.972262 -19904.291167 -62.727331
P 2 -21321.617042 -8048.187511 -13856.581227 -131.555527
P 4 -26107.382526 5010.736034 -422.963345 3.672587
P 5 7932.078481 21838.230749 -12767.671968 79.888744
*
*
*
P 28 13308.321924 -21306.183480 8935.290694 55.387446
P 29 -2059.774801 -23532.083663 12229.852140 3.719337
P 31 6034.395625 -25605.621951 -2843.783172 71.121661
54 changes: 54 additions & 0 deletions src/georinex/tests/data/example2.sp3a
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#aV1994 12 17 0 0 0.00000000 96 d ITR92 FIT NGS
## 779 518400.00000000 900.00000000 49703 0.0000000000000
+ 25 1 2 4 5 6 7 9 12 14 15 16 17 18 19 20 21 22
+ 23 24 25 26 27 28 29 31 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 7 6 5 5 5 5 5 5 5 6 5 5 5 5 6 5 5
++ 5 5 6 5 5 5 5 5 0 0 0 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc
%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc
%f 0.0000000 0.000000000 0.00000000000 0.000000000000000
%f 0.0000000 0.000000000 0.00000000000 0.000000000000000
%i 0 0 0 0 0 0 0 0 0
%i 0 0 0 0 0 0 0 0 0
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
/* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
* 1994 12 17 0 0 0.00000000
P 1 16258.524750 -3529.015750 -20611.427050 -62.540600
V 1 -6560.373522 25605.954994 -9460.427179 -0.024236
P 2 -21998.652100 -8922.093550 -12229.824050 -131.326200
V 2 -9852.750736 -12435.176313 25738.634180 -0.029422
P 4 -26019.547600 4809.810900 -2508.578200 3.544600
V 4 2559.038002 -3340.527442 -31621.490838 0.016744
*
*
*
P 29 -1638.431050 -24391.479200 10455.312650 3.690300
V 29 5754.005457 -12065.761570 -27707.056273 0.003537
P 31 6265.255800 -25687.986950 -753.359000 70.830800
V 31 3053.344058 -63.091750 31910.454757 0.033749
* 1994 12 17 0 15 0.00000000
P 1 15716.820135 -1169.850490 -21281.578766 -62.542746
V 1 -5439.955846 26738.341429 -5409.793390 -0.023226
P 2 -22813.261065 -9927.616864 -9816.490189 -131.328686
V 2 -8178.974330 -9924.329320 27813.754308 -0.025238
*
*
*
P 31 5629.986510 -25241.323751 -5659.769347 71.118497
V 31 5213.646243 -5585.922919 30831.379942 0.040199
* 1994 12 17 23 45 0.00000000
P 1 16708.907949 -5150.972262 -19904.291167 -62.727331
V 1 -7218.304166 24494.550676 -12283.334526 -0.023824
*
*
*
P 31 6034.395625 -25605.621951 -2843.783172 71.121661
V 31 3831.346050 -2469.229615 31655.436179 0.028935
File renamed without changes.
22 changes: 18 additions & 4 deletions src/georinex/tests/test_sp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@
R = Path(__file__).parent / "data"


def test_sp3c():
dat = gr.load(R / "igs19362.sp3")
@pytest.mark.parametrize("fn", ["example1.sp3a", "example2.sp3a"])
def test_sp3a(fn):
dat = gr.load(R / fn)

d0 = dat.sel(time="1994-12-17T00:15:00")

assert len(d0.sv) == 25

G2 = d0.sel(sv="2")
assert G2["position"].data == approx([-22813.261065, -9927.616864, -9816.490189])
assert G2["clock"].item() == approx(-131.328686)


@pytest.mark.parametrize("fn", ["igs19362.sp3c"])
def test_sp3c(fn):
dat = gr.load(R / fn)

d0 = dat.sel(time="2017-02-14T00:15:00")

assert len(d0.sv) == 32

G20 = d0.sel(sv="G20")

assert G20["position"].values == approx([-6468.900825, 14715.965428, 20990.8862])
assert G20.clock.item() == approx(459.946483)
assert G20["position"].data == approx([-6468.900825, 14715.965428, 20990.8862])
assert G20["clock"].item() == approx(459.946483)


def test_blank():
Expand Down

0 comments on commit d76c33d

Please sign in to comment.