77 - They are left available for easy swapping back in, if desired.
88"""
99
10+ from inspect import isfunction
11+
1012import numpy as np
1113
1214from fooof .core .errors import InconsistentDataError
1315
1416###################################################################################################
1517###################################################################################################
1618
17- def gaussian_function (xs , * params ):
19+ def gaussian_function (xs , cf , pw , bw , * params ):
1820 """Gaussian fitting function.
1921
2022 Parameters
2123 ----------
2224 xs : 1d array
2325 Input x-axis values.
26+ cf : float
27+ The center of the gaussian.
28+ pw : float
29+ The height of the gaussian.
30+ bw : float
31+ The width of the gaussian.
2432 *params : float
25- Parameters that define gaussian function .
33+ Additional centers, heights, and widths .
2634
2735 Returns
2836 -------
@@ -32,16 +40,17 @@ def gaussian_function(xs, *params):
3240
3341 ys = np .zeros_like (xs )
3442
43+ params = [cf , pw , bw , * params ]
44+
3545 for ii in range (0 , len (params ), 3 ):
3646
3747 ctr , hgt , wid = params [ii :ii + 3 ]
38-
3948 ys = ys + hgt * np .exp (- (xs - ctr )** 2 / (2 * wid ** 2 ))
4049
4150 return ys
4251
4352
44- def expo_function (xs , * params ):
53+ def expo_function (xs , offset , knee , exp ):
4554 """Exponential fitting function, for fitting aperiodic component with a 'knee'.
4655
4756 NOTE: this function requires linear frequency (not log).
@@ -50,26 +59,32 @@ def expo_function(xs, *params):
5059 ----------
5160 xs : 1d array
5261 Input x-axis values.
53- *params : float
54- Parameters (offset, knee, exp) that define Lorentzian function:
55- y = 10^offset * (1/(knee + x^exp))
62+ offset : float
63+ The y-intercept of the fit.
64+ knee : float
65+ The bend in the fit.
66+ exp : float
67+ The exponential slope of the fit.
5668
5769 Returns
5870 -------
5971 ys : 1d array
6072 Output values for exponential function.
73+
74+ Notes
75+ -----
76+ Parameters (offset, knee, exp) that define Lorentzian function:
77+ y = 10^offset * (1/(knee + x^exp))
6178 """
6279
6380 ys = np .zeros_like (xs )
6481
65- offset , knee , exp = params
66-
6782 ys = ys + offset - np .log10 (knee + xs ** exp )
6883
6984 return ys
7085
7186
72- def expo_nk_function (xs , * params ):
87+ def expo_nk_function (xs , offset , exp ):
7388 """Exponential fitting function, for fitting aperiodic component without a 'knee'.
7489
7590 NOTE: this function requires linear frequency (not log).
@@ -78,34 +93,40 @@ def expo_nk_function(xs, *params):
7893 ----------
7994 xs : 1d array
8095 Input x-axis values.
81- *params : float
82- Parameters (offset, exp) that define Lorentzian function:
83- y = 10^off * (1/(x^exp))
96+ offset : float
97+ The y-intercept of the fit.
98+ exp : float
99+ The exponential slope of the fit.
84100
85101 Returns
86102 -------
87103 ys : 1d array
88104 Output values for exponential function, without a knee.
105+
106+ Notes
107+ -----
108+ Parameters (offset, exp) that define Lorentzian function:
109+ y = 10^off * (1/(x^exp))
89110 """
90111
91112 ys = np .zeros_like (xs )
92113
93- offset , exp = params
94-
95114 ys = ys + offset - np .log10 (xs ** exp )
96115
97116 return ys
98117
99118
100- def linear_function (xs , * params ):
119+ def linear_function (xs , offset , slope ):
101120 """Linear fitting function.
102121
103122 Parameters
104123 ----------
105124 xs : 1d array
106125 Input x-axis values.
107- *params : float
108- Parameters that define linear function.
126+ offset : float
127+ The y-intercept of the fit.
128+ slope : float
129+ The slope of the fit.
109130
110131 Returns
111132 -------
@@ -115,22 +136,24 @@ def linear_function(xs, *params):
115136
116137 ys = np .zeros_like (xs )
117138
118- offset , slope = params
119-
120139 ys = ys + offset + (xs * slope )
121140
122141 return ys
123142
124143
125- def quadratic_function (xs , * params ):
144+ def quadratic_function (xs , offset , slope , curve ):
126145 """Quadratic fitting function.
127146
128147 Parameters
129148 ----------
130149 xs : 1d array
131150 Input x-axis values.
132- *params : float
133- Parameters that define quadratic function.
151+ offset : float
152+ The y-intercept of the fit.
153+ slope : float
154+ The slope of the fit.
155+ curve : float
156+ The curve of the fit.
134157
135158 Returns
136159 -------
@@ -140,8 +163,6 @@ def quadratic_function(xs, *params):
140163
141164 ys = np .zeros_like (xs )
142165
143- offset , slope , curve = params
144-
145166 ys = ys + offset + (xs * slope ) + ((xs ** 2 )* curve )
146167
147168 return ys
@@ -167,7 +188,7 @@ def get_pe_func(periodic_mode):
167188
168189 """
169190
170- if isinstance (periodic_mode , function ):
191+ if isfunction (periodic_mode ):
171192 pe_func = periodic_mode
172193 elif periodic_mode == 'gaussian' :
173194 pe_func = gaussian_function
@@ -196,7 +217,7 @@ def get_ap_func(aperiodic_mode):
196217 If the specified aperiodic mode label is not understood.
197218 """
198219
199- if isinstance (aperiodic_mode , function ):
220+ if isfunction (aperiodic_mode ):
200221 ap_func = aperiodic_mode
201222 elif aperiodic_mode == 'fixed' :
202223 ap_func = expo_nk_function
0 commit comments