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|2toN2. These are enabled automatically. - Optional NSRR mappings normalize additional event labels, such as
Mixed Apneatoapnea:mixed. These are off by default; enable them withnsrr-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 |
NREM1NREM1 sleepN1 sleepStage 1 sleep|1Sleep stage N1Sleep stage 1Stage N1StageN1Stage 1Stage1Stage NREM1StageNREM1S1 |
N2 |
NREM2NREM2 sleepN2 sleepStage 2 sleep|2Sleep stage N2Sleep stage 2Stage N2StageN2Stage 2Stage2Stage NREM2StageNREM2S2 |
N3 |
NREM3NREM3 sleepN3 sleepStage 3 sleep|3Sleep stage N3Sleep stage 3Stage N3StageN3Stage 3Stage3Stage NREM3StageNREM3S3N4NREM4NREM4 sleepN4 sleepStage 4 sleep|4Sleep stage N4Sleep stage 4Stage N4StageN4Stage 4Stage4Stage NREM4S4 |
R |
REMREM sleepREM sleep|5REM|5Sleep stage REMSleep stage RStage RStageRStage REMStageREM |
W |
WakeWake|0Sleep stage WakeSleep stage WStage WStageWStage WakeWake stage |
NR |
Sleep stage NSleep stage NRSleep stage NREMStage NStage NRStage NREMStageNStageNRStageNREMNREMNREM sleepNR sleep |
U |
UnscoredUnscored|9 |
? |
UnknownSleep stage ?Stage ?missing |
M |
MovementMovement|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:WakeSDO:WakeState |
N1 |
SRO:Stage1SleepSDO:NonRapidEyeMovementSleep-N1 |
N2 |
SRO:Stage2SleepSDO:NonRapidEyeMovementSleep-N2 |
N3 |
SRO:Stage3SleepSRO:Stage4SleepSRO:Stage34SleepSDO:NonRapidEyeMovementSleep-N3SDO:NonRapidEyeMovementSleep-N4 |
R |
SRO:RapidEyeMovementSDO:RapidEyeMovementSleep |
Lights and gaps
These mappings are also part of the default setup:
| Configured target | Defined input aliases |
|---|---|
L |
LightslightsLight |
lights_on |
Lights OnLightsOn |
lights_off |
Lights OffLightsOff |
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|ArousalArousal|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)RERAArousal (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_lmlml_arousallmr_arousallmb_arousalArousal_(ARO_Limb) |
arousal:plm |
arousal_plmArousal_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 ApneaObstructive Apneaapnea_obstructiveObstructive_apnea|APNEA-OBSTRUCTIVE |
apnea:central |
Central Apneaapnea_centralCentral apnea|Central ApneaCentral_apnea|APNEA-CENTRAL |
apnea:mixed |
Mixed Apneaapnea_mixedMixed apnea|Mixed ApneaMixed apnea|APNEA-MIXED |
hypopnea |
Hypopnea|Hypopnea |
hypopnea:obstructive |
hypopnea_obstructiveObstructive_Hypopnea |
hypopnea:central |
hypopnea_central |
periodic_breathing |
Periodic BreathingPeriodic breathing|Periodic Breathing |
respiratory_paradox |
Respiratory Paradox |
snoring |
Snoring |
cheynestokes_breathing |
cheynestokes_breathing |
desat |
SpO2 desaturationSpO2 desaturation|SpO2 desaturationSpO2 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 movementPeriodic 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 MovementLimb 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 artifactRespiratory artifact|Respiratory artifact |
artifact:proximal_pH |
Proximal pH artifactProximal_pH_artifact|Proximal_pH_artifact |
artifact:distal_pH |
Distal pH artifact |
artifact:pH |
Proximal_pH|Distal_pH_artifact |
artifact:blood_pressure |
Blood pressure artifactBlood_pressure_artifact|Blood_pressure_artifact |
artifact:TcCO2 |
TcCO2 artifactTcCO2 artifact|TcCO2 artifact |
artifact:SpO2 |
SpO2 artifactSpO2 artifact|SpO2 artifact |
artifact:EtCO2 |
EtCO2 artifactEtCO2 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 |
BradycardiaBradycardia|Bradycardia |
arrhythmia:tachycardia |
TachycardiaTachycardia|Tachycardia |
arrhythmia:narrow_complex_tachycardia |
Narrow Complex TachycardiaNarrow 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.