Skip to content

Commit bd01b61

Browse files
committed
merge udpates from 1.1 doc updates
1 parent 901c9b1 commit bd01b61

File tree

7 files changed

+113
-112
lines changed

7 files changed

+113
-112
lines changed

doc/reference.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ check the `__version__` from Python, using the following code:
7474
.. code-block:: python
7575
7676
# Check the version of the tool
77-
from fooof import __version__ as fooof_version
78-
print('Current fooof version:', fooof_version)
77+
from specparam import __version__ as specparam_version
78+
print('Current specparam version:', specparam_version)
7979
8080
Generating Methods Reports
8181
~~~~~~~~~~~~~~~~~~~~~~~~~~

examples/analyses/plot_dev_demo.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@
3131
import matplotlib.pyplot as plt
3232

3333
# Import the parameterization model objects
34-
from fooof import FOOOF, FOOOFGroup
34+
from specparam import SpectralModel, SpectralGroupModel
3535

3636
# Import useful parameterization related utilities and plot functions
37-
from fooof.bands import Bands
38-
from fooof.analysis import get_band_peak_fg
39-
from fooof.utils import trim_spectrum
40-
from fooof.utils.data import subsample_spectra
41-
from fooof.sim.gen import gen_aperiodic
42-
from fooof.data import FOOOFSettings
43-
from fooof.plts.templates import plot_hist
44-
from fooof.plts.spectra import plot_spectra
45-
from fooof.plts.periodic import plot_peak_fits, plot_peak_params
46-
from fooof.plts.aperiodic import plot_aperiodic_params, plot_aperiodic_fits
37+
from specparam.bands import Bands
38+
from specparam.analysis import get_band_peak_group
39+
from specparam.utils import trim_spectrum
40+
from specparam.utils.data import subsample_spectra
41+
from specparam.sim.gen import gen_aperiodic
42+
from specparam.data import ModelSettings
43+
from specparam.plts.templates import plot_hist
44+
from specparam.plts.spectra import plot_spectra
45+
from specparam.plts.periodic import plot_peak_fits, plot_peak_params
46+
from specparam.plts.aperiodic import plot_aperiodic_params, plot_aperiodic_fits
4747

4848
# Import functions to examine frequency-by-frequency error of model fits
49-
from fooof.analysis.error import compute_pointwise_error_fm, compute_pointwise_error_fg
49+
from specparam.analysis.error import compute_pointwise_error_model, compute_pointwise_error_group
5050

5151
# Import helper utility to access data
52-
from fooof.utils.download import fetch_fooof_data
52+
from specparam.utils.download import fetch_example_data
5353

5454
###################################################################################################
5555
# Access Example Data
@@ -67,8 +67,8 @@
6767
data_path = Path('data')
6868

6969
# Collect the example data
70-
fetch_fooof_data('freqs.csv', data_path, data_url)
71-
fetch_fooof_data('indv.csv', data_path, data_url)
70+
fetch_example_data('freqs.csv', data_path, data_url)
71+
fetch_example_data('indv.csv', data_path, data_url)
7272

7373
###################################################################################################
7474
# Fitting an Individual Power Spectrum
@@ -106,8 +106,8 @@
106106
###################################################################################################
107107

108108
# Initialize a model object for spectral parameterization, with some settings
109-
fm = FOOOF(peak_width_limits=peak_width, max_n_peaks=n_peaks,
110-
min_peak_height=peak_height, verbose=False)
109+
fm = SpectralModel(peak_width_limits=peak_width, max_n_peaks=n_peaks,
110+
min_peak_height=peak_height, verbose=False)
111111

112112
# Fit individual PSD over 3-40 Hz range
113113
fm.report(freqs, spectrum, PSD_range)
@@ -226,7 +226,7 @@
226226
# It can be useful to plot frequency-by-frequency error of the model fit,
227227
# to identify where in frequency space the spectrum is (or is not) being fit well.
228228
# When fitting individual spectrum, this can be accomplished using the
229-
# `compute_pointwise_error_fm` function.
229+
# `compute_pointwise_error_model` function.
230230
#
231231
# In this case, we can see that error fluctuates around 0.05, which is the same as
232232
# the mean absolute error for the model (MAE). There are points in the spectrum where
@@ -237,18 +237,18 @@
237237
###################################################################################################
238238

239239
# Plot frequency-by-frequency error
240-
compute_pointwise_error_fm(fm, plot_errors=True)
240+
compute_pointwise_error_model(fm, plot_errors=True)
241241

242242
###################################################################################################
243243

244244
# Compute the frequency-by-frequency errors
245-
errs_fm = compute_pointwise_error_fm(fm, plot_errors=False, return_errors=True)
245+
errs_fm = compute_pointwise_error_model(fm, plot_errors=False, return_errors=True)
246246

247247
###################################################################################################
248248

249249
# Note that the average of this error is the same as the global error stored
250250
print('Average freq-by-freq error:\t {:1.3f}'.format(np.mean(errs_fm)))
251-
print('FOOOF model fit error: \t\t {:1.3f}'.format(fm.error_))
251+
print('Total model fit error: \t\t {:1.3f}'.format(fm.error_))
252252

253253
###################################################################################################
254254
# Fitting a Group of Power Spectra
@@ -265,8 +265,8 @@
265265
###################################################################################################
266266

267267
# Collect the example data
268-
fetch_fooof_data('freqs.csv', data_path, data_url)
269-
fetch_fooof_data('eop.csv', data_path, data_url)
268+
fetch_example_data('freqs.csv', data_path, data_url)
269+
fetch_example_data('eop.csv', data_path, data_url)
270270

271271
###################################################################################################
272272

@@ -288,8 +288,8 @@
288288
###################################################################################################
289289

290290
# Initialize a model object for spectral parameterization, with some settings
291-
fg = FOOOFGroup(peak_width_limits=peak_width, max_n_peaks=n_peaks,
292-
min_peak_height=peak_height, verbose=False)
291+
fg = SpectralGroupModel(peak_width_limits=peak_width, max_n_peaks=n_peaks,
292+
min_peak_height=peak_height, verbose=False)
293293

294294
# Fit group PSDs over the 3-40 Hz range
295295
fg.fit(freqs, spectra, PSD_range)
@@ -311,7 +311,7 @@
311311
# As with the individual model object, the `get_params` method can be
312312
# used to access model fit attributes.
313313
#
314-
# In addition, here we will use a `Bands` object and the `get_band_peak_fg`
314+
# In addition, here we will use a `Bands` object and the `get_band_peak_group`
315315
# function to organize fit peaks into canonical band ranges.
316316
#
317317

@@ -342,9 +342,9 @@
342342
###################################################################################################
343343

344344
# Extract band-limited peaks information
345-
thetas = get_band_peak_fg(fg, bands.theta)
346-
alphas = get_band_peak_fg(fg, bands.alpha)
347-
betas = get_band_peak_fg(fg, bands.beta)
345+
thetas = get_band_peak_group(fg, bands.theta)
346+
alphas = get_band_peak_group(fg, bands.alpha)
347+
betas = get_band_peak_group(fg, bands.beta)
348348

349349
###################################################################################################
350350
#
@@ -451,13 +451,13 @@
451451
###################################################################################################
452452

453453
# Fit model object with model 1 settings
454-
fg1 = FOOOFGroup(peak_width_limits=m1_peak_width, max_n_peaks=m1_n_peaks,
455-
min_peak_height=m1_peak_height)
454+
fg1 = SpectralGroupModel(peak_width_limits=m1_peak_width, max_n_peaks=m1_n_peaks,
455+
min_peak_height=m1_peak_height)
456456
fg1.fit(m1_freq, m1_spectra)
457457

458458
# Create individual reports for model 1 settings (these could be saved and checked)
459459
for ind in range(len(fg1)):
460-
temp_model = fg1.get_fooof(ind, regenerate=True)
460+
temp_model = fg1.get_model(ind, regenerate=True)
461461

462462
###################################################################################################
463463
#
@@ -467,39 +467,39 @@
467467
###################################################################################################
468468

469469
# Fit model object with model 2 settings
470-
fg2 = FOOOFGroup(peak_width_limits=m2_peak_width, max_n_peaks=m2_n_peaks,
471-
min_peak_height=m2_peak_height)
470+
fg2 = SpectralGroupModel(peak_width_limits=m2_peak_width, max_n_peaks=m2_n_peaks,
471+
min_peak_height=m2_peak_height)
472472
fg2.fit(m2_freq, m2_spectra)
473473

474474
# Create individual reports for model 2 settings (these could be saved and checked)
475475
for ind in range(len(fg2)):
476-
temp_model = fg2.get_fooof(ind, regenerate=True)
476+
temp_model = fg2.get_model(ind, regenerate=True)
477477

478478
###################################################################################################
479479
#
480-
# There are also other ways to manage settings, for example, using the `FOOOFSettings` object.
480+
# There are also other ways to manage settings, for example, using the `ModelSettings` object.
481481
#
482-
# Here we will redefine group model objects (`FOOOFGroup`),
482+
# Here we will redefine group model objects (`SpectralGroupModel`),
483483
# again using different settings for each one.
484484
#
485485

486486
###################################################################################################
487487

488488
# Define settings for model 1
489-
settings1 = FOOOFSettings(peak_width_limits=m1_peak_width, max_n_peaks=m1_n_peaks,
489+
settings1 = ModelSettings(peak_width_limits=m1_peak_width, max_n_peaks=m1_n_peaks,
490490
min_peak_height=m1_peak_height, peak_threshold=2.,
491491
aperiodic_mode='fixed')
492492

493493
# Define settings for model 2
494-
settings2 = FOOOFSettings(peak_width_limits=m2_peak_width, max_n_peaks=m2_n_peaks,
494+
settings2 = ModelSettings(peak_width_limits=m2_peak_width, max_n_peaks=m2_n_peaks,
495495
min_peak_height=m2_peak_height, peak_threshold=2.,
496496
aperiodic_mode='fixed')
497497

498498
###################################################################################################
499499

500500
# Initialize model objects for spectral parameterization, with some settings
501-
fg1 = FOOOFGroup(*settings1)
502-
fg2 = FOOOFGroup(*settings2)
501+
fg1 = SpectralGroupModel(*settings1)
502+
fg2 = SpectralGroupModel(*settings2)
503503

504504
###################################################################################################
505505
#
@@ -545,7 +545,7 @@
545545
worst_fit_ind = np.argmax(fg.get_params('error'))
546546

547547
# Extract this model fit from the group
548-
fm = fg.get_fooof(worst_fit_ind, regenerate=True)
548+
fm = fg.get_model(worst_fit_ind, regenerate=True)
549549

550550
###################################################################################################
551551

@@ -565,7 +565,7 @@
565565
underfit_check = []
566566
for ind, res in enumerate(fg):
567567
if res.error > underfit_error_threshold:
568-
underfit_check.append(fg.get_fooof(ind, regenerate=True))
568+
underfit_check.append(fg.get_model(ind, regenerate=True))
569569

570570
###################################################################################################
571571

@@ -585,7 +585,7 @@
585585
overfit_check = []
586586
for ind, res in enumerate(fg):
587587
if res.error < overfit_error_threshold:
588-
overfit_check.append(fg.get_fooof(ind, regenerate=True))
588+
overfit_check.append(fg.get_model(ind, regenerate=True))
589589

590590
###################################################################################################
591591

@@ -619,7 +619,7 @@
619619
# It can be useful to plot frequency-by-frequency error of the model fit,
620620
# to identify where in frequency space the spectrum is (or is not) being fit well.
621621
# When fitting individual spectrum, this can be accomplished using the
622-
# `compute_pointwise_error_fg` function. When plotting the error, the plot line is
622+
# `compute_pointwise_error_group` function. When plotting the error, the plot line is
623623
# the mean error per frequency, across fits, and the shading indicates the standard deviation
624624
# of the error, also per frequency.
625625
#
@@ -634,12 +634,12 @@
634634
###################################################################################################
635635

636636
# Plot frequency-by-frequency error
637-
compute_pointwise_error_fg(fg, plot_errors=True)
637+
compute_pointwise_error_group(fg, plot_errors=True)
638638

639639
###################################################################################################
640640

641641
# Return the errors - this returns a 2D matrix of errors for all fits
642-
errs_fg = compute_pointwise_error_fg(fg, plot_errors=False, return_errors=True)
642+
errs_fg = compute_pointwise_error_group(fg, plot_errors=False, return_errors=True)
643643

644644
# Check which frequency has the highest error
645645
f_max_err = fg.freqs[np.argmax(np.mean(errs_fg, 0))]

examples/manage/plot_data_exporting.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
###################################################################################################
1212

1313
# Import model objects, and Bands object to define bands of interest
14-
from fooof import FOOOF, FOOOFGroup, Bands
14+
from specparam import SpectralModel, SpectralGroupModel, Bands
1515

1616
# Import simulation functions to create some example data
17-
from fooof.sim import gen_power_spectrum, gen_group_power_spectra
17+
from specparam.sim import sim_power_spectrum, sim_group_power_spectra
1818

1919
###################################################################################################
2020
# Exporting Results
@@ -25,8 +25,8 @@
2525
#
2626
# Note that the main use case of exporting models to pandas DataFrames is for
2727
# analysis across models. If you are just trying to access the model fit results from
28-
# a fit model, you may want the :meth:`~fooof.FOOOF.get_results` and/or
29-
# :meth:`~fooof.FOOOF.get_params` methods.
28+
# a fit model, you may want the :meth:`~specparam.SpectralModel.get_results` and/or
29+
# :meth:`~specparam.SpectralModel.get_params` methods.
3030
#
3131
# Defining Oscillation Bands
3232
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -36,7 +36,7 @@
3636
#
3737
# This means that we need to define some kind of strategy to organize the peak
3838
# parameters across different models. Across these examples, this will include using the
39-
# :class:`~fooof.Bands` object to define oscillations bands of interest.
39+
# :class:`~specparam.Bands` object to define oscillations bands of interest.
4040
#
4141

4242
###################################################################################################
@@ -45,19 +45,20 @@
4545
bands1 = Bands({'alpha' : [7, 14]})
4646

4747
# Initialize model object
48-
fm = FOOOF()
48+
fm = SpectralModel()
4949

5050
###################################################################################################
5151

5252
# Simulate example power spectrum
53-
freqs, powers = gen_power_spectrum([1, 50], [0, 10, 1], [10, 0.25, 2], freq_res=0.25)
53+
freqs, powers = sim_power_spectrum([1, 50], [0, 10, 1], [10, 0.25, 2], freq_res=0.25)
5454

5555
# Fit model to power spectrum
5656
fm.fit(freqs, powers)
5757

5858
###################################################################################################
5959
#
60-
# The :meth:`~fooof.FOOOF.to_df` method supports exporting model fit results to pandas objects.
60+
# The :meth:`~specparam.SpectralModel.to_df` method supports exporting model
61+
# fit results to pandas objects.
6162
#
6263

6364
###################################################################################################
@@ -116,21 +117,21 @@
116117
# In the above, we used the model object to show the basic exporting functionalities.
117118
#
118119
# This functionality is more useful when considering multiple model fits together, such
119-
# as can be done using the :meth:`~fooof.FOOOFGroup.to_df` method from the Group object,
120+
# as can be done using the :meth:`~specparam.SpectralGroupModel.to_df` method from the Group object,
120121
# which allows for exporting DataFrames of organized model fit parameters across power spectra.
121122
#
122123
# As with the above, keep in mind that for some cases you may want the
123-
# :meth:`~fooof.FOOOFGroup.get_results` and/or :meth:`~fooof.FOOOFGroup.get_params` methods
124-
# instead of doing a DataFrame export.
124+
# :meth:`~specparam.SpectralGroupModel.get_results` and/or
125+
# :meth:`~specparam.SpectralGroupModel.get_params` methods instead of doing a DataFrame export.
125126
#
126127

127128
###################################################################################################
128129

129130
# Simulate an example group of power spectra
130-
freqs, powers = gen_group_power_spectra(5, [1, 50], [0, 1], [10, 0.25, 2])
131+
freqs, powers = sim_group_power_spectra(5, [1, 50], [0, 1], [10, 0.25, 2])
131132

132133
# Initialize a group model object and fit power spectra
133-
fg = FOOOFGroup(verbose=False)
134+
fg = SpectralGroupModel(verbose=False)
134135
fg.fit(freqs, powers)
135136

136137
###################################################################################################

0 commit comments

Comments
 (0)