28
28
'min_peak_height' : {
29
29
'type' : 'float, optional, default: 0' ,
30
30
'description' : \
31
- 'Absolute threshold for detecting peaks.\n ' \
31
+ 'Absolute threshold for detecting peaks.'
32
+ '\n '
32
33
'This threshold is defined in absolute units of the power spectrum (log power).' ,
33
34
},
34
35
'peak_threshold' : {
35
36
'type' : 'float, optional, default: 2.0' ,
36
37
'description' : \
37
- 'Relative threshold for detecting peaks.\n ' \
38
+ 'Relative threshold for detecting peaks.'
39
+ '\n '
38
40
'Threshold is defined in relative units of the power spectrum (standard deviation).' ,
39
41
},
40
42
})
44
46
'ap_percentile_thresh' : {
45
47
'type' : 'float' ,
46
48
'description' : \
47
- 'Percentile threshold, to select points from a flat spectrum for an initial aperiodic fit.\n '
48
- 'Points are selected at a low percentile value to restrict to non-peak points.'
49
+ 'Percentile threshold to select data from flat spectrum for an initial aperiodic fit.'
50
+ '\n '
51
+ 'Points are selected at a low percentile value to restrict to non-peak points.' ,
49
52
},
50
53
'ap_guess' : {
51
54
'type' : 'list of float' ,
52
55
'description' : \
53
- 'Guess parameters for fitting the aperiodic component.\n '
54
- 'The length of the guess parameters should match the number & order of the aperiodic parameters.\n '
55
- 'If \' offset\' is a parameter & guess is None, the first value of the power spectrum is used as the guess.\n '
56
- 'If \' exponent\' is a parameter & guess is None, the abs(log-log slope) of first & last points is used.'
56
+ 'Guess parameters for fitting the aperiodic component.'
57
+ '\n '
58
+ 'The guess parameters should match the length and order of the aperiodic parameters.'
59
+ '\n '
60
+ 'If \' offset\' is a parameter, default guess is the first value of the power spectrum.'
61
+ '\n '
62
+ 'If \' exponent\' is a parameter, '
63
+ 'default guess is the abs(log-log slope) of first & last points.'
57
64
},
58
65
'ap_bounds' : {
59
66
'type' : 'tuple of tuple of float' ,
60
67
'description' : \
61
- 'Bounds for aperiodic fitting, as ((param1_low_bound, ...) (param1_high_bound, ...)).\n '
62
- 'By default, aperiodic fitting is unbound, but can be restricted here.'
68
+ 'Bounds for aperiodic fitting, as ((param1_low_bound, ...) (param1_high_bound, ...)).'
69
+ '\n '
70
+ 'By default, aperiodic fitting is unbound, but can be restricted here.' ,
63
71
},
64
72
'cf_bound' : {
65
73
'type' : 'float' ,
66
- 'description' : 'Parameter bounds for center frequency when fitting gaussians, in terms of +/- std dev.'
74
+ 'description' : \
75
+ 'Parameter bounds for center frequency when fitting gaussians, as +/- std dev.' ,
67
76
},
68
77
'bw_std_edge' : {
69
78
'type' : 'float' ,
70
79
'description' : \
71
- 'Threshold for how far a peak has to be from edge to keep.\n '
72
- 'This is defined in units of gaussian standard deviation.'
80
+ 'Threshold for how far a peak has to be from edge to keep.'
81
+ '\n '
82
+ 'This is defined in units of gaussian standard deviation.' ,
73
83
},
74
84
'gauss_overlap_thresh' : {
75
85
'type' : 'float' ,
76
86
'description' : \
77
- 'Degree of overlap between gaussian guesses for one to be dropped.\n '
78
- 'This is defined in units of gaussian standard deviation.'
87
+ 'Degree of overlap between gaussian guesses for one to be dropped.'
88
+ '\n '
89
+ 'This is defined in units of gaussian standard deviation.' ,
79
90
},
80
91
})
81
92
@@ -157,7 +168,8 @@ def _fit(self):
157
168
self .data .freqs , * np .ndarray .flatten (self .results .params .gaussian ))
158
169
159
170
# Create peak-removed (but not flattened) power spectrum
160
- self .results .model ._spectrum_peak_rm = self .data .power_spectrum - self .results .model ._peak_fit
171
+ self .results .model ._spectrum_peak_rm = \
172
+ self .data .power_spectrum - self .results .model ._peak_fit
161
173
162
174
# Run final aperiodic fit on peak-removed power spectrum
163
175
self .results .params .aperiodic = self ._simple_ap_fit (\
@@ -167,7 +179,8 @@ def _fit(self):
167
179
168
180
# Create remaining model components: flatspec & full power_spectrum model fit
169
181
self .results .model ._spectrum_flat = self .data .power_spectrum - self .results .model ._ap_fit
170
- self .results .model .modeled_spectrum = self .results .model ._peak_fit + self .results .model ._ap_fit
182
+ self .results .model .modeled_spectrum = \
183
+ self .results .model ._peak_fit + self .results .model ._ap_fit
171
184
172
185
## PARAMETER UPDATES
173
186
@@ -255,8 +268,10 @@ def _simple_ap_fit(self, freqs, power_spectrum):
255
268
warnings .simplefilter ("ignore" )
256
269
aperiodic_params , _ = curve_fit (self .modes .aperiodic .func , freqs , power_spectrum ,
257
270
p0 = ap_guess , bounds = self ._settings .ap_bounds ,
258
- maxfev = self ._cf_settings .maxfev , check_finite = False ,
259
- ftol = self ._cf_settings .tol , xtol = self ._cf_settings .tol ,
271
+ maxfev = self ._cf_settings .maxfev ,
272
+ check_finite = False ,
273
+ ftol = self ._cf_settings .tol ,
274
+ xtol = self ._cf_settings .tol ,
260
275
gtol = self ._cf_settings .tol )
261
276
except RuntimeError as excp :
262
277
error_msg = ("Model fitting failed due to not finding parameters in "
@@ -311,8 +326,10 @@ def _robust_ap_fit(self, freqs, power_spectrum):
311
326
aperiodic_params , _ = curve_fit (self .modes .aperiodic .func ,
312
327
freqs_ignore , spectrum_ignore ,
313
328
p0 = popt , bounds = self ._settings .ap_bounds ,
314
- maxfev = self ._cf_settings .maxfev , check_finite = False ,
315
- ftol = self ._cf_settings .tol , xtol = self ._cf_settings .tol ,
329
+ maxfev = self ._cf_settings .maxfev ,
330
+ check_finite = False ,
331
+ ftol = self ._cf_settings .tol ,
332
+ xtol = self ._cf_settings .tol ,
316
333
gtol = self ._cf_settings .tol )
317
334
except RuntimeError as excp :
318
335
error_msg = ("Model fitting failed due to not finding "
@@ -480,8 +497,10 @@ def _fit_peak_guess(self, flatspec, guess):
480
497
p0 = np .ndarray .flatten (guess ),
481
498
bounds = self ._get_pe_bounds (guess ),
482
499
jac = self .modes .periodic .jacobian ,
483
- maxfev = self ._cf_settings .maxfev , check_finite = False ,
484
- ftol = self ._cf_settings .tol , xtol = self ._cf_settings .tol ,
500
+ maxfev = self ._cf_settings .maxfev ,
501
+ check_finite = False ,
502
+ ftol = self ._cf_settings .tol ,
503
+ xtol = self ._cf_settings .tol ,
485
504
gtol = self ._cf_settings .tol )
486
505
487
506
except RuntimeError as excp :
@@ -614,14 +633,16 @@ def _create_peak_params(self, gaus_params):
614
633
615
634
# Collect peak parameter data
616
635
if self .modes .periodic .name == 'gaussian' : ## TEMP
617
- peak_params [ii ] = [peak [0 ],
618
- self .results .model .modeled_spectrum [ind ] - self .results .model ._ap_fit [ind ],
619
- peak [2 ] * 2 ]
636
+ peak_params [ii ] = [\
637
+ peak [0 ],
638
+ self .results .model .modeled_spectrum [ind ] - self .results .model ._ap_fit [ind ],
639
+ peak [2 ] * 2 ]
620
640
621
641
## TEMP:
622
642
if self .modes .periodic .name == 'skewnorm' :
623
- peak_params [ii ] = [peak [0 ],
624
- self .results .model .modeled_spectrum [ind ] - self .results .model ._ap_fit [ind ],
625
- peak [2 ] * 2 , peak [3 ]]
643
+ peak_params [ii ] = [\
644
+ peak [0 ],
645
+ self .results .model .modeled_spectrum [ind ] - self .results .model ._ap_fit [ind ],
646
+ peak [2 ] * 2 , peak [3 ]]
626
647
627
648
return peak_params
0 commit comments