diff --git a/src/georinex/nav2.py b/src/georinex/nav2.py index de985d8..2a43e85 100644 --- a/src/georinex/nav2.py +++ b/src/georinex/nav2.py @@ -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" diff --git a/src/georinex/nav3.py b/src/georinex/nav3.py index 02ed7e8..e2958b9 100644 --- a/src/georinex/nav3.py +++ b/src/georinex/nav3.py @@ -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]) @@ -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" @@ -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.") diff --git a/src/georinex/obs2.py b/src/georinex/obs2.py index 292db34..4180abd 100644 --- a/src/georinex/obs2.py +++ b/src/georinex/obs2.py @@ -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 @@ -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) @@ -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) @@ -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 @@ -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]) diff --git a/src/georinex/obs3.py b/src/georinex/obs3.py index a68dc21..03f54f5 100644 --- a/src/georinex/obs3.py +++ b/src/georinex/obs3.py @@ -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