Ejemplo n.º 1
0
def cli_sleep(data, hypno, config_file, annotations, downsample, use_mne,
              preload, show):
    """Open the graphical user interface of Sleep."""
    # File conversion :
    if data is not None:
        data = click.format_filename(data)
    if hypno is not None:
        hypno = click.format_filename(hypno)
    if config_file is not None:
        config_file = click.format_filename(config_file)
    if annotations is not None:
        annotations = click.format_filename(annotations)
    s = Sleep(data=data,
              hypno=hypno,
              downsample=downsample,
              use_mne=use_mne,
              preload=preload,
              config_file=config_file,
              annotations=annotations)
    if show:
        s.show()
###############################################################################
# Rapid eye movement function
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~

###############################################################################
# This function does NOT perform a real REM detection. It illustrates how to
# replace the default detection behavior by a basic thresholding function.
# Note that the function returns a boolean array indicating samples that are
# above a specific threshold.

def fcn_rem(data, sf, time, hypno):  # noqa
    """New REM detection function."""
    mean_data = np.mean(data)
    std_data = np.std(data)
    # Threshold is mean + 3 * STD
    return data > mean_data + 3. * std_data

###############################################################################
# Replace existing methods
###############################################################################
# Now we use the :class:`visbrain.Sleep.replace_detections` method to overwrite
# existing spindles and REM detections.

# Replace the spindle detection function :
sp.replace_detections('spindle', fcn_spindle)
# Replace the REM detection function :
sp.replace_detections('rem', fcn_rem)

# Finally, open the graphical user interface :
sp.show()