################################################################################################### # get_band_peak_group # ~~~~~~~~~~~~~~~~~~~ # # The :func:`get_band_peak_group` function can be used to select peaks within specific # frequency ranges, from across a group of FOOOF fits. # ################################################################################################### # Generate some synthetic power spectra and fit a FOOOFGroup to use freqs, spectra, _ = gen_group_power_spectra( n_spectra=10, freq_range=[3, 40], aperiodic_params=param_sampler([[20, 2], [35, 1.5]]), gauss_params=param_sampler([[], [10, 0.5, 2]])) ################################################################################################### # Fit FOOOF models across the group of synthesized power spectra fg = FOOOFGroup(peak_width_limits=[1, 8], min_peak_height=0.05, max_n_peaks=6, verbose=False) fg.fit(freqs, spectra) ################################################################################################### # Get all alpha oscillations from a FOOOFGroup object alphas = get_band_peak_group(fg.get_all_data('peak_params'), alpha_band,
# which can be used to iterate across parameters. # ################################################################################################### # param_sampler # ~~~~~~~~~~~~~ # # The :func:`param_sampler` function takes a list of parameter options and randomly selects from # the parameters to create each power spectrum. You can optionally specify the # probabilities with which to sample from the parameter options. # ################################################################################################### # Create a sampler to choose from two options for aperiodic parameters ap_opts = param_sampler([[1, 1.25], [1, 1]]) # Create sampler to choose from two options for periodic parameters, and specify probabilities gauss_opts = param_sampler([[10, 0.5, 1], [[10, 0.5, 1], [20, 0.25, 2]]], [0.75, 0.25]) ################################################################################################### # Generate some power spectra, using the param samplers fs, ps, syn_params = gen_group_power_spectra(10, [3, 40], ap_opts, gauss_opts) ################################################################################################### # Plot some of the spectra that were generated plot_spectra(fs, ps[0:4, :], log_powers=True)
# list of possible parameters, and creates an object that randomly samples from # them to generate power spectra. # # If you would like to generate single power spectra, you can use :func:`gen_power_spectrum`, # also in `fooof.synth.gen`. # ################################################################################################### # Settings for synthesizing power spectra n_spectra = 10 f_range = [3, 40] # Set some options for background parameters # Generated spectra will have an offset of either [20, 50, 35], and exponent of [2., 2.5, 1.5] ap_opts = param_sampler([[20, 2], [50, 2.5], [35, 1.5]]) # Set some options for peak parameters # Generated power spectra will have either no peaks, a 10 Hz peak, or a 10 Hz & 20 Hz peak gauss_opts = param_sampler([[], [10, 0.5, 2], [10, 0.5, 2, 20, 0.3, 4]]) ################################################################################################### # # We can now feed these settings into :func:`gen_group_power_spectra`, # that will generate a group of power spectra for us. # # Note that this function also returns a list of the parameters # used to generate each power spectrum. # ###################################################################################################
################################################################################################### import numpy as np # FOOOF imports from fooof import FOOOFGroup from fooof.funcs import fit_fooof_group_3d, combine_fooofs from fooof.synth.gen import gen_group_power_spectra from fooof.synth.params import param_sampler ################################################################################################### # Settings for creating synthetic data n_spectra = 10 freq_range = [3, 40] ap_opts = param_sampler([[0, 1.0], [0, 1.5], [0, 2]]) gauss_opts = param_sampler([[], [10, 1, 1], [10, 1, 1, 20, 2, 1]]) ################################################################################################### # Generate some synthetic power spectra, and organize into a 3D matrix spectra = [] for ind in range(3): fs, ps, _ = gen_group_power_spectra(n_spectra, freq_range, ap_opts, gauss_opts) spectra.append(ps) spectra = np.array(spectra) ################################################################################################### # Check the shape of the spectra # This kind of 3D organization can be thought to represent [n_conditions, n_channels, n_freqs]