From 061d7a136e37eb353e7786470225564a28a5674c Mon Sep 17 00:00:00 2001 From: Mads Christian Lund Date: Tue, 9 Jul 2024 11:31:45 +0200 Subject: [PATCH] Increased the real_time_utilities rounding precisions --- .../postprocess/real_time_utilities.py | 12 +++++----- tests/unit/bufr_export/test_get_bufr.py | 16 ++++++------- .../bufr_export/test_get_bufr_integration.py | 24 +++++++++---------- .../bufr_export/test_realtime_utilitites.py | 24 +++++++++---------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/pypromice/postprocess/real_time_utilities.py b/src/pypromice/postprocess/real_time_utilities.py index 17efac92..2352f30d 100644 --- a/src/pypromice/postprocess/real_time_utilities.py +++ b/src/pypromice/postprocess/real_time_utilities.py @@ -72,7 +72,7 @@ def get_latest_data( # Apply smoothing to z_boom_u # require at least 2 hourly obs? Sometimes seeing once/day data for z_boom_u - df_limited = rolling_window(df_limited, "z_boom_u", "72H", 2, 1) + df_limited = rolling_window(df_limited, "z_boom_u", "72H", 2, 3) # limit to single most recent valid row (convert to series) s_current = df_limited.loc[last_valid_index] @@ -149,9 +149,9 @@ def find_positions(df, time_limit): logger.info(f"last transmission: {df_limited.index.max()}") # Extrapolate recommended for altitude, optional for lat and lon. - df_limited, lat_valid = linear_fit(df_limited, "gps_lat", 6) - df_limited, lon_valid = linear_fit(df_limited, "gps_lon", 6) - df_limited, alt_valid = linear_fit(df_limited, "gps_alt", 1) + df_limited, lat_valid = linear_fit(df_limited, "gps_lat", 7) + df_limited, lon_valid = linear_fit(df_limited, "gps_lon", 7) + df_limited, alt_valid = linear_fit(df_limited, "gps_alt", 4) # If we have no valid lat, lon or alt data in the df_limited window, then interpolate # using full tx dataset. @@ -162,9 +162,9 @@ def find_positions(df, time_limit): logger.info(f"----> Using full history for linear extrapolation: {k}") logger.info(f"first transmission: {df.index.min()}") if k == "gps_alt": - df, valid = linear_fit(df, k, 1) + df, valid = linear_fit(df, k, 2) else: - df, valid = linear_fit(df, k, 6) + df, valid = linear_fit(df, k, 7) check_valid_again[k] = valid if check_valid_again[k] is True: df_limited[f"{k}_fit"] = df.loc[df_limited.index, f"{k}_fit"] diff --git a/tests/unit/bufr_export/test_get_bufr.py b/tests/unit/bufr_export/test_get_bufr.py index edb93b5b..a100cd55 100644 --- a/tests/unit/bufr_export/test_get_bufr.py +++ b/tests/unit/bufr_export/test_get_bufr.py @@ -61,9 +61,9 @@ def test_bufr_variables_gcnet(self): latitude=66.482488, longitude=-46.294266, heightOfStationGroundAboveMeanSeaLevel=2123.2, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.6, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, - heightOfBarometerAboveMeanSeaLevel=2125.25, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.59, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, + heightOfBarometerAboveMeanSeaLevel=2125.3, ) def test_bufr_variables_promice_v2(self): @@ -91,9 +91,9 @@ def test_bufr_variables_promice_v2(self): latitude=66.482488, longitude=-46.294266, heightOfStationGroundAboveMeanSeaLevel=2123.8, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.2, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, - heightOfBarometerAboveMeanSeaLevel=2124.45, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.19, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, + heightOfBarometerAboveMeanSeaLevel=2124.5, ) def test_bufr_variables_promice_v3(self): @@ -121,8 +121,8 @@ def test_bufr_variables_promice_v3(self): latitude=66.482488, longitude=-46.294266, heightOfStationGroundAboveMeanSeaLevel=2123.8, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.2, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.19, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, heightOfBarometerAboveMeanSeaLevel=2126, ) diff --git a/tests/unit/bufr_export/test_get_bufr_integration.py b/tests/unit/bufr_export/test_get_bufr_integration.py index fd755fd9..1a21b3ee 100644 --- a/tests/unit/bufr_export/test_get_bufr_integration.py +++ b/tests/unit/bufr_export/test_get_bufr_integration.py @@ -149,8 +149,8 @@ def test_get_bufr_has_new_data(self): longitude=-46.29427, heightOfStationGroundAboveMeanSeaLevel=2123.7, heightOfBarometerAboveMeanSeaLevel=2124.7, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.1, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.09, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, ) pd.testing.assert_series_equal( bufr_data.as_series(), @@ -188,8 +188,8 @@ def test_get_bufr_has_new_data_dont_store_position(self): longitude=-46.29427, heightOfStationGroundAboveMeanSeaLevel=2123.7, heightOfBarometerAboveMeanSeaLevel=2124.7, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.1, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.09, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, ) pd.testing.assert_series_equal( bufr_data.as_series(), @@ -268,8 +268,8 @@ def test_get_bufr_includes_datasets_not_in_latests_timestamps(self): longitude=-46.29427, heightOfStationGroundAboveMeanSeaLevel=2123.7, heightOfBarometerAboveMeanSeaLevel=2124.7, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.1, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.09, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, ) pd.testing.assert_series_equal( bufr_data.as_series(), @@ -329,8 +329,8 @@ def test_invalid_value_at_last_index(self): longitude=-46.29427, heightOfStationGroundAboveMeanSeaLevel=2123.7, heightOfBarometerAboveMeanSeaLevel=2124.7, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.1, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.09, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, ) pd.testing.assert_series_equal( bufr_data.as_series(), @@ -467,8 +467,8 @@ def test_ignore_newer_data_than_now_input(self): longitude=-46.29426, heightOfStationGroundAboveMeanSeaLevel=2123.3, heightOfBarometerAboveMeanSeaLevel=2124.3, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.1, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.09, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, ) pd.testing.assert_series_equal( bufr_data.as_series(), @@ -508,8 +508,8 @@ def test_land_station_export(self): longitude=-46.29427, heightOfStationGroundAboveMeanSeaLevel=2123.7, heightOfBarometerAboveMeanSeaLevel=2124.7, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.1, - heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.6, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=4.09, + heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=4.59, ) pd.testing.assert_series_equal( bufr_data.as_series(), diff --git a/tests/unit/bufr_export/test_realtime_utilitites.py b/tests/unit/bufr_export/test_realtime_utilitites.py index a7306a3f..1acdb5b7 100644 --- a/tests/unit/bufr_export/test_realtime_utilitites.py +++ b/tests/unit/bufr_export/test_realtime_utilitites.py @@ -50,10 +50,10 @@ def test_1(self): "gps_lon": -46.294232, "gps_alt": 2116.0, "z_boom_u": 4.1901, - "gps_lat_fit": 66.482479, - "gps_lon_fit": -46.294269, - "gps_alt_fit": 2121.4, - "z_boom_u_smooth": 4.2, + "gps_lat_fit": 66.4824788, + "gps_lon_fit": -46.2942685, + "gps_alt_fit": 2121.4118, + "z_boom_u_smooth": 4.188, }, name=datetime.datetime(2023, 12, 7, 6), ) @@ -94,10 +94,10 @@ def test_latest_data_row_is_invalid(self): "gps_lon": -46.294335, "gps_alt": 2125.0, "z_boom_u": 4.1844, - "gps_lat_fit": 66.482483, - "gps_lon_fit": -46.294275, - "gps_alt_fit": 2123.3, - "z_boom_u_smooth": 4.2, + "gps_lat_fit": 66.4824828, + "gps_lon_fit": -46.2942753, + "gps_alt_fit": 2123.3088, + "z_boom_u_smooth": 4.187, }, name=expected_output_timestamp, ) @@ -127,10 +127,10 @@ def test_latest_data_has_some_invalid_values(self): "gps_lon": -46.294232, "gps_alt": 2116.0, "z_boom_u": 4.1901, - "gps_lat_fit": 66.482479, - "gps_lon_fit": -46.294269, - "gps_alt_fit": 2121.4, - "z_boom_u_smooth": 4.2, + "gps_lat_fit": 66.4824788, + "gps_lon_fit": -46.2942685, + "gps_alt_fit": 2121.4118, + "z_boom_u_smooth": 4.188, }, name=datetime.datetime(2023, 12, 7, 6), )