Skip to content

Commit 6e817a1

Browse files
authored
Merge pull request #294 from SM-Figueroa/main
Create setters/getters for check modes and fix management
2 parents 825c4a4 + 6a53b35 commit 6e817a1

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

fooof/core/info.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_description():
1717
1818
- results : parameters for and measures of the model
1919
- settings : model settings
20+
- run_modes: checks performed and errors raised
2021
- data : input data
2122
- meta_data : meta data of the inputs
2223
- arrays : data stored in arrays
@@ -29,6 +30,7 @@ def get_description():
2930
'settings' : ['peak_width_limits', 'max_n_peaks',
3031
'min_peak_height', 'peak_threshold',
3132
'aperiodic_mode'],
33+
'run_modes': ['_debug', '_check_freqs', '_check_data'],
3234
'data' : ['power_spectrum', 'freq_range', 'freq_res'],
3335
'meta_data' : ['freq_range', 'freq_res'],
3436
'arrays' : ['freqs', 'power_spectrum', 'aperiodic_params_',

fooof/objs/fit.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def __init__(self, peak_width_limits=(0.5, 12.0), max_n_peaks=np.inf, min_peak_h
201201
# Set default debug mode - controls if an error is raised if model fitting is unsuccessful
202202
self._debug = False
203203
# Set default data checking modes - controls which checks get run on input data
204-
# check_freqs: check the frequency values, and raises an error for uneven spacing
204+
# check_freqs: checks the frequency values, and raises an error for uneven spacing
205205
self._check_freqs = True
206206
# check_data: checks the power values and raises an error for any NaN / Inf values
207207
self._check_data = True
@@ -570,6 +570,19 @@ def get_settings(self):
570570
for key in OBJ_DESC['settings']})
571571

572572

573+
def get_run_modes(self):
574+
"""Return run modes of the current object.
575+
576+
Returns
577+
-------
578+
data: dict
579+
Dictionary containing the run_modes from the current object.
580+
"""
581+
582+
return {key : getattr(self, key) \
583+
for key in OBJ_DESC['run_modes']}
584+
585+
573586
def get_meta_data(self):
574587
"""Return data information from the current object.
575588
@@ -724,7 +737,7 @@ def set_debug_mode(self, debug):
724737

725738
self._debug = debug
726739

727-
740+
728741
def set_check_modes(self, check_freqs=None, check_data=None):
729742
"""Set check modes, which controls if an error is raised based on check on the inputs.
730743
@@ -755,6 +768,23 @@ def set_check_data_mode(self, check_data):
755768
self.set_check_modes(check_data=check_data)
756769

757770

771+
def set_run_modes(self, debug, check_freqs, check_data):
772+
"""Simultaneously set all run modes.
773+
774+
Parameters
775+
----------
776+
debug : bool
777+
Whether to run in debug mode.
778+
check_freqs : bool
779+
Whether to run in check freqs mode.
780+
check_data : bool
781+
Whether to run in check data mode.
782+
"""
783+
784+
self.set_debug_mode(debug)
785+
self.set_check_modes(check_freqs, check_data)
786+
787+
758788
def to_df(self, peak_org):
759789
"""Convert and extract the model results as a pandas object.
760790

fooof/objs/group.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,9 @@ def get_fooof(self, ind, regenerate=True):
456456
The FOOOFResults data loaded into a FOOOF object.
457457
"""
458458

459-
# Initialize a FOOOF object, with same settings & check data mode as current FOOOFGroup
459+
# Initialize a FOOOF object, with same settings & run modes as current FOOOFGroup
460460
fm = FOOOF(*self.get_settings(), verbose=self.verbose)
461-
fm.set_check_modes(self._check_freqs, self._check_data)
462-
fm.set_debug_mode(self._debug)
461+
fm.set_run_modes(*self.get_run_modes().values())
463462

464463
# Add data for specified single power spectrum, if available
465464
# The power spectrum is inverted back to linear, as it is re-logged when added to FOOOF
@@ -495,10 +494,9 @@ def get_group(self, inds):
495494
# Check and convert indices encoding to list of int
496495
inds = check_inds(inds)
497496

498-
# Initialize a new FOOOFGroup object, with same settings as current FOOOFGroup
497+
# Initialize a new FOOOFGroup object, with same settings and run modes as current FOOOFGroup
499498
fg = FOOOFGroup(*self.get_settings(), verbose=self.verbose)
500-
fg.set_check_modes(self._check_freqs, self._check_data)
501-
fg.set_debug_mode(self._debug)
499+
fg.set_run_modes(*self.get_run_modes().values())
502500

503501
# Add data for specified power spectra, if available
504502
# The power spectra are inverted back to linear, as they are re-logged when added to FOOOF

0 commit comments

Comments
 (0)