Skip to content

Commit

Permalink
Adding tests for EcoPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling committed May 15, 2024
1 parent 2a0aa79 commit 11e8bf6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ecoscope/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def nsd(relocations):
relocations = relocations.to_crs(relocations.estimate_utm_crs())

times = relocations["fixtime"]
distances = relocations.distance(relocations.geometry[0]) ** 2
distances = relocations.distance(relocations.geometry.iat[0]) ** 2

fig = go.FigureWidget()

Expand Down
47 changes: 47 additions & 0 deletions tests/test_ecoplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import numpy as np
from ecoscope.plotting.plot import EcoPlotData, ecoplot, mcp, nsd, speed
from ecoscope.base import Trajectory


def test_ecoplot(movebank_relocations):
traj = Trajectory.from_relocations(movebank_relocations)
epd = EcoPlotData(traj.groupby("groupby_col"), "segment_start", "speed_kmhr", line=dict(color="blue"))
figure = ecoplot([epd], "EcoPlot")

habiba = traj.loc[traj["groupby_col"] == "Habiba"]
salif = traj.loc[traj["groupby_col"] == "Salif Keita"]

assert len(figure.data) == 2

assert figure.data[0].name == "Habiba"
assert np.equal(figure.data[0].x, habiba["segment_start"].array).all()
assert np.equal(figure.data[0].y, habiba["speed_kmhr"].array).all()

assert figure.data[1].name == "Salif Keita"
assert np.equal(figure.data[1].x, salif["segment_start"].array).all()
assert np.equal(figure.data[1].y, salif["speed_kmhr"].array).all()


def test_mcp(movebank_relocations):
figure = mcp(movebank_relocations)

assert len(figure.data) == 1
assert movebank_relocations["fixtime"].iat[0] == figure.data[0].x[0]
assert movebank_relocations["fixtime"].iat[-1] == figure.data[0].x[-1]


def test_nsd(movebank_relocations):
figure = nsd(movebank_relocations)

assert len(figure.data) == 1
assert len(figure.data[0].x) == len(movebank_relocations)
assert len(figure.data[0].y) == len(movebank_relocations)


def test_speed(movebank_relocations):
traj = Trajectory.from_relocations(movebank_relocations)
figure = speed(traj)

assert len(figure.data) == 1
len(figure.data[0].x) == len(traj) * 4
len(figure.data[0].y) == len(traj) * 4

0 comments on commit 11e8bf6

Please sign in to comment.