コード例 #1
0
def test_plot_bursts(tsig_burst):

    times = create_times(N_SECONDS, FS)
    bursts = detect_bursts_dual_threshold(tsig_burst, FS, (0.75, 1.5), F_RANGE)

    plot_bursts(times,
                tsig_burst,
                bursts,
                save_fig=True,
                file_path=TEST_PLOTS_PATH,
                file_name='test_plot_bursts.png')
コード例 #2
0
ファイル: burst.py プロジェクト: alexrockhill/bycycle
def detect_bursts_df_amp(df, sig, fs, f_range, amp_threshes=(1, 2),
                         n_cycles_min=3, filter_kwargs=None):
    """Determine which cycles in a signal are part of an oscillatory
    burst using an amplitude thresholding approach.

    Parameters
    ----------
    df : pandas DataFrame
        Dataframe of waveform features for individual cycles, trough-centered.
    sig : 1d array
        Time series.
    fs : float
        Sampling rate, Hz.
    f_range : tuple of (float, float)
        Frequency range (Hz) for oscillator of interest.
    amp_threshes : tuple (low, high), optional, default: (1, 2)
        Threshold values for determining timing of bursts.
        These values are in units of amplitude (or power, if specified) normalized to
        the median amplitude (value 1).
    n_cycles_min : int, optional, default: 3
        Minimum number of cycles to be identified as truly oscillating needed in a row in
        order for them to remain identified as truly oscillating.
    filter_kwargs : dict, optional
        Keyword arguments to :func:`~neurodsp.filt.filter.filter_signal`.

    Returns
    -------
    df : pandas DataFrame
        Same df as input, with an additional column to indicate
        if the cycle is part of an oscillatory burst.
    """

    # Detect bursts using the dual amplitude threshold approach
    sig_burst = detect_bursts_dual_threshold(sig, fs, amp_threshes, f_range,
                                             min_n_cycles=n_cycles_min, **filter_kwargs)

    # Compute fraction of each cycle that's bursting
    burst_fracs = []
    for _, row in df.iterrows():
        fraction_bursting = np.mean(sig_burst[int(row['sample_last_trough']):
                                              int(row['sample_next_trough'] + 1)])
        burst_fracs.append(fraction_bursting)

    # Determine cycles that are defined as bursting throughout the whole cycle
    df['is_burst'] = [frac == 1 for frac in burst_fracs]

    df = _min_consecutive_cycles(df, n_cycles_min=n_cycles_min)
    df['is_burst'] = df['is_burst'].astype(bool)

    return df
コード例 #3
0
# the lower amplitude threshold.
#
# **Other Parameters**
#
# - `avg_type`: used to set the average for normalization to either 'median' or 'mean'
# - `magnitude_type`: used to set the metric for thresholding, to 'amplitude' or 'power'
#

###################################################################################################

# Settings for the dual threshold algorithm
amp_dual_thresh = (1, 2)
f_range = (8, 12)

# Detect bursts using dual threshold algorithm
bursting = detect_bursts_dual_threshold(sig, fs, amp_dual_thresh, f_range)

###################################################################################################
#
# You can plot detected bursts using
# :func:`~.plot_bursts`.
#

###################################################################################################

# Plot original signal and burst activity
plot_bursts(times, sig, bursting, labels=['Simulated EEG', 'Detected Burst'])

###################################################################################################
#
# The graph above shows the bursting activity in red.
コード例 #4
0
# ---------------
#
# Now that we have a sense of the main rhythmicity of this piece of data, lets
# explore using NeuroDSP to investigate whether this rhythm is bursty.
#

###################################################################################################

# Burst settings
amp_dual_thresh = (1., 1.5)
f_range = (peak_cf - 2, peak_cf + 2)

###################################################################################################

# Detect bursts of high amplitude oscillations in the extracted signal
bursting = detect_bursts_dual_threshold(sig, fs, amp_dual_thresh, f_range)

###################################################################################################

# Plot original signal and burst activity
plot_bursts(times, sig, bursting, labels=['Raw Data', 'Detected Bursts'])

###################################################################################################
# Measure Rhythmicity with Lagged Coherence
# -----------------------------------------
#
# So far, in an example channel of data, we have explored some rhythmic properties of
# the EEG data. We did so by finding the main frequency of rhythmic power, and checking
# this frequency for bursting.
#
# Next, we can try applying similar analyses across all channels, to measure
コード例 #5
0
ファイル: mea.py プロジェクト: rajatsaxena/Ephys
def get_burst_epochs(data, fs, f_range, amp_thresh_dual):
    bursting = burst.detect_bursts_dual_threshold(data, fs, f_range, amp_thresh_dual)
    bursting_stats = burst.compute_burst_stats(bursting, fs)
    return bursting, bursting_stats
コード例 #6
0
# (default: median) amplitude of the whole time series. Two thresholds are
# defined based off of this normalized amplitude. In order for a burst to be
# detected, the amplitude must cross the higher amplitude threshold. The burst
# lasts until the amplitude then falls below the lower amplitude threshold.
#
# **Other Parameters:**
# * The average for normalization can be set to either the mean or median
# by modifying the `average_method` keyword argument.
# * Power can be used instead of amplitude by modifying the `magnitude_type`
# keyword argument.
#

# Detect bursts using 'deviation' algorithm
amp_dual_thresh = (1, 2)
f_range = (8, 12)
bursting = detect_bursts_dual_threshold(sig, fs, f_range, amp_dual_thresh)

# Plot original signal and burst activity
plot_bursts(times, sig, bursting, labels=['Simulated EEG', 'Detected Burst'])

###################################################################################################
#
# The graph above shows the bursting activity in red. The algorithm was
# used with thresh=(1, 2), so any time point with more than 3 times the
# median magnitude in the alpha range (8-12 Hz) was marked as bursting activity.

###################################################################################################
#
# Burst detection applied to real recordings
# ------------------------------------------