Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crs in get_displacement #342

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading