Coverage for physiodsp / activity / pim.py: 81%
27 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-07-14 19:36 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-07-14 19:36 +0000
1from numpy import abs
2from pandas import DataFrame
3from pydantic import BaseModel
5from physiodsp.base import BaseAlgorithm
6from physiodsp.sensors.imu.base import IMUData
9class PIMSettings(BaseModel):
10 """PIM Algorithm Settings"""
11 aggregation_window: int = 5
14class PIMAlgorithm(BaseAlgorithm):
15 """Proportional Integration Mode"""
17 _algorithm_name = "PIMAlgorithm"
18 _version = "0.1.0"
20 def __init__(self,
21 settings: PIMSettings = PIMSettings()
22 ) -> None:
23 self.settings = settings
24 self._aggregation_window = settings.aggregation_window
25 return None
27 def run(self, data: IMUData):
28 self.data = data
29 self.values_x = abs(data.x)
30 self.values_y = abs(data.y)
31 self.values_z = abs(data.z)
33 # Raw biomarker: combine absolute values for raw signal representation
34 self.biomarker = DataFrame({
35 'timestamps': data.timestamps,
36 'x': self.values_x,
37 'y': self.values_y,
38 'z': self.values_z
39 })
41 return self
43 def aggregate(self,
44 method: str = 'sum'
45 ):
47 df = self.biomarker.copy()
49 df['timestamps'] = (df['timestamps'] // self.aggregation_window) * self.aggregation_window
51 df_agg = df.groupby('timestamps')[["x", "y", "z"]].agg(method).reset_index(drop=False)
53 self.biomarker_agg = df_agg
55 return self