Skip to content

Luna & the National Sleep Research Resource

Luna reads polysomnography recordings and annotation files distributed by the National Sleep Research Resource (NSRR). This page explains how to build a sample list, enable optional NSRR annotation remappings, and select events using the resulting labels. See the annotation reference for the NSRR XML format.

NSRR sample lists

After downloading EDFs and their annotation files, create a sample list with --build:

luna --build /path/to/nsrr-data -nsrr > s.lst

The -nsrr option restricts annotation matching to the -nsrr.xml filename suffix, matching, for example, subject01.edf with subject01-nsrr.xml. The default builder already recognizes this suffix alongside other supported annotation extensions; -nsrr is useful when you want only the NSRR XML files attached. It controls filename matching, not annotation remapping or harmonization. Enable event remapping separately with nsrr-remap=T.

Some newer NSRR cohorts include original data that have not yet been harmonized to the usual NSRR formats and naming conventions. Their annotation files may use different names or formats, which -nsrr does not automatically handle. Check the cohort's files, then use the appropriate builder options or prepare the sample list manually. Unsupported annotation formats need to be converted to a format Luna can read; changing the sample list alone does not convert them.

Review the generated list to check that each EDF has the intended annotation files attached. See the builder reference for naming rules and additional options. Each row contains an ID, an EDF path, and optional annotation paths.

Annotation aliases

Annotation names vary between NSRR cohorts and scoring systems. Luna provides two sets of built-in annotation remappings:

  • Default mappings normalize common sleep-stage labels, such as Stage 2 sleep|2 to N2. These are enabled automatically.
  • Optional NSRR mappings normalize additional event labels, such as Mixed Apnea to apnea:mixed. These are off by default; enable them with nsrr-remap=T.

For example, load the first recording with NSRR event mappings enabled and inspect its annotations:

luna s.lst 1 nsrr-remap=T -s 'ANNOTS'

Remapping occurs while annotations are loaded. Subsequent commands must use the resulting labels. The mappings do not change the original files on disk. The same label sanitization and space-handling settings apply to registered aliases and incoming annotation labels. Unrecognized nonempty labels are retained after this normalization. The tables below list every alias-to-target definition in annot/nsrr-remap.cpp, grouped by purpose and separated into default and optional mappings. Inspect your recording's actual labels with ANNOTS before writing selection rules.

To use only the default mappings, omit nsrr-remap=T. Setting annot-remap=F clears all annotation remappings, including default sleep-stage mappings and any previously added NSRR mappings. annot-remap=F nsrr-remap=T clears the defaults and then adds NSRR mappings; nsrr-remap=T annot-remap=F clears both sets. nsrr-remap=F does not undo mappings already enabled earlier in the options. See remapping annotations for custom mappings.

Sleep staging

These mappings are defined in the default annotation setup and do not require nsrr-remap=T. Legacy stage 4 is combined with stage 3 as N3.

Configured target Defined input aliases
N1 NREM1
NREM1 sleep
N1 sleep
Stage 1 sleep|1
Sleep stage N1
Sleep stage 1
Stage N1
StageN1
Stage 1
Stage1
Stage NREM1
StageNREM1
S1
N2 NREM2
NREM2 sleep
N2 sleep
Stage 2 sleep|2
Sleep stage N2
Sleep stage 2
Stage N2
StageN2
Stage 2
Stage2
Stage NREM2
StageNREM2
S2
N3 NREM3
NREM3 sleep
N3 sleep
Stage 3 sleep|3
Sleep stage N3
Sleep stage 3
Stage N3
StageN3
Stage 3
Stage3
Stage NREM3
StageNREM3
S3
N4
NREM4
NREM4 sleep
N4 sleep
Stage 4 sleep|4
Sleep stage N4
Sleep stage 4
Stage N4
StageN4
Stage 4
Stage4
Stage NREM4
S4
R REM
REM sleep
REM sleep|5
REM|5
Sleep stage REM
Sleep stage R
Stage R
StageR
Stage REM
StageREM
W Wake
Wake|0
Sleep stage Wake
Sleep stage W
Stage W
StageW
Stage Wake
Wake stage
NR Sleep stage N
Sleep stage NR
Sleep stage NREM
Stage N
Stage NR
Stage NREM
StageN
StageNR
StageNREM
NREM
NREM sleep
NR sleep
U Unscored
Unscored|9
? Unknown
Sleep stage ?
Stage ?
missing
M Movement
Movement|6

NR denotes unspecified NREM sleep; U denotes unscored intervals, ? unknown stages, and M movement-time annotations. These are distinct from the five standard stage labels N1, N2, N3, R, and W.

Additional cohort-specific stage aliases require nsrr-remap=T:

Configured target Defined input aliases
W SRO:Wake
SDO:WakeState
N1 SRO:Stage1Sleep
SDO:NonRapidEyeMovementSleep-N1
N2 SRO:Stage2Sleep
SDO:NonRapidEyeMovementSleep-N2
N3 SRO:Stage3Sleep
SRO:Stage4Sleep
SRO:Stage34Sleep
SDO:NonRapidEyeMovementSleep-N3
SDO:NonRapidEyeMovementSleep-N4
R SRO:RapidEyeMovement
SDO:RapidEyeMovementSleep

Lights and gaps

These mappings are also part of the default setup:

Configured target Defined input aliases
L Lights
lights
Light
lights_on Lights On
LightsOn
lights_off Lights Off
LightsOff
G GAP
-

Arousals

The following event mappings require nsrr-remap=T. All aliases defined in the source are listed.

Configured target Defined input aliases
arousal Arousal ()
Arousal|Arousal ()
Arousal|Arousal
Arousal|Arousal (Standard)
Arousal_(STANDARD)
Arousal|Arousal_(Arousal)
ASDA arousal|Arousal (ADSA)
ASDA arousal|Arousal (ASDA)
Arousal (ASDA)
Arousal_(Asda)
EEG arousal
arousal:spontaneous Arousal (ARO SPONT)
Spontaneous arousal|Arousal (apon aro)
Spontaneous arousal|Arousal (ARO SPONT)
Spontaneous arousal|Arousal (SPON ARO)
arousal:respiratory Arousal resulting from respiratory effort|Arousal (ARO RES)
RERA
Arousal (ARO RES)
Arousal resulting from respiratory effort|Arousal (RESP ARO)
Respiratory effort related arousal|RERA
arousal:external External arousal|Arousal (External Arousal)
Arousal_(External_Arousal)
arousal:cheshire Arousal resulting from Chin EMG|Arousal (Cheshire)
Arousal_(CHESHIRE)
arousal:lm arousal_lm
lml_arousal
lmr_arousal
lmb_arousal
Arousal_(ARO_Limb)
arousal:plm arousal_plm
Arousal_resulting_from_periodic_leg_movement|Arousal_(PLM)
Arousal_resulting_from_periodic_leg_movement|Arousal_(PLM_ARO)

Respiratory events

Configured target Defined input aliases
apnea Apnea
apnea:obstructive Obstructive apnea|Obstructive Apnea
Obstructive Apnea
apnea_obstructive
Obstructive_apnea|APNEA-OBSTRUCTIVE
apnea:central Central Apnea
apnea_central
Central apnea|Central Apnea
Central_apnea|APNEA-CENTRAL
apnea:mixed Mixed Apnea
apnea_mixed
Mixed apnea|Mixed Apnea
Mixed apnea|APNEA-MIXED
hypopnea Hypopnea|Hypopnea
hypopnea:obstructive hypopnea_obstructive
Obstructive_Hypopnea
hypopnea:central hypopnea_central
periodic_breathing Periodic Breathing
Periodic breathing|Periodic Breathing
respiratory_paradox Respiratory Paradox
snoring Snoring
cheynestokes_breathing cheynestokes_breathing
desat SpO2 desaturation
SpO2 desaturation|SpO2 desaturation
SpO2 desaturation|DESAT

PLMs

Periodic leg movements (PLM) and other limb movements (LM) have separate targets, including left/right variants.

Configured target Defined input aliases
PLM Periodic leg movement
Periodic leg movement|PLM
PLM:left Periodic leg movement - left|PLM (Left)
PLM (Left)
PLM:right Periodic leg movement - right|PLM (Right)
PLM (Right)
LM Limb Movement
Limb movement|Limb Movement
LM:left Limb Movement (Left)
Limb movement - left|Limb Movement (Left)
LM:right Limb Movement (Right)
Limb movement - right|Limb Movement (Right)

Artifacts

Configured target Defined input aliases
artifact Signal artifact|SIGNAL-ARTIFACT
artifact:respiratory Respiratory artifact
Respiratory artifact|Respiratory artifact
artifact:proximal_pH Proximal pH artifact
Proximal_pH_artifact|Proximal_pH_artifact
artifact:distal_pH Distal pH artifact
artifact:pH Proximal_pH|Distal_pH_artifact
artifact:blood_pressure Blood pressure artifact
Blood_pressure_artifact|Blood_pressure_artifact
artifact:TcCO2 TcCO2 artifact
TcCO2 artifact|TcCO2 artifact
artifact:SpO2 SpO2 artifact
SpO2 artifact|SpO2 artifact
artifact:EtCO2 EtCO2 artifact
EtCO2 artifact|EtCO2 artifact
artifact:body_temperature Body_temperature_artifact|Body_temperature_artifact

Misc

Configured target Defined input aliases
unsure Unsure|Unsure|Unsure
movement Movement
position:left Body position change to left|POSITION-LEFT
position:right Body position change to right|POSITION-RIGHT
position:prone Body position change to prone|POSITION-PRONE
position:supine Body position change to supine|POSITION-SUPINE
position:upright Body position change to upright|POSITION-UPRIGHT
arrhythmia:bradycardia Bradycardia
Bradycardia|Bradycardia
arrhythmia:tachycardia Tachycardia
Tachycardia|Tachycardia
arrhythmia:narrow_complex_tachycardia Narrow Complex Tachycardia
Narrow complex tachycardia|Narrow Complex Tachycardia
notes Technician Notes

With the optional mappings enabled, plain Movement maps to the event label movement, overriding its default mapping to M. The default mapping of Movement|6 to M remains available.

For NSRR XML input, labels such as apnea:mixed are annotation class names and can be used directly in commands. When loading the six-column .annot format, the default class-instance-delimiter=: can instead split such a label into class apnea and instance ID mixed. Check the loaded labels when changing annotation formats; masks can also match instance IDs.

Selecting events

With NSRR event mappings enabled, exclude epochs overlapping a mixed apnea:

luna s.lst 1 nsrr-remap=T -s 'EPOCH & MASK if=apnea:mixed'

To exclude epochs overlapping any apnea or hypopnea class, use trailing wildcards:

luna s.lst 1 nsrr-remap=T -s 'EPOCH & MASK if=apnea*,hypopnea*'

This matches apnea and its subtype labels, plus hypopnea and its subtypes. A comma-separated annotation list uses OR logic: an epoch is masked if it overlaps any matching class. A mask marks epochs for subsequent analyses; it does not remove the annotation events themselves. See MASK for other selection rules.

Higher-level variables

Luna defines ${sleep} as N1,N2,N3,R during default annotation setup. For example, to retain only epochs overlapping scored sleep:

luna s.lst 1 -s 'EPOCH & MASK ifnot=${sleep}'

Other event groups can be defined with ordinary Luna variables. For example, define a study-specific respiratory-event group and use it in a mask:

luna s.lst 1 nsrr-remap=T resp_events='apnea*,hypopnea*' -s 'EPOCH & MASK if=${resp_events}'

Quote the variable value so that the shell passes the * characters to Luna instead of treating them as filename patterns. The separate single quotes around the command keep the shell from expanding ${resp_events} before Luna reads it. Defining a variable groups labels for substitution; it does not rename or merge annotation classes. Earlier documentation listed predefined ${apnea}, ${arousal}, ${artifact}, ${arrhythmia}, ${plm}, and individual-stage variables; these are not populated by the current NSRR remapping code. Define any such groups explicitly for your analysis.