Skip to content

Commit

Permalink
NPI-3670 add exception / warning for EP and EV flags in SP3 reading
Browse files Browse the repository at this point in the history
  • Loading branch information
treefern committed Dec 24, 2024
1 parent 3351248 commit b2e46c2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
15 changes: 13 additions & 2 deletions gnssanalysis/gn_io/sp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def read_sp3(
pOnly: bool = True,
nodata_to_nan: bool = True,
drop_offline_sats: bool = False,
continue_on_ep_ev_encountered: bool = True,
) -> _pd.DataFrame:
"""Reads an SP3 file and returns the data as a pandas DataFrame.
Expand All @@ -296,6 +297,9 @@ def read_sp3(
and converts 999999* (indicating nodata) to NaN in the SP3 CLK column. Defaults to True.
:param bool drop_offline_sats: If True, drops satellites from the DataFrame if they have ANY missing (nodata)
values in the SP3 POS column.
:param bool continue_on_ep_ev_encountered: If True, logs a warning and continues if EV or EP rows are found in
the input SP3. These are currently unsupported by this function and will be ignored. Set to false to
raise a NotImplementedError instead.
:return pandas.DataFrame: The SP3 data as a DataFrame.
:raise FileNotFoundError: If the SP3 file specified by sp3_path_or_bytes does not exist.
:raise Exception: For other errors reading SP3 file/bytes
Expand Down Expand Up @@ -339,18 +343,25 @@ def read_sp3(
sp3_pos_nodata_to_nan(sp3_df)
# Convert 999999* (which indicates nodata in the SP3 CLK column) to NaN
sp3_clock_nodata_to_nan(sp3_df)

# P/V/EP/EV flag handling is currently incomplete. The current implementation truncates to the first letter,
# so can't parse nor differenitate between EP and EV!
if "E" in sp3_df.index.get_level_values("PV_FLAG").unique():
if not continue_on_ep_ev_encountered:
raise NotImplementedError("EP and EV flag rows are currently not supported")
logger.warning("EP / EV flag rows encountered. These are not yet supported, and will be ignored!")

# Check very top of the header to see if this SP3 is Position only , or also contains Velocities
if pOnly or parsed_header.HEAD.loc["PV_FLAG"] == "P":
sp3_df = sp3_df.loc[sp3_df.index.get_level_values("PV_FLAG") == "P"]
sp3_df.index = sp3_df.index.droplevel("PV_FLAG")
# TODO consider exception handling if EP rows encountered
else:
position_df = sp3_df.xs("P", level="PV_FLAG")
velocity_df = sp3_df.xs("V", level="PV_FLAG")
# TODO consider exception handling if EV rows encountered
velocity_df.columns = SP3_VELOCITY_COLUMNS
sp3_df = _pd.concat([position_df, velocity_df], axis=1)

# sp3_df.drop(columns="PV_FLAG", inplace=True)
# Check for duplicate epochs, dedupe and log warning
if sp3_df.index.has_duplicates: # a literaly free check
# This typically runs in sub ms time. Marks all but first instance as duped:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_datasets/sp3_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@
EOF
"""

# Manual test dataset for EV and EP flags (currently just checking that exceptions are raised because we don't handle them yet)
sp3_test_data_ep_ev_rows = b"""#dV2007 4 12 0 0 0.00000000 1 ORBIT IGS14 BHN ESOC
## 1422 345600.00000000 900.00000000 54202 0.0000000000000
+ 1 G01 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 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
++ 8 8 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 0 0 0 0 0 0
++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
%c M cc GPS 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
/* EUROPEAN SPACE OPERATIONS CENTRE - DARMSTADT, GERMANY
/* ---------------------------------------------------------
/* SP3 FILE GENERATED BY NAPEOS BAHN TOOL (DETERMINATION)
/* PCV:IGS14_2022 OL/AL:EOT11A NONE YN ORB:CoN CLK:CoN
* 2007 4 12 0 0 0.00000000
PG01 -6114.801556 -13827.040252 22049.171610 999999.999999
EP 55 55 55 222 1234567 -1234567 5999999 -30 21 -1230000
VG01 27184.457428 -3548.055474 5304.058806 999999.999999
EV 22 22 22 111 1234567 1234567 1234567 1234567 1234567 1234567
EOF
"""
# NOTE: copied from SP3d PDF.. alignment of EP and EV seem to be quite wrong.
# TODO update with a proper source. Will do for now just to check exceptions on these flags being seen.


# second dataset is a truncated version of file COD0OPSFIN_20242010000_01D_05M_ORB.SP3
sp3_test_data_truncated_cod_final = b"""#dP2024 7 19 0 0 0.00000000 2 d+D IGS20 FIT AIUB
## 2323 432000.00000000 300.00000000 60510 0.0000000000000
Expand Down

0 comments on commit b2e46c2

Please sign in to comment.