예제 #1
0
def test_plot_burst_detect_params(only_result):
    """Test plotting burst detection."""

    # Simulate oscillating time series
    n_seconds = 25
    fs = 1000
    freq = 10
    f_range = (6, 14)

    osc_kwargs = {
        'amplitude_fraction_threshold': 0,
        'amplitude_consistency_threshold': .5,
        'period_consistency_threshold': .5,
        'monotonicity_threshold': .8,
        'n_cycles_min': 3
    }

    sig = sim_oscillation(n_seconds, fs, freq)

    df = compute_features(sig, fs, f_range)

    fig = plot_burst_detect_params(sig,
                                   fs,
                                   df,
                                   osc_kwargs,
                                   plot_only_result=only_result)

    if not only_result:
        for param in fig:
            assert param is not None
    else:
        assert fig is not None
예제 #2
0
def tsig_sine_long():

    yield sim_oscillation(N_SECONDS_LONG,
                          FS,
                          freq=FREQ_SINE,
                          variance=None,
                          mean=None)
예제 #3
0
def sim_args():

    sig = sim_oscillation(N_SECONDS, FS, FREQ)

    df_shapes = compute_shape_features(sig, FS, F_RANGE)
    df_burst = compute_burst_features(df_shapes, sig)
    df_features = compute_features(sig, FS, F_RANGE)

    threshold_kwargs = {
        'amp_fraction_threshold': 0.,
        'amp_consistency_threshold': .5,
        'period_consistency_threshold': .5,
        'monotonicity_threshold': .5,
        'min_n_cycles': 3
    }

    yield {
        'sig': sig,
        'fs': FS,
        'f_range': F_RANGE,
        'df_features': df_features,
        'df_shapes': df_shapes,
        'df_burst': df_burst,
        'threshold_kwargs': threshold_kwargs
    }
예제 #4
0
def sim_stationary():

    sig = sim_oscillation(N_SECONDS,
                          FS,
                          FREQ,
                          phase=0.15,
                          cycle="asine",
                          rdsym=.3)

    yield sig
예제 #5
0
def sim_args():

    # Simulate oscillating time series
    n_seconds = 10
    fs = 500
    freq = 10
    f_range = (6, 14)

    sig = sim_oscillation(n_seconds, fs, freq)

    df = compute_features(sig, fs, f_range)

    yield {'df': df, 'sig': sig, 'fs': fs}
예제 #6
0
# Simulate a Stationary Oscillation
# ---------------------------------
#
# Let's start by simulating an oscillation. We'll start with a simple, sinusoidal, oscillation.
#
# Continuous peridic signals can be created with :func:`~neurodsp.sim.periodic.sim_oscillation`.
#

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

# Simulation settings
n_seconds = 1
osc_freq = 6.6

# Simulate a sinusoidal oscillation
osc_sine = sim.sim_oscillation(n_seconds, fs, osc_freq, cycle='sine')

# Create a times vector for our simulation
times = create_times(n_seconds, fs)

# Plot the simulated data, in the time domain
plot_time_series(times, osc_sine)

###################################################################################################
# Cycle Kernels
# -------------
#
# To simulate oscillations, we can use a sinusoidal kernel, as above, or any of a
# selection of other cycle kernels.
#
# Different kernels represent different shapes and properties that may be useful to
예제 #7
0
# in phase, they will line up exactly (have a high correlation), while at others, when they
# are out of phase, they will have either low or anti-correlation.
#

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

# Simulation settings
n_seconds = 10
fs = 1000

# Define the frequencies for the sinusoids
freq1 = 10
freq2 = 20

# Simulate sinusoids
sig_osc1 = sim_oscillation(n_seconds, fs, freq1)
sig_osc2 = sim_oscillation(n_seconds, fs, freq2)

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

# Compute autocorrelation on the periodic time series
timepoints_osc1, autocorrs_osc1 = compute_autocorr(sig_osc1)
timepoints_osc2, autocorrs_osc2 = compute_autocorr(sig_osc2)

###################################################################################################
# Autocorrelation of a sinusoidal signal
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# The autocorrelation of the first sine wave is plotted below.
#
예제 #8
0
    # time it
    start = time.time()

    # simulate oscillation
    # get random oscillation between frequency ranges
    # osc_freq_rand = random.randint(osc_freq[0], osc_freq[1])
    osc_freq_rand = random.choice(freq_list)

    # if sinusiod
    asine_or_sine = random.choice(lf_waveform)

    if asine_or_sine == 'sine':

        signal = sim.sim_oscillation(n_seconds,
                                     fs,
                                     osc_freq_rand,
                                     cycle='sine')

        simulation_features['asine_rdsym'][aa] = .5

    elif asine_or_sine == 'asine':

        asine_rdsym = random.choice(lf_rdsym)
        signal = sim.sim_oscillation(n_seconds,
                                     fs,
                                     osc_freq_rand,
                                     cycle='asine',
                                     rdsym=asine_rdsym)

        simulation_features['asine_rdsym'][aa] = asine_rdsym
예제 #9
0
# rhythmic activity.
#

###################################################################################################
# Sinusoidal Signals
# ~~~~~~~~~~~~~~~~~~
#
# There are many different rhythmic signals we could simulate, in terms of different
# rhythmic shapes, and or temporal properties (such as rhythmic bursts). For this
# example, we will stick to simulating continuous sinusoidal signals.
#

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

# Generate an oscillating signal
osc_sig = sim.sim_oscillation(n_seconds, s_rate, freq=10)

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

# Plot the oscillating time series
plot_time_series(times, osc_sig)

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

# Compute the power spectrum of the oscillating signal
freqs, powers = compute_spectrum_welch(osc_sig, s_rate)

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

# Visualize the power spectrum of the oscillating signal
plot_power_spectra(freqs, powers)
예제 #10
0
import matplotlib.pyplot as plt
from neurodsp.sim import sim_oscillation, sim_bursty_oscillation
from neurodsp.utils import set_random_seed
from neurodsp.utils import create_times
from neurodsp.plts.time_series import plot_time_series

time = 1.5
sampling_rate = 100
oscillation_freq = 1
set_random_seed(0)
oscillation_sine = sim_oscillation(time,
                                   sampling_rate,
                                   oscillation_freq,
                                   cycle='sine')
timeSequenceMatrix = create_times(time, sampling_rate)
print("TIME : " + str(len(timeSequenceMatrix)))
print(timeSequenceMatrix)
print("OSCILACION : " + str(len(oscillation_sine)))
print(oscillation_sine)
plt.scatter(timeSequenceMatrix, oscillation_sine)
plt.show()
plot_time_series(timeSequenceMatrix, oscillation_sine)
예제 #11
0
###################################################################################################
#
# Simulate a stationary oscillator
# --------------------------------
#
# In addition to noise, you may also want to simulate an oscillatory process.
# We can do that with neurodsp, with arbitrary rise-decay symmetry.
#

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

# Simulate symmetric oscillator
n_seconds = 1
fs = 1000
osc_freq = 6.6
osc_a = sim.sim_oscillation(n_seconds, fs, osc_freq, cycle='asine', rdsym=.5)
osc_b = sim.sim_oscillation(n_seconds, fs, osc_freq, cycle='asine', rdsym=.2)

# HACK: REMOVE WHEN SIM UPDATED
osc_a = osc_a[0:n_seconds*fs]
osc_b = osc_b[0:n_seconds*fs]

times = create_times(n_seconds, fs)

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

# Plot the simulated data, in the time domain
plot_time_series(times, [osc_a, osc_b], ['rdsym='+str(.5), 'rdsym='+str(.3)])

###################################################################################################
예제 #12
0
fs = 200.  # Hz
n_points = int(n_seconds * fs)

f_beta = (14, 28)
high_fq = 80.0  # Hz; carrier frequency
low_fq = 24.0  # Hz; driver frequency
low_fq_width = 2.0  # Hz

noise_level = 0.25

# Simulate beta-gamma pac
sig_pac = simulate_pac(n_points=n_points, fs=fs, high_fq=high_fq, low_fq=low_fq,
                       low_fq_width=low_fq_width, noise_level=noise_level)

# Simulate 10 Hz spiking which couples to about 60 Hz
spikes = sim_oscillation(n_seconds, fs, 10, cycle='gaussian', std=0.005)
noise = normalize_variance(pink_noise(n_points, slope=1.), variance=.5)
sig_spurious_pac = spikes + noise

# Simulate a sine wave that is the driver frequency
sig_low_fq = sim_oscillation(n_seconds, fs, low_fq)

# Add the sine wave to pink noise to make a control, no pac signal
sig_no_pac = sig_low_fq + noise

####################################################################################################
# Check comodulogram for PAC
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Now, we will use the tools from pactools to compute the comodulogram which
# is a visualization of phase amplitude coupling. The stronger the driver