HeartbeatSegmentationNeurokit#

class pepbench.algorithms.heartbeat_segmentation.HeartbeatSegmentationNeurokit(*, variable_length: bool = True, start_factor: float = 0.35, r_peak_detection_method: str = 'neurokit', handle_missing_events: Literal['raise', 'warn', 'ignore'] = 'warn')[source]#

Segment ECG signal into individual heartbeats based on NeuroKit2.

This algorithm segments the ECG signal into individual heartbeats based on the R-peaks detected by Neurokit’s ecg_peaks function. The start of each heartbeat is determined based on the R-peak and the current RR-interval.

For more information on NeuroKit2, see [Mak21].

Parameters:
variable_lengthbool, optional

True if extracted heartbeats should have variable length (depending on the current RR-interval) or False if extracted heartbeats should have fixed length (same length for all heartbeats, depending on the mean heartrate of the complete signal, 35% of mean heartrate in seconds before R-peak and 50% after r_peak, see neurokit2.ecg_segment for details). For variable length heartbeats, the start of the next heartbeat follows directly after end of last (ends exclusive); For fixed length heartbeats, there might be spaces between heartbeat borders, or they might overlap. Default: True

start_factorfloat, optional

only needed if variable_length=True. This parameter defines where the start border between heartbeats is set depending on the RR-interval to previous heartbeat. For example, start_factor=0.35 means that the beat start is set at 35% of current RR-distance before the R-peak of the beat

r_peak_detection_methodstr, optional

Method to detect R-peaks that is passed to neurokit2.ecg_peaks. Default: “neurokit”

handle_missing_eventsone of {“warn”, “raise”, “ignore”}, optional

How to handle missing data in the input dataframes. Default: “warn”

Attributes:
heartbeat_list_HeartbeatSegmentationDataFrame
DataFrame containing the segmented heartbeats with the following columns:
  • start_time: Start time of the heartbeat

  • start_sample: Start sample of the heartbeat

  • end_sample: End sample of the heartbeat

  • r_peak_sample: Sample of the R-peak of the heartbeat

  • rr_interval_sample: RR-interval to the next heartbeat in samples

  • rr_interval_ms: RR-interval to the next heartbeat in milliseconds

References

[Mak21]

Makowski, D., Pham, T., Lau, Z. J., Brammer, J. C., Lesspinasse, F., Pham, H., Schölzel, C., & S.H. Chen (2021). NeuroKit2: A Python Toolbox for Neurophysiological Signal Processing. Behavior Research Methods. https://doi.org/10.3758/s13428-020-01516-y

Methods

clone()

Create a new instance of the class with all parameters copied over.

extract(*, ecg, sampling_rate_hz)

Segment ECG signal into heartbeats.

get_params([deep])

Get parameters for this algorithm.

set_params(**params)

Set the parameters of this Algorithm.

__init__(*, variable_length: bool = True, start_factor: float = 0.35, r_peak_detection_method: str = 'neurokit', handle_missing_events: Literal['raise', 'warn', 'ignore'] = 'warn')[source]#

Initialize new HeartbeatSegmentationNeurokit algorithm instance.

Parameters:
variable_lengthbool, optional

True if extracted heartbeats should have variable length (depending on the current RR-interval) or False if extracted heartbeats should have fixed length (same length for all heartbeats, depending on the mean heartrate of the complete signal, 35% of mean heartrate in seconds before R-peak and 50% after r_peak, see neurokit2.ecg_segment for details). For variable length heartbeats, the start of the next heartbeat follows directly after end of last (ends exclusive); For fixed length heartbeats, there might be spaces between heartbeat borders, or they might overlap. Default: True

start_factorfloat, optional

only needed if variable_length=True. This parameter defines where the start border between heartbeats is set depending on the RR-interval to previous heartbeat. For example, start_factor=0.35 means that the beat start is set at 35% of current RR-distance before the R-peak of the beat

r_peak_detection_methodstr, optional

Method to detect R-peaks that is passed to neurokit2.ecg_peaks. Default: “neurokit”

handle_missing_eventsone of {“warn”, “raise”, “ignore”}, optional

How to handle missing data in the input dataframes. Default: “warn”

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

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.

set_params(**params: Any) Self[source]#

Set the parameters of this Algorithm.

To set parameters of nested objects use nested_object_name__para_name=.

extract(*, ecg: _EcgRawDataFrame | DataFrame, sampling_rate_hz: float)[source]#

Segment ECG signal into heartbeats.

The function uses R-peak detection to segment the ECG signal into heartbeats. The start of each heartbeat is determined based on the R-peak and the current RR-interval.

The results (start and end sample, R-peak sample, current RR-interval in samples and milliseconds) are saved in the heartbeat_list_ attribute.

Parameters:
ecgSeries or DataFrame

ECG signal

sampling_rate_hzint

Sampling rate of ECG signal in hz

Returns:
self
Raises:
EventExtractionError

If the event extraction fails and handle_missing is set to “raise”