Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
2878076
move model components to sub-object
TomDonoghue Apr 12, 2025
0057188
update BaseModel docs
TomDonoghue Apr 12, 2025
38b6734
modeled_spectrum_ -> modeled_spectrum
TomDonoghue Apr 12, 2025
9bb2331
move ModelComponents
TomDonoghue Apr 12, 2025
3b2c2c0
add ModelParameters object
TomDonoghue Apr 12, 2025
114d20a
update to use results.params
TomDonoghue Apr 13, 2025
c5b8f96
add non-default settings to test objects
TomDonoghue Apr 13, 2025
bb3cee9
extend compare_model_objs
TomDonoghue Apr 13, 2025
9804529
udpate IO tests to be more stringent
TomDonoghue Apr 13, 2025
d9101d4
update add_from_dict to clean up & fix algo settings
TomDonoghue Apr 13, 2025
e0cb026
finish removing _check_loaded_results
TomDonoghue Apr 13, 2025
ab9d696
deprecate results fields / add as property to params
TomDonoghue Apr 13, 2025
e4656d9
bands repr -> str
TomDonoghue Apr 13, 2025
d0b8831
drop trailing underscores
TomDonoghue Apr 13, 2025
23c1346
remove trailing underscores - null
TomDonoghue Apr 13, 2025
d161992
clean up data checks
TomDonoghue Apr 13, 2025
08c8961
sweep for docstrings content
TomDonoghue Apr 13, 2025
eb8d39c
tweak / update SettingsDefinitions
TomDonoghue Apr 14, 2025
e8f83d1
tweak Algorithm object for settings
TomDonoghue Apr 14, 2025
91720a3
add SettingsValues
TomDonoghue Apr 14, 2025
4418e1f
use SettingsValues
TomDonoghue Apr 14, 2025
9803c2f
udpate across code to use algorithm.settings
TomDonoghue Apr 14, 2025
47fef97
update spectral fit settings def dict name
TomDonoghue Apr 14, 2025
ad6c0e0
add private_settings to Algorithm
TomDonoghue Apr 15, 2025
cabf8af
use private settings on spectral fit algorithm object
TomDonoghue Apr 15, 2025
71cd252
update process for peak_width_limits -> gaussian std
TomDonoghue Apr 15, 2025
f751262
drop reset internal settings - no longer used
TomDonoghue Apr 15, 2025
7aaeb42
add clear method to settings values
TomDonoghue Apr 15, 2025
944e812
drop _check_loaded_settings
TomDonoghue Apr 15, 2025
4564872
update algo to use cf settings
TomDonoghue Apr 15, 2025
104128c
lints
TomDonoghue Apr 15, 2025
9b51f6d
udpate line spacing and settings docs
TomDonoghue Apr 15, 2025
edce4ec
add AlgorithmCF object
TomDonoghue Apr 17, 2025
e743691
add algo_cf initialize methods
TomDonoghue Apr 17, 2025
33d0eb0
use algocf initialization for ap
TomDonoghue Apr 17, 2025
6df8eb1
update _get_pe_bounds
TomDonoghue Apr 17, 2025
d96ed69
udpate _fit_peaks for modes
TomDonoghue Apr 17, 2025
6048b8c
update peak tuning for modes
TomDonoghue Apr 17, 2025
736a0be
udpate param conversion to use modes
TomDonoghue Apr 17, 2025
c488888
update / clean up descriptions
TomDonoghue Apr 17, 2025
394a0eb
Merge branch 'main' into resobj
TomDonoghue May 5, 2025
31c2479
Merge branch 'main' into resobj
TomDonoghue May 21, 2025
17c5e27
unpack & update annotated peak search plots
TomDonoghue Oct 8, 2025
6e77fa2
add sort_peaks function
TomDonoghue Oct 8, 2025
eb27bf9
use sort peaks across module
TomDonoghue Oct 8, 2025
de969fe
tweak styling options for plot annotated
TomDonoghue Oct 8, 2025
3d6a7af
add estimate_fwhm
TomDonoghue Oct 8, 2025
dc79fc8
use estimate_fwhm in algorithm
TomDonoghue Oct 8, 2025
533e165
fix doctest example
TomDonoghue Oct 8, 2025
b515ff8
Merge branch 'main' into resobj
TomDonoghue Oct 21, 2025
a345fc2
initial version ComponentParameters
TomDonoghue Oct 25, 2025
943da0b
clean up CParams object
TomDonoghue Oct 25, 2025
9e194c2
add tests for CParams
TomDonoghue Oct 25, 2025
4216bdc
update CParams in MParams
TomDonoghue Oct 25, 2025
4f40090
update Params objs & tests
TomDonoghue Oct 25, 2025
34fee42
update algo for new params mgmt
TomDonoghue Oct 25, 2025
21f278e
update for new params mgmt
TomDonoghue Oct 25, 2025
251ba9c
params objs updates
TomDonoghue Oct 25, 2025
55af156
add get_metrics
TomDonoghue Oct 25, 2025
4dc1abc
Big update: get new param mgmt working
TomDonoghue Oct 25, 2025
6c620f8
add metric resetting which fixes failed fit issue
TomDonoghue Oct 25, 2025
0bd83a8
lints
TomDonoghue Oct 25, 2025
d046c1a
interim fix ups
TomDonoghue Oct 26, 2025
db0a3e9
drop params.fields
TomDonoghue Oct 26, 2025
8188735
add & use modes.components
TomDonoghue Oct 26, 2025
daff533
add ndim info to mode
TomDonoghue Oct 26, 2025
65b5b1e
fix up params mgmt & use in results
TomDonoghue Oct 26, 2025
0ee26d8
update model obj get_params
TomDonoghue Oct 26, 2025
d2a1af4
fix up motivations for udpates
TomDonoghue Oct 26, 2025
b5076d8
update get_metrics functionality
TomDonoghue Oct 26, 2025
76223cc
update / add get_params / get_metrics
TomDonoghue Oct 26, 2025
fcec1d9
make get_metrics return single value if thats the size
TomDonoghue Oct 26, 2025
cc18dec
udpate examples to work with code changes
TomDonoghue Oct 26, 2025
bb61795
update tutorials to work with code changes
TomDonoghue Oct 26, 2025
60539b5
update tests for data utils
TomDonoghue Oct 27, 2025
28e28b3
add check_params to modes
TomDonoghue Oct 27, 2025
e8bf0b8
drop getting metrics from get_*_params
TomDonoghue Oct 27, 2025
386d922
allow for null Modes in Results
TomDonoghue Oct 27, 2025
e0f4a78
fix docstring quirk
TomDonoghue Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ The following functions operate on arrays of peak parameters, which may be usefu
get_band_peak_group_arr
get_highest_peak
threshold_peaks
sort_peaks

Measures
--------
Expand Down
38 changes: 19 additions & 19 deletions examples/analyses/plot_dev_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
###################################################################################################

# Access the model fit parameters & related attributes from the model object
print('Aperiodic parameters: \n', fm.results.aperiodic_params_, '\n')
print('Peak parameters: \n', fm.results.peak_params_, '\n')
print('Number of fit peaks: \n', fm.results.n_peaks_)
print('Aperiodic parameters: \n', fm.results.params.aperiodic.params, '\n')
print('Peak parameters: \n', fm.results.params.periodic.params, '\n')
print('Number of fit peaks: \n', fm.results.n_peaks)

###################################################################################################

Expand All @@ -148,21 +148,21 @@

###################################################################################################

# Extract aperiodic and periodic parameter
aps = fm.get_params('aperiodic_params')
peaks = fm.get_params('peak_params')
# Extract aperiodic and periodic parameters
aps = fm.get_params('aperiodic')
peaks = fm.get_params('peak')

###################################################################################################

# Extract goodness of fit information
err = fm.get_params('metrics', 'error_mae')
r2s = fm.get_params('metrics', 'gof_rsquared')
# Extract specific parameters
exp = fm.get_params('aperiodic', 'exponent')
cfs = fm.get_params('peak', 'CF')

###################################################################################################

# Extract specific parameters
exp = fm.get_params('aperiodic_params', 'exponent')
cfs = fm.get_params('peak_params', 'CF')
# Extract goodness of fit information
err = fm.get_metrics('error')
r2s = fm.get_metrics('gof')

###################################################################################################

Expand Down Expand Up @@ -323,19 +323,19 @@
###################################################################################################

# Extract aperiodic and full periodic parameters
aps = fg.get_params('aperiodic_params')
per = fg.get_params('peak_params')
aps = fg.get_params('aperiodic')
per = fg.get_params('peak')

###################################################################################################

# Extract group fit information
err = fg.get_params('metrics', 'error_mae')
r2s = fg.get_params('metrics', 'gof_rsquared')
err = fg.get_metrics('error')
r2s = fg.get_metrics('gof')

###################################################################################################

# Check the average number of fit peaks, per model
print('Average number of fit peaks: ', np.mean(fg.results.n_peaks_))
print('Average number of fit peaks: ', np.mean(fg.results.n_peaks))

###################################################################################################

Expand Down Expand Up @@ -551,7 +551,7 @@
###################################################################################################

# Find the index of the worst model fit from the group
worst_fit_ind = np.argmax(fg.get_params('metrics', 'error_mae'))
worst_fit_ind = np.argmax(fg.get_metrics('error'))

# Extract this model fit from the group
fm = fg.get_model(worst_fit_ind, regenerate=True)
Expand Down Expand Up @@ -669,7 +669,7 @@
###################################################################################################

# Drop poor model fits based on MAE
fg.results.drop(fg.get_params('metrics', 'error_mae') > 0.10)
fg.results.drop(fg.get_metrics('error', 'mae') > 0.10)

###################################################################################################
# Conclusions
Expand Down
2 changes: 1 addition & 1 deletion examples/analyses/plot_mne_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def check_nans(data, nan_policy='zero'):
###################################################################################################

# Extract aperiodic exponent values
exps = fg.get_params('aperiodic_params', 'exponent')
exps = fg.get_params('aperiodic', 'exponent')

###################################################################################################

Expand Down
14 changes: 7 additions & 7 deletions examples/manage/plot_failed_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
#
# These attributes are:
#
# - ``n_null_`` : the number of model results that are null
# - ``null_inds_`` : the indices of any null model results
# - ``n_null`` : the number of model results that are null
# - ``null_inds`` : the indices of any null model results
#

###################################################################################################

# Check for failed model fits
print('Number of Null models : \t', fg.results.n_null_)
print('Indices of Null models : \t', fg.results.null_inds_)
print('Number of Null models : \t', fg.results.n_null)
print('Indices of Null models : \t', fg.results.null_inds)

###################################################################################################
# Inducing Model Fit Failures
Expand All @@ -86,7 +86,7 @@
###################################################################################################

# Hack the object to induce model failures
fg._maxfev = 50
fg.algorithm._cf_settings.maxfev = 50

###################################################################################################

Expand All @@ -102,8 +102,8 @@
###################################################################################################

# Check how many model fit failures we have failed model fits
print('Number of Null models : \t', fg.results.n_null_)
print('Indices of Null models : \t', fg.results.null_inds_)
print('Number of Null models : \t', fg.results.n_null)
print('Indices of Null models : \t', fg.results.null_inds)

###################################################################################################
# Debug Mode
Expand Down
2 changes: 1 addition & 1 deletion examples/manage/plot_fit_models_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
# Compare the aperiodic exponent results across conditions
for ind, fg in enumerate(fgs):
print("Aperiodic exponent for condition {} is {:1.4f}".format(
ind, np.mean(fg.get_params('aperiodic_params', 'exponent'))))
ind, np.mean(fg.get_params('aperiodic', 'exponent'))))

###################################################################################################
# Managing Model Objects
Expand Down
8 changes: 4 additions & 4 deletions examples/manage/plot_manipulating_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
###################################################################################################

# Drop all model fits above an error threshold
fg.results.drop(fg.get_params('metrics', 'error_mae') > 0.01)
fg.results.drop(fg.get_metrics('error') > 0.01)

###################################################################################################
# Note on Dropped or Failed Fits
Expand All @@ -186,8 +186,8 @@
###################################################################################################

# Check information on null models (dropped models)
print('Number of Null models : \t', fg.results.n_null_)
print('Indices of Null models : \t', fg.results.null_inds_)
print('Number of Null models : \t', fg.results.n_null)
print('Indices of Null models : \t', fg.results.null_inds)

# Despite the dropped model, the total number of models in the object is the same
# This means that the indices are still the same as before dropping models
Expand All @@ -196,7 +196,7 @@
###################################################################################################

# Null models are defined as all NaN (not a number)
for ind in fg.results.null_inds_:
for ind in fg.results.null_inds:
print(fg.results[ind])

###################################################################################################
Expand Down
6 changes: 3 additions & 3 deletions examples/models/plot_aperiodic_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
###################################################################################################

# Check the aperiodic parameters
fm.results.aperiodic_params_
fm.results.params.aperiodic.params

###################################################################################################

Expand Down Expand Up @@ -140,7 +140,7 @@
###################################################################################################

# Check the measured aperiodic parameters
fm.results.aperiodic_params_
fm.results.params.aperiodic.params

###################################################################################################
# Knee Frequency
Expand All @@ -158,7 +158,7 @@
###################################################################################################

# Compute the knee frequency from aperiodic parameters
knee_frequency = compute_knee_frequency(*fm.results.aperiodic_params_[1:])
knee_frequency = compute_knee_frequency(*fm.results.params.aperiodic.params[1:])
print('Knee frequency: ', knee_frequency)

###################################################################################################
Expand Down
18 changes: 9 additions & 9 deletions examples/models/plot_data_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
###################################################################################################

# Plot the power spectrum model from the object
plot_spectra(fm.data.freqs, fm.results.modeled_spectrum_, color='red')
plot_spectra(fm.data.freqs, fm.results.model.modeled_spectrum, color='red')

###################################################################################################
# Isolated Components
Expand All @@ -70,7 +70,7 @@
# To access these components, we can use the following `getter` methods:
#
# - :meth:`~specparam.SpectralModel.get_data`: allows for accessing data components
# - :meth:`~specparam.SpectralModel.results.get_component`: allows for accessing model components
# - :meth:`~specparam.SpectralModel.results.model.get_component`: allows for accessing model components
#

###################################################################################################
Expand All @@ -91,7 +91,7 @@
###################################################################################################

# Plot the peak removed spectrum, with the model aperiodic fit
plot_spectra(fm.data.freqs, [fm.get_data('aperiodic'), fm.results.get_component('aperiodic')],
plot_spectra(fm.data.freqs, [fm.get_data('aperiodic'), fm.results.model.get_component('aperiodic')],
colors=['black', 'blue'], linestyle=['-', '--'])

###################################################################################################
Expand All @@ -113,7 +113,7 @@
###################################################################################################

# Plot the flattened spectrum data with the model peak fit
plot_spectra(fm.data.freqs, [fm.get_data('peak'), fm.results.get_component('peak')],
plot_spectra(fm.data.freqs, [fm.get_data('peak'), fm.results.model.get_component('peak')],
colors=['black', 'green'], linestyle=['-', '--'])

###################################################################################################
Expand All @@ -128,7 +128,7 @@

# Plot the full model fit, as the combination of the aperiodic and peak model components
plot_spectra(fm.data.freqs,
[fm.results.get_component('aperiodic') + fm.results.get_component('peak')],
[fm.results.model.get_component('aperiodic') + fm.results.model.get_component('peak')],
color='red')

###################################################################################################
Expand Down Expand Up @@ -157,7 +157,7 @@

# Plot the peak removed spectrum, with the model aperiodic fit
plot_spectra(fm.data.freqs, [fm.get_data('aperiodic', 'linear'),
fm.results.get_component('aperiodic', 'linear')],
fm.results.model.get_component('aperiodic', 'linear')],
colors=['black', 'blue'], linestyle=['-', '--'])

###################################################################################################
Expand All @@ -171,7 +171,7 @@

# Plot the flattened spectrum data with the model peak fit
plot_spectra(fm.data.freqs,
[fm.get_data('peak', 'linear'), fm.results.get_component('peak', 'linear')],
[fm.get_data('peak', 'linear'), fm.results.model.get_component('peak', 'linear')],
colors=['black', 'green'], linestyle=['-', '--'])

###################################################################################################
Expand Down Expand Up @@ -199,8 +199,8 @@

# Plot the linear model, showing the combination of peak + aperiodic matches the full model
plot_spectra(fm.data.freqs,
[fm.results.get_component('full', 'linear'),
fm.results.get_component('aperiodic', 'linear') + fm.results.get_component('peak', 'linear')],
[fm.results.model.get_component('full', 'linear'),
fm.results.model.get_component('aperiodic', 'linear') + fm.results.model.get_component('peak', 'linear')],
linestyle=['-', 'dashed'], colors=['black', 'red'], alpha=[0.3, 0.75])

###################################################################################################
Expand Down
4 changes: 2 additions & 2 deletions examples/plots/plot_model_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@
###################################################################################################

# Extract the aperiodic parameters for each group
aps1 = fg1.get_params('aperiodic_params')
aps2 = fg2.get_params('aperiodic_params')
aps1 = fg1.get_params('aperiodic')
aps2 = fg2.get_params('aperiodic')

###################################################################################################
# Plotting Aperiodic Parameters
Expand Down
4 changes: 2 additions & 2 deletions examples/sims/plot_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@

# Check the measured exponent values
print("Original exponent value:\t {:1.2f}".format(\
fm1.get_params('aperiodic_params', 'exponent')))
fm1.get_params('aperiodic', 'exponent')))
print("Rotated exponent value:\t{:1.2f}".format(\
fm2.get_params('aperiodic_params', 'exponent')))
fm2.get_params('aperiodic', 'exponent')))

###################################################################################################
# Rotation Related Offset Changes
Expand Down
8 changes: 4 additions & 4 deletions motivations/measurements/plot_BandByBand.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
def compare_exp(fm1, fm2):
"""Compare exponent values."""

exp1 = fm1.get_params('aperiodic_params', 'exponent')
exp2 = fm2.get_params('aperiodic_params', 'exponent')
exp1 = fm1.get_params('aperiodic', 'exponent')
exp2 = fm2.get_params('aperiodic', 'exponent')

return exp1 - exp2

Expand Down Expand Up @@ -203,7 +203,7 @@ def compare_band_pw(fm1, fm2, band_def):

# Plot the power spectra differences
plot_spectra_shading(freqs,
[fm_bands_g1.results._spectrum_flat, fm_bands_g2.results._spectrum_flat],
[fm_bands_g1.get_data('peak'), fm_bands_g2.get_data('peak')],
log_powers=False, linewidth=3,
shades=bands.definitions, shade_colors=shade_cols,
labels=labels)
Expand Down Expand Up @@ -294,7 +294,7 @@ def compare_band_pw(fm1, fm2, band_def):

# Plot the power spectra differences
plot_spectra_shading(freqs,
[fm_pa_g1.results._spectrum_flat, fm_pa_g2.results._spectrum_flat],
[fm_pa_g1.get_data('peak'), fm_pa_g2.get_data('peak')],
log_powers=False, linewidth=3,
shades=bands.definitions, shade_colors=shade_cols,
labels=labels)
Expand Down
Loading