Skip to content

Commit

Permalink
Merge pull request #34 from yupidevs/develop
Browse files Browse the repository at this point in the history
New version
  • Loading branch information
jmorgadov authored Jun 17, 2021
2 parents 09bed63 + 9f3f1a8 commit bed4afc
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 136 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# CHANGELOG

## [0.5.1] 2021-06-17

### Added

- Add `uniformly_spaced` property on trajectory
- Add constant add and sub on trajectories
- Add contant multiplication on trajectories

### Fixed

- Change time data calculation if only dt is given
- Fix comparation using threshold
- Fix a bug on default parameters of trackers
- Fix logging on algorithms

### Others

- Improve tests

## [0.4.2] 2021-06-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
author = 'Gustavo Viera-López, Alfredo Reyes, Jorge Morgado, Ernesto Altshuler'

# The full version, including alpha/beta/rc tags
release = '0.5.0'
release = '0.5.1'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "yupi"
version = "0.5.0"
version = "0.5.1"
description = "A package for tracking and analysing objects trajectories"
authors = [
"Gustavo Viera-López <gvieralopez@gmail.com>",
Expand Down
82 changes: 0 additions & 82 deletions tests/test_trajectory.py

This file was deleted.

82 changes: 82 additions & 0 deletions tests/test_trajectory/test_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pytest
from yupi import Trajectory


def test_creation_by_xyz():
Trajectory(x=[1, 2])
Trajectory(x=[1, 2], y=[2, 3])
Trajectory(x=[1, 2], y=[2, 3], z=[1, 4])

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2])

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2], z=[2, 5])

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2, 6], z=[5])

with pytest.raises(ValueError):
Trajectory(x=[2], y=[2, 6], z=[5, 8])


def test_creation_by_dimensions():
Trajectory(dimensions=[[1, 2]])
Trajectory(dimensions=[[1, 2], [2, 3]])
Trajectory(dimensions=[[1, 2], [2, 3], [1, 4]])
Trajectory(dimensions=[[1, 2], [2, 3], [1, 4], [7, 8]])

with pytest.raises(ValueError):
Trajectory(dimensions=[[1, 2], [2]])

with pytest.raises(ValueError):
Trajectory(dimensions=[[1, 2], [2], [2, 5]])

with pytest.raises(ValueError):
Trajectory(dimensions=[[1, 2], [2, 6], [5]])

with pytest.raises(ValueError):
Trajectory(dimensions=[[2], [2, 6], [5, 8]])


def test_creation_by_points():
Trajectory(points=[[1, 2]])
Trajectory(points=[[1, 2], [2, 3]])
Trajectory(points=[[1, 2, 4], [2, 3, 2], [1, 4, 8]])
Trajectory(points=[[1, 2, 7, 3], [2, 3, 5, 3]])

with pytest.raises(ValueError):
Trajectory(points=[[1, 2], [2]])

with pytest.raises(ValueError):
Trajectory(points=[[1, 2], [2], [2, 5]])


def test_creation_with_time():
Trajectory(x=[1, 2], y=[2, 3], t=[0, 0.1])
Trajectory(x=[1, 2], y=[2, 3], dt=0.1)
Trajectory(x=[1, 2], y=[2, 3], t=[0, 0.1], dt=0.1)
Trajectory(x=[1, 2], y=[2, 3], t=[0.4, 0.5], dt=0.1, t0=0.4)

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2, 3], t=[0])

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2, 3], t=[0, 0.1], dt=0.2)

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2, 3], t=[0.4, 0.5], dt=0.1)

def test_creation_with_ang():
Trajectory(x=[1, 2], y=[2, 3], ang=[0, 0.1])

with pytest.raises(ValueError):
Trajectory(x=[1, 2], y=[2, 3], ang=[0.1])


def test_creation_general():
Trajectory(x=[1, 2], y=[2, 3], t=[0, 1], ang=[0, 0], traj_id='test')
Trajectory(x=[1, 2], y=[2, 3], dt=0.5, ang=[0, 1.2], traj_id='test')
Trajectory(points=[[1, 2], [2, 3]], dt=0.5, ang=[0, 1.2], traj_id='test')
Trajectory(dimensions=[[1, 2], [2, 3]], dt=0.5, t=[1, 1.5], t0=1,
traj_id='test')
37 changes: 37 additions & 0 deletions tests/test_trajectory/test_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import numpy as np
import pytest
from yupi import Trajectory


def test_save():
t1 = Trajectory(x=[1,2,3], y=[4,5,6])

# Wrong trajectory file extension at saving
with pytest.raises(ValueError):
t1.save('t1', file_type='abc')

# Saving json
t1.save('t1', file_type='json')

# Saving csv
t1.save('t1', file_type='csv')


def test_load():
# Wrong trajectory file extension at loading
with pytest.raises(ValueError):
t1 = Trajectory.load('t1.abc')

# Loading json
t1 = Trajectory.load('t1.json')
for tp, point in zip(t1, [[1,4], [2,5], [3,6]]):
assert (np.array(point) == tp.r).all()

# Loading csv
t1 = Trajectory.load('t1.csv')
for tp, point in zip(t1, [[1,4], [2,5], [3,6]]):
assert (np.array(point) == tp.r).all()

os.remove('t1.json')
os.remove('t1.csv')
122 changes: 122 additions & 0 deletions tests/test_trajectory/test_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import numpy as np
from pytest import approx, fixture
import pytest
from yupi import Trajectory

APPROX_REL_TOLERANCE = 1e-12

@fixture
def points():
return np.array([[1, 2], [4, 3], [4, 1]], dtype=float)


@fixture
def angles():
return np.array([0, 1, 2], dtype=float)


@fixture
def traj(points, angles):
return Trajectory(points=points, ang=angles)


def test_length(traj):
assert len(traj) == 3


def test_copy(traj):
copy_traj = traj.copy()

assert traj.r == approx(copy_traj.r, APPROX_REL_TOLERANCE)
assert traj.dt == approx(copy_traj.dt, APPROX_REL_TOLERANCE)
assert traj.t == approx(copy_traj.t, APPROX_REL_TOLERANCE)
assert traj.v == approx(copy_traj.v, APPROX_REL_TOLERANCE)
assert traj.ang == approx(copy_traj.ang, APPROX_REL_TOLERANCE)


def test_iteration(points, angles, traj):
time = traj.t

for i, tp in enumerate(traj):
point = points[i]
ang = angles[i]
t = time[i]

assert point == approx(tp.r, APPROX_REL_TOLERANCE) # Position
assert t == approx(tp.t, APPROX_REL_TOLERANCE) # Time
assert ang == approx(tp.ang, APPROX_REL_TOLERANCE) # Angle


def test_constant_addition(points, traj):
new_traj = traj + 10
new_points = points + 10

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_point_addition(points, traj):
new_traj = traj + (1, 3)
new_points = points + (1, 3)

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_traj_addition(points, traj):
other_traj = traj.copy()
new_traj = traj + other_traj
new_points = points + points

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_wrong_addition(traj):
with pytest.raises(TypeError):
traj += 'wrong'


def test_constant_substraction(points, traj):
new_traj = traj - 10
new_points = points - 10

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_point_substraction(points, traj):
new_traj = traj - (1, 3)
new_points = points - (1, 3)

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_traj_substraction(points, traj):
other_traj = traj.copy()
new_traj = traj - other_traj
new_points = points - points

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_wrong_substraction(traj):
with pytest.raises(TypeError):
traj -= 'wrong'


def test_constant_multiplication(points, traj):
new_traj = traj * 3
new_points = points * 3

for true_point, point in zip(new_points, new_traj.r):
assert true_point == approx(point, APPROX_REL_TOLERANCE)


def test_wrong_multiplication(traj):
with pytest.raises(TypeError):
traj *= 'wrong'
with pytest.raises(TypeError):
traj *= [1, 2]
2 changes: 1 addition & 1 deletion yupi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
'Vector'
]

__version__ = '0.5.0'
__version__ = '0.5.1'
4 changes: 3 additions & 1 deletion yupi/tracking/algorithms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
import cv2
import logging
import numpy as np


Expand Down Expand Up @@ -97,7 +98,8 @@ def get_centroid(self, bin_img):
cX = int(M['m10'] / M['m00'])
cY = int(M['m01'] / M['m00'])
return cX, cY
print('[ERROR] Nothing was over threshold')
logging.warning("Nothing was over threshold. Algorithm: %s",
type(self).__name__)
return None

def preprocess(self, frame, roi_bound, preprocessing):
Expand Down
Loading

0 comments on commit bed4afc

Please sign in to comment.