EmpkinsDataset#
- class pepbench.datasets.EmpkinsDataset(base_path: path_t, groupby_cols: Sequence[str] | None = None, subset_index: Sequence[str] | None = None, *, return_clean: bool = True, exclude_missing_data: bool = False, use_cache: bool = True, only_labeled: bool = False, label_type: str = 'rater_01')[source]#
Dataset class for the EmpkinS Dataset.
This class is the
tpcpdataset class for the EmpkinS dataset. It provides access to the Biopac data (for ECG and ICG), the timelogs for the different experimental phases, the reference annotations for the ECG and ICG annotations, as well as metadata like age, gender, and BMI.- Attributes:
icgIcgRawDataFrameReturn the ICG channel from the biopac data.
ecgEcgRawDataFrameReturn the ECG channel from the biopac data.
sampling_rate_ecgintReturn the sampling rate of the ECG signal.
sampling_rate_icgintReturn the sampling rate of the ICG signal.
heartbeatsHeartbeatSegmentationDataFrameSegment heartbeats from the ECG data and return the heartbeat borders.
reference_pepDataFrameReturn the reference PEP values.
reference_heartbeatsDataFrameReturn the reference heartbeats.
reference_labels_ecgDataFrameReturn the reference labels for the ECG channel.
reference_labels_icgDataFrameReturn the reference labels for the ICG channel.
ageDataFrameReturn the age of the selected participants.
genderDataFrameReturn the gender of the selected participants.
bmiDataFrameCompute the BMI of the selected participants and return it.
metadataDataFrameReturn metadata for the selected participants.
timelogDataFrameReturn the timelog data.
labeling_bordersDataFrameReturn the labeling borders for the selected participant, condition, and phase(s).
Methods
as_attrs()Return a version of the Dataset class that can be subclassed using
attrsdefined classes.Return a version of the Dataset class that can be subclassed using dataclasses.
assert_is_single(groupby_cols, property_name)Raise error if index does contain more than one group/row with the given groupby settings.
assert_is_single_group(property_name)Raise error if index does contain more than one group/row.
clone()Create a new instance of the class with all parameters copied over.
Create the full index for the dataset.
create_string_group_labels(label_cols)Generate a list of string labels for each group/row in the dataset.
get_params([deep])Get parameters for this algorithm.
get_subset(*[, group_labels, index, bool_map])Get a subset of the dataset.
groupby(groupby_cols)Return a copy of the dataset grouped by the specified columns.
Get all datapoint labels of the dataset (i.e. a list of the rows of the index as named tuples).
is_single(groupby_cols)Return True if index contains only one row/group with the given groupby settings.
Return True if index contains only one group.
iter_level(level)Return generator object containing a subset for every category from the selected level.
set_params(**params)Set the parameters of this Algorithm.
create_group_labels
- __init__(base_path: path_t, groupby_cols: Sequence[str] | None = None, subset_index: Sequence[str] | None = None, *, return_clean: bool = True, exclude_missing_data: bool = False, use_cache: bool = True, only_labeled: bool = False, label_type: str = 'rater_01') None[source]#
Initialize a new
EmpkinsDatasetinstance.- Parameters:
- base_path
Pathor str Path to the root directory of the EmpkinS dataset.
- return_cleanbool
Whether to return the preprocessed/cleaned ECG and ICG data when accessing the respective properties. Default:
True.- exclude_missing_databool
Whether to exclude participants where parts of the data are missing. Default:
False.- use_cachebool
Whether to use caching for loading biopac data. Default:
True.- only_labeledbool
Whether to only return sections of the biopac data that are labeled (i.e., cut to labeling borders). This is necessary when using the dataset for evaluating the performance of PEP extraction algorithms or for training ML-based PEP extraction algorithms. Default:
False.- label_type: str, optional
Which annotations to use. Can be either “rater_01”, “rater_02”, or “average”. Default: “rater_01”.
- base_path
- create_index() DataFrame[source]#
Create the full index for the dataset.
This needs to be implemented by the subclass.
Warning
Make absolutely sure that the dataframe you return is deterministic and does not change between runs! This can lead to some nasty bugs! We try to catch them internally, but it is not always possible. As tips, avoid reliance on random numbers and make sure that the order is not depend on things like file system order, when creating an index by scanning a directory. Particularly nasty are cases when using non-sorted container like
set, that sometimes maintain their order, but sometimes don’t. At the very least, we recommend to sort the final dataframe you return increate_index.
- property sampling_rate: dict[str, float]#
Return the sampling rates of the ECG and ICG signals.
- Returns:
- dict
Dictionary with the sampling rates of the ECG and ICG signals in Hz.
- property sampling_rate_ecg: int#
Return the sampling rate of the ECG signal.
- Returns:
- int
Sampling rate of the ECG data in Hz.
- property sampling_rate_icg: int#
Return the sampling rate of the ICG signal.
- Returns:
- int
Sampling rate of the ICG data in Hz.
- property biopac: DataFrame[source]#
Return the biopac data.
This method returns the biopac data for the selected participant, condition, and phase. If only one participant and condition is selected, the entire dataset is returned. If only one participant, condition, and phase is selected, only the data for this phase is returned. In all other cases (i.e., data from multiple participants or from multiple conditions), a
ValueErroris raised.- Returns:
DataFrameBiopac data as a pandas DataFrame.
- Raises:
- ValueError
If the current subset is not a single participant and condition or a single participant, condition, and phase.
- property icg: _IcgRawDataFrame | DataFrame#
Return the ICG channel from the biopac data.
If
return_cleanis set toTruein the__init__, the ICG signal is preprocessed and cleaned using theIcgPreprocessingBandpassalgorithm before returning it.- Returns:
DataFrameICG data as a pandas DataFrame.
- Raises:
- ValueError
If the current subset is not a single participant, condition, and phase or a single participant and condition.
- property ecg: _EcgRawDataFrame | DataFrame#
Return the ECG channel from the biopac data.
If
return_cleanis set toTruein the__init__, the ECG signal is preprocessed and cleaned using theEcgPreprocessingNeurokitalgorithm before returning it.- Returns:
EcgRawDataFrameECG data as a pandas DataFrame.
- property timelog: DataFrame#
Return the timelog data.
The timelog data contains information about the start and end of each experimental phase.
- Returns:
DataFrameTimelog data as a pandas DataFrame.
- property labeling_borders: DataFrame#
Return the labeling borders for the selected participant, condition, and phase(s).
- Returns:
DataFrameLabeling borders as a pandas DataFrame.
- property reference_heartbeats: DataFrame#
Return the reference heartbeats.
- Returns:
DataFrameReference heartbeats as a pandas DataFrame
- property reference_labels_ecg: DataFrame | dict[str, DataFrame]#
Return the reference labels for the ECG channel.
- Returns:
DataFrameReference labels for the ECG channel as a pandas DataFrame.
- property reference_labels_icg: DataFrame | dict[str, DataFrame]#
Return the reference labels for the ICG channel.
- Returns:
DataFrameReference labels for the ICG channel as a pandas DataFrame.
- property heartbeats: _HeartbeatSegmentationDataFrame | DataFrame#
Segment heartbeats from the ECG data and return the heartbeat borders.
- Returns:
HeartbeatSegmentationDataFrameHeartbeats as a pandas DataFrame.
- property metadata: DataFrame#
Return metadata for the selected participants.
- Returns:
DataFrameMetadata as a pandas DataFrame.
- property age: DataFrame#
Return the age of the selected participants.
- Returns:
DataFrameAge as a pandas DataFrame.
- classmethod as_attrs()[source]#
Return a version of the Dataset class that can be subclassed using
attrsdefined classes.Note, this requires
attrsto be installed!
- classmethod as_dataclass()[source]#
Return a version of the Dataset class that can be subclassed using dataclasses.
- assert_is_single(groupby_cols: list[str] | str | None, property_name) None[source]#
Raise error if index does contain more than one group/row with the given groupby settings.
This should be used when implementing access to data values, which can only be accessed when only a single trail/participant/etc. exist in the dataset.
- Parameters:
- groupby_cols
None (no grouping) or a valid subset of the columns available in the dataset index.
- property_name
Name of the property this check is used in. Used to format the error message.
- assert_is_single_group(property_name) None[source]#
Raise error if index does contain more than one group/row.
Note that this is different from
assert_is_singleas it is aware of the current grouping. Instead of checking that a certain combination of columns is left in the dataset, it checks that only a single group exists with the already selected grouping as defined byself.groupby_cols.- Parameters:
- property_name
Name of the property this check is used in. Used to format the error message.
- clone() Self[source]#
Create a new instance of the class with all parameters copied over.
This will create a new instance of the class itself and all nested objects
- create_string_group_labels(label_cols: str | list[str]) list[str][source]#
Generate a list of string labels for each group/row in the dataset.
Note
This has a different use case than the dataset-wide groupby. Using
groupbyreduces the effective size of the dataset to the number of groups. This method produces a group label for each group/row that is already in the dataset, without changing the dataset.The output of this method can be used in combination with
GroupKFoldas the group label.- Parameters:
- label_cols
The columns that should be included in the label. If the dataset is already grouped, this must be a subset of
self.groupby_cols.
- get_params(deep: bool = True) dict[str, Any][source]#
Get parameters for this algorithm.
- Parameters:
- deep
Only relevant if object contains nested algorithm objects. If this is the case and deep is True, the params of these nested objects are included in the output using a prefix like
nested_object_name__(Note the two “_” at the end)
- Returns:
- params
Parameter names mapped to their values.
- get_subset(*, group_labels: list[tuple[str, ...]] | None = None, index: DataFrame | None = None, bool_map: Sequence[bool] | None = None, **kwargs: list[str] | str) Self[source]#
Get a subset of the dataset.
Note
All arguments are mutable exclusive!
- Parameters:
- group_labels
A valid row locator or slice that can be passed to
self.grouped_index.loc[locator, :]. This basically needs to be a subset ofself.group_labels. Note that this is the only indexer that works on the grouped index. All other indexers work on the pure index.- index
pd.DataFramethat is a valid subset of the current dataset index.- bool_map
bool-map that is used to index the current index-dataframe. The list must be of same length as the number of rows in the index.
- **kwargs
The key must be the name of an index column. The value is a list containing strings that correspond to the categories that should be kept. For examples see above.
- Returns:
- subset
New dataset object filtered by specified parameters.
- property group: GroupLabelT#
Get the current group label. Deprecated, use
group_labelinstead.
- property group_label: GroupLabelT#
Get the current group label.
The group is defined by the current groupby settings.
Note, this attribute can only be used, if there is just a single group. This will return a named tuple. The tuple will contain only one entry if there is only a single groupby column or column in the index. The elements of the named tuple will have the same names as the groupby columns and will be in the same order.
- property group_labels: list[GroupLabelT]#
Get all group labels of the dataset based on the set groupby level.
This will return a list of named tuples. The tuples will contain only one entry if there is only one groupby level or index column.
The elements of the named tuples will have the same names as the groupby columns and will be in the same order.
Note, that if one of the groupby levels/index columns is not a valid Python attribute name (e.g. in contains spaces or starts with a number), the named tuple will not contain the correct column name! For more information see the documentation of the
renameparameter ofcollections.namedtuple.For some examples and additional explanation see this example.
- groupby(groupby_cols: list[str] | str | None) Self[source]#
Return a copy of the dataset grouped by the specified columns.
This does not change the order of the rows of the dataset index.
Each unique group represents a single data point in the resulting dataset.
- Parameters:
- groupby_cols
None (no grouping) or a valid subset of the columns available in the dataset index.
- property groups: list[GroupLabelT]#
Get the current group labels. Deprecated, use
group_labelsinstead.
- index_as_tuples() list[GroupLabelT][source]#
Get all datapoint labels of the dataset (i.e. a list of the rows of the index as named tuples).
- property index_is_unchanged: bool#
Returns True if the index is the same as the one created by
create_index.This can be used to check, if the index represents a subset or the actual full index. Note, that this is independent of the
groupby_colssetting.Note
Under the hood this uses the attrs functionality of pandas to store a hash of the original index on the dataframe. If the index is modified or a new index is created, this property does either not exist anymore or the content is modified.
- is_single(groupby_cols: list[str] | str | None) bool[source]#
Return True if index contains only one row/group with the given groupby settings.
If
groupby_cols=Nonethis checks if there is only a single row left. If you want to check if there is only a single group within the current grouping, useis_single_groupinstead.- Parameters:
- groupby_cols
None (no grouping) or a valid subset of the columns available in the dataset index.
- iter_level(level: str) Iterator[Self][source]#
Return generator object containing a subset for every category from the selected level.
- Parameters:
- level
Optional
strthat sets the level which shall be used for iterating. This must be one of the columns names of the index.
- Returns:
- subset
New dataset object containing only one category in the specified
level.
- property reference_pep: DataFrame#
Return the reference PEP values.
- Returns:
DataFrameReference PEP values as a pandas DataFrame
- set_params(**params: Any) Self[source]#
Set the parameters of this Algorithm.
To set parameters of nested objects use
nested_object_name__para_name=.
- property shape: tuple[int]#
Get the shape of the dataset.
This only reports a single dimension. This is equal to the number of rows in the index, if
self.groupby_cols=None. Otherwise, it is equal to the number of unique groups.