From 66882083ac2b2d8abf8945b175dd25cc6e1e4806 Mon Sep 17 00:00:00 2001 From: William Pringle Date: Mon, 14 Apr 2025 16:14:11 -0500 Subject: [PATCH 1/2] set an infinity translation speed to NaN (will be filled) --- stormevents/nhc/track.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stormevents/nhc/track.py b/stormevents/nhc/track.py index 2b0d4fb..5413719 100644 --- a/stormevents/nhc/track.py +++ b/stormevents/nhc/track.py @@ -1135,6 +1135,8 @@ def __compute_velocity(data: DataFrame) -> DataFrame: .astype(float) ) speeds = pandas.Series(distances / abs(intervals), index=indices) + # if Inf (interval is zero but distance != 0) set to NaN + speeds[speeds == numpy.inf] = numpy.nan bearings = pandas.Series(inverse_azimuths % 360, index=indices) # use forward azimuths for negative intervals bearings[intervals < 0] = pandas.Series( From cccb00067c3de2ffc3648575c83716a0f010886f Mon Sep 17 00:00:00 2001 From: William Pringle Date: Tue, 15 Apr 2025 13:44:25 -0500 Subject: [PATCH 2/2] adding unit test case the duplicated non-zero forecast hour case --- tests/test_nhc.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_nhc.py b/tests/test_nhc.py index 6d4fb3b..1438ccb 100644 --- a/tests/test_nhc.py +++ b/tests/test_nhc.py @@ -312,6 +312,25 @@ def test_vortex_track_forecast_time_fromfile_arg(): assert pandas.to_datetime(dates) == pandas.to_datetime("09-10-2018") +def test_vortex_track_forecast_time_fromfile_duplicated_forecast_hours(): + # Test from_file to accept forecast_time argument + # this file has analysis times with several 0 forecast hours + # followed by hourly timestep forecasts from the forecast_time. + # One of the >0 forecast_hours is duplicated which creates and Inf + # trans speed which is then set to NaN by the code to avoid an error + input_directory = INPUT_DIRECTORY / "test_vortex_track_from_file" + + track = VortexTrack.from_file( + input_directory / "helene2024_fort.22", + file_deck="a", + advisories="OFCL", + forecast_time="2024-09-24 12:00", + ) + + dates = track.data.track_start_time.unique() + assert len(dates) == 1 + + # def test_vortex_track_forecast_time_outofbound_date(): # # Test it raises if forecast time is not between start and end # msg = ""