Skip to content

Luna: software for the analysis of sleep signal data

Luna is an open-source C/C++ software package for manipulating and analyzing polysomnographic recordings, with a focus on the sleep EEG. Primarily oriented around command-line scripting (lunaC), we are developing various extensions, including a package for the R statistical package (lunaR). We have also recently developed an interactive viewer and web-based frontend, Moonlight that also conatains Moonbeam, a connector to NSRR data. The current release is v0.99 (5-Dec-2023): see here for a list of changes/additions.

Getting started

After downloading Luna, the best place to start is the tutorial. Then work your way through the pages listed in the left-hand side menu. (On devices with smaller screens this may be minimized: if so, click the top left three horizontal bars icon.) In particular, the lunaC describes many key concepts and conventions (many of which are also relevant for the R package).

The Luna package comprises a number of components, primarily:


Both lunaC and lunaR are based on the same underlying Luna library: see the reference overview for detailed descriptions of Luna's commands. In this documentation, we often refer to lunaC simply as Luna: luna is the filename of both the actual command line executable and the R package, and so we use the terms lunaC to lunaR to disambiguate where necessary, but most material is common to both (i.e. as both are based on the same basic Luna library).

Installation options

You can install Luna in a number of ways. The easiest approach is to download binary executables; you can also compile from source):


An alternative is to run Luna in a Docker container. If you can install Docker on your machine, this may be a good route to test-drive Luna. We've generated a Docker container that includes lunaC, lunaR and also Moonlight, and can be deployed in either in the classic R environment, or via RStudio:


Things Luna aims to do

The reference pages list all currently-supported commands. Main areas are summarized below.

Primary use cases

  • Read, manipulate and write large sets of EDF and EDF+ signals
  • Filter, resample and re-reference signals
  • Generate a variety of (per-epoch) summary statistics
  • Statistical artifact detection for EEG channels
  • Annotate and mask/filter epochs
  • Estimate key features of sleep macro-architecture
  • Automated sleep staging
  • Spectral analyses
  • Spindle and slow oscillation detection
  • Coherence and cross-frequency coupling
  • Multi-channnel, topographical analyses
  • Visual data exploration via Moonlight

Things Luna doesn't aim to do

Luna was originally designed to work with the large number of polysomnograms at the NSRR, with a focus on intersecting sleep EEG signals with other annotations. As such, some areas are not well supported, or effectively outside of Luna's scope.

Areas outside of Luna's primary focus

  • Methods development platform: although the R extension can support methods development, other tools (including general purpose Matlab packages such as EEGLAB) will naturally be better suited for expert users interested in flexibly altering and developing new analyses

  • Online signal processing: Luna is set up for all analyses being done offline, i.e. on the entire recording

  • Support for multiple formats: currently, Luna is mainly based around EDF and EDF+ files (as well as plain text)

  • Analyses of cardiac and respiratory events: most of Luna's specialized sleep analyses are currently focused on EEG signals (e.g. spindles and slow oscillations)

Back to top