Skip to content

Commit

Permalink
Merge pull request #175 from nismod/bugfix/handle_no_tracks_in_slice
Browse files Browse the repository at this point in the history
Handle case where there is no valid track
  • Loading branch information
thomas-fred authored Feb 5, 2024
2 parents 62cbfe5 + 035ba36 commit e6a9d27
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 e6a9d27

Please sign in to comment.