# Both the :meth:`~fooof.FOOOFGroup.get_group` and :meth:`~fooof.FOOOFGroup.drop` methods
# take an input of the indices of FOOOF model to select or drop.
#
# In both cases, the input can be defined in multiple ways, including directly indicating
# the indices as a list of integers, or boolean masks.
#

###################################################################################################
# Averaging Across Model Fits
# ---------------------------
#
# Finally, let's average across the models in our FOOOFGroup object, to examine
# the average model of the data.
#
# Note that in order to be able to average across individual models, we need to define
# a set of frequency bands to average peaks across. Otherwise, there is no clear way
# to average across all the peaks across all models.
#

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

# Define the periodic band regions to use to average across
#   Since our simulated data only had alpha peaks, we will only define alpha here
bands = Bands({'alpha': [7, 14]})

# Average across individual models fits, specifying bands and an averaging function
afm = average_fg(fg, bands, avg_method='median')

# Plot our average model of the data
afm.plot()
Esempio n. 2
0
#

###################################################################################################
# Plotting Periodic Topographies
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Lets start start by plotting some periodic model parameters.
#
# To do so, we will use to :obj:`~.Bands` object to manage some band
# definitions, and some analysis utilities to extracts peaks from bands of interest.
#

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

# Define frequency bands of interest
bands = Bands({'theta': [3, 7], 'alpha': [7, 14], 'beta': [15, 30]})

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

# Extract alpha peaks
alphas = get_band_peak_fg(fg, bands.alpha)

# Extract the power values from the detected peaks
alpha_pw = alphas[:, 1]

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

# Plot the topography of alpha power
plot_topomap(alpha_pw, raw.info, cmap=cm.viridis, contours=0)

###################################################################################################
Esempio n. 3
0
###################################################################################################
# Periodic Components
# -------------------
#
# First, let's have a look at the periodic components.
#
# To do so, we will use the :obj:`~.Bands` object to store our frequency
# band definitions, which we can then use to sub-select peaks within bands of interest.
#
# We can then plot visualizations of the peak parameters, and the reconstructed fits.
#

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

# Define frequency bands of interest
bands = Bands({'theta': [4, 8], 'alpha': [8, 13], 'beta': [13, 30]})

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

# Extract alpha peaks from each group
g1_alphas = get_band_peak_fg(fg1, bands.alpha)
g2_alphas = get_band_peak_fg(fg2, bands.alpha)

###################################################################################################
# Plotting Peak Parameters
# ~~~~~~~~~~~~~~~~~~~~~~~~
#
# The :func:`~.plot_peak_params` function takes in peak parameters,
# and visualizes them, as:
#
# - Center Frequency on the x-axis
# Analyzing Periodic Components
# -----------------------------
#
# We will start by analyzing the periodic components.
#
# These utilities mostly serve to help organize and extract periodic components,
# for example extracting peaks that fall within defined frequency bands.
#
# This also includes the :class:`~.Bands` object, which is a custom, dictionary-like object,
# that is provided to store frequency band definitions.
#

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

# Define frequency bands of interest
bands = Bands({'theta': [4, 8], 'alpha': [8, 12], 'beta': [15, 30]})

###################################################################################################
# Extracting peaks from FOOOF Objects
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# The :func:`~.get_band_peak_fm` function takes in a
# :class:`~.FOOOF` object and extracts peak(s) from a requested frequency range.
#
# You can optionally specify:
#
# - whether to return one peak from the specified band, in which case the highest peak is
#   returned, or whether to return all peaks from within the band
# - whether to apply a minimum threshold to extract peaks, for example, to extract
#   peaks only above some minimum power threshold
#
Esempio n. 5
0
"""Settings for EEGFOOOF."""

from fooof.bands import Bands

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

# Set paths
DATA_PATH = '/Users/tom/Documents/Data/02-Shared/Voytek_WMData/G2/'
RESULTS_PATH = '../data/'

# Define default band definitions
BANDS = Bands({'alpha': [7, 14]})

# Group index information
YNG_INDS = list(range(14, 31))
OLD_INDS = list(range(0, 14))

# Group colour settings
YNG_COL = "#0d82c1"
OLD_COL = "#239909"

# Group data information
N_LOADS = 3
N_SUBJS = 31
N_TIMES = 3
)

# compute the coherence
coh = conn_spec(data, **kw).astype(np.float32, keep_attrs=True).mean("times")
coh_surr = conn_spec(data_surr, **kw).astype(np.float32,
                                             keep_attrs=True).mean("times")

coh = np.clip(coh - coh_surr.quantile(0.95, "trials"), 0, np.inf)
###############################################################################
# Finding peaks in the spectra
###############################################################################

bands = Bands({
    "theta": [0, 6],
    "alpha": [6, 14],
    "beta": [14, 26],
    "high_beta": [26, 43],
    "gamma": [26, 43],
})

# Number of spectra per roi
n_spectra = w.sizes["trials"]
# Frequency axis
freqs = w.freqs.data
# Frequency range
freq_range = [freqs[0], freqs[-1]]
# ROI names
rois = w.roi.data
# Trial labels
trials = w.trials.data
# Import the Bands object, for managing frequency band definitions
from fooof.bands import Bands

# Imports from NeuroDSP to simulate & plot time series
from neurodsp.sim import sim_powerlaw, set_random_seed
from neurodsp.filt import filter_signal
from neurodsp.plts import plot_time_series
from neurodsp.utils import create_times

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

# Define our bands of interest
bands = Bands({'delta' : [2, 4],
               'theta' : [4, 8],
               'alpha' : [8, 13],
               'beta' : [13, 30],
               'low_gamma' : [30, 50],
               'high_gamma' : [50, 150]})

###################################################################################################
# Simulating Data
# ~~~~~~~~~~~~~~~
#
# We will use simulated data for this example, to create some example aperiodic signals,
# that we can then apply filters to. First, let's simulate some data.
#

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

# Simulation settings
s_rate = 1000
Esempio n. 8
0
# Define band definitions
THETA_BAND = [4, 8]
ALPHA_BAND = [8, 13]
BETA_BAND = [13, 30]

# Alias relative band labels
LOW_BAND = THETA_BAND
MIDDLE_BAND = ALPHA_BAND
HIGH_BAND = BETA_BAND

# Define default aperiodic definition
AP_DEF = [0, 1]

# Define bands
BANDS = Bands({"theta": THETA_BAND, "beta": BETA_BAND, "alpha": ALPHA_BAND})
BAND_LABELS = {"T": "Theta", "A": "Alpha", "B": "Beta"}

# Define ratio
RATIOS = {
    "TBR": ["theta", "beta"],
    "TAR": ["theta", "alpha"],
    "ABR": ["alpha", "beta"]
}

# Define labels & indices
SINGLE_SIM_PARAM_IND = {
    "CF": (0, 0),
    "PW": (0, 1),
    "BW": (0, 2),
    "EXP": (1),
Esempio n. 9
0
import numpy as np
import matplotlib.pyplot as plt

# Import simulation, utility, and plotting tools
from fooof.bands import Bands
from fooof.utils import trim_spectrum
from fooof.sim.gen import gen_power_spectrum
from fooof.sim.utils import set_random_seed
from fooof.plts.spectra import plot_spectrum_shading, plot_spectra_shading

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

# General Settings

# Define band definitions
bands = Bands({'theta': [4, 8], 'beta': [20, 30]})

# Define helper variables for indexing peak data
icf, ipw, ibw = 0, 1, 2

# Plot settings
shade_color = '#0365C0'

###################################################################################################
# Simulating Data
# ~~~~~~~~~~~~~~~
#
# For this example, we will use simulated data. Let's start by simulating a
# a baseline power spectrum.
#
Esempio n. 10
0
# component.
#

###################################################################################################
# Settings
# ~~~~~~~~
#
# First, we can define some settings for this notebook and analysis.
#

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

# Define our frequency bands of interest
bands = Bands({'delta' : [1, 4],
               'theta' : [4, 8],
               'alpha' : [8, 13],
               'beta' : [13, 30],
               'gamma' : [30, 50]})

# Define plot settings
t_settings = {'fontsize' : 24, 'fontweight' : 'bold'}
shade_cols = ['#e8dc35', '#46b870', '#1882d9', '#a218d9', '#e60026']
labels = ['Group-1', 'Group-2']

# General simulation settings
f_range = [1, 50]
nlv = 0

# Define some template strings for reporting
exp_template = "The difference of aperiodic exponent is: \t {:1.2f}"
pw_template = ("The difference of {:5} power is  {: 1.2f}\t"
Esempio n. 11
0
###################################################################################################
# Simulating Data
# ~~~~~~~~~~~~~~~
#
# For this example, we will use simulated data, and consider the example case of
# investigating differences in alpha activity.
#
# We will start by simulating a baseline power spectrum, with an alpha peak, and
# concurrent aperiodic activity. We will also simulate several altered versions of
# this spectrum, each which a change in a specific parameter of the power spectrum.
#

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

# Define our bands of interest
bands = Bands({'alpha': (8, 12)})

# Simulation Settings
nlv = 0
f_res = 0.1
f_range = [3, 35]

# Define baseline parameter values
ap_base = [0, 1.5]
pe_base = [[10, 0.5, 1], [22, 0.2, 2]]

# Define parameters sets with changes in each parameter
pw_diff = [[10, 0.311, 1], [22, 0.2, 2]]
cf_diff = [[11.75, 0.5, 1], [22, 0.2, 2]]
off_diff = [-0.126, 1.5]
exp_diff = [-0.87, 0.75]
Esempio n. 12
0
def get_tbands():
    """Get a bands object, for testing."""

    return Bands({'theta': (4, 8), 'alpha': (8, 12), 'beta': (13, 30)})