Skip to content

Commit

Permalink
NPI-3430 fix SP3 header orbit accuracy regex to be more robust and ha…
Browse files Browse the repository at this point in the history
…ndle negative integers
  • Loading branch information
treefern committed Aug 2, 2024
1 parent ee8d48d commit 84c46ed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions gnssanalysis/gn_io/sp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@
# Regex to extract Satellite Vehicle (SV) names (E.g. G02). Regex options/flags: multiline, findall
_RE_SP3_HEAD_SV = _re.compile(rb"^\+[ ]+(?:[\d]+|)[ ]+((?:[A-Z]\d{2})+)\W", _re.MULTILINE)

# Regex for orbits accuracy codes (E.g. ' 15' - space padded, blocks are three chars wide).
# Regex for orbit accuracy codes (E.g. ' 15' - space padded, blocks are three chars wide).
# Note: header is padded with ' 0' entries after the actual data, so empty fields are matched and then trimmed.
_RE_SP3_ACC = _re.compile(rb"^\+{2}[ ]+([\d\s]{51})$", _re.MULTILINE)
_RE_SP3_HEADER_ACC = _re.compile(rb"^\+{2}[ ]+((?:[\-\d\s]{2}\d){17})$", _re.MULTILINE)
# This matches orbit accuracy codes which are three chars long, left padded with spaces, and always contain at
# least one digit. They can be negative, though such values are unrealistic. Empty 'entries' are '0', so we have to
# work out where to trim the data based on the number of SVs in the header.
# Breakdown of regex:
# - Match the accuracy code line start of '++' then arbitary spaces, then
# - 17 columns of:
# [space or digit or - ] (times two), then [digit]
# - Then end of line.

# Most data matches whether or not we specify the end of line, as we are quite explicit about the format of
# data we expect. However, using \W instead can be risky, as it fails to match the last line if there is no
# newline following it. Note though that in SV parsing $ doesn't traverse multiline, the \W works...

# File descriptor and clock
_RE_SP3_HEAD_FDESCR = _re.compile(rb"\%c[ ]+(\w{1})[ ]+cc[ ](\w{3})")
Expand Down Expand Up @@ -267,7 +279,7 @@ def parse_sp3_header(header: str) -> _pd.DataFrame:

head_svs = _np.asarray(b"".join(_RE_SP3_HEAD_SV.findall(header)))[_np.newaxis].view("S3").astype(str)
head_svs_std = (
_np.asarray(b"".join(_RE_SP3_ACC.findall(header)))[_np.newaxis].view("S3")[: head_svs.shape[0]].astype(int)
_np.asarray(b"".join(_RE_SP3_HEADER_ACC.findall(header)))[_np.newaxis].view("S3")[: head_svs.shape[0]].astype(int)
)
sv_tbl = _pd.Series(head_svs_std, index=head_svs)

Expand Down

0 comments on commit 84c46ed

Please sign in to comment.