Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 49 additions & 32 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ Metric Object
Metric
check_metrics

Metric Functions (GoF)
~~~~~~~~~~~~~~~~~~~~~~

.. currentmodule:: specparam.metrics.gof

.. autosummary::
:toctree: generated/

compute_r_squared
compute_adj_r_squared

Metric Functions (Error)
~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -187,16 +198,31 @@ Metric Functions (Error)
compute_root_mean_squared_error
compute_median_abs_error

Metric Functions (GoF)
~~~~~~~~~~~~~~~~~~~~~~
Metric Functions (Pointwise error)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. currentmodule:: specparam.metrics.gof
**Object Inputs**

The following functions take in model objects directly.

.. currentmodule:: specparam.metrics.pointwise

.. autosummary::
:toctree: generated/
:toctree: generated/

compute_r_squared
compute_adj_r_squared
compute_pointwise_error
compute_pointwise_error_group

**Array Inputs**

The following functions operate on arrays of models and data, which may be useful for more custom work-flows.

.. currentmodule:: specparam.metrics.pointwise

.. autosummary::
:toctree: generated/

compute_pointwise_error_arr

Data Objects
------------
Expand Down Expand Up @@ -276,51 +302,42 @@ An object for defining frequency band definitions.

Bands

Measures
--------

Functionality to analyze power spectrum models and the results parameters / components.

Model Errors
~~~~~~~~~~~~

Functions for analyzing the error of model fits.
Parameters
----------

**Object Inputs**
Functionality for working with and converting parameters.

The following functions take in model objects directly.
Converters
~~~~~~~~~~

.. currentmodule:: specparam.measures.pointwise
.. currentmodule:: specparam.params.converter

.. autosummary::
:toctree: generated/

compute_pointwise_error
compute_pointwise_error_group

**Array Inputs**
AperiodicParamConverter
PeriodicParamConverter

The following functions operate on arrays of models and data, which may be useful for more custom work-flows.
Aperiodic Parameters
~~~~~~~~~~~~~~~~~~~~

.. currentmodule:: specparam.measures.pointwise
.. currentmodule:: specparam.params.aperiodic

.. autosummary::
:toctree: generated/

compute_pointwise_error_arr

Parameters
~~~~~~~~~~
compute_knee_frequency
compute_time_constant

Measures & utilities for working with and converting parameters.
Periodic Parameters
~~~~~~~~~~~~~~~~~~~

.. currentmodule:: specparam.measures.params
.. currentmodule:: specparam.params.periodic

.. autosummary::
:toctree: generated/

compute_knee_frequency
compute_time_constant
compute_peak_height

Simulation Code
---------------
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Set project information
project = 'specparam'
copyright = '2018-{}, VoytekLab'.format(date.today().year)
copyright = '2018-{}'.format(date.today().year)
author = 'Thomas Donoghue'

# Get and set the current version number
Expand Down
2 changes: 1 addition & 1 deletion doc/make_doc_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from specparam.sim.gen import gen_power_spectrum
from specparam.plts.utils import check_ax
from specparam.plts.spectra import plot_spectrum
from specparam.utils.download import load_example_data
from specparam.demo.download import load_example_data

###################################################################################################
###################################################################################################
Expand Down
6 changes: 3 additions & 3 deletions examples/analyses/plot_dev_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from specparam.measures.pointwise import compute_pointwise_error, compute_pointwise_error_group

# Import helper utility to access data
from specparam.utils.download import fetch_example_data
from specparam.demo.download import fetch_example_data

###################################################################################################
# Access Example Data
Expand Down Expand Up @@ -302,7 +302,7 @@
###################################################################################################

# Print out the group results and plots of fit parameters
fg.print_results()
fg.print()
fg.plot()

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

# Check results and visualize the extracted model
fm.print_results()
fm.print()
fm.plot()

###################################################################################################
Expand Down
10 changes: 5 additions & 5 deletions examples/customize/plot_custom_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@
class DummyAlgorithm(Algorithm):
"""Dummy object to mimic a fit algorithm."""

def __init__(self, modes=None, data=None, results=None, debug=False):
def __init__(self, modes=None, data=None, results=None, model=None, debug=False):
"""Initialize DummyAlgorithm instance."""

# Initialize base algorithm object with algorithm metadata
super().__init__(
name='dummy_fit_algo',
description='Dummy fit algorithm.',
public_settings=DUMMY_ALGO_SETTINGS,
modes=modes, data=data, results=results, debug=debug)
modes=modes, data=data, results=results, model=None, debug=debug)

def _fit(self):
"""Define the full fitting algorithm."""
Expand All @@ -133,7 +133,7 @@ def _fit(self):
# components (`model.results.model._ap_fit` & `model.results.model._peak_fit`)
#
# If the above you do the above, the model object can be used as normal, and you can do
# (fit / print_results / plot / report / as well as save and load results).
# (fit / print / plot / report / as well as save and load results).
#
# There are also some additional procedures / outputs that a custom fit process may do:
#
Expand Down Expand Up @@ -206,15 +206,15 @@ def _fit(self):
class CustomAlgorithm(Algorithm):
"""Custom fitting algorithm."""

def __init__(self, guess_cf, modes=None, data=None, results=None, debug=False):
def __init__(self, guess_cf, modes=None, data=None, results=None, model=None, debug=False):
"""Initialize DummyAlgorithm instance."""

# Initialize base algorithm object with algorithm metadata
super().__init__(
name='custom_fit_algo',
description='Example custom algorithm.',
public_settings=CUSTOM_ALGO_SETTINGS,
modes=modes, data=data, results=results, debug=debug)
modes=modes, data=data, results=results, model=None, debug=debug)

## Public settings
self.settings.guess_cf = guess_cf
Expand Down
3 changes: 2 additions & 1 deletion examples/customize/plot_custom_param_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from specparam import SpectralModel

from specparam.utils.download import load_example_data
# Import utility to load example data
from specparam.demo import load_example_data

# Import the default set of parameter conversions
from specparam.convert.definitions import check_converters, DEFAULT_CONVERTERS
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 @@ -246,5 +246,5 @@
all_fg = combine_model_objs(fgs)

# Explore the results from across all model fits
all_fg.print_results()
all_fg.print()
all_fg.plot()
18 changes: 9 additions & 9 deletions examples/models/plot_data_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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.data.get_data`: allows for accessing data components
# - :meth:`~specparam.SpectralModel.results.model.get_component`: allows for accessing model components
#

Expand All @@ -86,12 +86,12 @@
###################################################################################################

# Plot the peak removed spectrum data component
plot_spectra(fm.data.freqs, fm.get_data('aperiodic'), color='black')
plot_spectra(fm.data.freqs, fm.data.get_data('aperiodic'), color='black')

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

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

###################################################################################################
Expand All @@ -108,12 +108,12 @@
###################################################################################################

# Plot the flattened spectrum data component
plot_spectra(fm.data.freqs, fm.get_data('peak'), color='black')
plot_spectra(fm.data.freqs, fm.data.get_data('peak'), color='black')

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

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

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

# Plot the peak removed spectrum, with the model aperiodic fit
plot_spectra(fm.data.freqs, [fm.get_data('aperiodic', 'linear'),
plot_spectra(fm.data.freqs, [fm.data.get_data('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.model.get_component('peak', 'linear')],
[fm.data.get_data('peak', 'linear'), fm.results.model.get_component('peak', 'linear')],
colors=['black', 'green'], linestyle=['-', '--'])

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

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

###################################################################################################
Expand Down
4 changes: 3 additions & 1 deletion examples/models/plot_model_component_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

from specparam.utils.array import unlog
from specparam.utils.select import nearest_ind
from specparam.utils.download import load_example_data

# Import utility to load example data
from specparam.demo import load_example_data

# Import function to directly compute peak heights
from specparam.convert.params import compute_peak_height
Expand Down
4 changes: 2 additions & 2 deletions motivations/measurements/plot_BandByBand.py
Original file line number Diff line number Diff line change
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.get_data('peak'), fm_bands_g2.get_data('peak')],
[fm_bands_g1.data.get_data('peak'), fm_bands_g2.data.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.get_data('peak'), fm_pa_g2.get_data('peak')],
[fm_pa_g1.data.get_data('peak'), fm_pa_g2.data.get_data('peak')],
log_powers=False, linewidth=3,
shades=bands.definitions, shade_colors=shade_cols,
labels=labels)
Expand Down
6 changes: 3 additions & 3 deletions tutorials/plot_02-PSDModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from specparam import SpectralModel

# Import a utility to download and load example data
from specparam.utils.download import load_example_data
from specparam.demo import load_example_data

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

Expand Down Expand Up @@ -78,7 +78,7 @@
# The above method 'report', is a convenience method that calls a series of methods:
#
# - :meth:`~specparam.SpectralModel.fit`: fits the power spectrum model
# - :meth:`~specparam.SpectralModel.print_results`: prints out the results
# - :meth:`~specparam.SpectralModel.print`: prints out the results
# - :meth:`~specparam.SpectralModel.plot`: plots the data and model fit
#
# Each of these methods can also be called individually.
Expand All @@ -90,7 +90,7 @@
fm.fit(freqs, spectrum, freq_range)

# After fitting, plotting and parameter fitting can be called independently:
# fm.print_results()
# fm.print()
# fm.plot()

###################################################################################################
Expand Down
Loading
Loading