7
7
- They are left available for easy swapping back in, if desired.
8
8
"""
9
9
10
+ from inspect import isfunction
11
+
10
12
import numpy as np
11
13
12
14
from fooof .core .errors import InconsistentDataError
13
15
14
16
###################################################################################################
15
17
###################################################################################################
16
18
17
- def gaussian_function (xs , * params ):
19
+ def gaussian_function (xs , cf , pw , bw , * params ):
18
20
"""Gaussian fitting function.
19
21
20
22
Parameters
21
23
----------
22
24
xs : 1d array
23
25
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.
24
32
*params : float
25
- Parameters that define gaussian function .
33
+ Additional centers, heights, and widths .
26
34
27
35
Returns
28
36
-------
@@ -32,16 +40,17 @@ def gaussian_function(xs, *params):
32
40
33
41
ys = np .zeros_like (xs )
34
42
43
+ params = [cf , pw , bw , * params ]
44
+
35
45
for ii in range (0 , len (params ), 3 ):
36
46
37
47
ctr , hgt , wid = params [ii :ii + 3 ]
38
-
39
48
ys = ys + hgt * np .exp (- (xs - ctr )** 2 / (2 * wid ** 2 ))
40
49
41
50
return ys
42
51
43
52
44
- def expo_function (xs , * params ):
53
+ def expo_function (xs , offset , knee , exp ):
45
54
"""Exponential fitting function, for fitting aperiodic component with a 'knee'.
46
55
47
56
NOTE: this function requires linear frequency (not log).
@@ -50,26 +59,32 @@ def expo_function(xs, *params):
50
59
----------
51
60
xs : 1d array
52
61
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.
56
68
57
69
Returns
58
70
-------
59
71
ys : 1d array
60
72
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))
61
78
"""
62
79
63
80
ys = np .zeros_like (xs )
64
81
65
- offset , knee , exp = params
66
-
67
82
ys = ys + offset - np .log10 (knee + xs ** exp )
68
83
69
84
return ys
70
85
71
86
72
- def expo_nk_function (xs , * params ):
87
+ def expo_nk_function (xs , offset , exp ):
73
88
"""Exponential fitting function, for fitting aperiodic component without a 'knee'.
74
89
75
90
NOTE: this function requires linear frequency (not log).
@@ -78,34 +93,40 @@ def expo_nk_function(xs, *params):
78
93
----------
79
94
xs : 1d array
80
95
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.
84
100
85
101
Returns
86
102
-------
87
103
ys : 1d array
88
104
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))
89
110
"""
90
111
91
112
ys = np .zeros_like (xs )
92
113
93
- offset , exp = params
94
-
95
114
ys = ys + offset - np .log10 (xs ** exp )
96
115
97
116
return ys
98
117
99
118
100
- def linear_function (xs , * params ):
119
+ def linear_function (xs , offset , slope ):
101
120
"""Linear fitting function.
102
121
103
122
Parameters
104
123
----------
105
124
xs : 1d array
106
125
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.
109
130
110
131
Returns
111
132
-------
@@ -115,22 +136,24 @@ def linear_function(xs, *params):
115
136
116
137
ys = np .zeros_like (xs )
117
138
118
- offset , slope = params
119
-
120
139
ys = ys + offset + (xs * slope )
121
140
122
141
return ys
123
142
124
143
125
- def quadratic_function (xs , * params ):
144
+ def quadratic_function (xs , offset , slope , curve ):
126
145
"""Quadratic fitting function.
127
146
128
147
Parameters
129
148
----------
130
149
xs : 1d array
131
150
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.
134
157
135
158
Returns
136
159
-------
@@ -140,8 +163,6 @@ def quadratic_function(xs, *params):
140
163
141
164
ys = np .zeros_like (xs )
142
165
143
- offset , slope , curve = params
144
-
145
166
ys = ys + offset + (xs * slope ) + ((xs ** 2 )* curve )
146
167
147
168
return ys
@@ -167,7 +188,7 @@ def get_pe_func(periodic_mode):
167
188
168
189
"""
169
190
170
- if isinstance (periodic_mode , function ):
191
+ if isfunction (periodic_mode ):
171
192
pe_func = periodic_mode
172
193
elif periodic_mode == 'gaussian' :
173
194
pe_func = gaussian_function
@@ -196,7 +217,7 @@ def get_ap_func(aperiodic_mode):
196
217
If the specified aperiodic mode label is not understood.
197
218
"""
198
219
199
- if isinstance (aperiodic_mode , function ):
220
+ if isfunction (aperiodic_mode ):
200
221
ap_func = aperiodic_mode
201
222
elif aperiodic_mode == 'fixed' :
202
223
ap_func = expo_nk_function
0 commit comments