Skip to content

Commit

Permalink
handling special case where no previous times available for new forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
WPringle committed Jul 11, 2024
1 parent d43edea commit 90679be
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions stormevents/nhc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,14 @@ def __compute_velocity(data: DataFrame) -> DataFrame:
shift_time = advisory_data.loc[ind[1], "datetime"]
if shift_time > this_time:
# update shift index
shifted_indices[counter] = advisory_data["datetime"][
advisory_data["datetime"] < this_time
].index[-1]
if (advisory_data["datetime"] < this_time).sum() == 0:
shifted_indices[counter] = advisory_data["datetime"][
advisory_data["datetime"] > this_time
].index[0]
else:
shifted_indices[counter] = advisory_data["datetime"][
advisory_data["datetime"] < this_time
].index[-1]

_, inverse_azimuths, distances = geodetic.inv(
advisory_data.loc[indices, "longitude"],
Expand All @@ -1096,8 +1101,10 @@ def __compute_velocity(data: DataFrame) -> DataFrame:

intervals = (
(
advisory_data.loc[indices, "datetime"].values
- advisory_data.loc[shifted_indices, "datetime"].values
abs(
advisory_data.loc[indices, "datetime"].values
- advisory_data.loc[shifted_indices, "datetime"].values
)
)
.astype("timedelta64[s]")
.astype(float)
Expand Down

0 comments on commit 90679be

Please sign in to comment.