Skip to content

Commit

Permalink
Fix crs in get_displacement (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Wu authored Nov 29, 2024
1 parent 6606406 commit fbe8125
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions ecoscope/base/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import warnings
from functools import cached_property

import geopandas as gpd
import numpy as np
Expand All @@ -13,7 +14,6 @@
RelocsSpeedFilter,
TrajSegFilter,
)
from functools import cached_property


class EcoDataFrame(gpd.GeoDataFrame):
Expand Down Expand Up @@ -352,7 +352,7 @@ def from_relocations(cls, gdf, *args, **kwargs):
assert isinstance(gdf, Relocations)
assert {"groupby_col", "fixtime", "geometry"}.issubset(gdf)

if kwargs.get("copy") is not False:
if kwargs.get("copy"):
gdf = gdf.copy()

gdf = EcoDataFrame(gdf)
Expand All @@ -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
4 changes: 2 additions & 2 deletions 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 All @@ -89,7 +89,7 @@ def test_displacement_property(movebank_relocations):
def test_tortuosity(movebank_relocations):
trajectory = ecoscope.base.Trajectory.from_relocations(movebank_relocations)
expected = pd.Series(
[51.65388458528601, 75.96149479123005],
[51.64971990070838, 75.85297059494991],
index=pd.Index(["Habiba", "Salif Keita"], name="groupby_col"),
)
pd.testing.assert_series_equal(
Expand Down

0 comments on commit fbe8125

Please sign in to comment.