Skip to content

Commit

Permalink
Handle single points
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaraphael committed Nov 10, 2023
1 parent 88bdbc4 commit 46f2178
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions cerulean_cloud/cloud_function_ais_analysis/utils/ais.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,32 @@ def build_trajectories(self):
"""
ais_trajectories = list()
for st_name, group in self.ais_gdf.groupby("ssvid"):
if (
len(group) > 1
): # ignore single points # XXX Should NOT ignore single points!
# build trajectory
traj = mpd.Trajectory(df=group, traj_id=st_name, t="timestamp")

# interpolate/extrapolate to times in time_vec
times = list()
positions = list()
for t in self.time_vec:
pos = traj.interpolate_position_at(t)
times.append(t)
positions.append(pos)

# store as trajectory
interpolated_traj = mpd.Trajectory(
df=gpd.GeoDataFrame(
{"timestamp": times, "geometry": positions},
crs=self.crs_meters,
),
traj_id=st_name,
t="timestamp",
)

ais_trajectories.append(interpolated_traj)
# Duplicate the row if there's only one point
if len(group) == 1:
group = pd.concat([group] * 2).reset_index(drop=True)

# build trajectory
traj = mpd.Trajectory(df=group, traj_id=st_name, t="timestamp")

# interpolate/extrapolate to times in time_vec
times = list()
positions = list()
for t in self.time_vec:
pos = traj.interpolate_position_at(t)
times.append(t)
positions.append(pos)

# store as trajectory
interpolated_traj = mpd.Trajectory(
df=gpd.GeoDataFrame(
{"timestamp": times, "geometry": positions},
crs=self.crs_meters,
),
traj_id=st_name,
t="timestamp",
)

ais_trajectories.append(interpolated_traj)

self.ais_trajectories = mpd.TrajectoryCollection(ais_trajectories)

Expand Down

0 comments on commit 46f2178

Please sign in to comment.