33from pyeyesweb .data_models .sliding_window import SlidingWindow
44from pyeyesweb .low_level .kinetic_energy import KineticEnergy
55from pyeyesweb .analysis_primitives .rarity import Rarity
6- from pyeyesweb .utils .math_utils import (compute_sparc , compute_jerk_rms , normalize_signal , extract_velocity_from_position )
76from pyeyesweb .utils .validators import validate_numeric , validate_boolean
87from pyeyesweb .utils .signal_processing import apply_savgol_filter
98
10- class Lightness :
11-
129
10+ class Lightness :
1311 sliding_window = SlidingWindow (50 , 1 ) # Store velocity values
14- lightness = Rarity ()
12+ kinetic_energy = KineticEnergy ()
13+ rarity = Rarity ()
1514
1615 def __init__ (self , rate_hz = 50.0 , use_filter = True , signal_type = 'velocity' ):
1716 self .rate_hz = validate_numeric (rate_hz , 'rate_hz' , min_val = 0.01 , max_val = 100000 )
@@ -21,44 +20,26 @@ def __init__(self, rate_hz=50.0, use_filter=True, signal_type='velocity'):
2120 if signal_type not in ['velocity' , 'position' ]:
2221 raise ValueError (f"signal_type must be 'velocity' or 'position', got '{ signal_type } '" )
2322 self .signal_type = signal_type
24-
25-
26-
27-
28- def _filter_signal (self , signal ):
29- """Apply Savitzky-Golay filter if enabled and enough data.
30-
31- Parameters
32- ----------
33- signal : array-like
34- Input signal to filter.
35-
36- Returns
37- -------
38- ndarray
39- Filtered signal or original if filtering disabled/not possible.
40- """
41- if not self .use_filter :
42- return np .array (signal )
43- return apply_savgol_filter (signal , self .rate_hz )
4423
4524 def __call__ (self , velocity , alpha : float = 0.5 ) -> dict :
4625
47-
4826 vel = np .array ([velocity ])
4927
50- ke = KineticEnergy ()
51- resultKE = ke (vel )
28+ ke = self .kinetic_energy (vel )
5229
5330 # use total energy (scalar) rather than the whole dict
54- weight_index = resultKE ["component_energy" ][1 ]/ resultKE ["total_energy" ]
55-
31+ weight_index = ke ["component_energy" ][1 ] / ke ["total_energy" ]
5632
5733 if not isinstance (weight_index , (float , np .floating )) or not np .isfinite (weight_index ):
5834 weight_index = 0.0
5935
36+ self .sliding_window .append ([1.0 - weight_index ]) # ora sliding_window contiene floats
37+
38+ lightness = self .rarity (self .sliding_window , alpha = alpha ) # Rarity riceve una sequenza di numeri
6039
61- self .sliding_window .append ([1.0 - weight_index ]) # ora sliding_window contiene floats
62-
63- resultLightness = self .lightness (self .sliding_window ) # Rarity riceve una sequenza di numeri
64- return (resultLightness )
40+ return {"lightness" : lightness }
41+
42+ def _filter_signal (self , signal ):
43+ if not self .use_filter :
44+ return np .array (signal )
45+ return apply_savgol_filter (signal , self .rate_hz )
0 commit comments