yasa.Hypnogram.consolidate_stages#
- Hypnogram.consolidate_stages(new_n_stages)[source]#
Reduce the number of stages in a hypnogram to match actigraphy or wearables.
For example, a standard 5-stage hypnogram (W, N1, N2, N3, REM) could be consolidated to a hypnogram more common with actigraphy (e.g. 2-stage: [Wake, Sleep] or 4-stage: [W, Light, Deep, REM]).
- Parameters:
- new_n_stagesint
Desired number of sleep stages. Must be lower than the current number of stages. Valid target values and their stage sets are:
4-stage (Wake, Light, Deep, REM)
3-stage (Wake, NREM, REM)
2-stage (Wake, Sleep)
Note
Unscored and Artefact are always allowed.
- Returns:
- hyp
yasa.Hypnogram The consolidated Hypnogram object. This function returns a copy, i.e. the original hypnogram is not modified in place.
- hyp
Examples
>>> from yasa import Hypnogram >>> hyp = Hypnogram(["W", "W", "N1", "N2", "N2", "N2", "N2", "W"], n_stages=5) >>> hyp_2s = hyp.consolidate_stages(2) >>> print(hyp_2s.hypno) Epoch 0 WAKE 1 WAKE 2 SLEEP 3 SLEEP 4 SLEEP 5 SLEEP 6 SLEEP 7 WAKE Name: Stage, dtype: category Categories (4, str): ['WAKE', 'SLEEP', 'ART', 'UNS']