From 5322df2f424dbaf43c14dabac97f4440adbc4bd4 Mon Sep 17 00:00:00 2001 From: Robert Richer Date: Wed, 7 Feb 2024 14:39:41 +0100 Subject: [PATCH] created template for TFMDataset --- src/biopsykit/io/__init__.py | 3 ++- src/biopsykit/io/tfm.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/biopsykit/io/tfm.py diff --git a/src/biopsykit/io/__init__.py b/src/biopsykit/io/__init__.py index a117f1f..fbd519f 100644 --- a/src/biopsykit/io/__init__.py +++ b/src/biopsykit/io/__init__.py @@ -1,5 +1,5 @@ """Module providing input/output functions.""" -from biopsykit.io import carwatch_logs, ecg, eeg, nilspod, saliva, sleep, sleep_analyzer +from biopsykit.io import carwatch_logs, ecg, eeg, nilspod, saliva, sleep, sleep_analyzer, tfm from biopsykit.io.io import ( convert_time_log_datetime, convert_time_log_dict, @@ -33,4 +33,5 @@ "saliva", "sleep", "sleep_analyzer", + "tfm", ] diff --git a/src/biopsykit/io/tfm.py b/src/biopsykit/io/tfm.py new file mode 100644 index 0000000..3abd719 --- /dev/null +++ b/src/biopsykit/io/tfm.py @@ -0,0 +1,34 @@ +from typing import Dict, Optional + +import pandas as pd + + +class TFMDataset: + """Class for loading and processing Task Force Monitor (TFM) data.""" + + CHANNEL_MAPPING = {} + + _tz: str + + def __init__( + self, data_dict: Dict[str, pd.DataFrame], sampling_rate_dict: Dict[str, float], tz: Optional[str] = None + ): + """Initialize a TFM dataset. + + Parameters + ---------- + data_dict : dict + Dictionary containing TFM data. Keys are channel names, values are dataframes with the TFM data. + tz : str, optional + Timezone of the data. Default: None + + """ + self._data = data_dict + self._sampling_rate = sampling_rate_dict + for name, data in data_dict.items(): + setattr(self, name, data) + for name, sampling_rate in sampling_rate_dict.items(): + setattr(self, f"sampling_rate_hz_{name}", sampling_rate) + setattr(self, "channels", list(self._data.keys())) + + self._tz = tz