Skip to content

Commit

Permalink
Fix crs in get_displacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Wu committed Nov 29, 2024
1 parent 161ee88 commit 4a36d7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions ecoscope/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4a36d7d

Please sign in to comment.