From becb5239d66fe8f0138b5ee3c6a3ff1a509432ac Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 22:48:06 +0200 Subject: [PATCH 01/10] REMOVE: removed unnecessary comment blocks --- double_pendula/double_pendula.py | 2 -- double_pendula/equations.py | 2 -- double_pendula/pendulum.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 8b1df57..3f36352 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -1,6 +1,4 @@ """Model of a double pendulum""" -# Author: Chris Greening -# Date: 2019-07-15 from typing import Tuple, List diff --git a/double_pendula/equations.py b/double_pendula/equations.py index d4a6609..b60f398 100644 --- a/double_pendula/equations.py +++ b/double_pendula/equations.py @@ -1,6 +1,4 @@ """Module for storing equations relevant to calculating the double pendulum's movement""" -# Author: Chris Greening -# Date: 2022-10-29 import numpy as np import scipy.integrate diff --git a/double_pendula/pendulum.py b/double_pendula/pendulum.py index 4b35ba8..4909e0f 100644 --- a/double_pendula/pendulum.py +++ b/double_pendula/pendulum.py @@ -1,6 +1,4 @@ """Model of a single pendulum""" -# Author: Chris Greening -# Date: 2022-10-29 from typing import Tuple From f8b24e00c36a9ddfe2fa4573d5f0fffb30f076e0 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:05:23 +0200 Subject: [PATCH 02/10] REFACTOR: refactor the dict to be cleaner --- double_pendula/pendulum.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/double_pendula/pendulum.py b/double_pendula/pendulum.py index 4909e0f..e0b9df1 100644 --- a/double_pendula/pendulum.py +++ b/double_pendula/pendulum.py @@ -44,8 +44,12 @@ def calculate_path(self, theta: float, dtheta: float, x0: float = 0, y0: float = self.dtheta = dtheta self.x = self.L*np.sin(self.theta) + x0 self.y = self.L*np.cos(self.theta) + y0 - self.df = pd.DataFrame({"theta": self.theta, "dtheta": self.dtheta, - "x": self.x, "y": self.y}) + self.df = pd.DataFrame({ + "theta": self.theta, + "dtheta": self.dtheta, + "x": self.x, + "y": self.y + }) def get_max_x(self) -> float: """Return the maximum x-value that this pendulum reaches""" From b3e0a795f156929cef0d0ca650860039453c09cd Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:15:05 +0200 Subject: [PATCH 03/10] ADD: added improved docstring to get_frame_x --- double_pendula/double_pendula.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 3f36352..4fb9d9a 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -49,7 +49,20 @@ def __init__(self, L1: int = 1, L2: int = 1, m1: int = 1, m2: int = 1, self.max_length = self.pendulum1.L + self.pendulum2.L def get_frame_x(self, i: int) -> Tuple[int]: - """Return x coordinates of the system of a specific index""" + """Return x coordinates of the system of a specific index. + + Parameters + ---------- + i : int + The index of the frame for which to return x coordinates. + + Returns + ------- + Tuple[int] + A tuple containing the x coordinates of the system at the specified index. + The first element is always 0, followed by the x coordinate of `pendulum1` and + the x coordinate of `pendulum2`. + """ return (0, self.pendulum1.x[i], self.pendulum2.x[i]) def get_frame_y(self, i: int) -> Tuple[int]: From 974bf379806fb17e62d9cd145e2c857b28913be0 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:16:40 +0200 Subject: [PATCH 04/10] ADD: added improved docstring for get_frame_y --- double_pendula/double_pendula.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 4fb9d9a..16c52b0 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -66,7 +66,21 @@ def get_frame_x(self, i: int) -> Tuple[int]: return (0, self.pendulum1.x[i], self.pendulum2.x[i]) def get_frame_y(self, i: int) -> Tuple[int]: - """Return y coordinates of the system of a specific index""" + """ + Return y coordinates of the system of a specific index. + + Parameters + ---------- + i : int + The index of the frame for which to return y coordinates. + + Returns + ------- + Tuple[int] + A tuple containing the y coordinates of the system at the specified index. + The first element is always 0, followed by the y coordinate of `pendulum1` and + the y coordinate of `pendulum2`. + """ return (0, self.pendulum1.y[i],self.pendulum2.y[i]) def get_frame_coordinates(self, i: int) -> Tuple[Tuple[int]]: From 771e75bed6580ebbe00f748989e213f6ef8f499e Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:21:37 +0200 Subject: [PATCH 05/10] ADD: added docstring --- double_pendula/double_pendula.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 16c52b0..24e2f98 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -84,7 +84,21 @@ def get_frame_y(self, i: int) -> Tuple[int]: return (0, self.pendulum1.y[i],self.pendulum2.y[i]) def get_frame_coordinates(self, i: int) -> Tuple[Tuple[int]]: - """Return the x,y coordinates at a given frame""" + """Return the x,y coordinates at a given frame. + + Parameters + ---------- + i : int + The index of the frame for which to return x,y coordinates. + + Returns + ------- + Tuple[Tuple[int]] + A tuple containing two tuples: the first one is the x coordinates + and the second one is the y coordinates of the system at the specified + index. Each inner tuple follows the format: + (coordinate of origin, coordinate of `pendulum1`, coordinate of `pendulum2`). + """ return (self.get_frame_x(i), self.get_frame_y(i)) def get_max_x(self) -> float: From 3a06c3a4388e4e24b9ecc74dac3cb03e2d4c1e8d Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:23:45 +0200 Subject: [PATCH 06/10] ADD: added get_max_x and get_max_y docstrings --- double_pendula/double_pendula.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 24e2f98..77bc657 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -102,11 +102,25 @@ def get_frame_coordinates(self, i: int) -> Tuple[Tuple[int]]: return (self.get_frame_x(i), self.get_frame_y(i)) def get_max_x(self) -> float: - """Return the maximum x-coord of the double pendulum""" + """ + Return the maximum x-coordinate of the double pendulum. + + Returns + ------- + float + The maximum x-coordinate that the double pendulum reaches. + """ return self.pendulum2.get_max_x() def get_max_y(self) -> float: - """Return the maximum y-coord of the double pendulum""" + """ + Return the maximum y-coordinate of the double pendulum. + + Returns + ------- + float + The maximum y-coordinate that the double pendulum reaches. + """ return self.pendulum2.get_max_y() def get_max_coordinates(self) -> float: From 1a598d04f37f26e0fadc33a6890ec724f26d5991 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:25:16 +0200 Subject: [PATCH 07/10] ADD: added improved docstring for get_max_coordinates --- double_pendula/double_pendula.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 77bc657..4e54152 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -124,7 +124,14 @@ def get_max_y(self) -> float: return self.pendulum2.get_max_y() def get_max_coordinates(self) -> float: - """Return the maximum coordinates the overall system reaches""" + """ + Return the maximum coordinates the overall system reaches. + + Returns + ------- + float + The maximum distance from the origin that the overall double pendulum system reaches. + """ return self.pendulum2.get_max_coordinates() @classmethod From 25a2967f66284d45cdda671fce804bef04ca5365 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:30:15 +0200 Subject: [PATCH 08/10] MODIFY: modified the docstring and improved it --- double_pendula/double_pendula.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/double_pendula/double_pendula.py b/double_pendula/double_pendula.py index 4e54152..4588d43 100644 --- a/double_pendula/double_pendula.py +++ b/double_pendula/double_pendula.py @@ -138,8 +138,34 @@ def get_max_coordinates(self) -> float: def create_multiple_double_pendula( cls, num_pendula: int = 1, L1: float = 1.0, L2: float = 1.0, m1: float = 1.0, m2: float = 1.0, - initial_theta: float = 90, dtheta: float = .05) -> List["DoublePendulum"]: - """Returns a list of DoublePendulum's each offset slightly from each other""" + initial_theta: float = 90, dtheta: float = .05) -> List["DoublePendula"]: + """ + Creates and returns a list of DoublePendula objects with initial + conditions offset by dtheta. + + Parameters + ---------- + num_pendula : int, optional + Number of DoublePendula objects to create, default is 1. + L1 : float, optional + Length of the first pendulum arm, default is 1.0. + L2 : float, optional + Length of the second pendulum arm, default is 1.0. + m1 : float, optional + Mass of the first pendulum bob, default is 1.0. + m2 : float, optional + Mass of the second pendulum bob, default is 1.0. + initial_theta : float, optional + Initial angle in degrees of the first pendulum, default is 90. + dtheta : float, optional + Offset in initial angle in degrees for each subsequent pendulum, + default is 0.05. + + Returns + ------- + List["DoublePendula"] + A list containing the created DoublePendula objects. + """ # pylint: disable=too-many-arguments pendula = [] created_pendula = 0 @@ -189,4 +215,4 @@ def _calculate_system(self) -> None: def __repr__(self): # pylint: disable=line-too-long - return f"< DoublePendulum: L1={self.pendulum1.L} m1={self.pendulum1.m} L2={self.pendulum2.L} m2={self.pendulum2.m} y0={self.y0} >" + return f"< DoublePendula: L1={self.pendulum1.L} m1={self.pendulum1.m} L2={self.pendulum2.L} m2={self.pendulum2.m} y0={self.y0} >" From 30446003def3683da53f15269103270fde9b9a74 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:33:31 +0200 Subject: [PATCH 09/10] ADD: added improved docstring to get_max_coordinates --- double_pendula/pendulum.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/double_pendula/pendulum.py b/double_pendula/pendulum.py index e0b9df1..e5273d6 100644 --- a/double_pendula/pendulum.py +++ b/double_pendula/pendulum.py @@ -52,13 +52,34 @@ def calculate_path(self, theta: float, dtheta: float, x0: float = 0, y0: float = }) def get_max_x(self) -> float: - """Return the maximum x-value that this pendulum reaches""" + """ + Return the maximum x-coordinate of the pendulum. + + Returns + ------- + float + The maximum x-coordinate that the pendulum reaches. + """ return max(self.x) def get_max_y(self) -> float: - """Return the maximum y-value that this pendulum reaches""" + """ + Return the maximum y-coordinate of the double pendulum. + + Returns + ------- + float + The maximum y-coordinate that the double pendulum reaches. + """ return max(self.y) def get_max_coordinates(self) -> Tuple[float, float]: - """Return maximum cartesian coordinate that this system reaches""" + """ + Return the maximum coordinates the overall system reaches. + + Returns + ------- + float + The maximum distance from the origin that the overall double pendulum system reaches. + """ return (self.get_max_x(), self.get_max_y()) From 263af225e727239f6904aa13b427d6fd26475bbe Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Fri, 20 Oct 2023 23:34:58 +0200 Subject: [PATCH 10/10] MODIFY: inc patch version to 0..1.5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 13badbf..532e321 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="double-pendula", - version="0.1.4", + version="0.1.5", author="Chris Greening", author_email="chris@christophergreening.com", description="Library for animating double pendula in Python",