Skip to content

Summaries

Basic commands to give overviews of the structure of an EDF

Command Description
DESC Simple description of an EDF, sent to the console
SUMMARY More verbose description, sent to the console
HEADERS Tabulate (channel-specific) EDF header information
TAG Generic command to add a tag (level/factor) to the output
STATS Basic signal statistics (min/max, mean, RMS, etc)

DESC

Basic information on the attached EDF, written to the console

Writes the EDF filename, ID, EDF duration, number of signals and the labels and sampling rates of those signals. If multiple EDFs are specified in a sample list, this information will be repeated for each one.

Parameters

There are no command options for DESC.

Outputs

Text written to the log/console. Note that, unlike most Luna commands, the DESC command does not generate any other output, i.e. via Luna's formal output mechanism.

Example

Using DESC on the command-line with a single EDF:

luna my.edf -s DESC 
EDF filename    : my.edf
ID              : id001
Clock time      : 23:07:56 - 07:39:00
Duration        : 08:31:04
# signals       : 6
Signals         : EOG-L[256] EOG-R[256] EMG[256] EEG1[256] EEG2[256] EEG3[256]

SUMMARY

A more verbose display of EDF header information, written to the console

Similar to DESC, this command writes basic information from the EDF header to the console; per-channel information from the EDF header is also displayed.

Parameters

There are no command options for SUMMARY.

Outputs

Text written to the log/console. Note that, unlike most Luna commands, SUMMARY does not generate any other output, i.e. via Luna's formal output mechanism.

Example

To obtain a SUMMARY on the command-line with a single EDF:

luna my.edf -s SUMMARY
Patient ID     : my.edf
Recording info :
Start date     : 07.06.16
Start time     : 23:07:56

# signals      : 6
# records      : 30664
Duration       : 1

Signal 1 : [EOG-L]
   # samples per record : 256
   transducer type      : G02
   physical dimension   : uV
   min/max (phys)       : -125/125
   EDF min/max (phys)   : -125/125
   min/max (digital)    : -2048/2047
   EDF min/max (digital): -2048/2047
   pre-filtering        : LP:35.00Hz HP:0.30Hz NOTCH:0

Signal 2 : [EOG-R]
   # samples per record : 256
   transducer type      : G03
   physical dimension   : uV
   min/max (phys)       : -125/125
   EDF min/max (phys)   : -125/125
   min/max (digital)    : -2048/2047
   EDF min/max (digital): -2048/2047
   pre-filtering        : LP:35.00Hz HP:0.30Hz NOTCH:0

   ... (etc) ...

HEADERS

Tabulate EDF header information

This command produces similar information to the SUMMARY command, except it uses Luna's standard output mechanism, rather than writing to the console.

Parameters

There are no options for HEADERS.

Outputs

Basic EDF header information (strata: none)

Variable Description
NR Number of records
NS Number of signals/channels
REC.DUR Duration of each record (seconds)
TOT.DUR.SEC Total duration of EDF (seconds)
TOT.DUR.HMS Total duration of EDF (hh:mm:ss string)

Per-channel header information (strata: CH)

Variable Description
DMAX Digital max
DMIN Digital min
PDIM Physical dimension
PMAX Physical min
PMIN Physical max
SR Sample rate (Hz)

Example

To obtain each channel's sampling rate from a single EDF my.edf, and create an output database out.db:

luna my.edf -o out.db -s HEADERS
To view the contents of out.db:
destrat out.db
-------------------------------------------------------------------------
out.db: 1 command(s), 1 individual(s), 11 variable(s), 89 values
-------------------------------------------------------------------------
  command #1:   c1  Wed Mar 27 11:03:17 2019    HEADERS 
-------------------------------------------------------------------------
distinct strata group(s):
  commands      : factors           : levels        : variables 
----------------:------------:---------------:---------------------------
  [HEADERS]     : .          : 1 level(s)    : NR NS REC.DUR TOT.DUR.HMS 
                :            :               : TOT.DUR.SEC
                :            :               : 
  [HEADERS]     : CH         : 14 level(s)   : DMAX DMIN PDIM PMAX PMIN SR
                :            :               : 
----------------:------------:---------------:---------------------------

This shows there are two strata: the first is a baseline strata, i.e. with factor . (period) to indicate no stratification, meaning there is only one value for that variable for that EDF. The second strata is by channel (CH), which has 14 levels, corresponding to the 14 channels/signals in the EDF.

To view its data dictionary, i.e. describing each variable, use the -d flag:

destrat out.db -d
out.db  NS           HEADERS  Number of signals
out.db  NR           HEADERS  Number of records
out.db  REC.DUR      HEADERS  Record duration (sec)
out.db  TOT.DUR.SEC  HEADERS  Total recording duration (sec)
out.db  TOT.DUR.HMS  HEADERS  Total recording duration (hh:mm:ss)
out.db  SR           HEADERS  Sampling race (points per second)
out.db  PDIM         HEADERS  Physical dimension/units
out.db  PMIN         HEADERS  Physical minimum
out.db  PMAX         HEADERS  Physical maximum
out.db  DMIN         HEADERS  Digital minimum
out.db  DMAX         HEADERS  Digital maximum

To extract the baseline information from the HEADERS command:

destrat out.db +HEADERS 
ID      NR     NS  REC.DUR  TOT.DUR.HMS  TOT.DUR.SEC
nsrr01  40920  14  1        11:22:00     40920

To extract only the sample rate variable (SR), which is stratified per-channel (CH):

destrat out.db +HEADERS -r CH -v SR 
ID       CH        SR
nsrr01   SaO2      1
nsrr01   PR        1
nsrr01   EEG(sec)  125
nsrr01   ECG       250
nsrr01   EMG       125
nsrr01   EOG(L)    50
nsrr01   EOG(R)    50
nsrr01   EEG       125
nsrr01   AIRFLOW   10
nsrr01   THOR RES  10
nsrr01   ABDO RES  10
nsrr01   POSITION  1
nsrr01   LIGHT     1
nsrr01   OX STAT   1

Alternatively, to extract all variables for EMG and ECG channels only:

destrat out.db +HEADERS -r CH/EMG,ECG
ID       CH     DMAX    DMIN    PDIM    PMAX    PMIN     SR
nsrr01   ECG    127     -128    mV      1.25    -1.25    250
nsrr01   EMG    127     -128    uV      31.5    -31.5    125

TAG

Used to mark specific analyses in output

TAGs allow you to arbitrarily add extra levels by which output is stratified, which can be useful to distinguish similar commands performed within the same analysis-run (for example, if several rounds of MASKs and RESTRUCTUREs are specified in one analysis).

Parameters

Parameter Example Description
tag RUN/L1 Add tag with level L1 to factor RUN in output
tag tag=RUN/L1 Identical to the above, but explicitly using the tag option

If a . (period) is specified as the level, that particular TAG is removed from any subsequent output. For example, the following would remove the RUN tag from all subsequent output:

TAG RUN/.

To remove all tags, use the following:

TAG .

Hint

Do not select a TAG factor name that is already used by a Luna command (e.g. F, CH, E, B, etc).

Output

No specific output is generated, beyond adding the specified stratifying factors in the output.

Example

By way of context, here we review the concept of strata that Luna uses extensively in its output. For example, some analyses may have their output stratified by two factors: channel and spectral band, for which it uses the labels CH and B. The B (spectral power band) factor has a number of levels, e.g. SIGMA and so on. When using the destrat tool, one might request output for all channels but only the sigma band, for example:

destrat out.db +PSD -r CH B/SIGMA 

where the syntax is {factor}/{level} for spectral power. How does this apply to tags? Consider the following command script cmd.txt, which runs the STATS command (described below):

% Create statistics for the entire night, tagged by ALL for the RUN factor

TAG RUN/ALL
STATS epoch

% Perform some kind of operation to change the data

EPOCH 
MASK epoch=1-10
RESTRUCTURE

% If repeating the same STATS command, we need to distinguish 
% the output from the prior STATS command, so we now set the RUN 
% factor to FLT, i.e. to indicate these are filtered results
% (Note that the choice of 'RUN', 'ALL' and 'FLT' are completely 
% arbitrary)

TAG RUN/FLT
STATS epoch

If we run this command:

luna s.lst -o out.db < cmd.txt

and look at the output:

destrat out.db 

we will see that the RUN factor (specified by the TAG command) appears as an additional factor:

 [STATS] : CH RUN   : 28 level(s) : MAX MEAN MEDIAN MEDIAN.MEAN MEDIAN.MEDIAN 
                                    MEDIAN.RMS MEDIAN.SD MIN NE NE1 RMS SD

 [STATS] : E CH RUN : (...)       : MAX MEAN MEDIAN MIN RMS SD

If we, for example, want to extract the RMS variable, here only for the channel EEG:

destrat out.db +STATS -v RMS -r CH/EEG RUN 

then we'll see it has values for two levels of RUN, i.e. for ALL and FLT, in other words before and after applying the mask:

ID  CH  RUN RMS
nsrr01  EEG ALL 37.801350632511
nsrr01  EEG FLT 17.0591938957608

Alternatively, to extract RMS for all channels but from only the second set of values, one would write (mirroring the original TAG RUN/FLT command, and adding -p 2 to control the number of decimal places output):

destrat out.db +STATS -v RMS -r CH RUN/FLT -p 2 

which yields:

ID       CH          RUN   RMS
nsrr01   SaO2        FLT   95.24
nsrr01   PR          FLT   73.18
nsrr01   EEG(sec)    FLT   14.76
nsrr01   ECG         FLT   0.07
nsrr01   EMG         FLT   8.73
nsrr01   EOG(L)      FLT   53.26
nsrr01   EOG(R)      FLT   50.11
nsrr01   EEG         FLT   17.06
nsrr01   AIRFLOW     FLT   0.12
nsrr01   THOR RES    FLT   0.18
nsrr01   ABDO RES    FLT   0.06
nsrr01   POSITION    FLT   2.01
nsrr01   LIGHT       FLT   1.00
nsrr01   OX STAT     FLT   0.26

STATS

Calculates basic (per-epoch) statistics per-channel

Calculates the mean, median, RMS, standard deviation and min/max for each channel. By default, this is for the entire duration of the recording, i.e. including both masked and unmasked epochs. For epoched data, adding the epoch option generates additional epoch-level output as well as the median (across epochs) of the per-epoch mean, median, RMS and SD. Results from the epoch option are based on unmasked epochs only.

Parameters

Parameter Example Description
sig sig=C3,F3 Restrict analysis to these channels
epoch epoch Calculate per-epoch statistics

Outputs

Whole-night, per-channel statistics, based on all epochs (strata: CH)

Variable Description
MIN Signal minimum (from data, not EDF header)
MAX Signal maximum (from data, not EDF header)
MEAN Signal mean
MEDIAN Signal median
RMS Signal root mean square
SD Signal standard deviation

Per-epoch, per-channel statistics for unmasked epochs only (option: epoch, strata: CH x E)

Variable Description
MIN Signal minimum (from data, not EDF header)
MAX Signal maximum (from data, not EDF header)
MEAN Signal mean
MEDIAN Signal median
RMS Signal root mean square
SD Signal standard deviation

Whole-night, per-channel statistics, only using unmasked epochs (option: epoch, strata: CH)

Variable Description
NE Total number of epochs in record
NE1 Number of unmasked epochs actually used in calculations
MEDIAN.MEAN Median of all per-epoch means
MEDIAN.MEDIAN Median of all per-epoch medians
MEDIAN.RMS Median of all per-epoch RMS values
MEDIAN.SD Median of all per-epoch SD values

Example

As an arbitrary example: to see how the RMS of the ECG signal changes over the night during sleep, using data from the tutorial data (second individual in this case):

luna s.lst nsrr02 -o out.db -s "EPOCH & MASK if=wake & RESTRUCTURE & STATS epoch sig=ECG" 
destrat out.db +STATS -r E CH -v RMS > res.txt

Using the R package, load and plot these epoch-wise values (run these commands within R):

d <- read.table("res.txt",header=T)
plot( d$E , d$RMS , col = d$ID , pch=20 , xlab = "Epoch" , ylab = "RMG(ECG)" ) 

img