Download Data

Downloading files is EASY with the NSRR downloader tool [1].

gem install nsrr
Fetching: nsrr-0.4.0.gem
Successfully installed nsrr-0.4.0
1 gem installed
nsrr download shhs/polysomnography/edfs
Get Token: https://sleepdata.org/token
Enter Token:
    create shhs/polysomnography/edfs/
    create shhs/polysomnography/edfs/shhs1/
downloaded shhs1-200001.edf
downloaded shhs1-200002.edf
downloaded shhs1-200003.edf
downloaded shhs1-200004.edf
downloaded shhs1-200005.edf
Finished in 15.623997 seconds.
2 folders created, 5 files downloaded, 187 MiBs downloaded, 0 files skipped, 0 files failed

Generate Statistics

Datasets are stored in CSVs described by Data Dictionaries [2].

nsrr download shhs/datasets --shallow
Get Token: https://sleepdata.org/token
Enter Token:
    create shhs/datasets/
downloaded CHANGELOG.md
downloaded KNOWNISSUES.md
downloaded shhs1-dataset-0.13.0.csv
downloaded shhs2-dataset-0.13.0.csv
downloaded shhs-cvd-events-dataset-0.13.0.csv
downloaded shhs-cvd-summary-dataset-0.13.0.csv
downloaded shhs-data-dictionary-0.13.0-domains.csv
downloaded shhs-data-dictionary-0.13.0-forms.csv
downloaded shhs-data-dictionary-0.13.0-variables.csv
downloaded shhs-interim-followup-dataset-0.13.0.csv
Finished in 2.677877 seconds.
1 folder created, 10 files downloaded, 36 MiBs downloaded, 0 files skipped, 0 files failed
open shhs/datasets/generate-statistics.rb
# generate-statistics.rb
require "csv"
csv = File.open("shhs1-dataset-0.13.0.csv")
mcount = fcount = 0
CSV.parse(csv, headers: true) do |row|
  case row["gender"]
  when "1"
    mcount += 1
  when "2"
    fcount += 1
puts "There are #{mcount} male participants in SHHS 1."
puts "There are #{fcount} female participants in SHHS 1."
ruby shhs/datasets/generate-statistics.rb
There are 2765 male participants in SHHS 1.
There are 3039 female participants in SHHS 1.

Compare results to https://sleepdata.org/datasets/shhs/variables/gender

Extract Signals from EDFs [3].

gem install edfize
require "rubygems"
require "edfize"
# Loads the file and reads the EDF Header
edf = Edfize::Edf.new("shhs1-200001.edf")
# Loads the data section of the EDF into Signal objects
# Print out information on the signals
puts "EDF #{edf.filename} contains #{edf.signals.count} signal #{"s" unless edf.signals.count == 1} : \n\n "

edf.signals.each do |signal|
  puts "Signal Label : #{signal.label} "
  puts "Samples Per Data Record : #{signal.samples_per_data_record} "
  puts "First 10 Physical Values : #{(signal.physical_values[0..10] + ["..."]).inspect} \n\n "
EDF shhs1-200001.edf contains 14 signals:
Signal Label : SaO2
Samples Per Data Record : 1
First 10 Physical Values : [95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 94.14053559166858, 94.14053559166858, 94.14053559166858, "..."]

Full output of this code snippet can be found here: https://github.com/sleepepi/edfize


  1. The NSRR downloader is built using Ruby and greatly simplifies downloading large amounts of files from the NSRR website.
    Instructions on installing Ruby on Windows and on Linux/Mac can be found here: https://github.com/nsrr/nsrr-gem
  2. The NSRR maintains its data dictionaries using the Spout Data Dictionary Management Tool. Spout creates a framework that simplifies data dictionary management and creation, and allows researchers to identify documentation gaps between the dataset and the data dictionary.
  3. Edfize is a Ruby gem that provides access to signals and epochs in EDF polysomnographs. Edfize is used by Altamira Web EDF Viewer to render EDFs in your web browser.
Still have questions? Email us!