yasa.Hypnogram.get_mask#

Hypnogram.get_mask(stages)[source]#

Return a boolean NumPy array marking epochs that match the given stages.

Parameters:
stagesstr or list of str

One or more stage labels, e.g. "N2" or ["N2", "N3"]. Must be valid labels for this hypnogram (see labels).

Returns:
masknumpy.ndarray of bool

Boolean array of length n_epochs, True where the hypnogram matches any of the requested stages.

Examples

>>> from yasa import Hypnogram
>>> hyp = Hypnogram(["W", "N1", "N2", "N2", "N3", "REM"], n_stages=5)
>>> hyp.get_mask(["N2", "N3"])
array([False, False,  True,  True,  True, False])
>>> hyp.get_mask("REM")
array([False, False, False, False, False,  True])