yasa.Hypnogram.as_int#
- Hypnogram.as_int()[source]#
Return hypnogram values as integers.
The default mapping from string to integer is:
2-stage: {“WAKE”: 0, “SLEEP”: 1, “ART”: -1, “UNS”: -2}
3-stage: {“WAKE”: 0, “NREM”: 2, “REM”: 4, “ART”: -1, “UNS”: -2}
4-stage: {“WAKE”: 0, “LIGHT”: 2, “DEEP”: 3, “REM”: 4, “ART”: -1, “UNS”: -2}
5-stage: {“WAKE”: 0, “N1”: 1, “N2”: 2, “N3”: 3, “REM”: 4, “ART”: -1, “UNS”: -2}
Users can define a custom mapping:
>>> hyp.mapping = {"WAKE": 0, "NREM": 1, "REM": 2}
Examples
Convert a 2-stage hypnogram to a pandas.Series of integers
>>> from yasa import Hypnogram >>> hyp = Hypnogram(["W", "W", "S", "S", "W", "S"], n_stages=2) >>> hyp.as_int() Epoch 0 0 1 0 2 1 3 1 4 0 5 1 Name: Stage, dtype: int16
Same with a 4-stage hypnogram
>>> from yasa import Hypnogram >>> hyp = Hypnogram(["W", "W", "LIGHT", "LIGHT", "DEEP", "REM", "WAKE"], n_stages=4) >>> hyp.as_int() Epoch 0 0 1 0 2 2 3 2 4 3 5 4 6 0 Name: Stage, dtype: int16