Skip to content

Commit

Permalink
SleepStaging returns a yasa.Hypnogram instance (#127)
Browse files Browse the repository at this point in the history
* First commit to update SleepStaging

* Black formatting

* Match stage names SleepStaging -> Hypnogram

* Update CI

* Add `proba` to yasa.Hypnogram + __repr__ to SleepStaging

* Black formatting

* __str__ returns __repr__

* Remove annoying warning

* Add assertionchecks all strings

* renamed to as_events

* Adress PR comments

* Update notebook

* Minor fix deprecations mne and pandas

* use rename_categories

* Add virtual_documents to gitignore
  • Loading branch information
raphaelvallat authored Dec 27, 2024
1 parent 0e4689d commit 6e6a067
Show file tree
Hide file tree
Showing 7 changed files with 868 additions and 291 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@ notebooks/20_catch_errors.ipynb
*.pptx

# Custom
*/.virtual_documents/
notebooks/debug*
notebooks/my_hypno.csv
15 changes: 10 additions & 5 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ which comes with several pre-built functions (aka methods) and attributes. See f
hyp.duration # Total duration of the hypnogram, in minutes
hyp.sampling_frequency # Sampling frequency of the hypnogram
hyp.mapping # Mapping from strings to integers
hyp.proba # Probability of each sleep stage, if specified
# Below are some class methods
hyp.sleep_statistics() # Calculate the sleep statistics
hyp.plot_hypnogram() # Plot the hypnogram
hyp.upsample_to_data() # Upsample to data
Please see the documentation of :py:class:`yasa.Hypnogram` for more details.
This brings along critical changes to several YASA function, for example:

.. important::
The adoption of object-oriented :py:class:`yasa.Hypnogram` usage brings along critical changes to several YASA function, for example:
* :py:class:`yasa.SleepStaging` now returns a :py:class:`yasa.Hypnogram` instead of a :py:class:`numpy.ndarray`. The probability of each sleep stage for each epoch can now be accessed with :py:attr:`yasa.Hypnogram.proba`.
* :py:func:`yasa.simulate_hypnogram` now returns a :py:class:`yasa.Hypnogram` instead of a :py:class:`numpy.ndarray`.
* The suggested approach to plotting hypnograms is through the :py:meth:`yasa.Hypnogram.plot_hypnogram` method. The old function :py:func:`yasa.plot_hypnogram` still exists, but now *requires* a :py:class:`yasa.Hypnogram` instance as input.

**Other improvements**

* :py:func:`yasa.simulate_hypnogram` now returns a :py:class:`yasa.Hypnogram` instead of a :py:class:`numpy.ndarray`.
* The suggested approach to plotting hypnograms is through the :py:meth:`yasa.Hypnogram.plot_hypnogram` method. The old function :py:func:`yasa.plot_hypnogram` still exists, but now *requires* a :py:class:`yasa.Hypnogram` instance as input.
* Added helpful string representation (__repr__) to :py:class:`yasa.SleepStaging`.
* :py:func:`yasa.simulate_hypnogram` now returns a :py:class:`yasa.Hypnogram` instead of a :py:class:`numpy.ndarray`.
* The suggested approach to plotting hypnograms is through the :py:meth:`yasa.Hypnogram.plot_hypnogram` method. The old function :py:func:`yasa.plot_hypnogram` still exists, but now *requires* a :py:class:`yasa.Hypnogram` instance as input.

----------------------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 6e6a067

Please sign in to comment.