Skip to content

Commit 98a96c1

Browse files
Fix: Add validation for rate_hz and use_filter parameters in Smoothness class
1 parent 3717508 commit 98a96c1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pyeyesweb/mid_level/smoothness.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@ class Smoothness:
6262
"""
6363

6464
def __init__(self, rate_hz=50.0, use_filter=True):
65-
self.rate_hz = rate_hz
65+
# Validate rate_hz
66+
if not isinstance(rate_hz, (int, float)):
67+
raise TypeError(f"rate_hz must be a number, got {type(rate_hz).__name__}")
68+
if rate_hz <= 0:
69+
raise ValueError(f"rate_hz must be positive, got {rate_hz}")
70+
if rate_hz > 100000: # 100 kHz is a reasonable upper limit
71+
raise ValueError(f"rate_hz too high ({rate_hz} Hz), maximum is 100,000 Hz")
72+
73+
# Validate use_filter
74+
if not isinstance(use_filter, bool):
75+
raise TypeError(f"use_filter must be boolean, got {type(use_filter).__name__}")
76+
77+
self.rate_hz = float(rate_hz) # Ensure it's a float
6678
self.use_filter = use_filter
6779

6880
def _filter_signal(self, signal):

0 commit comments

Comments
 (0)