Skip to content

Commit c5c9736

Browse files
committed
update set check modes
1 parent 560ba17 commit c5c9736

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

fooof/objs/fit.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
_debug : bool
4646
Whether the object is set in debug mode.
4747
This should be controlled by using the `set_debug_mode` method.
48-
_check_data : bool
49-
Whether to check added data for NaN or Inf values, and fail out if present.
50-
This should be controlled by using the `set_check_data_mode` method.
48+
_check_data, _check_freqs : bool
49+
Whether to check added inputs for incorrect inputs, failing if present.
50+
Frequency data is checked for linear spacing.
51+
Power values are checked for data for NaN or Inf values.
52+
These modes default to True, and can be controlled with the `set_check_modes` method.
5153
5254
Code Notes
5355
----------
@@ -723,6 +725,24 @@ def set_debug_mode(self, debug):
723725
self._debug = debug
724726

725727

728+
def set_check_modes(self, check_freqs=None, check_data=None):
729+
"""Set check modes, which controls if an error is raised based on check on the inputs.
730+
731+
Parameters
732+
----------
733+
check_freqs : bool, optional
734+
Whether to run in check freqs mode, which checks the frequency data.
735+
check_data : bool, optional
736+
Whether to run in check data mode, which checks the power spectrum values data.
737+
"""
738+
739+
if check_freqs is not None:
740+
self._check_freqs = check_freqs
741+
if check_data is not None:
742+
self._check_data = check_data
743+
744+
745+
# This kept for backwards compatibility, but to be removed in 2.0 in favor of `set_check_modes`
726746
def set_check_data_mode(self, check_data):
727747
"""Set check data mode, which controls if an error is raised if NaN or Inf data are added.
728748
@@ -732,7 +752,7 @@ def set_check_data_mode(self, check_data):
732752
Whether to run in check data mode.
733753
"""
734754

735-
self._check_data = check_data
755+
self.set_check_modes(check_data=check_data)
736756

737757

738758
def to_df(self, peak_org):

fooof/tests/objs/test_fit.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,24 @@ def test_fooof_debug():
414414
with raises(FitError):
415415
tfm.fit(*gen_power_spectrum([3, 50], [50, 2], [10, 0.5, 2, 20, 0.3, 4]))
416416

417-
def test_fooof_check_data():
418-
"""Test FOOOF in with check data mode turned off, including with NaN data."""
417+
def test_fooof_set_check_modes(tfm):
418+
"""Test changing check_modes using set_check_modes, and that checks get turned off.
419+
Note that testing for checks raising errors happens in test_fooof_checks.`"""
419420

420421
tfm = FOOOF(verbose=False)
421422

422-
tfm.set_check_data_mode(False)
423+
tfm.set_check_modes(False, False)
424+
assert tfm._check_freqs is False
423425
assert tfm._check_data is False
424426

425-
# Add data, with check data turned off
426-
# In check data mode, adding data with NaN should run
427-
freqs = gen_freqs([3, 50], 0.5)
427+
# Add bad frequency data, with check freqs turned off
428+
freqs = np.array([1, 2, 4])
429+
powers = np.array([1, 2, 3])
430+
tfm.add_data(freqs, powers)
431+
assert tfm.has_data
432+
433+
# Add bad power values data, with check data turned off
434+
freqs = gen_freqs([3, 30], 1)
428435
powers = np.ones_like(freqs) * np.nan
429436
tfm.add_data(freqs, powers)
430437
assert tfm.has_data
@@ -433,6 +440,11 @@ def test_fooof_check_data():
433440
tfm.fit()
434441
assert not tfm.has_model
435442

443+
# Reset check modes to true
444+
tfm.set_check_modes(True, True)
445+
assert tfm._check_freqs is True
446+
assert tfm._check_data is True
447+
436448
def test_fooof_to_df(tfm, tbands, skip_if_no_pandas):
437449

438450
df1 = tfm.to_df(2)

0 commit comments

Comments
 (0)