Skip to content

Commit

Permalink
Merge pull request #27 from yupidevs/develop
Browse files Browse the repository at this point in the history
Minor changes
  • Loading branch information
jmorgadov authored Jun 12, 2021
2 parents 43a34f9 + f7f1828 commit acbc546
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 306 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,5 @@ jobs:
run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH
- name: Install yupi on venv
run: poetry install
- name: Install Pytest
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests
run: poetry run pytest ./tests/
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
# CHANGELOG

## [0.4.2] 2021-06-12

### Added

- Add documentation for example002
- Implement offset add and sub on trajectoies
- Implement add and sub between trajectories
- Implement polar offset

### Fixed

- Fix examples links on documentation

## [0.4.1] 2021-06-09

### Added

- Add yupi exceptions
- Add recursively parameter in load_folder method
- Add framedifferencing tracking algorithm
- Add vector docstrings
- Add a background estimator for videos
- Add lazy paremeter on trajectory
- Add background subtraction as tracking algoritm
- Add `plot_trajectory` function on `__init__.py`
- Add template matching algorithm
- Add optical flow algorithm

### Fixed

- Fix exception handling on trajectory loading
- Change velocity calculation on trajectory
- Fix docstring on load_folder
- Change scipy dependency version
- Fix start_in_frame param in track trackingscenario
- Fix trackers for algorithms requiring 2 frames
- Fix drifting in trackers failing detecting a frame
- Fix docstring in frame differencing
- Fix docstring of some algorithms
- Fix wrong references in the docs of algorithms
- Fix a typo in readme

### Others

- Update the api of tracking algorithms
- Update the readme
- Update docs trajectory creation methods
- All tracking algorithms to return an empty mask
- Set version 0.4.1

## [0.4.0] 2021-05-7

### 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.4.1'
release = '0.4.2'


# -- General configuration ---------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions docs/source/examples/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In this table you can easily find the examples that better suits you.
| of a lysozyme molecule in water. Several molecule
| trajectories are generated and later analyzed.
- * Generation:
* :py:class:`~generators.LangevinGenerator`
* :py:class:`~generating.LangevinGenerator`
* Statistics:
* :py:func:`~statistics.estimate_velocity_samples`
* :py:func:`~statistics.estimate_turning_angles`
Expand All @@ -50,15 +50,15 @@ In this table you can easily find the examples that better suits you.
- * Visualization:
* :py:func:`~visualization.plot_trajectories`
* Tracking:
* :py:func:`~tracking.ROI`
* :py:func:`~tracking.ObjectTracker`
* :py:func:`~tracking.TrackingScenario`
* :py:func:`~tracking.ColorMatching`
* :py:func:`~tracking.FrameDifferencing`
* :py:func:`~tracking.BackgroundEstimator`
* :py:func:`~tracking.BackgroundSubtraction`
* :py:func:`~tracking.TemplateMatching`
* :py:func:`~tracking.OpticalFlow`
* :py:func:`~tracking.trackers.ROI`
* :py:func:`~tracking.trackers.ObjectTracker`
* :py:func:`~tracking.trackers.TrackingScenario`
* :py:func:`~tracking.algorithms.ColorMatching`
* :py:func:`~tracking.algorithms.FrameDifferencing`
* :py:func:`~tracking.algorithms.BackgroundEstimator`
* :py:func:`~tracking.algorithms.BackgroundSubtraction`
* :py:func:`~tracking.algorithms.TemplateMatching`
* :py:func:`~tracking.algorithms.OpticalFlow`


.. toctree::
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.4.1"
version = "0.4.2"
description = "A package for tracking and analysing objects trajectories"
authors = [
"Gustavo Viera-López <gvieralopez@gmail.com>",
Expand Down
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.4.1'
__version__ = '0.4.2'
2 changes: 1 addition & 1 deletion yupi/analyzing/processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from yupi.trajectory import Trajectory
import numpy as np
from yupi.trajectory import Trajectory
from yupi.analyzing.transformations import wrap_theta


Expand Down
11 changes: 5 additions & 6 deletions yupi/analyzing/statistics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
from yupi.trajectory import Trajectory
import numpy as np
import scipy.stats
import numpy as np
from yupi.trajectory import Trajectory
from yupi.analyzing import turning_angles, subsample_trajectory


Expand Down Expand Up @@ -148,8 +148,8 @@ def estimate_msd_time(trajs: List[Trajectory], lag: int):
def estimate_msd(trajs: List[Trajectory], time_avg=True, lag=None):
"""
Estimate the mean square displacement of the list of Trajectory
objects, ``trajs``, providing the options of averaging over the ensemble
of realizations or over time.
objects, ``trajs``, providing the options of averaging over the
ensemble of realizations or over time.
Parameters
----------
Expand Down Expand Up @@ -384,5 +384,4 @@ def estimate_kurtosis(trajs: List[Trajectory], time_avg=True, lag=None):

if not time_avg:
return estimate_kurtosis_ensemble(trajs)
else:
return estimate_kurtosis_time(trajs, lag)
return estimate_kurtosis_time(trajs, lag)
6 changes: 3 additions & 3 deletions yupi/analyzing/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ def wrap_theta(ang: np.ndarray, degrees=False, centered=False):
discont = 360 if degrees else 2 * np.pi
if not centered:
return ang % discont
else:
discont_half = discont / 2
return -((discont_half - ang) % discont - discont_half)

discont_half = discont / 2
return -((discont_half - ang) % discont - discont_half)
47 changes: 12 additions & 35 deletions yupi/generating/generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
import abc
import numpy as np
from yupi import Trajectory


Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(self, T: float, dim: int = 1, N: int = 1, dt: float = 1,
# Only right/left jumps, uniform probabilities for it
# And equal length for all jumps are set as default
# TODO: Check that the model parameters received have the
#Eexpected shape
# expected shape
if actions is None:
actions = np.array([1, -1])
if actions_prob is None:
Expand All @@ -103,7 +103,7 @@ def __init__(self, T: float, dim: int = 1, N: int = 1, dt: float = 1,

# Compute vector position as a function of time for
# All the walkers of the ensemble
def get_r(self):
def _get_r(self):
# Get movements for every space coordinates according
# To the sample space of probabilities in self.actions_prob
dr = [np.random.choice(self.actions, p=p, size=(self.n - 1, self.N))
Expand All @@ -122,14 +122,14 @@ def get_r(self):
# Get position vectors and generate RandomWalk object
def generate(self):
# Get position vectors
r = self.get_r()
r = self._get_r()

# Generate RandomWalk object
trajs = []
for i in range(self.N):
points = r[:, :, i]
trajs.append(Trajectory(points=points, dt=self.dt, t=self.t,
traj_id="Random Walker {}".format(i+1)))
traj_id=f"Random Walker {i + 1}"))
return trajs


Expand Down Expand Up @@ -211,12 +211,12 @@ def set_scale(self, v_scale=None, r_scale=None, t_scale=None):
self.t_scale = t_scale

# Fill noise array with custom noise properties
def get_noise(self):
def _get_noise(self):
dist = getattr(np.random, self.noise_pdf)
self.noise = dist(scale=self.noise_scale, size=self.shape)

# Solve Langevin Equation using the numerical method of Euler-Maruyama
def solve_rv(self):
def _solve_rv(self):
for i in range(self.n - 1):
# Solving for position
self.r[i + 1] = self.r[i] + \
Expand All @@ -228,13 +228,13 @@ def solve_rv(self):
self.noise[i] * np.sqrt(self.dt)

# Simulate the process
def simulate(self):
self.get_noise() # Set the attribute self.noise
self.solve_rv() # Solve the Langevin equation
def _simulate(self):
self._get_noise() # Set the attribute self.noise
self._solve_rv() # Solve the Langevin equation

# Generate yupi Trajectory objects
def generate(self):
self.simulate()
self._simulate()

self.r *= self.r_scale
self.v *= self.v_scale
Expand All @@ -245,28 +245,5 @@ def generate(self):
for i in range(self.N):
points = self.r[:, :, i]
trajs.append(Trajectory(points=points, dt=self.dt, t=self.t,
traj_id="LangevinSolution {}".format(i+1)))
traj_id=f"LangevinSolution {i + 1}"))
return trajs


# Testing
if __name__ == '__main__':
from yupi.analyzing.visualization import plot_trajectories

np.random.seed(0)

print("Testing RandomWalker")

# Set parameter values
T = 500
dim = 2
N = 5
dt = 1
actions = [1, 0, -1]
prob = [[.5, .1, .4],
[.5, 0, .5]]

# Get RandomWalk object and get position vectors
rw = LatticeRandomWalkGenerator(T, dim, N, dt, actions, prob)
tr = rw.generate()
plot_trajectories(tr, max_trajectories=3, legend=False)
Loading

0 comments on commit acbc546

Please sign in to comment.