Last active
January 15, 2024 15:53
-
-
Save joaofig/967e0f5d9430ddd871ddc57a46cfec36 to your computer and use it in GitHub Desktop.
Final methods of the compound trajectory class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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