Skip to content

Commit 32c4b3b

Browse files
fix lightness calculation to ensure sliding window length is an integer and prevent division by zero
1 parent f44971e commit 32c4b3b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pyeyesweb/mid_level/lightness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, sliding_window_max_length=50.0, rate_hz=50.0, use_filter=True
2222
self.rate_hz = validate_numeric(rate_hz, 'rate_hz', min_val=0.01, max_val=100000)
2323
self.use_filter = validate_boolean(use_filter, 'use_filter')
2424

25-
self.sliding_window = SlidingWindow(self.sliding_window_max_length, 1)
25+
self.sliding_window = SlidingWindow(int(self.sliding_window_max_length), 1)
2626

2727
# Validate signal_type
2828
if signal_type not in ['velocity', 'position']:
@@ -36,7 +36,7 @@ def __call__(self, velocity, alpha: float = 0.5) -> dict:
3636
ke = self.kinetic_energy(vel)
3737

3838
# use total energy (scalar) rather than the whole dict
39-
weight_index = ke["component_energy"][1] / ke["total_energy"]
39+
weight_index = ke["component_energy"][1] / (ke["total_energy"] + 1e-9)
4040

4141
if not isinstance(weight_index, (float, np.floating)) or not np.isfinite(weight_index):
4242
weight_index = 0.0
@@ -45,7 +45,7 @@ def __call__(self, velocity, alpha: float = 0.5) -> dict:
4545

4646
lightness = self.rarity(self.sliding_window, alpha=alpha)
4747

48-
return {"lightness": lightness.get("rarity", 0)}
48+
return {"lightness": lightness.get("rarity", 0), "weight_index": weight_index}
4949

5050
def _filter_signal(self, signal):
5151
if not self.use_filter:

0 commit comments

Comments
 (0)