Skip to content

Commit dd5658d

Browse files
committed
update to use FOOOFRunMode object
1 parent 4b6bf56 commit dd5658d

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

fooof/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Data sub-module for FOOOF."""
22

3-
from .data import FOOOFSettings, FOOOFMetaData, FOOOFResults, SimParams
3+
from .data import FOOOFSettings, FOOOFRunModes, FOOOFMetaData, FOOOFResults, SimParams

fooof/data/data.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ class FOOOFSettings(namedtuple('FOOOFSettings', ['peak_width_limits', 'max_n_pea
3838
__slots__ = ()
3939

4040

41+
class FOOOFRunModes(namedtuple('FOOOFRunModes', ['debug', 'check_freqs', 'check_data'])):
42+
"""Checks performed and errors raised by the model.
43+
44+
Parameters
45+
----------
46+
debug : bool
47+
Whether to run in debug mode.
48+
check_freqs : bool
49+
Whether to run in check freqs mode.
50+
check_data : bool
51+
Whether to run in check data mode.
52+
53+
Notes
54+
-----
55+
This object is a data object, based on a NamedTuple, with immutable data attributes.
56+
"""
57+
__slots__ = ()
58+
59+
4160
class FOOOFMetaData(namedtuple('FOOOFMetaData', ['freq_range', 'freq_res'])):
4261
"""Metadata information about a power spectrum.
4362

fooof/objs/fit.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
from fooof.plts.fm import plot_fm
7979
from fooof.utils.data import trim_spectrum
8080
from fooof.utils.params import compute_gauss_std
81-
from fooof.data import FOOOFResults, FOOOFSettings, FOOOFMetaData
81+
from fooof.data import FOOOFSettings, FOOOFRunModes, FOOOFMetaData, FOOOFResults
8282
from fooof.data.conversions import model_to_dataframe
8383
from fooof.sim.gen import gen_freqs, gen_aperiodic, gen_periodic, gen_model
8484

@@ -575,11 +575,12 @@ def get_run_modes(self):
575575
576576
Returns
577577
-------
578-
data: dict
579-
Dictionary containing the run_modes from the current object.
578+
FOOOFRunModes
579+
Object containing the run modes from the current object.
580580
"""
581581

582-
return {key : getattr(self, key) for key in OBJ_DESC['run_modes']}
582+
return FOOOFRunModes(**{key.strip('_') : getattr(self, key) \
583+
for key in OBJ_DESC['run_modes']})
583584

584585

585586
def get_meta_data(self):

fooof/objs/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def get_fooof(self, ind, regenerate=True):
458458

459459
# Initialize a FOOOF object, with same settings & run modes as current FOOOFGroup
460460
fm = FOOOF(*self.get_settings(), verbose=self.verbose)
461-
fm.set_run_modes(*self.get_run_modes().values())
461+
fm.set_run_modes(*self.get_run_modes())
462462

463463
# Add data for specified single power spectrum, if available
464464
# The power spectrum is inverted back to linear, as it is re-logged when added to FOOOF
@@ -496,7 +496,7 @@ def get_group(self, inds):
496496

497497
# Initialize a new FOOOFGroup object, with same settings and run modes as current FOOOFGroup
498498
fg = FOOOFGroup(*self.get_settings(), verbose=self.verbose)
499-
fg.set_run_modes(*self.get_run_modes().values())
499+
fg.set_run_modes(*self.get_run_modes())
500500

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

fooof/tests/data/test_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ def test_fooof_settings():
1919
for field in OBJ_DESC['settings']:
2020
assert getattr(settings, field)
2121

22+
def test_fooof_run_modes():
23+
24+
run_modes = FOOOFRunModes(True, True, True)
25+
assert run_modes
26+
27+
for field in OBJ_DESC['run_modes']:
28+
assert getattr(run_modes, field.strip('_'))
29+
2230
def test_fooof_meta_data():
2331

2432
meta_data = FOOOFMetaData([1, 50], 0.5)

0 commit comments

Comments
 (0)