yasa.sleep_statistics

yasa.sleep_statistics(hypno, sf_hyp)[source]

Compute sleep stats from an hypnogram vector.

New in version 0.1.9.

Parameters
hypnoarray_like

Hypnogram vector, assumed to be already cropped to time in bed (TIB).

Note

The default hypnogram format in YASA is a 1D integer vector where:

  • -1 = Artefact / Movement

  • 0 = Wake

  • 1 = N1 sleep

  • 2 = N2 sleep

  • 3 = N3 sleep

  • 4 = REM sleep

sf_hypfloat

The sampling frequency of the hypnogram. Should be 1/30 if there is one value per 30-seconds, 1/20 if there is one value per 20-seconds, 1 if there is one value per second, and so on.

Returns
stats: dict

Sleep statistics (expressed in minutes)

Notes

All values except SE and percentages are expressed in minutes.

  • Time in Bed (TIB): total duration of the hypnogram.

  • Sleep Period Time (SPT): duration from first to last period of sleep.

  • Wake After Sleep Onset (WASO): duration of wake periods within SPT.

  • Total Sleep Time (TST): SPT - WASO.

  • Sleep Efficiency (SE): TST / SPT * 100 (%).

  • W, N1, N2, N3 and REM: sleep stages duration. NREM = N1 + N2 + N3.

  • % (W, … REM): sleep stages duration expressed in percentages of TST.

  • Latencies: latencies of sleep stages from the beginning of the record.

Examples

>>> from yasa import sleep_statistics
>>> hypno = [0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 3, 3, 4, 4, 4, 4, 0, 0]
>>> # Assuming that we have one-value per 30-second.
>>> sleep_statistics(hypno, sf_hyp=1/30)
{'TIB': 10.0,
 'N1': 1.5,
 'N2': 2.0,
 'N3': 2.5,
 'REM': 2.0,
 'NREM': 6.0,
 'Lat_N1': 1.0,
 'Lat_N2': 2.5,
 'Lat_N3': 4.0,
 'Lat_REM': 7.0,
 'SPT': 8.0,
 'WASO': 0.0,
 'TST': 8.0,
 '%N1': 18.75,
 '%N2': 25.0,
 '%N3': 31.25,
 '%REM': 25.0,
 '%NREM': 75.0,
 'SE': 100.0}