Goal: make yasa.Hypnogram the industry-standard Python object for handling sleep hypnograms.
Hypnogram(values, n_stages, freq, start, tz, scorer, proba)— string-based, categorical storagefrom_integers(values, mapping, ...)— migrate from legacy integer arraysfrom_profusion(fname, ...)— load Compumedics Profusion XML (NSRR format)start/endproperties — optional absolute timestamp anchoring; a plain timezone-naive string is sufficient for EDF alignmentupsample_to_data(data, sf, meas_date_is_local=True)— align to EEG data by sample count or absolute timestamps (MNEmeas_date); defaultTruetreatsmeas_dateas a local absolute timestamp per the EDF+ standard (which definesstarttimeas local time at the patient's location; MNE mislabels it as UTC); setFalseonly for files that genuinely store UTC
sleep_statistics()— full AASM summary (TIB, TST, SE, SOL, WASO, stage durations, ...)transition_matrix()— stage transition counts and probabilitiesfind_periods(threshold)— detect consecutive runs of a stageconsolidate_stages(new_n_stages)— merge to 2/3/4-stage hypnogramevaluate(obs_hyp)— epoch-by-epoch agreement metrics (kappa, MCC, F1, ...)
__len__—len(hyp)returns number of epochs__eq__—hyp1 == hyp2returns a boolean NumPy array (element-wise)__getitem__—hyp[0],hyp[-1],hyp[10:50]return a newHypnogramcrop(start, end)— slice by epoch index (inclusive) or absolute timestamp time
plot_hypnogram()— standard hypnogram figureplot_hypnodensity()— per-epoch stage probabilities as a stacked area chart (requiresproba); supports 2/3/4/5-stage hypnograms and datetime x-axis whenstartis setas_int()— integer-encodedpandas.Seriesas_events()— BIDS-compatible eventsDataFrame(onset, duration, stage)upsample(new_freq)— change epoch resolutionto_json(fname)/from_json(fname)— save and load to disk, preserving all metadatato_dict()/from_dict(d)— JSON-serializable in-memory representation (same format asto_json)get_mask(*stages)— return a boolean NumPy array for one or more stages (e.g.,hyp.get_mask("N2", "N3")).
HypnogramSet— new container class for multiple scorers of the same night (alignment, pairwise agreement, consensus scoring). See HYPNOGRAM_MULTIPLE_SCORERS.md for the full design plan.