Skip to content

Commit 86185a2

Browse files
committed
update how ap bounds are managed to fix setting reloading
1 parent ad9eef9 commit 86185a2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

fooof/objs/fit.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,10 @@ def _reset_internal_settings(self):
238238
# Bandwidth limits are given in 2-sided peak bandwidth
239239
# Convert to gaussian std parameter limits
240240
self._gauss_std_limits = tuple([bwl / 2 for bwl in self.peak_width_limits])
241-
# Bounds for aperiodic fitting. Drops bounds on knee parameter if not set to fit knee
242-
self._ap_bounds = self._ap_bounds if self.aperiodic_mode == 'knee' \
243-
else tuple(bound[0::2] for bound in self._ap_bounds)
244241

245242
# Otherwise, assume settings are unknown (have been cleared) and set to None
246243
else:
247244
self._gauss_std_limits = None
248-
self._ap_bounds = None
249245

250246

251247
def _reset_data_results(self, clear_freqs=False, clear_spectrum=False, clear_results=False):
@@ -722,6 +718,10 @@ def _simple_ap_fit(self, freqs, power_spectrum):
722718
np.log10(self.freqs[-1]) - np.log10(self.freqs[0]))
723719
if not self._ap_guess[2] else self._ap_guess[2]]
724720

721+
# Get bounds for aperiodic fitting, dropping knee bound if not set to fit knee
722+
ap_bounds = self._ap_bounds if self.aperiodic_mode == 'knee' \
723+
else tuple(bound[0::2] for bound in self._ap_bounds)
724+
725725
# Collect together guess parameters
726726
guess = np.array([off_guess + kne_guess + exp_guess])
727727

@@ -734,7 +734,7 @@ def _simple_ap_fit(self, freqs, power_spectrum):
734734
warnings.simplefilter("ignore")
735735
aperiodic_params, _ = curve_fit(get_ap_func(self.aperiodic_mode),
736736
freqs, power_spectrum, p0=guess,
737-
maxfev=self._maxfev, bounds=self._ap_bounds)
737+
maxfev=self._maxfev, bounds=ap_bounds)
738738
except RuntimeError:
739739
raise FitError("Model fitting failed due to not finding parameters in "
740740
"the simple aperiodic component fit.")
@@ -779,14 +779,18 @@ def _robust_ap_fit(self, freqs, power_spectrum):
779779
freqs_ignore = freqs[perc_mask]
780780
spectrum_ignore = power_spectrum[perc_mask]
781781

782+
# Get bounds for aperiodic fitting, dropping knee bound if not set to fit knee
783+
ap_bounds = self._ap_bounds if self.aperiodic_mode == 'knee' \
784+
else tuple(bound[0::2] for bound in self._ap_bounds)
785+
782786
# Second aperiodic fit - using results of first fit as guess parameters
783787
# See note in _simple_ap_fit about warnings
784788
try:
785789
with warnings.catch_warnings():
786790
warnings.simplefilter("ignore")
787791
aperiodic_params, _ = curve_fit(get_ap_func(self.aperiodic_mode),
788792
freqs_ignore, spectrum_ignore, p0=popt,
789-
maxfev=self._maxfev, bounds=self._ap_bounds)
793+
maxfev=self._maxfev, bounds=ap_bounds)
790794
except RuntimeError:
791795
raise FitError("Model fitting failed due to not finding "
792796
"parameters in the robust aperiodic fit.")

0 commit comments

Comments
 (0)