Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create setters/getters for check modes and fix management #294

Merged
merged 8 commits into from
Jul 23, 2023
2 changes: 2 additions & 0 deletions fooof/core/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def get_description():

- results : parameters for and measures of the model
- settings : model settings
- run_modes: checks performed and errors raised
- data : input data
- meta_data : meta data of the inputs
- arrays : data stored in arrays
Expand All @@ -29,6 +30,7 @@ def get_description():
'settings' : ['peak_width_limits', 'max_n_peaks',
'min_peak_height', 'peak_threshold',
'aperiodic_mode'],
'run_modes': ['_debug', '_check_freqs', '_check_data'],
'data' : ['power_spectrum', 'freq_range', 'freq_res'],
'meta_data' : ['freq_range', 'freq_res'],
'arrays' : ['freqs', 'power_spectrum', 'aperiodic_params_',
Expand Down
34 changes: 32 additions & 2 deletions fooof/objs/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __init__(self, peak_width_limits=(0.5, 12.0), max_n_peaks=np.inf, min_peak_h
# Set default debug mode - controls if an error is raised if model fitting is unsuccessful
self._debug = False
# Set default data checking modes - controls which checks get run on input data
# check_freqs: check the frequency values, and raises an error for uneven spacing
# check_freqs: checks the frequency values, and raises an error for uneven spacing
self._check_freqs = True
# check_data: checks the power values and raises an error for any NaN / Inf values
self._check_data = True
Expand Down Expand Up @@ -570,6 +570,19 @@ def get_settings(self):
for key in OBJ_DESC['settings']})


def get_run_modes(self):
"""Return run modes of the current object.

Returns
-------
data: dict
Dictionary containing the run_modes from the current object.
"""

return {key : getattr(self, key) \
for key in OBJ_DESC['run_modes']}


def get_meta_data(self):
"""Return data information from the current object.

Expand Down Expand Up @@ -724,7 +737,7 @@ def set_debug_mode(self, debug):

self._debug = debug


def set_check_modes(self, check_freqs=None, check_data=None):
"""Set check modes, which controls if an error is raised based on check on the inputs.

Expand Down Expand Up @@ -755,6 +768,23 @@ def set_check_data_mode(self, check_data):
self.set_check_modes(check_data=check_data)


def set_run_modes(self, debug, check_freqs, check_data):
"""Simultaneously set all run modes.

Parameters
----------
debug : bool
Whether to run in debug mode.
check_freqs : bool
Whether to run in check freqs mode.
check_data : bool
Whether to run in check data mode.
"""

self.set_debug_mode(debug)
self.set_check_modes(check_freqs, check_data)


def to_df(self, peak_org):
"""Convert and extract the model results as a pandas object.

Expand Down
10 changes: 4 additions & 6 deletions fooof/objs/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,9 @@ def get_fooof(self, ind, regenerate=True):
The FOOOFResults data loaded into a FOOOF object.
"""

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

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

# Initialize a new FOOOFGroup object, with same settings as current FOOOFGroup
# Initialize a new FOOOFGroup object, with same settings and run modes as current FOOOFGroup
fg = FOOOFGroup(*self.get_settings(), verbose=self.verbose)
fg.set_check_modes(self._check_freqs, self._check_data)
fg.set_debug_mode(self._debug)
fg.set_run_modes(*self.get_run_modes().values())

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