PSGDataBaseMixin

class torch_ecg.databases.PSGDataBaseMixin[source]

Bases: object

A mixin class for PSG databases.

Contains methods for

  • convertions between sleep stage intervals and sleep stage masks

  • hypnogram plotting

plot_hypnogram(mask: ndarray, granularity: int = 30, class_map: Dict[str, int] | None = None, **kwargs) tuple[source]

Hypnogram visualization.

Parameters:
  • mask (numpy.ndarray) – Sleep stage mask.

  • granularity (int, default 30) – Granularity of the sleep stage mask to be plotted, with units in seconds.

  • class_map (dict, optional) – A dictionary mapping sleep stages to integers. If the database reader does not have a sleep_stage_names attribute, this parameter must be provided.

  • kwargs (dict, optional) – Additional keyword arguments passed to matplotlib.pyplot.plot().

Returns:

  • fig (matplotlib.figure.Figure) – Figure object.

  • ax (matplotlib.axes.Axes) – Axes object.

sleep_stage_intervals_to_mask(intervals: Dict[str, List[List[int]]], fs: int | None = None, granularity: int = 30, class_map: Dict[str, int] | None = None) ndarray[source]

Convert sleep stage intervals to sleep stage mask.

Parameters:
  • intervals (dict) – Sleep stage intervals, in the format of dict of list of lists of int. Keys are sleep stages and values are lists of lists of start and end indices of the sleep stages.

  • fs (int, optional) – Sampling frequency corresponding to the sleep stage intervals, defaults to the sampling frequency of the database.

  • granularity (int, default 30) – Granularity of the sleep stage mask, with units in seconds.

  • class_map (dict, optional) – A dictionary mapping sleep stages to integers. If the database reader does not have a sleep_stage_names attribute, this parameter must be provided.

Returns:

Sleep stage mask.

Return type:

numpy.ndarray