Skip to content

Commit 15e4e63

Browse files
feat: add Equilibrium class for elliptical postural balance analysis
1 parent 3c0f463 commit 15e4e63

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pyeyesweb/low_level/equilibrium.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class Equilibrium(StaticFeature):
5454
y_weight : float, optional
5555
Weighting factor for the semi-minor axis of the ellipse.
5656
Defaults to `0.5`.
57+
axes : tuple of int, optional
58+
Indices of the axes to project onto the floor plane.
59+
Defaults to `(0, 1)` (X and Y). Use `(0, 2)` for X and Z.
5760
5861
Examples
5962
--------
@@ -68,14 +71,16 @@ def __init__(
6871
right_foot_idx: int = 1,
6972
barycenter_idx: int = 2,
7073
margin_mm: float = 100.0,
71-
y_weight: float = 0.5
74+
y_weight: float = 0.5,
75+
axes: tuple[int, int] = (0, 1)
7276
):
7377
super().__init__() # Crucial for proper inheritance
7478
self.left_foot_idx = left_foot_idx
7579
self.right_foot_idx = right_foot_idx
7680
self.barycenter_idx = barycenter_idx
7781
self.margin = margin_mm
7882
self.y_weight = y_weight
83+
self.axes = axes
7984

8085
@property
8186
def left_foot_idx(self) -> int:
@@ -122,6 +127,18 @@ def y_weight(self) -> float:
122127
def y_weight(self, value: float):
123128
self._y_weight = float(value)
124129

130+
@property
131+
def axes(self) -> tuple[int, int]:
132+
"""Indices of the axes forming the support plane."""
133+
return self._axes
134+
135+
@axes.setter
136+
def axes(self, value: tuple[int, int]):
137+
if len(value) != 2:
138+
raise ValueError("Axes must be a sequence of two integers.")
139+
self._axes = (int(value[0]), int(value[1]))
140+
self._axes_list = list(self._axes)
141+
125142
def compute(self, frame_data: np.ndarray) -> EquilibriumResult:
126143
"""Compute the elliptical equilibrium score.
127144
@@ -142,9 +159,9 @@ def compute(self, frame_data: np.ndarray) -> EquilibriumResult:
142159
return EquilibriumResult(is_valid=False)
143160

144161
# 2. Extract 2D positions
145-
p_left = frame_data[self.left_foot_idx][:2]
146-
p_right = frame_data[self.right_foot_idx][:2]
147-
p_barycenter = frame_data[self.barycenter_idx][:2]
162+
p_left = frame_data[self.left_foot_idx][self._axes_list]
163+
p_right = frame_data[self.right_foot_idx][self._axes_list]
164+
p_barycenter = frame_data[self.barycenter_idx][self._axes_list]
148165

149166
# 3. Compute Rotation-Invariant Ellipse Geometry
150167
center = (p_left + p_right) / 2.0

0 commit comments

Comments
 (0)