Skip to content

Commit

Permalink
Merge pull request #93 from yupidevs/develop
Browse files Browse the repository at this point in the history
Example issues
  • Loading branch information
jmorgadov authored Mar 18, 2022
2 parents b840d53 + c72f1b6 commit 2a3367e
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 36 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.5'
release = '0.8.6'


# -- General configuration ---------------------------------------------------
Expand Down
23 changes: 8 additions & 15 deletions docs/source/examples/example1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ Import all the dependencies:
plot_velocity_hist
)
Fix the random generator seed to make results reproducible:

.. code-block:: python
np.random.seed(0)
.. _Definition of parameters 1:

2. Definition of parameters
Expand Down Expand Up @@ -113,7 +106,7 @@ we just need to instantiate the class and generate the Trajectories:

.. code-block:: python
lg = LangevinGenerator(tt, dim, N, dt, tau, sigma)
lg = LangevinGenerator(tt, dim, N, dt, tau, sigma, seed=0)
trajs = lg.generate()
Expand All @@ -132,7 +125,7 @@ Plot spacial trajectories

.. code-block:: python
ax1 = plt.subplot(231)
plt.subplot(231)
plot_2D(trajs[:5], legend=False, show=False)
Plot velocity histogram
Expand All @@ -149,7 +142,7 @@ Plot turning angles
theta = turning_angles_ensemble(trajs)
ax3 = plt.subplot(233, projection='polar')
plot_angles_hist(theta, bins=60, show=False)
plot_angles_hist(theta, bins=60, ax=ax3, show=False)
Plot Velocity autocorrelation function
Expand All @@ -158,7 +151,7 @@ Plot Velocity autocorrelation function
lag_vacf = 50
vacf, _ = vacf(trajs, time_avg=True, lag=lag_vacf)
ax6 = plt.subplot(234)
plt.subplot(234)
plot_vacf(vacf, dt, lag_vacf, show=False)
Expand All @@ -168,17 +161,17 @@ Plot Mean Square Displacement
lag_msd = 30
msd, msd_std = msd(trajs, time_avg=True, lag=lag_msd)
ax4 = plt.subplot(235)
plt.subplot(235)
plot_msd(msd, msd_std, dt, lag=lag_msd, show=False)
Plot Kurtosis

.. code-block:: python
kurtosis = kurtosis(trajs, time_avg=False, lag=30)
kurt, _ = kurtosis(trajs, time_avg=False, lag=30)
kurt_ref = kurtosis_reference(trajs)
ax5 = plt.subplot(236)
plot_kurtosis(kurtosis, kurtosis_ref=kurt_ref, dt=dt, show=False)
plt.subplot(236)
plot_kurtosis(kurt, kurtosis_ref=kurt_ref, dt=dt, show=False)
Generate plot
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/example4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ effect of gravity:

.. code-block:: python
tl[0].rotate(- pi / 2)
tl[1].rotate(- pi / 2)
tl[0].rotate2d(- pi / 2)
tl[1].rotate2d(- pi / 2)
Next, we update the coordinate system to place it at the initial position of
Expand Down
9 changes: 1 addition & 8 deletions docs/source/examples/example6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ Import all the dependencies:
from yupi.graphics import plot_hists
from yupi.generators import DiffDiffGenerator
Fix the random generator seed to make results reproducible:

.. code-block:: python
np.random.seed(0)
.. _Definition of parameters 6:

2. Definition of parameters
Expand All @@ -69,7 +62,7 @@ we just need to instantiate the class and generate the Trajectories:

.. code-block:: python
dd = DiffDiffGenerator(T, N=N, dt=dt)
dd = DiffDiffGenerator(T, N=N, dt=dt, seed=0)
trajs = dd.generate()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Rotation can be made using the :py:func:`~yupi.Trajectory.rotate` method:
.. code-block:: python
traj_2 = Trajectory(points=[[0,0], [1,0]])
traj_2.rotate(-np.pi / 2) # traj_2 points: [[0,0], [0,1]]
traj_2.rotate2d(-np.pi / 2) # traj_2 points: [[0,0], [0,1]]
Indexing and slicing
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.8.5"
version = "0.8.6"
description = "A package for tracking and analysing objects trajectories"
authors = [
"Gustavo Viera-López <gvieralopez@gmail.com>",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_trajectory/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_rotation(simple_traj):

# [0, 0] -> [0, 0]
# [1, 1] -> [0, sqrt(2)]
simple_traj.rotate(ang)
simple_traj.rotate2d(ang)

assert simple_traj.r[0] == approx([0,0], APPROX_REL_TOLERANCE)
assert simple_traj.r[1] == approx([0,np.sqrt(2)], APPROX_REL_TOLERANCE)
Expand All @@ -76,12 +76,12 @@ def test_rotation(simple_traj):
def test_rotation_3d():
traj = Trajectory(x=[0,1], y=[0,0], z=[0,0])

traj.rotate3d([0, 0, 3], -np.pi / 2)
traj.rotate3d(-np.pi / 2, [0, 0, 3])

assert traj.r[0] == approx([0, 0, 0], APPROX_REL_TOLERANCE)
assert traj.r[1] == approx([0, 1, 0], APPROX_REL_TOLERANCE)

traj.rotate3d([1, 0, 0], np.pi)
traj.rotate3d(np.pi, [1, 0, 0])

assert traj.r[1] == approx([0, -1, 0], APPROX_REL_TOLERANCE)

Expand Down
2 changes: 1 addition & 1 deletion yupi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
'Vector'
]

__version__ = '0.8.5'
__version__ = '0.8.6'
4 changes: 3 additions & 1 deletion yupi/graphics/_stats_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def plot_angles_hist(ang, bins, show: bool = True, ax=None, **kwargs):
"""

if ax is None:
ax = plt.gca(projection="polar")
ax = plt.axes(projection="polar")
elif ax.name != "polar":
raise ValueError("The axes must be polar")
default_kwargs = {"color": LIGHT_BLUE, "ec": (0, 0, 0, 0.6), "density": True}
default_kwargs.update(kwargs)
plt.hist(ang, bins, **default_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion yupi/graphics/_trajs_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def plot_3D(trajs: Union[List[Trajectory], Trajectory], line_style: str = LINE,
colors = color


ax = plt.gca(projection='3d')
ax = plt.axes(projection='3d')

if connected:
lengths = list(map(len, trajs))
Expand Down
4 changes: 2 additions & 2 deletions yupi/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def add_polar_offset(self, radius: float, angle: float) -> None:
y = rad * np.sin(ang)
self.r = Vector.create([x,y]).T

def rotate(self, angle: float):
def rotate2d(self, angle: float):
"""
Rotates the trajectory around the center coordinates [0,0]
Expand All @@ -373,7 +373,7 @@ def rotate(self, angle: float):
"""
self.add_polar_offset(0, angle)

def rotate3d(self, vector: Union[list, np.ndarray], angle: float):
def rotate3d(self, angle: float, vector: Union[list, np.ndarray]):
"""
Rotates the trajectory around a given vector.
Expand Down

0 comments on commit 2a3367e

Please sign in to comment.