Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return leap second #102

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/georinex/nav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def rinexnav2(fn: T.TextIO | Path, tlim: tuple[datetime, datetime] | None = None
nav[name] *= 1e3

# %% other attributes
if "LEAP SECONDS" in header:
nav.attrs["leap_seconds"] = int(header["LEAP SECONDS"])
nav.attrs["version"] = header["version"]
nav.attrs["svtype"] = [svtype] # Use list for consistency with NAV3.
nav.attrs["rinextype"] = "nav"
Expand Down
9 changes: 5 additions & 4 deletions src/georinex/nav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def rinexnav3(
raw += ln[STARTCOL3:80]
# one line per SV
raws.append(raw.replace("D", "E").replace("\n", ""))

# %% parse collected data per SV
# NOTE: must be 'ns' or .to_netcdf will fail!
t = np.array([np.datetime64(t, "ns") for t in times])
Expand Down Expand Up @@ -153,7 +152,8 @@ def rinexnav3(
nav.attrs["ionospheric_corr_BDS"] = np.hstack((corr["BDSA"], corr["BDSB"]))
if "IRNA" in corr and "IRNB" in corr:
nav.attrs["ionospheric_corr_IRN"] = np.hstack((corr["IRNA"], corr["IRNB"]))

if "LEAP SECONDS" in header:
nav.attrs["leap_seconds"] = int(header["LEAP SECONDS"].split()[0])
nav.attrs["version"] = header["version"]
nav.attrs["svtype"] = svtypes
nav.attrs["rinextype"] = "nav"
Expand Down Expand Up @@ -227,9 +227,10 @@ def _sparefields(cf: list[str], sys: str, N: int) -> list[str]:
elif N == 27: # no middle or trailing spare fields
cf = cf[:22] + cf[23:-3]
elif sys == "I":
if N == 28:
if N == 26:
cf = cf[:22] + cf[23:26] + [cf[27]]
elif N == 28:
cf = cf[:28]

if N != len(cf):
raise ValueError(f"System {sys} NAV data is not the same length as the number of fields.")

Expand Down
31 changes: 17 additions & 14 deletions src/georinex/obs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ def rinexobs2(
fast=fast,
interval=interval,
)

if len(o.variables) > 0:
attrs = o.attrs
obs = xarray.merge((obs, o))

obs.attrs = attrs

return obs


Expand Down Expand Up @@ -253,7 +250,6 @@ def rinexsystem2(
data[i, j, isv] = darr[:, k]
# %% output gathering
data = data[:, : times.size, :] # trims down for unneeded preallocated

fields = []
for field in hdr["fields"]:
fields.append(field)
Expand Down Expand Up @@ -283,19 +279,19 @@ def rinexsystem2(
obs = obs.dropna(dim="time", how="all") # when tlim specified
# %% attributes
obs.attrs["version"] = hdr["version"]

# Get interval from header or derive it from the data
if "interval" in hdr.keys():
if "interval" in hdr.keys() and np.isfinite(hdr["interval"]):
obs.attrs["interval"] = hdr["interval"]
elif "time" in obs.coords.keys():
# median is robust against gaps
try:
obs.attrs["interval"] = np.median(np.diff(obs.time) / np.timedelta64(1, "s"))
except TypeError:
pass
else:
obs.attrs["interval"] = np.nan

print ("Couldn't process interval")
# else:
# obs.attrs["interval"] = np.nan
obs.attrs["rinextype"] = "obs"
obs.attrs["fast_processing"] = int(fast) # bool is not allowed in NetCDF4
obs.attrs["time_system"] = determine_time_system(hdr)
Expand All @@ -305,10 +301,14 @@ def rinexsystem2(
obs.attrs["rxmodel"] = hdr["rxmodel"]
if "position" in hdr.keys():
obs.attrs["position"] = hdr["position"]

if "position_geodetic" in hdr.keys():
obs.attrs["position_geodetic"] = hdr["position_geodetic"]

if "LEAP SECONDS" in hdr.keys():
try:
obs.attrs["leap_seconds"] = int(hdr["LEAP SECONDS"])
except:
pass

return obs


Expand Down Expand Up @@ -450,11 +450,14 @@ def obsheader2(
except (KeyError, ValueError):
pass

try: # This key is OPTIONAL
try:
hdr["interval"] = float(hdr["INTERVAL"][:10])
except (KeyError, ValueError):
pass

try:
hdr["version"] = float(hdr["RINEX VERSION / TYPE"].split()[0])
except (KeyError, ValueError):
pass
try:
s = " "
hdr["rxmodel"] = s.join(hdr["REC # / TYPE / VERS"].split()[1:-1])
Expand Down
3 changes: 2 additions & 1 deletion src/georinex/obs3.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def rinexobs3(
data.attrs["receiver_clock_offset_applied"] = int(hdr["RCV CLOCK OFFS APPL"])
except ValueError:
pass

if "LEAP SECONDS" in hdr.keys():
data.attrs["leap_seconds"] = int(hdr["LEAP SECONDS"].split()[0])
return data


Expand Down