Coverage for physiodsp / activity / pim.py: 76%
21 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-26 21:14 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-26 21:14 +0000
1from numpy import abs
2from pandas import DataFrame
4from physiodsp.base import BaseAlgorithm
5from physiodsp.sensors.imu.base import IMUData
8class PIMAlgorithm(BaseAlgorithm):
9 """Proportional Integration Mode"""
11 _algorithm_name = "PIMAlgorithm"
12 _version = 'v0.1.0'
13 _aggregation_window = 5
15 def __init__(self) -> None:
17 return None
19 def estimate(self, data: IMUData):
21 self.values_x = abs(data.x)
22 self.values_y = abs(data.y)
23 self.values_z = abs(data.z)
25 return self
27 def aggregate(self,
28 method: str = 'sum'
29 ):
31 df = DataFrame(
32 list(zip(self.data.timestamps, self.values_x, self.values_y, self.values_z)),
33 columns=['timestamps', 'x', 'y', 'z']
34 )
36 df['timestamps'] = df[
37 'timestamps'].apply(lambda x: x // self.aggregation_window)
39 df_agg = df.groupby('timestamps')[["x", "y", "z"]].agg(method).reset_index(drop=False)
41 self.biomarker_agg = df_agg
43 return self