-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
314 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"folium", | ||
"geopandas<=0.14.2", | ||
"igraph", | ||
"ipywidgets", | ||
"kaleido", | ||
"mapclassify", | ||
"matplotlib", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pyproj | ||
from ecoscope.analysis import astronomy | ||
|
||
|
||
def test_to_EarthLocation(movebank_relocations): | ||
geometry = movebank_relocations["geometry"] | ||
test_point = geometry.iloc[0] | ||
|
||
transformed = astronomy.to_EarthLocation(geometry) | ||
|
||
assert len(geometry) == len(transformed) | ||
|
||
transform = pyproj.Transformer.from_proj( | ||
proj_from="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", | ||
proj_to="+proj=geocent +ellps=WGS84 +datum=WGS84 +units=m +no_defs", | ||
) | ||
|
||
# Check the projected values in the returned EarthLocation are what we expect | ||
test_val = transform.transform(xx=test_point.x, yy=test_point.y, zz=0) | ||
assert test_val[0] == transformed[0].x.value | ||
assert test_val[1] == transformed[0].y.value | ||
assert test_val[2] == transformed[0].z.value | ||
|
||
|
||
def test_is_night(movebank_relocations): | ||
subset = movebank_relocations.iloc[12:15].copy() | ||
|
||
subset["is_night"] = astronomy.is_night(subset.geometry, subset.fixtime) | ||
|
||
assert subset["is_night"].values.tolist() == [True, True, False] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
from ecoscope.analysis.proximity import SpatialFeature, Proximity, ProximityProfile | ||
from ecoscope.base import Trajectory | ||
|
||
|
||
@pytest.mark.skipif(not pytest.earthranger, reason="No connection to EarthRanger") | ||
def test_proximity(er_io): | ||
er_features = er_io.get_spatial_features_group(spatial_features_group_id="15698426-7e0f-41df-9bc3-495d87e2e097") | ||
|
||
prox_profile = ProximityProfile([]) | ||
|
||
for row in er_features.iterrows(): | ||
prox_profile.spatial_features.append(SpatialFeature(row[1]["name"], row[1]["pk"], row[1]["geometry"])) | ||
|
||
relocations = er_io.get_subjectgroup_observations(group_name=er_io.GROUP_NAME) | ||
trajectory = Trajectory.from_relocations(relocations) | ||
|
||
proximity_events = Proximity.calculate_proximity(proximity_profile=prox_profile, trajectory=trajectory) | ||
|
||
assert len(proximity_events["spatialfeature_id"].unique()) == len(prox_profile.spatial_features) |
Oops, something went wrong.