wonambi.detect.slowwave module

Module to detect slow waves.

class wonambi.detect.slowwave.DetectSlowWave(method='Massimini2004', duration=None)[source]

Bases: object

Design slow wave detection on a single channel.

Parameters:
  • method (str) – one of the predefined methods

  • duration (tuple of float) – min and max duration of SWs

invert

pass

Type:

bool

trough_duration

pass

Type:

float

wonambi.detect.slowwave.detect_Massimini2004(dat_orig, s_freq, time, opts)[source]

Slow wave detection based on Massimini et al., 2004.

Parameters:
  • dat_orig (ndarray (dtype='float')) – vector with the data for one channel

  • s_freq (float) – sampling frequency

  • time (ndarray (dtype='float')) – vector with the time points for each sample

  • opts (instance of 'DetectSlowWave') –

    ‘det_filt’dict

    parameters for ‘butter’,

    ’duration’tuple of float

    min and max duration of SW

    ’min_ptp’float

    min peak-to-peak amplitude

    ’trough_duration’tuple of float

    min and max duration of first half-wave (trough)

    ’max_trough_amp’float

    The trough amplitude has a negative value, so this parameter sets the minimum depth of the trough

Returns:

  • list of dict – list of detected SWs

  • float – SW density, per 30-s epoch

References

Massimini, M. et al. J Neurosci 24(31) 6862-70 (2004).

wonambi.detect.slowwave.detect_Ngo2015(dat_orig, s_freq, time, opts)[source]

Slow wave detection based on Ngo et al., 2015.

Parameters:
  • dat_orig (ndarray (dtype='float')) – vector with the data for one channel

  • s_freq (float) – sampling frequency

  • time (ndarray (dtype='float')) – vector with the time points for each sample

  • opts (instance of 'DetectSlowWave') –

    ‘lowpass’dict

    parameters for ‘low_butter’,

    ’duration’tuple of float

    min and max duration of SW

    ’peak_thresh’float

    mean trough amplitude is multiplied by this scalar to yield threshold; SWs above this threshold are kept

    ’ptp_thresh’float

    percentile of mean ptp values, above which SW is kept

Returns:

list of dict – list of detected SWs

References

Ngo, H-V. et al. J Neurosci 35(17) 6630-8 (2015).

wonambi.detect.slowwave.detect_Staresina2015(dat_orig, s_freq, time, opts)[source]

Slow wave detection based on Ngo et al., 2015.

Parameters:
  • dat_orig (ndarray (dtype='float')) – vector with the data for one channel

  • s_freq (float) – sampling frequency

  • time (ndarray (dtype='float')) – vector with the time points for each sample

  • opts (instance of 'DetectSlowWave') –

    ‘lowpass’dict

    parameters for ‘low_butter’,

    ’duration’tuple of float

    min and max duration of SW

    ’ptp_thresh’float

    percentile of mean ptp values, above which SW is kept

Returns:

list of dict – list of detected SWs

References

Staresina, B. et al. 18(11) 1679-86 (2015).

wonambi.detect.slowwave.find_intervals(indices, s_freq, duration)[source]

From sample indices, find intervals within a certain duration.

Parameters:
  • indices (ndarray (dtype='int')) – vector with the indices

  • s_freq (float) – sampling frequency of indices/data

  • duration (tuple of float) – min and max duration (s) of intervals

Returns:

ndarray (dtype=’int’) – N x 2 matrix with start and end samples

wonambi.detect.slowwave.find_peaks_in_slowwwave(data, events)[source]

Find trough, - to + zero-crossing and peak from start/end times.

Parameters:
  • data (ndarray (dtype='float')) – vector with the data

  • events (ndarray (dtype='int')) – N x 2 matrix with start, end samples

Returns:

ndarray (dtype=’int’) – N x 5 matrix with start, trough, - to + zero crossing, peak, and end samples

wonambi.detect.slowwave.find_zero_crossings(data, xtype='all')[source]

Find indices of zero-crossings in data.

Parameters:
  • data (ndarray (dtype='float')) – vector with the data

  • xtype (str) – if ‘all’, returns all zero crossings if ‘neg_to_pos’, returns only negative-to-positive zero-crossings if ‘pos_to_neg’, returns only positive-to-negative zero-crossings

Returns:

nadarray of int – indices of zero-crossings in the data

Note

A value of exactly 0 in data will always create a zero-crossing with nonzero values preceding of following it.

wonambi.detect.slowwave.make_slow_waves(events, data, time, s_freq)[source]

Create dict for each slow wave, based on events of time points.

Parameters:
  • events (ndarray (dtype='int')) – N x 5 matrix with start, trough, zero, peak, end samples

  • data (ndarray (dtype='float')) – vector with the data

  • time (ndarray (dtype='float')) – vector with time points

  • s_freq (float) – sampling frequency

Returns:

list of dict – list of all the SWs, with information about start, trough_time, zero_time, peak_time, end, duration (s), trough_val, peak_val, peak-to-peak amplitude (signal units), area_under_curve (signal units * s)

wonambi.detect.slowwave.select_peaks(data, events, limit)[source]

Check whether event satisfies amplitude limit.

Parameters:
  • data (ndarray (dtype='float')) – vector with data

  • events (ndarray (dtype='int')) – N x 2+ matrix with peak/trough in second position

  • limit (float) – low and high limit for spindle duration

Returns:

ndarray (dtype=’int’) – N x 2+ matrix with peak/trough in second position