<jupyter_start><jupyter_text>Simulations SetupThis notebook introduces the power spectrum simulations and describes the settings and parameters for them.<jupyter_code>%matplotlib inline
from fooof import FOOOF
from fooof.sim import gen_power_spectrum
from fooof.plts import plot_spectrum
# Import project specific (local) custom code
import sys
sys.path.append('../code')
from settings import *
from utils import print_settings<jupyter_output><empty_output><jupyter_text>Simulate example power spectraFirst, we will simulate a single example power spectrum.<jupyter_code># Simulation settings
ap = [0, 1]
osc = [10, 0.25, 1.5]
nlv = 0.0

# Generate the spectrum
freqs, powers = gen_power_spectrum(F_RANGE, ap, osc, nlv, F_RES)
# Plot example simulated power spectrum
plot_spectrum(freqs, powers, log_powers=True)
# Parameterize our simulated spectrum
fm = FOOOF(aperiodic_mode='fixed', verbose=False)
fm.report(freqs, powers, plt_log=False)
# Compare actual parameters to FOOOF fit
print(ap, '\t', fm.aperiodic_params_)
print(osc, '\t', fm.gaussian_params_)<jupyter_output>[0, 1] 	 [0.00290008 1.00179528]
[10, 0.25, 1.5] 	 [[10.00629043  0.24771999  1.47166652]]<jupyter_text>Simulate another power spectrum, this one with a knee<jupyter_code># Settings
ap = [1, 100, 2]
osc = [10, 0.3, 1]
nlv = 0.

# Simulate the power spectrum
fs, ps = gen_power_spectrum(F_RANGE_LONG, ap, osc, nlv, F_RES_LONG)
# Parameterize the power spectrum
fm = FOOOF(aperiodic_mode='knee', verbose=False)
fm.report(fs, ps, plt_log=True)
# Compare actual parameters to FOOOF fit
print(ap, '\t', fm.aperiodic_params_)
print(osc, '\t', fm.gaussian_params_)<jupyter_output>[1, 100, 2] 	 [  1.00049649 100.04337418   2.00028283]
[10, 0.3, 1] 	 [[10.00018128  0.29916498  0.99465244]]<jupyter_text>Settings for Simulating Power SpectraSettings to be used for simulating power spectra are defined in `code/settings.py`. Here we will check the settings that are being used.<jupyter_code># Check the settings for the number of oscillations
print_settings(N_PEAK_OPTS, N_PEAK_PROBS, '# of oscs')
# Check the settings for the oscillation center frequencies
print_settings(CF_OPTS, CF_PROBS, 'CFs')
# Check the settings for the oscillation powers
print_settings(PW_OPTS, PW_PROBS, 'PWs')
# Check the settings for the oscillation bandwidths
print_settings(BW_OPTS, BW_PROBS, 'BWs')
# Check the settings for the aperiodic offsets
print_settings(OFF_OPTS, OFF_PROBS, 'aperiodic offset')
# Check the settings for the aperiodic knee
print_settings(KNE_OPTS, KNE_PROBS, 'aperiodic knee')
# Check the settings for the aperiodic exponents
print_settings(EXP_OPTS, EXP_PROBS, 'aperiodic exponent')
# Sanity check probabilities are set correctly
for probs in [CF_PROBS, PW_PROBS, BW_PROBS, OFF_PROBS, KNE_PROBS, EXP_PROBS]:
    assert np.isclose(sum(probs), 1, 1e-10)
print('All probabilities check out.')<jupyter_output>All probabilities check out.<jupyter_text>Settings for Spectral ParameterizationCheck the settings used for fitting the power spectra.<jupyter_code># Check the settings used for fitting the smaller frequency range
FOOOF(*FOOOF_SETTINGS).print_settings()
# Check the settings used for fitting across the larger frequency range
FOOOF(*FOOOF_SETTINGS_KNEE).print_settings()<jupyter_output>==================================================================================================
                                                                                                  
                                         FOOOF - SETTINGS                                         
                                                                                                  
                                    Peak Width Limits : [1, 8]                                    
                                     Max Number of Peaks : 6                                      
                                    Minimum Peak Height : 0.1                                     
                                       Peak Threshold: 2.0                                        
                                      Aperiodic Mode : knee                                       
                                                                                                  
==========[...]<jupyter_text>Set up foldersIf you want to run this set of simulations locally, you will need to make sure you have the right set of folders set up for data and figures (as well as using the Github repository structure). To check this, and build the folders if they are needed, you can run the following code.<jupyter_code># Set whether to check and build folders
BUILD_FOLDERS = False
# Check and build folders
if BUILD_FOLDERS:

    import os
    from settings import FOLDER_NAMES

    for folder in ['../data', '../figures']:
        if not os.path.exists(folder):
            os.mkdir(folder)
            for sub_folder in FOLDER_NAMES:
                os.mkdir(os.path.join(folder, sub_folder))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09587670136108888, 'fraction_numerical': 0.03102481985588471, 'mean_word_length': 2.5769506084466713, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '463692', 'license': 'MIT', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1368, 'n_words': 454, 'path': 'notebooks/00-SimulationsSetup.ipynb', 'repo_name': 'TomDonoghue/SIMparam', 'size': '4996'}