Example #1
0
                                    [6, 0.2, 1, 10, 0.3, 1, 25, 0.15, 3])
ps1, ps2 = ps

###################################################################################################
# The FOOOF plotting module has plots for plotting single or multiple
# power spectra, options for plotting in linear or log space, and
# plots for shading frequency regions of interest.
#
# Plotting in FOOOF uses matplotlib. Plotting functions can also take in any
# matplotlib keyword arguments, that will be passed into the plot call.

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

# Create a spectrum plot with a single power spectrum
plot_spectrum(fs, ps2, log_powers=True)

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

# Plot multiple spectra on the same plot
plot_spectra(fs, ps, log_freqs=True, log_powers=True)

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

# Plot a single power spectrum, with a shaded region covering alpha
plot_spectrum_shading(fs, ps1, [8, 12], log_powers=True)

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

# Plot multiple power spectra, with shades covering theta & beta ranges
plot_spectra_shading(fs, ps, [[4, 8], [20, 30]], log_powers=True)
Example #2
0
# for example, when examining power in particular frequency regions.
#
# The :func:`~.plot_spectra_shading` function takes in a power spectrum and one or more
# shaded regions, and plot the power spectrum with the indicated region shaded.
#
# The same can be done for multiple power spectra with :func:`~.plot_spectra_shading`.
#
# These functions take in an input designating one or more shade regions, each specified
# as [freq_low, freq_high] of the region to shade. They also take in an optional argument
# of `shade_colors` which can be used to control the color(s) of the shade regions.
#

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

# Plot a single power spectrum, with a shaded region covering alpha
plot_spectra_shading(freqs, powers1, [8, 12], log_powers=True)

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

# Plot multiple power spectra, with shades covering theta & beta ranges
plot_spectra_shading(freqs, [powers1, powers2], [[4, 8], [20, 30]],
                     log_powers=True,
                     shade_colors=['green', 'blue'])

###################################################################################################
# Put it all together
# -------------------
#
# Finally, we can put all these plotting tools together.
#
# To do so, note also that all plot functions also take in an optional `ax` argument
Example #3
0
pe_g2 = [[2, 0.5, 1], [6, 0.3, 1], [10, 0.5, 1.5], [20, 0.15, 3], [40, 0.15, 3.5]]

# Set random seed, for consistency generating simulated data
set_random_seed(21)

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

# Simulate example power spectra for each group
freqs, g1_spectrum_bands = gen_power_spectrum(f_range, ap_params, pe_g1, nlv)
freqs, g2_spectrum_bands = gen_power_spectrum(f_range, ap_params, pe_g2, nlv)

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

# Plot the power spectra differences, representing the 'band-by-band' idea
plot_spectra_shading(freqs, [g1_spectrum_bands, g2_spectrum_bands],
                     log_powers=True, linewidth=3,
                     shades=bands.definitions, shade_colors=shade_cols,
                     labels=labels)
plt.xlim(f_range);
plt.title('Band-by-Band', t_settings);

###################################################################################################
# Flatten the Spectra
# ~~~~~~~~~~~~~~~~~~~
#
# Under the band-by-band idea, controlling for aperiodic activity and flattening
# the spectra should show specific differences in each band.
#
# It should also find no systematic difference in the aperiodic activity between groups.
#
# To check this, we can fit power spectrum models, and examine which parameters are
# changing in the data.
Example #4
0
        print('TBR difference from   {:20}   is \t {:1.3f}'.format(\
            label, tbr - calc_band_ratio(freqs, spectrum, bands.theta, bands.beta)))

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

# Create figure of periodic changes
title_settings = {'fontsize': 16, 'fontweight': 'bold'}
fig, axes = plt.subplots(3, 3, figsize=(15, 14))

for ax, (label, spectrum) in zip(axes.flatten(), spectra.items()):

    if spectrum is None: continue

    plot_spectra_shading(freqs, [powers, spectrum], [bands.theta, bands.beta],
                         shade_colors=shade_color,
                         log_freqs=False,
                         log_powers=True,
                         ax=ax)

    ax.set_title(label, **title_settings)
    ax.set_xlim([0, 35])
    ax.set_ylim([-1.75, 0])
    ax.xaxis.label.set_visible(False)
    ax.yaxis.label.set_visible(False)

# Turn off empty axes & space out axes
fig.subplots_adjust(hspace=.3, wspace=.3)
_ = [ax.axis('off') for ax in [axes[0, 0], axes[1, 1]]]

###################################################################################################
#
Example #5
0
# - a change in alpha **power**, part of the periodic component
# - a change in alpha **center frequency**, part of the periodic component
# - a change in the **offset** of the aperiodic component
# - a change in the **exponent** of the aperiodic component
#

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

# Plot and compare all of our power spectra
fig, axes = plt.subplots(2, 2, figsize=(16, 12))
for ax, (title, powers) in zip(axes.reshape(-1), all_powers.items()):

    # Create spectrum plot, with alpha band of interest shaded in
    plot_spectra_shading(freqs, [powers_base, powers],
                         bands.alpha,
                         shade_colors=shade_color,
                         log_freqs=log_freqs,
                         log_powers=log_powers,
                         ax=ax)

    # Add the title, and do some plot styling
    ax.set_title(title, {'fontsize': 20})
    ax.xaxis.label.set_visible(False)
    ax.yaxis.label.set_visible(False)

###################################################################################################
# Comparing Power Spectra
# ~~~~~~~~~~~~~~~~~~~~~~~
#
# Now let's compare our different power spectra, in terms of band-specific power measures.
#
# To do so, we will first define a helper function that calculates the average power in