Skip to content

Commit

Permalink
added lorentzian function
Browse files Browse the repository at this point in the history
  • Loading branch information
thissop committed Apr 1, 2024
1 parent d850f73 commit 170fa1a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
29 changes: 28 additions & 1 deletion specparam/core/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ def gaussian_function(xs, *params):

return ys

def lorentzian_function(xs, *params):
"""Lorentzian fitting function.
Parameters
----------
xs : 1d array
Input x-axis values.
*params : float
Parameters that define a lorentzian function.
Returns
-------
ys : 1d array
Output values for lorentzian function.
"""

ys = np.zeros_like(xs)

for ctr, hgt, wid in zip(*[iter(params)] * 3):

ys = hgt*wid**2/((xs-ctr)**2+wid**2)

return ys

def expo_function(xs, *params):
"""Exponential fitting function, for fitting aperiodic component with a 'knee'.
Expand Down Expand Up @@ -138,7 +161,7 @@ def get_pe_func(periodic_mode):
Parameters
----------
periodic_mode : {'gaussian'}
periodic_mode : {'gaussian','lorentzian'}
Which periodic fitting function to return.
Returns
Expand All @@ -155,6 +178,10 @@ def get_pe_func(periodic_mode):

if periodic_mode == 'gaussian':
pe_func = gaussian_function

elif periodic_mode == 'lorentzian':
pe_func = lorentzian_function

else:
raise ValueError("Requested periodic mode not understood.")

Expand Down
3 changes: 2 additions & 1 deletion specparam/objs/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SpectralModel():
# pylint: disable=attribute-defined-outside-init

def __init__(self, peak_width_limits=(0.5, 12.0), max_n_peaks=np.inf, min_peak_height=0.0,
peak_threshold=2.0, aperiodic_mode='fixed', verbose=True):
peak_threshold=2.0, periodic_mode:str='gaussian', aperiodic_mode='fixed', verbose=True):
"""Initialize model object."""

# Set input settings
Expand All @@ -169,6 +169,7 @@ def __init__(self, peak_width_limits=(0.5, 12.0), max_n_peaks=np.inf, min_peak_h
self.min_peak_height = min_peak_height
self.peak_threshold = peak_threshold
self.aperiodic_mode = aperiodic_mode
self.periodic_mode = periodic_mode
self.verbose = verbose

## PRIVATE SETTINGS
Expand Down

0 comments on commit 170fa1a

Please sign in to comment.