Skip to content

Commit

Permalink
updated tfm importer
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajorkowitz committed May 2, 2024
1 parent 79d2eb1 commit 2ad99fb
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/biopsykit/io/tfm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from typing import Dict, Optional

import pandas as pd
from scipy.io import loadmat

from biopsykit.utils._types import path_t


class TFMDataset:
"""Class for loading and processing Task Force Monitor (TFM) data."""

CHANNEL_MAPPING = {"ecg_1": "rawECG1", "ecg_2": "rawECG2", "icg_der": "rawICG"}
_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

@classmethod
def from_mat_file(
cls,
path: path_t,
# channel_mapping: Optional[Dict[str, str]] = None,
tz: Optional[str] = "Europe/Berlin",
):
data = loadmat(path, struct_as_record=False, squeeze_me=True)
data_raw = data["RAW_SIGNALS"]
# keys = [s for s in dir(data_raw) if not s.startswith("_")]
# print(keys)
data_dict = {key: getattr(data_raw, value) for key, value in cls.CHANNEL_MAPPING.items()}
return cls(data_dict=data_dict, tz=tz, sampling_rate_dict={})

def data_as_df(self):
return self._data

0 comments on commit 2ad99fb

Please sign in to comment.