Skip to content

Commit

Permalink
check for negative time intervals and use abs for computing speed and…
Browse files Browse the repository at this point in the history
… forward_azimuth for computing bearing (usually inverse_azimuth)
  • Loading branch information
WPringle committed Jul 25, 2024
1 parent d67e3d5 commit 0f93840
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stormevents/nhc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def __compute_velocity(data: DataFrame) -> DataFrame:
advisory_data["datetime"] < this_time
].index[-1]

_, inverse_azimuths, distances = geodetic.inv(
forward_azimuths, inverse_azimuths, distances = geodetic.inv(
advisory_data.loc[indices, "longitude"],
advisory_data.loc[indices, "latitude"],
advisory_data.loc[shifted_indices, "longitude"],
Expand All @@ -1101,16 +1101,18 @@ def __compute_velocity(data: DataFrame) -> DataFrame:

intervals = (
(
abs(
advisory_data.loc[indices, "datetime"].values
- advisory_data.loc[shifted_indices, "datetime"].values
)
advisory_data.loc[indices, "datetime"].values
- advisory_data.loc[shifted_indices, "datetime"].values
)
.astype("timedelta64[s]")
.astype(float)
)
speeds = pandas.Series(distances / intervals, index=indices)
speeds = pandas.Series(distances / abs(intervals), index=indices)
bearings = pandas.Series(inverse_azimuths % 360, index=indices)
# use forward azimuths for negative intervals
bearings[intervals < 0] = pandas.Series(
forward_azimuths[intervals < 0] % 360, index=indices[intervals < 0]
)
bearings[pandas.isna(speeds)] = numpy.nan
# fill in nans carrying forward, because it is same valid time
# and forecast but different isotach.
Expand Down

0 comments on commit 0f93840

Please sign in to comment.