Skip to content

Commit 9b51f6d

Browse files
committed
udpate line spacing and settings docs
1 parent 104128c commit 9b51f6d

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

specparam/algorithms/spectral_fit.py

+50-29
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
'min_peak_height' : {
2929
'type' : 'float, optional, default: 0',
3030
'description' : \
31-
'Absolute threshold for detecting peaks.\n ' \
31+
'Absolute threshold for detecting peaks.'
32+
'\n '
3233
'This threshold is defined in absolute units of the power spectrum (log power).',
3334
},
3435
'peak_threshold' : {
3536
'type' : 'float, optional, default: 2.0',
3637
'description' : \
37-
'Relative threshold for detecting peaks.\n ' \
38+
'Relative threshold for detecting peaks.'
39+
'\n '
3840
'Threshold is defined in relative units of the power spectrum (standard deviation).',
3941
},
4042
})
@@ -44,38 +46,47 @@
4446
'ap_percentile_thresh' : {
4547
'type' : 'float',
4648
'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.',
4952
},
5053
'ap_guess' : {
5154
'type' : 'list of float',
5255
'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.'
5764
},
5865
'ap_bounds' : {
5966
'type' : 'tuple of tuple of float',
6067
'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.',
6371
},
6472
'cf_bound' : {
6573
'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.',
6776
},
6877
'bw_std_edge' : {
6978
'type' : 'float',
7079
'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.',
7383
},
7484
'gauss_overlap_thresh' : {
7585
'type' : 'float',
7686
'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.',
7990
},
8091
})
8192

@@ -157,7 +168,8 @@ def _fit(self):
157168
self.data.freqs, *np.ndarray.flatten(self.results.params.gaussian))
158169

159170
# 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
161173

162174
# Run final aperiodic fit on peak-removed power spectrum
163175
self.results.params.aperiodic = self._simple_ap_fit(\
@@ -167,7 +179,8 @@ def _fit(self):
167179

168180
# Create remaining model components: flatspec & full power_spectrum model fit
169181
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
171184

172185
## PARAMETER UPDATES
173186

@@ -255,8 +268,10 @@ def _simple_ap_fit(self, freqs, power_spectrum):
255268
warnings.simplefilter("ignore")
256269
aperiodic_params, _ = curve_fit(self.modes.aperiodic.func, freqs, power_spectrum,
257270
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,
260275
gtol=self._cf_settings.tol)
261276
except RuntimeError as excp:
262277
error_msg = ("Model fitting failed due to not finding parameters in "
@@ -311,8 +326,10 @@ def _robust_ap_fit(self, freqs, power_spectrum):
311326
aperiodic_params, _ = curve_fit(self.modes.aperiodic.func,
312327
freqs_ignore, spectrum_ignore,
313328
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,
316333
gtol=self._cf_settings.tol)
317334
except RuntimeError as excp:
318335
error_msg = ("Model fitting failed due to not finding "
@@ -480,8 +497,10 @@ def _fit_peak_guess(self, flatspec, guess):
480497
p0=np.ndarray.flatten(guess),
481498
bounds=self._get_pe_bounds(guess),
482499
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,
485504
gtol=self._cf_settings.tol)
486505

487506
except RuntimeError as excp:
@@ -614,14 +633,16 @@ def _create_peak_params(self, gaus_params):
614633

615634
# Collect peak parameter data
616635
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]
620640

621641
## TEMP:
622642
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]]
626647

627648
return peak_params

0 commit comments

Comments
 (0)