Skip to content

Commit

Permalink
Handle case where there is no valid track
Browse files Browse the repository at this point in the history
The pandas.concat function will raise an exception on being passed an
empty list, so check length first.
  • Loading branch information
thomas-fred committed Feb 5, 2024
1 parent 62cbfe5 commit 035ba36
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions workflow/scripts/preprocess/slice_storm_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@
assert np.all(np.diff(sliced.timestep) == 1)
sliced_tracks_by_track.append(sliced)

sliced_tracks = pd.concat(sliced_tracks_by_track)
logging.info(
f"Filtered to {len(sliced_tracks.track_id.unique())} valid (n > 1) tracks, with {len(sliced_tracks)} points"
)
if len(sliced_tracks_by_track) > 0:
sliced_tracks = pd.concat(sliced_tracks_by_track)
logging.info(
f"Filtered to {len(sliced_tracks.track_id.unique())} "
f"valid (n > 1) tracks, with {len(sliced_tracks)} points"
)
else:
sliced_tracks = gpd.GeoDataFrame({"geometry": []}, crs=4326)
logging.info("No valid tracks found")

logging.info("Writing tracks subset to disk")
os.makedirs(os.path.dirname(sliced_tracks_path), exist_ok=True)
Expand Down

0 comments on commit 035ba36

Please sign in to comment.