Skip to content

Commit fa3c19a

Browse files
committed
tweaks & udpate to dev demo example
1 parent a95c8bb commit fa3c19a

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

examples/analyses/plot_dev_demo.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from fooof.bands import Bands
3838
from fooof.analysis import get_band_peak_fg
3939
from fooof.utils import trim_spectrum
40+
from fooof.utils.data import subsample_spectra
4041
from fooof.sim.gen import gen_aperiodic
4142
from fooof.data import FOOOFSettings
4243
from fooof.plts.templates import plot_hist
@@ -87,10 +88,6 @@
8788
freqs = np.ravel(pd.read_csv(data_path / "freqs.csv"))
8889
spectrum = np.ravel(pd.read_csv(data_path / "indv.csv"))[1:101]
8990

90-
# Check shapes of loaded data
91-
print(freqs.shape)
92-
print(spectrum.shape)
93-
9491
###################################################################################################
9592
#
9693
# Now that we have loaded the data, we can parameterize our power spectrum!
@@ -161,16 +158,16 @@
161158
###################################################################################################
162159

163160
# 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')
166163

167164
###################################################################################################
168165

169166
# Print out a custom parameter report
170167
template = ("With an error level of {error:1.2f}, specparam fit an exponent "
171168
"of {exponent:1.2f} and peaks of {cfs:s} Hz.")
172169
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]))))
174171

175172
###################################################################################################
176173
#
@@ -275,7 +272,7 @@
275272

276273
# Load csv files containing frequency and power values
277274
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]
279276

280277
###################################################################################################
281278

@@ -362,7 +359,7 @@
362359
###################################################################################################
363360

364361
# 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))
366363
all_bands = [thetas, alphas, betas]
367364
for ax, label, peaks in zip(np.ravel(axes), bands.labels, all_bands):
368365
plot_peak_params(peaks, ax=ax)
@@ -379,7 +376,7 @@
379376
###################################################################################################
380377

381378
# Plot reconstructions of model components
382-
_, axes = plt.subplots(1, 2, figsize=(14,6))
379+
_, axes = plt.subplots(1, 2, figsize=(14, 6))
383380
plot_peak_fits(alphas, ax=axes[0])
384381
plot_aperiodic_fits(aps, fg.freq_range, ax=axes[1])
385382

@@ -405,13 +402,9 @@
405402
# Set random seed
406403
np.random.seed(1)
407404

408-
# Define settings for subsampling a selection of power spectra
405+
# Define settings for & subsample a selection of power spectra
409406
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)
415408

416409
###################################################################################################
417410
#
@@ -526,9 +519,10 @@
526519

527520
###################################################################################################
528521
#
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+
#
532526

533527
###################################################################################################
534528
#

0 commit comments

Comments
 (0)