Skip to content

Commit

Permalink
Merge pull request #94 from yupidevs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jmorgadov authored Mar 18, 2022
2 parents 2a3367e + 0f8f433 commit 08dace1
Show file tree
Hide file tree
Showing 16 changed files with 506 additions and 152 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
author = 'Gustavo Viera-López, Alfredo Reyes, Jorge Morgado, Ernesto Altshuler'

# The full version, including alpha/beta/rc tags
release = '0.8.6'
release = '0.8.7'


# -- General configuration ---------------------------------------------------
Expand Down
Binary file modified docs/source/images/example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/images/tutorial009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions docs/source/tutorials/analyzing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ detailed explanation of the parameters.)
.. code-block:: python
from yupi.generators import LangevinGenerator
lg = LangevinGenerator(500, 2, 500, 0.5, 2, 0.1)
lg = LangevinGenerator(500, 2, 500, 0.5, 2, 0.1, seed=0)
trajs = lg.generate()
Expand Down Expand Up @@ -45,7 +45,7 @@ Plotting in three dimensions can be achieved in a similar way. Let us generate 3
.. code-block:: python
from yupi.generators import LangevinGenerator
lg = LangevinGenerator(500, 3, 5, 0.5, 2, 0.1)
lg = LangevinGenerator(500, 3, 5, 0.5, 2, 0.1, seed=0)
trajs3D = lg.generate()
Expand Down Expand Up @@ -128,8 +128,8 @@ a linear function of time. To estimate the MSD of a list of
Kurtosis
========

Another useful quantity is the kurtosis, $\kappa$, a measure of the disparity of
spatial scales of a dispersal process and also an intuitive means to understand
Another useful quantity is the kurtosis, a measure of the disparity of spatial
scales of a dispersal process and also an intuitive means to understand
normality. It can be estimated using:

.. code-block:: python
Expand All @@ -138,7 +138,7 @@ normality. It can be estimated using:
from yupi.graphics import plot_kurtosis
ref = yupi.stats.kurtosis_reference(trajs)
kurtosis = yupi.stats.kurtosis(trajs, time_avg=False, lag=30)
kurtosis, _ = yupi.stats.kurtosis(trajs, time_avg=False, lag=30)
yupi.graphics.plot_kurtosis(kurtosis, kurtosis_ref=ref, dt=dt)
Expand Down Expand Up @@ -181,9 +181,9 @@ enables the characterization of the motion in terms of the frequency components.
from yupi.stats import psd
from yupi.graphics import plot_psd
psd_mean, psd_std, omega = psd(trajs, lag=150, omega=True)
plot_psd(psd_mean, omega, psd_std)
psd_mean, psd_std, frec = psd(trajs, lag=150)
plot_psd(psd_mean, frec, psd_std)
.. figure:: /images/tutorial009.png
:alt: PSD IMAGE
:align: center
:align: center
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.8.6"
version = "0.8.7"
description = "A package for tracking and analysing objects trajectories"
authors = [
"Gustavo Viera-López <[email protected]>",
Expand Down
36 changes: 15 additions & 21 deletions tests/test_stats/test_stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
from yupi import Trajectory
from yupi import Trajectory, VelMethod
from yupi.stats import *

APPROX_REL_TOLERANCE = 1e-10
Expand All @@ -9,19 +9,19 @@
@pytest.fixture
def traj():
points = [[0, 0], [1, 0], [1, 1], [2, 1]]
return Trajectory(points=points)
return Trajectory(points=points, vel_est={"method": VelMethod.FORWARD})


@pytest.fixture
def traj1():
x = [0, 8, 5, 11]
return Trajectory(x, dt=2)
return Trajectory(x, dt=2, vel_est={"method": VelMethod.FORWARD})


@pytest.fixture
def traj2():
x = [0, 8.5, 4.9, 10.5]
return Trajectory(x, dt=2)
return Trajectory(x, dt=2, vel_est={"method": VelMethod.FORWARD})


def test_turning_angles(traj):
Expand All @@ -33,8 +33,9 @@ def test_turning_angles(traj):


def test_speed_ensemble(traj1):
print(traj1.v)
se = speed_ensemble([traj1, traj1])
assert se == pytest.approx([4, 1.5, 3, 4, 1.5, 3], APPROX_REL_TOLERANCE)
assert se == pytest.approx([4, 1.5, 3, 3, 4, 1.5, 3, 3], APPROX_REL_TOLERANCE)


def test_msd(traj1, traj2):
Expand All @@ -49,23 +50,17 @@ def test_msd(traj1, traj2):
assert msd_t[1] == pytest.approx([1.26166667, 1.4975])


def test_vacf():
traj1 = Trajectory([0, 8, 5, 11])
traj2 = Trajectory([0, 8.5, 4.9, 10.5])

def test_vacf(traj1, traj2):
vacf_e = vacf([traj1, traj2], time_avg=False)
assert vacf_e[0] == pytest.approx([68.125, -27.3, 47.8])
assert vacf_e[1] == pytest.approx([4.125, 3.3, 0.2])
assert vacf_e[0] == pytest.approx([17.03125, -6.825, 11.95, 11.95])
assert vacf_e[1] == pytest.approx([1.03125, 0.825, 0.05, 0.05])

vacf_t = vacf([traj1, traj2], time_avg=True, lag=2)
assert vacf_t[0] == pytest.approx([-23.19, 47.8])
assert vacf_t[1] == pytest.approx([2.19, 0.2])

assert vacf_t[0] == pytest.approx([-1.05833333, 3.59])
assert vacf_t[1] == pytest.approx([0.55833333, 0.16])

def test_kurtosis():
traj1 = Trajectory([0, 8, 5, 11])
traj2 = Trajectory([0, 8.5, 4.9, 10.5])

def test_kurtosis(traj1, traj2):
kurt_e = kurtosis([traj1, traj2], time_avg=False)
assert kurt_e[0] == pytest.approx([0, 1, 1, 1])

Expand All @@ -75,13 +70,12 @@ def test_kurtosis():
assert kurt_t[1] == pytest.approx([0, 0])


def test_psd():
traj1 = Trajectory([0, 8, 5, 11])
def test_psd(traj1):
lag = 2
psd_o = psd([traj1], lag=lag, omega=True)
assert psd_o[0] == pytest.approx([69, 27])
assert psd_o[0] == pytest.approx([8.5, 6.5])
assert psd_o[1] == pytest.approx([0, 0])
assert psd_o[2] == pytest.approx([-3.14159265, 0])
assert psd_o[2] == pytest.approx([-9.8696044, 0.])


def test_checkers():
Expand Down
61 changes: 55 additions & 6 deletions tests/test_trajectory/test_creation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from yupi import Trajectory
from yupi import Trajectory, VelMethod, VelPadding

APPROX_REL_TOLERANCE = 1e-10


def test_creation_by_xyz():
Expand Down Expand Up @@ -68,6 +70,7 @@ def test_creation_with_time():
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])

Expand All @@ -76,8 +79,54 @@ def test_creation_with_ang():


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')
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")


def test_velocity_estimation_methods():
x = [1, 2, 4, 8, 16]

Trajectory.global_vel_method(VelMethod.FORWARD)
traj = Trajectory(x=x)

assert traj.v == pytest.approx([1, 2, 4, 8, 8], rel=APPROX_REL_TOLERANCE)

Trajectory.global_vel_method(VelMethod.CENTERED)
traj.set_vel_method(VelMethod.BACKWARD)

assert traj.v == pytest.approx([1, 1, 2, 4, 8], rel=APPROX_REL_TOLERANCE)

traj = Trajectory(x=x)

assert traj.v == pytest.approx([3 / 2, 3 / 2, 3, 6, 6], rel=APPROX_REL_TOLERANCE)

traj = Trajectory(x=x, vel_est={"method": VelMethod.FORWARD, "h": 2})

assert traj.v == pytest.approx([3 / 2, 3, 6, 6, 6], rel=APPROX_REL_TOLERANCE)

traj = Trajectory(
x=x,
vel_est={
"method": VelMethod.BACKWARD,
"h": 2,
"padding": VelPadding.VALUE,
"padding_val": 0,
},
)

assert traj.v == pytest.approx([0, 0, 3 / 2, 3, 6], rel=APPROX_REL_TOLERANCE)

traj.set_vel_method(VelMethod.CENTERED, h=2)

assert traj.v == pytest.approx(
[15 / 4, 15 / 4, 15 / 4, 15 / 4, 15 / 4], rel=APPROX_REL_TOLERANCE
)

with pytest.raises(ValueError):
traj.set_vel_method(VelMethod.CENTERED, h=0)

with pytest.raises(ValueError):
traj.set_vel_method(VelMethod.CENTERED, h=8)

3 changes: 2 additions & 1 deletion tests/test_trajectory/test_operations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from pytest import approx, fixture
import pytest
from yupi import Trajectory
from yupi import Trajectory, VelMethod

APPROX_REL_TOLERANCE = 1e-12

Expand Down Expand Up @@ -47,6 +47,7 @@ def test_copy(traj):
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)
assert traj.vel_est == copy_traj.vel_est


def test_iteration(points, angles, traj):
Expand Down
7 changes: 5 additions & 2 deletions yupi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from yupi.features import Features
from yupi.trajectory import Trajectory, TrajectoryPoint
from yupi.vector import Vector
from yupi._vel_estimators import VelMethod, VelPadding

logging.basicConfig(
level=logging.INFO,
Expand All @@ -18,7 +19,9 @@
'Trajectory',
'TrajectoryPoint',
'Features',
'Vector'
'Vector',
'VelMethod',
'VelPadding'
]

__version__ = '0.8.6'
__version__ = '0.8.7'
Loading

0 comments on commit 08dace1

Please sign in to comment.