|
37 | 37 | from fooof.bands import Bands |
38 | 38 | from fooof.analysis import get_band_peak_fg |
39 | 39 | from fooof.utils import trim_spectrum |
| 40 | +from fooof.utils.data import subsample_spectra |
40 | 41 | from fooof.sim.gen import gen_aperiodic |
41 | 42 | from fooof.data import FOOOFSettings |
42 | 43 | from fooof.plts.templates import plot_hist |
|
87 | 88 | freqs = np.ravel(pd.read_csv(data_path / "freqs.csv")) |
88 | 89 | spectrum = np.ravel(pd.read_csv(data_path / "indv.csv"))[1:101] |
89 | 90 |
|
90 | | -# Check shapes of loaded data |
91 | | -print(freqs.shape) |
92 | | -print(spectrum.shape) |
93 | | - |
94 | 91 | ################################################################################################### |
95 | 92 | # |
96 | 93 | # Now that we have loaded the data, we can parameterize our power spectrum! |
|
161 | 158 | ################################################################################################### |
162 | 159 |
|
163 | 160 | # Extract specific parameters |
164 | | -exp = fm.get_params('aperiodic_params','exponent') |
165 | | -cfs = fm.get_params('peak_params','CF') |
| 161 | +exp = fm.get_params('aperiodic_params', 'exponent') |
| 162 | +cfs = fm.get_params('peak_params', 'CF') |
166 | 163 |
|
167 | 164 | ################################################################################################### |
168 | 165 |
|
169 | 166 | # Print out a custom parameter report |
170 | 167 | template = ("With an error level of {error:1.2f}, specparam fit an exponent " |
171 | 168 | "of {exponent:1.2f} and peaks of {cfs:s} Hz.") |
172 | 169 | print(template.format(error=err, exponent=exp, |
173 | | - cfs=' & '.join(map(str, [round(CF,2) for CF in cfs])))) |
| 170 | + cfs=' & '.join(map(str, [round(CF, 2) for CF in cfs])))) |
174 | 171 |
|
175 | 172 | ################################################################################################### |
176 | 173 | # |
|
275 | 272 |
|
276 | 273 | # Load csv files containing frequency and power values |
277 | 274 | freqs = np.ravel(pd.read_csv(data_path / "freqs.csv")) |
278 | | -spectra = np.array(pd.read_csv(data_path / "eop.csv"))[:,1:101] |
| 275 | +spectra = np.array(pd.read_csv(data_path / "eop.csv"))[:, 1:101] |
279 | 276 |
|
280 | 277 | ################################################################################################### |
281 | 278 |
|
|
362 | 359 | ################################################################################################### |
363 | 360 |
|
364 | 361 | # Plot the parameters for peaks, split up by band |
365 | | -_, axes = plt.subplots(1, 3, figsize=(14,7)) |
| 362 | +_, axes = plt.subplots(1, 3, figsize=(14, 7)) |
366 | 363 | all_bands = [thetas, alphas, betas] |
367 | 364 | for ax, label, peaks in zip(np.ravel(axes), bands.labels, all_bands): |
368 | 365 | plot_peak_params(peaks, ax=ax) |
|
379 | 376 | ################################################################################################### |
380 | 377 |
|
381 | 378 | # Plot reconstructions of model components |
382 | | -_, axes = plt.subplots(1, 2, figsize=(14,6)) |
| 379 | +_, axes = plt.subplots(1, 2, figsize=(14, 6)) |
383 | 380 | plot_peak_fits(alphas, ax=axes[0]) |
384 | 381 | plot_aperiodic_fits(aps, fg.freq_range, ax=axes[1]) |
385 | 382 |
|
|
405 | 402 | # Set random seed |
406 | 403 | np.random.seed(1) |
407 | 404 |
|
408 | | -# Define settings for subsampling a selection of power spectra |
| 405 | +# Define settings for & subsample a selection of power spectra |
409 | 406 | subsample_frac = 0.10 |
410 | | -n_sample = int(n_subjs * subsample_frac) |
411 | | - |
412 | | -# Select a random selection of spectra to explore |
413 | | -select = np.random.choice(n_subjs, int(n_subjs * subsample_frac), replace=False) |
414 | | -spectra_subsample = spectra[select, :] |
| 407 | +spectra_subsample = subsample_spectra(spectra, subsample_frac) |
415 | 408 |
|
416 | 409 | ################################################################################################### |
417 | 410 | # |
|
526 | 519 |
|
527 | 520 | ################################################################################################### |
528 | 521 | # |
529 | | -# # Print and save subset results and plots of fit parameters, for further examination |
530 | | -# fg1.save_report(file_name='EOP_' + 'fg1_settings', file_path=output_path) |
531 | | -# fg2.save_report(file_name='EOP_' + 'fg2_settings', file_path=output_path) |
| 522 | +# At this point, it may typically be useful to save out reports from the above |
| 523 | +# different model fits (using `.save_report`), such that these different setting regimes |
| 524 | +# can be compared. |
| 525 | +# |
532 | 526 |
|
533 | 527 | ################################################################################################### |
534 | 528 | # |
|
0 commit comments