OSCR

Automated sleep scoring in hibernating and non-hibernating American black bears.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 193 lines · 7.8 KB · GPL-3.0

  1. #!/usr/bin/env python
  2. """
  3. Example script demonstrating how to preprocess a set of datasets and saving out the results.
  4. TODO:
  5. - provide different entry point by command line argument parsing using argparse
  6. - fix plotting (`time` encapsulated at the moment...)
  7. """
  8. import numpy as np
  9. import matplotlib.pyplot as plt
  10. try:
  11. # Ideally, we use a multitaper approach to compute LFP/EEG/EMG spectrograms.
  12. # An implementation is available on github and can be installed using:
  13. # pip install git+https://github.com/hbldh/lspopt.git#egg=lspopt
  14. from lspopt import spectrogram_lspopt
  15. from functools import partial
  16. get_spectrogram = partial(spectrogram_lspopt, c_parameter=20.)
  17. except ImportError:
  18. import warnings
  19. message = "Falling back to scipy.signal.spectrogram to compute the spectrogram,"
  20. message += "\nwhich computes the standard Baum-Welch spectrogram."
  21. message += "\nA multitaper approach may yield better results, "
  22. message += "\nfor which an implementation is available on github and can be installed with:"
  23. message += "\npip install git+https://github.com/hbldh/lspopt.git#egg=lspopt"
  24. warnings.warn(message)
  25. from scipy.signal import spectrogram as get_spectrogram
  26. from data_io import (
  27. ArgumentParser,
  28. load_dataframe,
  29. check_dataframe,
  30. load_raw_signals,
  31. export_preprocessed_signals,
  32. )
  33. from somnotate._utils import (
  34. robust_normalize,
  35. )
  36. def preprocess(raw_signal, sampling_frequency_in_hz,
  37. time_resolution_in_sec = 1,
  38. low_cut = 1.,
  39. high_cut = 90.,
  40. notch_low_cut = 45.,
  41. notch_high_cut = 55.,
  42. ):
  43. """Wrapper around get_spectrogram, that
  44. 1) computes the spectrogram for the given LFP/EEG/EMG trace,
  45. 2) normalizes it such that the power in a given frequency band is
  46. approximately normally distributed, and
  47. 3) excludes frequencies that are contaminated by noise using the equivalent
  48. of a notch filter.
  49. Arguments:
  50. ----------
  51. raw_signal -- (total samples, ) ndarray
  52. The electrophysiological signal.
  53. sampling_frequency_in_hz -- float
  54. The sampling frequency of `raw_signals`.
  55. time_resolution_in_sec -- int (default 1)
  56. The time resolution of the output array.
  57. low_cut, high_cut -- float (default 1.)
  58. The minimum/maximum frequency for which to compute the power.
  59. notch_low_cut, notch_high_cut -- float (default 45.)
  60. The frequency band for which NOT to compute the power
  61. (to eliminate 50 Hz noise from the output signal).
  62. Returns:
  63. --------
  64. preprocessed_signal -- (total samples / (sampling frequency * time resolution), total frequencies)
  65. The normalized spectrogram of the given signal.
  66. """
  67. # compute spectrogram
  68. frequencies, time, spectrogram = get_spectrogram(raw_signal,
  69. fs = sampling_frequency_in_hz,
  70. nperseg = sampling_frequency_in_hz * time_resolution_in_sec,
  71. noverlap = 0)
  72. # exclude ill-determined frequencies
  73. mask = (frequencies >= low_cut) & (frequencies < high_cut)
  74. frequencies = frequencies[mask]
  75. spectrogram = spectrogram[mask]
  76. # exclude noise-contaminated frequencies around 50 Hz;
  77. # this improves performance (generally, 0.1-0.5%, but 3% in at least one case)
  78. mask = (frequencies >= notch_low_cut) & (frequencies <= notch_high_cut)
  79. frequencies = frequencies[~mask]
  80. spectrogram = spectrogram[~mask]
  81. # the power in each frequency band tends to be log-normally distributed, and
  82. # taking the log hence transforms the distribution of power values to a normal distribution;
  83. # shift power values by +1 such that values close to zero remain close to zero
  84. # (and do not become large, negative values after log transformation)
  85. spectrogram = np.log(spectrogram + 1)
  86. # normalize the data by de-meaning and rescaling by the standard deviation
  87. spectrogram = robust_normalize(spectrogram, p=5., axis=1, method='standard score')
  88. return time, frequencies, spectrogram
  89. if __name__ == '__main__':
  90. from configuration import (
  91. time_resolution,
  92. state_annotation_signals,
  93. plot_raw_signals,
  94. )
  95. # --------------------------------------------------------------------------------
  96. # parse and check inputs
  97. parser = ArgumentParser()
  98. parser.add_argument("spreadsheet_file_path", help="Use datasets specified in /path/to/spreadsheet.csv")
  99. parser.add_argument("-s", "--show", action="store_true", help="Plot the output figures of the script.")
  100. parser.add_argument('--only',
  101. nargs = '+',
  102. type = int,
  103. help = 'Indices corresponding to the rows to use (default: all). Indexing starts at zero.'
  104. )
  105. args = parser.parse_args()
  106. # load spreadsheet / data frame
  107. datasets = load_dataframe(args.spreadsheet_file_path)
  108. # check contents of spreadsheet
  109. check_dataframe(datasets,
  110. columns = [
  111. 'file_path_raw_signals',
  112. 'sampling_frequency_in_hz',
  113. 'file_path_preprocessed_signals',
  114. ] + state_annotation_signals,
  115. column_to_dtype = {
  116. 'file_path_raw_signals' : str,
  117. 'sampling_frequency_in_hz' : (int, float),
  118. 'file_path_preprocessed_signals' : str,
  119. }
  120. )
  121. if args.only:
  122. datasets = datasets.loc[np.in1d(range(len(datasets)), args.only)]
  123. # --------------------------------------------------------------------------------
  124. # preprocess specified files
  125. for ii, (idx, dataset) in enumerate(datasets.iterrows()):
  126. print("{} ({}/{})".format(dataset['file_path_raw_signals'], ii+1, len(datasets)))
  127. # determine edf signals to load
  128. signal_labels = [dataset[column_name] for column_name in state_annotation_signals]
  129. # load data
  130. raw_signals = load_raw_signals(dataset['file_path_raw_signals'], signal_labels)
  131. preprocessed_signals = []
  132. for signal in raw_signals.T:
  133. time, frequencies, preprocessed_signal = preprocess(signal, dataset['sampling_frequency_in_hz'],
  134. time_resolution_in_sec = time_resolution,
  135. low_cut = 1.,
  136. high_cut = 90.,
  137. notch_low_cut = 45.,
  138. notch_high_cut = 55.,
  139. )
  140. preprocessed_signals.append(preprocessed_signal)
  141. # show input and outputs (not concatenated) for first dataset for quality control
  142. if args.show:
  143. fig, axes = plt.subplots(1+len(preprocessed_signals), 1, sharex=True)
  144. plot_raw_signals(
  145. raw_signals,
  146. sampling_frequency = dataset['sampling_frequency_in_hz'],
  147. ax = axes[0],
  148. )
  149. for signal, ax in zip(preprocessed_signals, axes[1:]):
  150. ax.imshow(signal, aspect='auto', origin='lower', extent=[time[0], time[-1], frequencies[0], frequencies[-1]])
  151. ax.set_ylabel('Frequency')
  152. ax.set_xlabel('Time [seconds]')
  153. # concatenate spectrograms into one set of features and save out
  154. preprocessed_signals = np.concatenate([signal.T for signal in preprocessed_signals], axis=1)
  155. export_preprocessed_signals(dataset['file_path_preprocessed_signals'], preprocessed_signals)
  156. plt.show()

01_preprocess_signals.py at commit a20f33d, under GPL-3.0 · at the source

Overview

  1. Institute of Arctic Biology, University of Alaska Fairbanks, Fairbanks, Alaska, United States of America
  2. Department of Biology, Stanford University, Stanford, California, United States of America
  3. Radcliffe Department of Medicine, University of Oxford, Oxford, United Kingdom
  4. Department of Pharmacology, University of Oxford, Oxford, United Kingdom
  5. Florey Department of Neuroscience and Mental Health, University of Melbourne, Parkville, Victoria, Australia
  6. Somnivore Pty Ltd, Bacchus Marsh, Victoria, Australia
Journal: PloS one, volume 21, issue 8, article e0352640
Dates: received 6 September 2025; accepted 11 June 2026; published online 5 August 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1371/journal.pone.0352640 · PMID 42555601 · PMCID PMC13440796 · OpenAlex W4409185970
Open access: gold, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: EEG (modality), other (modality)
Methods: Spectral & time-frequency, Statistics, Preprocessing, Physiology & signal measures
MeSH: Hibernation*, Sleep*, Ursidae*, Animals, Body Temperature, Electroencephalography, Electromyography, Female, Machine Learning, Male (* major topic)
Topic: Bat Biology and Ecology Studies (Ecology, Evolution, Behavior and Systematics, Agricultural and Biological Sciences), according to OpenAlex
Funding: NIGMS NIH HHS (P20 GM103395, P20 GM130443)
Citations: not cited yet (Europe PMC); 26 references in the paper

Abstract

Hibernating bears show remarkable metabolic suppression. Their decline in core body temperature (Tb) is moderate (from 38°C to 30−35°C), but their metabolism declines as much as 75%. To understand the role of sleep in this hypometabolic state, we recorded biotelemetrically EEG, EOG and EMG data over 3500 days from 16 captive American black bears in and out of hibernation under semi-natural conditions. This data set is too large to score manually for Wake, REM- and NREM sleep, so we tested two machine learning classifiers: (1) Somnotate trained on multiple one-day recordings, and (2) Somnivore, trained on a small subset from each recording. As automated scoring methods have not been applied to hibernating species before, a major concern is the effect changing brain temperature has on the EEG and on the machine learning based detection. Therefore, we selected reference data using consensus by 3 manual sleep scorers from each of 6 bears, two one-day recordings at the highest and lowest body temperatures during hibernation when Tb was oscillating in multiday cycles, and a non-hibernating one-day recording in summer. Somnotate results were excellent when trained separately for hibernating and non-hibernating data. Training Somnotate separately for high and low Tb within hibernation did not improve results further. Sleep times in hibernation were about 2x that in summer for both automated scores and manual scores (p < 0.0001). There were no significant differences in occupancy of vigilance states between automated and manual scores in hibernation (p > 0.05), but a small overestimate of sleep time in summer (p < 0.05). Both applications yielded F-measures against manual scores in the 0.90–0.98 range. Outliers in the 0.67–0.88 range were correlated between the two applications, indicating that specific files are more challenging to annotate. We conclude that both applications have accuracies approaching that of manual scorers when trained on high quality data.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above.

paulbrodersen/somnotate

License: GPL-3.0
State: the link answers, verified on 30 October 2026
Evidence: files inventoried
Commit: a20f33de62511d8c172e333896608b7fc166d0f0, 5 January 2026
Languages: Python (20)
Size: 27 files, 20 scripts
Software Heritage: archived
Found in: “Data Availability”
Holds: README, license file, environment (pyproject.toml, requirements.txt, example_pipeline/requirements.txt)
Not found: CITATION.cff, tests, continuous integration, documentation
Tools: NumPy (17 files), Matplotlib (11 files), SciPy (5 files), scikit-learn (2 files), pandas (1 file)
Availability: 2 checks, the latest on 30 October 2026: the link answers
  • 30 October 2026: the link answers
  • 27 September 2026: the link answers
22 files

otoien/ConsensusCode

License: CC0-1.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: eaee8b368256b795c81fd9251fc4d7ca88ff08e2, 6 August 2025
Size: 11 files, 0 scripts
Software Heritage: not archived
Found in: “Data Availability”
Holds: license file
Not found: README, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
1 file

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 20 scripts, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data Availability

The data underlying the results presented in the study are available from the National Sleep Research Resource (https://doi.org/10.25822/cp4n-fh44) at https://sleepdata.org/datasets/toien-2025. The code for Somnotate is available at https://github.com/paulbrodersen/somnotate. The alaska branch contains custom modifications for the project. The Somnivore code is proprietary. The code used for extracting consensus scores is available at https://github.com/otoien/ConsensusCode.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 3, 28 September 2026

  • Authors: added Yi-Ge Huang (0000-0002-1034-1517); Paul J N Brodersen (0000-0001-5216-7863); Giancarlo Allocca (0000-0003-2237-6722); removed Yi-Ge Huang; Paul J N Brodersen; Giancarlo Allocca

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 7 authors, 10 MeSH terms, 1 funder, 23 references.

Cite

This paper

Tøien, Ø., Pittaras, E. C., Huang, Y.-G., Brodersen, P. J. N., Allocca, G., Barnes, B. M., & Heller, H. C. (2026). Automated sleep scoring in hibernating and non-hibernating American black bears. PloS one, 21(8), e0352640. https://doi.org/10.1371/journal.pone.0352640

BibTeX

@article{tien2026automated,
author = {Tøien, Øivind and Pittaras, Elsa Cecile and Huang, Yi-Ge and Brodersen, Paul J N and Allocca, Giancarlo and Barnes, Brian M and Heller, H Craig},
title = {{Automated sleep scoring in hibernating and non-hibernating American black bears}},
journal = {PloS one},
year = {2026},
month = aug,
volume = {21},
number = {8},
pages = {e0352640},
publisher = {PLOS},
issn = {1932-6203},
doi = {10.1371/journal.pone.0352640},
url = {https://doi.org/10.1371/journal.pone.0352640},
pmid = {42555601},
pmcid = {PMC13440796}
}

RIS

TY - JOUR
AU - Tøien, Øivind
AU - Pittaras, Elsa Cecile
AU - Huang, Yi-Ge
AU - Brodersen, Paul J N
AU - Allocca, Giancarlo
AU - Barnes, Brian M
AU - Heller, H Craig
TI - Automated sleep scoring in hibernating and non-hibernating American black bears
T2 - PloS one
J2 - PLoS One
PY - 2026
DA - 2026/08/05
VL - 21
IS - 8
SP - e0352640
SN - 1932-6203
PB - PLOS
DO - 10.1371/journal.pone.0352640
UR - https://doi.org/10.1371/journal.pone.0352640
LA - en
ER -

CSL-JSON

{
"id": "10.1371/journal.pone.0352640",
"type": "article-journal",
"title": "Automated sleep scoring in hibernating and non-hibernating American black bears",
"container-title": "PloS one",
"author": [
{
"family": "Tøien",
"given": "Øivind"
},
{
"family": "Pittaras",
"given": "Elsa Cecile"
},
{
"family": "Huang",
"given": "Yi-Ge"
},
{
"family": "Brodersen",
"given": "Paul J N"
},
{
"family": "Allocca",
"given": "Giancarlo"
},
{
"family": "Barnes",
"given": "Brian M"
},
{
"family": "Heller",
"given": "H Craig"
}
],
"container-title-short": "PLoS One",
"volume": "21",
"issue": "8",
"page": "e0352640",
"DOI": "10.1371/journal.pone.0352640",
"PMID": "42555601",
"PMCID": "PMC13440796",
"ISSN": "1932-6203",
"publisher": "PLOS",
"URL": "https://doi.org/10.1371/journal.pone.0352640",
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
5
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1371/journal.pcbi.1011793 [code]
Somnotate: A probabilistic sleep stage classifier for studying vigilance state transitions.
Journal: PLoS computational biology
In common: scikit-learn, pandas, SciPy, 2 other tools, EEG, 3 references, 2 authors
[2] doi:10.1038/s42003-022-03431-8
Hypothalamic remodeling of thyroid hormone signaling during hibernation in the arctic ground squirrel.
Journal: Communications biology
In common: 5 references
[3] doi:10.1038/s41746-024-01115-7 [code]
Generalized sleep decoding with basal ganglia signals in multiple movement disorders.
Journal: NPJ digital medicine
In common: scikit-learn, pandas, SciPy, 2 other tools, 3 references
[4] doi:10.1371/journal.pbio.3003198 [code]
A unified framework to model synaptic dynamics during the sleep-wake cycle.
Journal: PLoS biology
In common: scikit-learn, pandas, SciPy, 2 other tools, 2 references
[5] doi:10.7717/peerj-cs.1561 [code]
Automatic sleep staging by a hybrid model based on deep 1D-ResNet-SE and LSTM with single-channel raw EEG signals.
Journal: PeerJ. Computer science
In common: scikit-learn, pandas, SciPy, 2 other tools, EEG, 2 references
[6] doi:10.3389/fphys.2023.1287342 [code]
Deep transfer learning for automated single-lead EEG sleep staging with channel and population mismatches.
Journal: Frontiers in physiology
In common: scikit-learn, pandas, Matplotlib, 1 other tool, other, EEG, 2 references
[7] doi:10.1038/s41746-025-02237-2 [code]
SLEEPYLAND: trust begins with fair evaluation of automatic sleep staging models.
Journal: NPJ digital medicine
In common: scikit-learn, pandas, SciPy, 2 other tools, 2 references
[8] doi:10.1523/eneuro.0226-25.2025 [code]
Automated Classification of Sleep-Wake States and Seizures in Mice.
Journal: eNeuro
In common: scikit-learn, pandas, SciPy, 2 other tools, other, EEG, 1 reference
[9] doi:10.1093/sleep/zsaf164 [code]
The Hypno-PC: uncovering sleep dynamics through principal component analysis and hidden Markov modeling of electrophysiological signals.
Journal: Sleep
In common: scikit-learn, pandas, SciPy, 2 other tools, other, EEG, 1 reference
[10] doi:10.3390/s25030921 [code]
Open-Source Algorithm for Automated Vigilance State Classification Using Single-Channel Electroencephalogram in Rodents.
Journal: Sensors (Basel, Switzerland)
In common: scikit-learn, pandas, SciPy, 2 other tools, EEG, 1 reference

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1371/journal.pone.0352640.svg)](https://openscicode.org/badge/doi/10.1371/journal.pone.0352640)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1371/journal.pone.0352640.svg
   :target: https://openscicode.org/badge/doi/10.1371/journal.pone.0352640
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1371/journal.pone.0352640"><img src="https://openscicode.org/badge/doi/10.1371/journal.pone.0352640.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.