From 4a36d7d0b7eb2a159337cd3f938a9246edfdba39 Mon Sep 17 00:00:00 2001 From: Yun Wu Date: Fri, 29 Nov 2024 14:35:46 +0800 Subject: [PATCH] Fix crs in get_displacement --- ecoscope/base/base.py | 9 +++------ tests/test_base.py | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ecoscope/base/base.py b/ecoscope/base/base.py index 4bb886e5..ba82a0fb 100644 --- a/ecoscope/base/base.py +++ b/ecoscope/base/base.py @@ -367,14 +367,11 @@ def get_displacement(self): """ Get displacement in meters between first and final fixes. """ - if not self["segment_start"].is_monotonic_increasing: self = self.sort_values("segment_start") - - gs = self.geometry.iloc[[0, -1]] - start, end = gs.to_crs(gs.estimate_utm_crs()) - - return start.distance(end) + start = self.geometry.iloc[0].coords[0] + end = self.geometry.iloc[-1].coords[1] + return Geod(ellps="WGS84").inv(start[0], start[1], end[0], end[1])[2] def get_tortuosity(self): """ diff --git a/tests/test_base.py b/tests/test_base.py index 7277088f..34ac2bf8 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -77,7 +77,7 @@ def test_trajectory_properties(movebank_relocations): def test_displacement_property(movebank_relocations): trajectory = ecoscope.base.Trajectory.from_relocations(movebank_relocations) expected = pd.Series( - [2633.760505, 147749.545621], + [2633.9728734217356, 147960.93352796172], index=pd.Index(["Habiba", "Salif Keita"], name="groupby_col"), ) pd.testing.assert_series_equal(