Tutorials
Automated sleep analysis at your fingertips. We walk you through some examples in our tutorials.
SomnoBot uses neural networks that run in your web browser on your computer to analyze human sleep with state-of-the-art accuracy. No data transfer to a server or other third party is required. The neural networks have been validated, published, and are open access.
Tutorial 1: Sleep Scoring with SomnoBot
In the first tutorial, we show you how to use SomnoBot to score human sleep. We will also show you how to use the scores to calculate sleep statistics.
Step 1: Select Recordings
-
Open the Sleep Scoring Webpage.
-
Click on "Select EDF file(s)" and select one or several of your EEG sleep recordings from your computer that you want SomnoBot to score (see figure 1, step 1).
- If you do not have an appropriate file at hand, you can download a recording from one of the publicly available data repositories, for instance this file from the SleepEDF dataset.
- We only support files in EDF format at this time. SomnoBot automatically scores human sleep based on electroencephalographic (EEG) recordings derived from scalp electrodes that were placed using the 10-20 system recommended by the American Academy of Sleep Medicine (AASM). We do not yet support the scoring of animal sleep or the scoring of intracranial recordings.
- Your EDF files are not shared with us or any other third party. Find out more here.
- Check the checkboxes of those files for which you want SomnoBot to score sleep (see figure 1, step 2).
- Optional: If you happen to know the lights off and lights on times for your recordings, you can enter them in the last two columns of the table (figure 1, step 3). If in doubt, don't change the prefilled values.
- lights off and lights on determine where SomnoBot starts and ends to score sleep in the recording. The first scored epoch starts with lights off.
- The automatically determined values for lights off and lights on correspond to the start and end times of the recording.
- By entering the actual lights off and on times, you can calculate more sleep statistics in step 4 of this tutorial.
Figure 1: File selection for example EDF files. Click on (1) to select one or several EDF files from your computer. The table shows details of your files. Click on (2) to select or deselect those files that you want or do not want to score. Optional: If you know "lights off" and "lights on" times, you can enter these at (3). If in doubt, do not change the prefilled values.
Step 2: Select Channels
You need to select channels, which will be used by SomnoBot to detect sleep stages. SomnoBot uses a neural network that is robust with respect to different channels and EEG montages. However, to achieve best scoring accuracies with SomnoBot, we recommend to select at least two EEG and one EOG channel (learn more about channel selection here).
- In the select channels panel, select at least two EEG and one EOG channel (see figure 2)
- The select channels panel will show only those channels that were recorded in all selected EDF files. If your EDF files do not share any channel, the channel selection panel will be empty.
- The more channels you select, the better SomnoBot will be able to score your recordings. However, more channels will increase compute time and memory requirements. We recommend to start with a small number of channels (e.g., three channels).
Figure 2: Channel selection for an example EDF file. The channel selection panel shows channels that you can select and all recordings have in common.
Step 3: Score Sleep and Download Scores
Automated sleep scoring can take several minutes per EDF file, depending on your computing hardware, the file sizes, and the number of selected channels. We recommend to close other applications and to free memory before starting the sleep staging process.
-
Click on "Classify Sleep Stages" to let SomnoBot score your sleep recordings (see figure 3).
-
Click on "Download Annotations" and "Download Metadata" to download the sleep scores and information (metadata) that can be useful when you need to describe the sleep scoring process for a scientific publication or thesis.
- SomnoBot will detect sleep stages regardless whether your recordings are strongly contaminated with artifacts or not. This is often very helpful, particularly for contaminated recordings. However, SomnoBot will yield sleep stages even for segments such as flatlines (e.g., when electrodes were not plugged in). This is expected behavior. We plan to detect artifacts in a future version of SomnoBot.
-
Inspect and download, if desired, hypnograms for the scored recordings.
- In case you selected several EDF files for scoring, you can visualize hypnograms for different EDF files using the select file for hypnogram panel.
Figure 3: Download panel and example hypnogram.
Step 4: Calculate Sleep Statistics
Sleep statistics and other metrics can be calculated using your favorite tools. Here we demonstrate how you can calculate sleep statistics using a spreadsheet.
-
Open the file that you downloaded in the previous step.
-
Unzip the downloaded file to extract the txt file containing the sleep scores.
-
Each line of the txt file corresponds to an epoch of 30 seconds of the EEG recording.
-
The first column of the txt file contains the time point (in seconds) at which the epoch begins. Second 0 corresponds to the lights off time provided to SomnoBot when scoring sleep. If you did not change lights off/on times, SomnoBot will score the entire length of the recording. In this case, second 0 corresponds to the beginning of the recording.
-
The second column of the txt file contains the sleep scores. Both columns are separated by commas. Sleep scores are encoded as:
-
Sleep Score | Corresponding Sleep Stage |
---|---|
0 | Wake |
5 | REM |
1 | N1 |
2 | N2 |
3 | N3 |
-
Open and copy the spreadsheet we created for you here.
- Use the file menu to download the sheet or create a copy of the sheet that you can edit.
-
Copy the sleep scores from the annotation file into the sheet column titled "Sleep Data 01".
- Tip: You can easily extract the sleep scores from the txt file by opening the txt file in a spreadsheet.
-
Read the sleep statistics that were automatically calculated by the sheet.
Step 5 (optional): Assess Scoring Accuracy
SomnoBot uses a validated and published neural network to score human sleep with high accuracy. However, if you want to assess how SomnoBot scores compare to those of a human expert, we suggest the following.
-
Read and learn about sleep scoring accuracy of human experts and automated systems here.
-
Select one or several of your sleep recordings and score human sleep manually (or let another expert annotator score human sleep).
-
Use SomnoBot to determine sleep scores for your sleep recordings from step 3.
- Make sure that the epochs scored by SomnoBot are aligned to those scored by the human expert. The first epoch scored by SomnoBot begins at the lights off time you provided when selecting recordings (step 1).
-
Determine Cohen's Kappa between SomnoBot's scores and the manually determined scores. We provide a spreadsheet that can help you with calculating Cohen's Kappa.
-
Compare your Cohen's Kappa value with a distribution of Kappa values determined between pairs of expert scorers.
- By comparing your Cohen's Kappa value to this distribution, you can assess how close your and SomnoBot's scores are to the average agreement expected between different human expert raters.
Tutorial 2: Sleep Spindle Detection with SomnoBot
In our second tutorial, we show you how to use SomnoBot to detect sleep spindles in human sleep. We will also show you how to combine this analysis with sleep staging to limit spindle detection to valid sleep stages.
Step 1: Select Recordings
-
Open the Spindle Detection Webpage.
-
Click on "Select EDF file(s)" and select one or several of your EEG sleep recordings from your computer that you want SomnoBot to score (see figure 4, step 1).
- If you do not have an appropriate file at hand, you can download a recording from one of the publicly available data repositories, for instance this file from the SleepEDF dataset.
- We only support files in EDF format at this time. SomnoBot automatically annotates human sleep based on electroencephalographic (EEG) recordings derived from scalp electrodes that were placed using the 10-20 system recommended by the American Academy of Sleep Medicine (AASM). We do not yet support the scoring of animal sleep or the scoring of intracranial recordings.
- Your EDF files are not shared with us or any other third party. Find out more here.
- Check the checkboxes of those files for which you want SomnoBot to detect sleep spindles (see figure 4, step 2).
- Optional: If you happen to know the lights off and lights on times for your recordings, you can enter them in the last two columns of the table (figure 4, step 3). If in doubt, don't change the prefilled values.
- lights off and lights on determine where SomnoBot starts and ends to detect sleep spindles in the recording. The lights off time corresponds to the start of the analysis.
- The automatically determined values for lights off and lights on correspond to the start and end times of the recording.
Figure 4: File selection for example EDF files. Click on (1) to select one or several EDF files from your computer. The table shows details of your files. Click on (2) to select or deselect those files that you want or do not want to score. Optional: If you know "lights off" and "lights on" times, you can enter these at (3). If in doubt, do not change the prefilled values.
Step 2: Configure Sleep Staging
Before detecting spindles, you can configure an additional sleep staging step (see here for more information on the sleep staging process). This step is optional and can be used to prevent spindle detection in unplausible sleep stages.
By default, SomnoBot will perform sleep staging and only detect spindles in N2 sleep. We recommend to keep this default setting because this is the setting that was used to validate the neural network. If you nevertheless want to change this behavior, you can follow the steps below:
-
Open the Configure Sleep Staging panel. You should now see the configuration options (see figure 5).
-
The first switch controls whether sleep staging is performed or not. If sleep staging is performed (default), each spindle will be mapped to the sleep stage in which it was detected. This information is also included in the spindle annotations, which you can download in step 4.
-
The second switch controls whether spindle detection is only performed in N2 sleep. If the switch is on (default), the neural network will only analyze epochs that are scored as N2 sleep. If the switch is off, all sleep stages will be analyzed. This might lead to spurious spindle detections in unplausible sleep stages (e.g., Wake or REM).
-
You can use the third switch to analyze N1 and N3 sleep in addition to N2 sleep. Following the AASM guidelines, only the latter half of N1 epochs that are followed by either N2 or N3 sleep will be analyzed. If this switch is off (default), only N2 sleep will be analyzed.
Figure 5: Configuration of optional sleep staging step. The first switch controls whether sleep staging is performed or not. If the second switch is on, spindles are only detected in N2 sleep. With the third switch, you can additionally detect spindles in N3 sleep or in the latter half of N1 epochs that are followed by N2 or N3 sleep.
Step 3: Select Channels
Depending on the configurations you made in the previous step, you need to select two sets of channels: one set will be used by SomnoBot to detect sleep stages, the other set will be used to detect spindles. To achieve best scoring accuracies with SomnoBot, we recommend to select at least two EEG and one EOG channel for sleep staging and a central EEG channel (e.g., C3-A2 or C4-A1) for spindle detection (learn more about channel selection for sleep staging and spindle detection).
-
In the select channels for sleep staging panel, select at least two EEG and one EOG channel (see figure 6)
- The select channels for sleep staging panel will show only those channels that were recorded in all selected EDF files. If your EDF files do not share any channel, the channel selection panel will be empty and you will receive a warning message.
- The more channels you select, the better SomnoBot will be able to score your recordings. However, more channels will increase compute time and memory requirements. We recommend to start with a small number of channels (e.g., three channels).
Figure 6: Sleep staging channel selection for an example EDF file. The "select channels for sleep staging" panel shows channels that all selected recordings have in common. -
In the select channel for spindle detection panel, select a central EEG channel (e.g., C3-A2 or C4-A1) (see figure 7)
- The select channel for spindle detection panel will show only those channels that were recorded in all selected EDF files. If your EDF files do not share any channel, the channel selection panel will be empty and you will receive a warning message.
Figure 7: Spindle detection channel selection for an example EDF file. The "select channel for spindle detection" panel shows channels that all selected recordings have in common.
Step 4: Analyze Sleep and Download Spindles
SomnoBot might need several minutes to analyze each EDF file, depending on your computing hardware, the file sizes, and the number of selected channels. We recommend to close other applications and to free memory before starting the sleep staging process.
-
Click on "Start Annotation Process" to let SomnoBot analyze your sleep recordings (see figure 8).
-
Click on "Download Annotations" and "Download Metadata" to download the sleep scores, spindles and information (metadata) that can be useful when you need to describe the sleep scoring process for a scientific publication or thesis.
- SomnoBot will detect sleep stages regardless whether your recordings are strongly contaminated with artifacts or not. This is often very helpful, particularly for contaminated recordings. However, SomnoBot will yield sleep stages even for segments such as flatlines (e.g., when electrodes were not plugged in). This is expected behavior. We plan to detect artifacts in a future version of SomnoBot.
- Without pre-selecting only N2 data, SomnoBot will detect sleep spindles in unplausible sleep stages (e.g., Wake or REM). This is expected behavior because the neural network used for spindle detection hasn't been taught to differentiate between sleep stages. You can use the optional sleep staging step to prevent this behavior.
Figure 8: Annotation and download panel.