yasa.Hypnogram.crop#

Hypnogram.crop(start=None, end=None)[source]#

Crop the hypnogram to a range of epochs or absolute timestamps.

Both start and end are inclusive. Pass integers for epoch-based cropping, or strings / Timestamp objects for time-based cropping (requires start to be set on the hypnogram).

Parameters:
startint, str, or pandas.Timestamp, optional

First epoch to include. Defaults to the first epoch.

endint, str, or pandas.Timestamp, optional

Last epoch to include (inclusive). Defaults to the last epoch.

Returns:
hypHypnogram

A new Hypnogram covering the selected range.

Examples

Epoch-based crop (first 10 epochs):

>>> from yasa import simulate_hypnogram
>>> hyp = simulate_hypnogram(tib=60, seed=0)
>>> hyp.crop(end=9).n_epochs
10

Time-based crop (requires start to be set):

>>> hyp = simulate_hypnogram(tib=60, start="2022-12-15 22:30:00", seed=0)
>>> cropped = hyp.crop(start="2022-12-15 23:00:00", end="2022-12-15 23:30:00")
>>> cropped.n_epochs
60
>>> cropped.start
Timestamp('2022-12-15 23:00:00')