Skip to content

Instantly share code, notes, and snippets.

@joaofig
Last active January 15, 2024 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaofig/967e0f5d9430ddd871ddc57a46cfec36 to your computer and use it in GitHub Desktop.
Save joaofig/967e0f5d9430ddd871ddc57a46cfec36 to your computer and use it in GitHub Desktop.
Final methods of the compound trajectory class
@classmethod
def _trim_array(cls, array: np.ndarray) -> np.ndarray:
if array.shape[0] > 2:
return array[1:-1]
else:
return array
def to_trajectory(self) -> Trajectory:
lat = np.concatenate([self._trim_array(segment.lat) for segment in self.segments])
lon = np.concatenate([self._trim_array(segment.lon) for segment in self.segments])
time = np.concatenate([self._trim_array(segment.time) for segment in self.segments])
# Remove duplicates
diff_lat = np.where(np.diff(lat) == 0)[0]
lat = np.delete(lat, diff_lat)
lon = np.delete(lon, diff_lat)
time = np.delete(time, diff_lat)
return Trajectory(lat=lat, lon=lon, time=time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment