Skip to content

Commit

Permalink
Enable clock normalisation with sp3_difference
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneDu-GA committed Sep 19, 2024
1 parent a5f90ff commit c16aba1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
24 changes: 13 additions & 11 deletions gnssanalysis/gn_diffaux.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def compare_clk(
:return _pd.DataFrame: clk differences in the same units as input clk dfs (usually seconds)
"""

clk_a = _gn_io.clk.get_AS_entries(clk_a)
clk_b = _gn_io.clk.get_AS_entries(clk_b)
clk_a = _gn_io.clk.get_sv_clocks(clk_a)
clk_b = _gn_io.clk.get_sv_clocks(clk_b)

if not isinstance(norm_types, list): # need list for 'sv' to be correctly converted to array of SVs to use for norm
norm_types = list(norm_types)
Expand Down Expand Up @@ -708,32 +708,35 @@ def format_index(
def sp3_difference(
base_sp3_file: _Path,
test_sp3_file: _Path,
clk_norm_types: list = [],
) -> _pd.DataFrame:
"""
Compare two SP3 files to calculate orbit and clock differences. The orbit differences will be represented
in both X/Y/Z ECEF frame and R/A/C orbit frame, and the clock differences will NOT be normalised.
:param _Path base_sp3_file: Path of the baseline SP3 file
:param _Path test_sp3_file: Path of the test SP3 file
:param clk_norm_types list: Clock normalizations to apply. Available options include 'epoch', 'daily', 'sv',
any satellite PRN, or any combination of them, defaults to empty list
:return _pd.DataFrame: The Pandas DataFrame containing orbit and clock differences
"""
base_sp3_df = _gn_io.sp3.read_sp3(str(base_sp3_file))
test_sp3_df = _gn_io.sp3.read_sp3(str(test_sp3_file))

common_indices = base_sp3_df.index.intersection(test_sp3_df.index)
diff_est_df = test_sp3_df.loc[common_indices, "EST"] - base_sp3_df.loc[common_indices, "EST"]

diff_clk_df = diff_est_df["CLK"].to_frame(name="CLK") * 1e3 # TODO: normalise clocks
diff_xyz_df = diff_est_df.drop(columns=["CLK"]) * 1e3
diff_rac_df = _gn_io.sp3.diff_sp3_rac(base_sp3_df, test_sp3_df, hlm_mode=None) # TODO: hlm_mode

diff_rac_df = _gn_io.sp3.diff_sp3_rac(base_sp3_df, test_sp3_df, hlm_mode=None) # TODO: hlm_mode
diff_rac_df.columns = diff_rac_df.columns.droplevel(0)

diff_rac_df = diff_rac_df * 1e3

diff_clk_df = compare_clk(test_sp3_df, base_sp3_df, norm_types=clk_norm_types)
diff_clk_df = diff_clk_df.stack(dropna=False).to_frame(name="Clock") * 1e3

diff_sp3_df = diff_xyz_df.join(diff_rac_df)
diff_sp3_df["3D-Total"] = diff_xyz_df.pow(2).sum(axis=1, min_count=3).pow(0.5)
diff_sp3_df["Clock"] = diff_clk_df
diff_sp3_df = diff_sp3_df.join(diff_clk_df)
diff_sp3_df["|Clock|"] = diff_clk_df.abs()

format_index(diff_sp3_df)
Expand All @@ -744,23 +747,22 @@ def sp3_difference(
def clk_difference(
base_clk_file: _Path,
test_clk_file: _Path,
norm_types: list = [],
clk_norm_types: list = [],
) -> _pd.DataFrame:
"""
Compare two CLK files to calculate clock differences with common mode removed (if specified)
based on the chosen normalisations.
:param _Path base_clk_file: Path of the baseline CLK file
:param _Path test_clk_file: Path of the test CLK file
:param norm_types list: Normalizations to apply. Available options include 'epoch', 'daily', 'sv',
:param clk_norm_types list: Clock normalizations to apply. Available options include 'epoch', 'daily', 'sv',
any satellite PRN, or any combination of them, defaults to empty list
:return _pd.DataFrame: The Pandas DataFrame containing clock differences
"""
base_clk_df = _gn_io.clk.read_clk(base_clk_file)
test_clk_df = _gn_io.clk.read_clk(test_clk_file)

diff_clk_df = compare_clk(test_clk_df, base_clk_df, norm_types=norm_types)

diff_clk_df = compare_clk(test_clk_df, base_clk_df, norm_types=clk_norm_types)
diff_clk_df = diff_clk_df.stack(dropna=False).to_frame(name="Clock") * 1e9
diff_clk_df["|Clock|"] = diff_clk_df.abs()

Expand Down
16 changes: 11 additions & 5 deletions gnssanalysis/gn_io/clk.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ def read_clk(clk_path):
return clk_df


def get_AS_entries(clk_df: _pd.DataFrame) -> _pd.Series:
"""fastest method to grab a specific category!, same as clk_df.EST.loc['AS'] but >6 times faster"""
AS_cat_code = clk_df.index.levels[0].categories.get_loc("AS")
mask = clk_df.index.codes[0] == AS_cat_code
return _pd.Series(data=clk_df.values[:, 0][mask], index=clk_df.index.droplevel(0)[mask])
def get_sv_clocks(clk_df: _pd.DataFrame) -> _pd.Series:
"""Retrieve satellite clocks from a CLK or SP3 dataframe"""
if clk_df.index.names == ['A', 'J2000', 'CODE']:
# fastest method to grab a specific category!, same as clk_df.EST.loc['AS'] but >6 times faster
AS_cat_code = clk_df.index.levels[0].categories.get_loc("AS")
mask = clk_df.index.codes[0] == AS_cat_code
return _pd.Series(data=clk_df.values[:, 0][mask], index=clk_df.index.droplevel(0)[mask])
elif clk_df.index.names == ['J2000', 'PRN']:
return _pd.Series(data=clk_df[("EST", "CLK")].values, index=clk_df.index)
else:
raise IndexError("Incorrect index names of dataframe")


def rm_epoch_gnss_bias(clk_df_unst: _pd.DataFrame):
Expand Down

0 comments on commit c16aba1

Please sign in to comment.