diff --git a/gnssanalysis/gn_io/sp3.py b/gnssanalysis/gn_io/sp3.py index b5c43ef..0b03bd1 100644 --- a/gnssanalysis/gn_io/sp3.py +++ b/gnssanalysis/gn_io/sp3.py @@ -54,7 +54,7 @@ def sp3_pos_nodata_to_nan(sp3_df: _pd.DataFrame) -> None: & (sp3_df[("EST", "Y")] == SP3_POS_NODATA_NUMERIC) & (sp3_df[("EST", "Z")] == SP3_POS_NODATA_NUMERIC) ) - sp3_df.loc[nan_mask, [("EST", "X"), ("EST", "Y"), ("EST", "Z")]] = _np.NAN + sp3_df.loc[nan_mask, [("EST", "X"), ("EST", "Y"), ("EST", "Z")]] = _np.nan def sp3_clock_nodata_to_nan(sp3_df: _pd.DataFrame) -> None: @@ -66,7 +66,7 @@ def sp3_clock_nodata_to_nan(sp3_df: _pd.DataFrame) -> None: :return None """ nan_mask = sp3_df[("EST", "CLK")] >= SP3_CLOCK_NODATA_NUMERIC - sp3_df.loc[nan_mask, ("EST", "CLK")] = _np.NAN + sp3_df.loc[nan_mask, ("EST", "CLK")] = _np.nan def mapparm(old, new): @@ -153,6 +153,7 @@ def read_sp3(sp3_path, pOnly=True, nodata_to_nan=True): if nodata_to_nan: sp3_pos_nodata_to_nan(sp3_df) # Convert 0.000000 (which indicates nodata in the SP3 POS column) to NaN sp3_clock_nodata_to_nan(sp3_df) # Convert 999999* (which indicates nodata in the SP3 CLK column) to NaN + # print(sp3_df.index.has_duplicates()) if pOnly or parsed_header.HEAD.loc["PV_FLAG"] == "P": sp3_df = sp3_df[sp3_df.index.get_level_values("PV_FLAG") == "P"] diff --git a/tests/test_sp3.py b/tests/test_sp3.py new file mode 100644 index 0000000..5e926aa --- /dev/null +++ b/tests/test_sp3.py @@ -0,0 +1,59 @@ +import unittest +from unittest.mock import patch, mock_open + +import numpy as np + +import gnssanalysis.gn_io.sp3 as sp3 + +# dataset is part of the IGS benchmark (modified to include non null data on clock) +input_data = b"""#dV2007 4 12 0 0 0.00000000 289 ORBIT IGS14 BHN ESOC +## 1422 345600.00000000 900.00000000 54202 0.0000000000000 ++ 2 G01G02 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 +VG01 27184.457428 -3548.055474 5304.058806 999999.999999 +PG02 12947.223282 22448.220655 6215.570741 999999.999999 +VG02 -7473.756152 -4355.288568 29939.333728 999999.999999 +* 2007 4 12 0 15 0.00000000 +PG01 -3659.032812 -14219.662913 22339.175481 123456.999999 +VG01 27295.435569 -5170.061971 1131.227754 999999.999999 +PG02 12163.580358 21962.803659 8849.429007 999999.999999 +VG02 -9967.334764 -6367.969150 28506.683280 999999.999999 +* 2007 4 12 0 30 0.00000000 +PG01 -1218.171155 -14755.013599 22252.168480 999999.999999 +VG01 26855.435366 -6704.236117 -3062.394499 999999.999999 +PG02 11149.555664 21314.099837 11331.977499 123456.999999 +VG02 -12578.915944 -7977.396362 26581.116225 999999.999999 +EOF""" + + +class TestSp3(unittest.TestCase): + @patch("builtins.open", new_callable=mock_open, read_data=input_data) + def test_read_sp3_pOnly(self, mock_file): + result = sp3.read_sp3("mock_path", pOnly=True) + self.assertEqual(len(result), 6) + + @patch("builtins.open", new_callable=mock_open, read_data=input_data) + def test_read_sp3_pv(self, mock_file): + result = sp3.read_sp3("mock_path", pOnly=False) + self.assertTrue(len(result) == 12) + self.assertEqual((np.isnan(result[("EST", "CLK")])).sum(), 10)