-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from DuncDennis/feature/get_ready_for_v002
Feature/get ready for v002
- Loading branch information
Showing
17 changed files
with
288 additions
and
61 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Examples: | ||
|
||
### Contents | ||
- ``double_pendulum_lyapunov_spectrum.py``: Plot the lyapunov spectrum of the double pendulum. | ||
- ``lyapunov_spectra_of_3d_autonomous_flows.py``: Plot the Lyapunov spectrum of all 3D autonomous dissipative flow systems. | ||
|
||
⚠️ Not many examples here yet, and examples might be flawed. | ||
|
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,68 @@ | ||
"""Lyapunov Spectrum of single system.""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from lorenzpy import measures as meas | ||
from lorenzpy import simulations as sims | ||
|
||
sys_obj = sims.DoublePendulum(dt=0.1) | ||
dt = sys_obj.dt | ||
|
||
# Calculate exponents: | ||
m = 4 | ||
deviation_scale = 1e-10 | ||
steps = 1000 | ||
part_time_steps = 15 | ||
steps_skip = 0 | ||
|
||
iterator_func = sys_obj.iterate | ||
starting_point = sys_obj.get_default_starting_pnt() | ||
|
||
le_spectrum = meas.lyapunov_exponent_spectrum( | ||
iterator_func=iterator_func, | ||
starting_point=starting_point, | ||
deviation_scale=deviation_scale, | ||
steps=steps, | ||
part_time_steps=part_time_steps, | ||
steps_skip=steps_skip, | ||
dt=dt, | ||
m=m, | ||
initial_pert_directions=None, | ||
return_convergence=True, | ||
) | ||
|
||
fig, ax = plt.subplots( | ||
1, 1, figsize=(6, 6), layout="constrained", sharex=True, sharey=False | ||
) | ||
|
||
# x and y titles: | ||
fig.supxlabel("Number of renormalization steps") | ||
fig.supylabel("Lyapunov exponent convergence") | ||
|
||
x = np.arange(1, steps + 1) | ||
ax.plot( | ||
x, | ||
le_spectrum, | ||
linewidth=1, | ||
) | ||
ax.grid(True) | ||
|
||
final_les = np.round(le_spectrum[-1, :], 4).tolist() | ||
final_les = [str(x) for x in final_les] | ||
le_string = "\n".join(final_les) | ||
le_string = "Final LEs: \n" + le_string | ||
x_position = 0.1 # X-coordinate of the upper-left corner for each subplot | ||
y_position = 0.5 | ||
ax.text( | ||
x_position, | ||
y_position, | ||
le_string, | ||
fontsize=10, | ||
bbox=dict(facecolor="white", edgecolor="black", boxstyle="round"), | ||
verticalalignment="center", | ||
horizontalalignment="left", | ||
transform=ax.transAxes, | ||
) | ||
|
||
plt.show() |
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,91 @@ | ||
"""Calculate and plot the Lyapunov Spectra of all three-dimensional chaotic flows.""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from lorenzpy import measures as meas | ||
from lorenzpy import simulations as sims | ||
|
||
systems = [ | ||
"Lorenz63", | ||
"Chen", | ||
"ChuaCircuit", | ||
"ComplexButterfly", | ||
"DoubleScroll", | ||
"Halvorsen", | ||
"Roessler", | ||
"Rucklidge", | ||
"Thomas", | ||
"WindmiAttractor", | ||
] | ||
|
||
# Calculate exponents: | ||
m = 3 | ||
deviation_scale = 1e-10 | ||
steps = 1000 | ||
part_time_steps = 15 | ||
steps_skip = 50 | ||
|
||
solver = "rk4" | ||
# solver = sims.solvers.create_scipy_ivp_solver(method="RK45") | ||
|
||
lyap_dict = {} | ||
for i_sys, system in enumerate(systems): | ||
print(system) | ||
sys_obj = getattr(sims, system)(solver=solver) | ||
iterator_func = sys_obj.iterate | ||
starting_point = sys_obj.get_default_starting_pnt() | ||
dt = sys_obj.dt | ||
|
||
lyap_dict[system] = meas.lyapunov_exponent_spectrum( | ||
iterator_func=iterator_func, | ||
starting_point=starting_point, | ||
deviation_scale=deviation_scale, | ||
steps=steps, | ||
part_time_steps=part_time_steps, | ||
steps_skip=steps_skip, | ||
dt=dt, | ||
m=m, | ||
initial_pert_directions=None, | ||
return_convergence=True, | ||
) | ||
|
||
fig, axs = plt.subplots( | ||
2, 5, figsize=(15, 8), layout="constrained", sharex=True, sharey=False | ||
) | ||
|
||
# x and y titles: | ||
fig.supxlabel("Number of renormalization steps") | ||
fig.supylabel("Lyapunov exponent convergence") | ||
|
||
axs = axs.flatten() | ||
x = np.arange(1, steps + 1) | ||
for i_ax, ax in enumerate(axs): | ||
system = systems[i_ax] | ||
le_spectrum = lyap_dict[system] | ||
ax.title.set_text(system) | ||
ax.plot( | ||
x, | ||
le_spectrum, | ||
linewidth=1, | ||
) | ||
ax.grid(True) | ||
|
||
final_les = np.round(le_spectrum[-1, :], 4).tolist() | ||
final_les = [str(x) for x in final_les] | ||
le_string = "\n".join(final_les) | ||
le_string = "Final LEs: \n" + le_string | ||
x_position = 0.1 # X-coordinate of the upper-left corner for each subplot | ||
y_position = 0.5 | ||
ax.text( | ||
x_position, | ||
y_position, | ||
le_string, | ||
fontsize=10, | ||
bbox=dict(facecolor="white", edgecolor="black", boxstyle="round"), | ||
verticalalignment="center", | ||
horizontalalignment="left", | ||
transform=ax.transAxes, | ||
) | ||
|
||
plt.show() |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[project] | ||
name = "lorenzpy" | ||
readme = "README.md" | ||
version = "0.0.1" | ||
version = "0.0.2" | ||
description = "A Python package to simulate and measure chaotic dynamical systems." | ||
authors = [ | ||
{name = "Dennis Duncan", email = "[email protected]"}, | ||
|
@@ -41,7 +41,6 @@ dev = [ | |
"pre-commit==3.1.1", # add version? | ||
] | ||
plot = [ | ||
"plotly>=5.11", | ||
"matplotlib>=3.5" | ||
] | ||
|
||
|
@@ -59,7 +58,7 @@ line-length = 88 | |
files = "src/lorenzpy/" | ||
|
||
[[tool.mypy.overrides]] | ||
module = ['plotly.*', 'numpy', 'pytest', "scipy.*", "matplotlib.*", "PIL"] # ignore missing imports from the plotly package. | ||
module = ['numpy', 'pytest', "scipy.*", "matplotlib.*", "PIL", "mpl_toolkits.*"] | ||
ignore_missing_imports = true | ||
|
||
[tool.ruff] | ||
|
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
|
||
from . import measures, simulations | ||
|
||
__version__ = "0.0.1" | ||
__version__ = "0.0.2" |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
"""Submodule to plot chaotic dynamics systems.""" | ||
from .plot import create_3d_line_plot |
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,39 @@ | ||
"""Plot the data of dynamical systems.""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from mpl_toolkits.mplot3d import Axes3D | ||
|
||
|
||
def create_3d_line_plot(data: np.ndarray, ax: "Axes3D" = None, **kwargs) -> "Axes3D": | ||
"""Create a three-dimensional line plot of data. | ||
Args: | ||
data (np.ndarray): A NumPy array containing 3D data points with shape (n, 3). | ||
ax (Axes3D, optional): A Matplotlib 3D axis to use for plotting. | ||
If not provided, a new 3D plot will be created. | ||
**kwargs: Additional keyword arguments to pass to ax.plot. | ||
Returns: | ||
Axes3D: The Matplotlib 3D axis used for the plot. | ||
Example: | ||
>>> data = np.random.rand(100, 3) # Replace this with your own 3D data | ||
>>> create_3d_line_plot(data, color='b', linestyle='--') | ||
>>> plt.show() | ||
""" | ||
if ax is None: | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection="3d") | ||
|
||
x = data[:, 0] | ||
y = data[:, 1] | ||
z = data[:, 2] | ||
|
||
ax.plot(x, y, z, **kwargs) # Use plot for a line plot with kwargs | ||
|
||
ax.set_xlabel("X Axis") | ||
ax.set_ylabel("Y Axis") | ||
ax.set_zlabel("Z Axis") | ||
|
||
return ax |
This file was deleted.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.