yasa.Hypnogram.crop#
- Hypnogram.crop(start=None, end=None)[source]#
Crop the hypnogram to a range of epochs or absolute timestamps.
Both
startandendare inclusive. Pass integers for epoch-based cropping, or strings /Timestampobjects for time-based cropping (requiresstartto 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.
- startint, str, or
- Returns:
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
startto 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')