Skip to content

Commit b14a840

Browse files
committed
Update core.info names
1 parent 23857c0 commit b14a840

File tree

11 files changed

+45
-42
lines changed

11 files changed

+45
-42
lines changed

fooof/core/info.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Internal functions to manage info related to FOOOF objects."""
22

3-
def get_obj_desc():
4-
"""Get dictionary specifying FOOOF object names and kind of attributes.
3+
###################################################################################################
4+
###################################################################################################
5+
6+
def get_description():
7+
"""Get dictionary specifying FOOOF attributes, and what kind of data they store.
58
69
Returns
710
-------
@@ -24,8 +27,8 @@ def get_obj_desc():
2427
return attributes
2528

2629

27-
def get_data_indices(aperiodic_mode):
28-
"""Get a dictionary mapping the column labels to indices in FOOOF data (FOOOFResults).
30+
def get_indices(aperiodic_mode):
31+
"""Get a dictionary mapping indices of FOOOF params to column labels.
2932
3033
Parameters
3134
----------
@@ -35,7 +38,7 @@ def get_data_indices(aperiodic_mode):
3538
Returns
3639
-------
3740
indices : dict
38-
Mapping for data columns to the column indices in which they appear.
41+
Mapping of the column indices for the FOOOF model fit params.
3942
"""
4043

4144
indices = {

fooof/core/io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
from json import JSONDecodeError
77

8-
from fooof.core.info import get_obj_desc
8+
from fooof.core.info import get_description
99
from fooof.core.utils import dict_array_to_lst, dict_select_keys, dict_lst_to_array
1010

1111
###################################################################################################
@@ -89,7 +89,7 @@ def save_fm(fm, file_name, file_path=None, append=False,
8989

9090
# Set and select which variables to keep. Use a set to drop any potential overlap
9191
# Note that results also saves frequency information to be able to recreate freq vector
92-
attributes = get_obj_desc()
92+
attributes = get_description()
9393
keep = set((attributes['results'] + attributes['meta_data'] if save_results else []) + \
9494
(attributes['settings'] if save_settings else []) + \
9595
(attributes['data'] if save_data else []))
@@ -183,7 +183,7 @@ def load_json(file_name, file_path):
183183
dat = json.loads(file_name.readline())
184184

185185
# Get dictionary of available attributes, and convert specified lists back into arrays
186-
dat = dict_lst_to_array(dat, get_obj_desc()['arrays'])
186+
dat = dict_lst_to_array(dat, get_description()['arrays'])
187187

188188
return dat
189189

fooof/fit.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from fooof.core.reports import save_report_fm
4040
from fooof.core.funcs import gaussian_function, get_ap_func, infer_ap_func
4141
from fooof.core.utils import group_three, check_array_dim
42-
from fooof.core.info import get_obj_desc, get_data_indices
42+
from fooof.core.info import get_description, get_indices
4343
from fooof.core.modutils import copy_doc_func_to_method
4444
from fooof.core.strings import (gen_settings_str, gen_results_fm_str,
4545
gen_issue_str, gen_width_warning_str)
@@ -256,7 +256,7 @@ def add_settings(self, fooof_settings):
256256
A FOOOF data object containing the settings for a FOOOF model.
257257
"""
258258

259-
for setting in get_obj_desc()['settings']:
259+
for setting in get_description()['settings']:
260260
setattr(self, setting, getattr(fooof_settings, setting))
261261

262262
self._check_loaded_settings(fooof_settings._asdict())
@@ -271,7 +271,7 @@ def add_meta_data(self, fooof_meta_data):
271271
A FOOOF meta data object containing meta data information.
272272
"""
273273

274-
for meta_dat in get_obj_desc()['meta_data']:
274+
for meta_dat in get_description()['meta_data']:
275275
setattr(self, meta_dat, getattr(fooof_meta_data, meta_dat))
276276

277277
self._regenerate_freqs()
@@ -449,7 +449,7 @@ def get_settings(self):
449449
Object containing the settings from the current FOOOF object.
450450
"""
451451

452-
return FOOOFSettings(**{key : getattr(self, key) for key in get_obj_desc()['settings']})
452+
return FOOOFSettings(**{key : getattr(self, key) for key in get_description()['settings']})
453453

454454

455455
def get_meta_data(self):
@@ -461,7 +461,7 @@ def get_meta_data(self):
461461
Object containing meta data from the current FOOOF object.
462462
"""
463463

464-
return FOOOFMetaData(**{key : getattr(self, key) for key in get_obj_desc()['meta_data']})
464+
return FOOOFMetaData(**{key : getattr(self, key) for key in get_description()['meta_data']})
465465

466466

467467
def get_params(self, name, col=None):
@@ -492,7 +492,7 @@ def get_params(self, name, col=None):
492492

493493
# If col specified as string, get mapping back to integer
494494
if isinstance(col, str):
495-
col = get_data_indices(self.aperiodic_mode)[col]
495+
col = get_indices(self.aperiodic_mode)[col]
496496

497497
# Extract the request data field from object
498498
out = getattr(self, name + '_')
@@ -521,7 +521,7 @@ def get_results(self):
521521
"""
522522

523523
return FOOOFResults(**{key.strip('_') : getattr(self, key) \
524-
for key in get_obj_desc()['results']})
524+
for key in get_description()['results']})
525525

526526

527527
@copy_doc_func_to_method(plot_fm)
@@ -1028,7 +1028,7 @@ def _check_loaded_results(self, data):
10281028

10291029
# If results loaded, check dimensions of peak parameters
10301030
# This fixes an issue where they end up the wrong shape if they are empty (no peaks)
1031-
if set(get_obj_desc()['results']).issubset(set(data.keys())):
1031+
if set(get_description()['results']).issubset(set(data.keys())):
10321032
self.peak_params_ = check_array_dim(self.peak_params_)
10331033
self.gaussian_params_ = check_array_dim(self.gaussian_params_)
10341034

@@ -1044,10 +1044,10 @@ def _check_loaded_settings(self, data):
10441044

10451045
# If settings not loaded from file, clear from object, so that default
10461046
# settings, which are potentially wrong for loaded data, aren't kept
1047-
if not set(get_obj_desc()['settings']).issubset(set(data.keys())):
1047+
if not set(get_description()['settings']).issubset(set(data.keys())):
10481048

10491049
# Reset all public settings to None
1050-
for setting in get_obj_desc()['settings']:
1050+
for setting in get_description()['settings']:
10511051
setattr(self, setting, None)
10521052

10531053
# Infer whether knee fitting was used, if aperiodic params have been loaded

fooof/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from fooof.core.reports import save_report_fg
1717
from fooof.core.strings import gen_results_fg_str
1818
from fooof.core.io import save_fg, load_jsonlines
19-
from fooof.core.info import get_data_indices
19+
from fooof.core.info import get_indices
2020
from fooof.core.modutils import copy_doc_func_to_method, copy_doc_class, safe_import
2121

2222
###################################################################################################
@@ -221,7 +221,7 @@ def get_params(self, name, col=None):
221221

222222
# If col specified as string, get mapping back to integer
223223
if isinstance(col, str):
224-
col = get_data_indices(self.aperiodic_mode)[col]
224+
col = get_indices(self.aperiodic_mode)[col]
225225

226226
# Pull out the requested data field from the group data
227227
# As a special case, peak_params are pulled out in a way that appends

fooof/sim/params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from fooof.core.funcs import infer_ap_func
66
from fooof.core.utils import check_flat
7-
from fooof.core.info import get_data_indices
7+
from fooof.core.info import get_indices
88
from fooof.data import SimParams
99

1010
###################################################################################################
@@ -45,7 +45,7 @@ def update_sim_ap_params(sim_params, delta, field=None):
4545
delta = list([delta]) if not isinstance(delta, list) else delta
4646

4747
for cur_field, cur_delta in zip(field, delta):
48-
dat_ind = get_data_indices(infer_ap_func(sim_params.aperiodic_params))[cur_field]
48+
dat_ind = get_indices(infer_ap_func(sim_params.aperiodic_params))[cur_field]
4949
ap_params[dat_ind] = ap_params[dat_ind] + cur_delta
5050

5151
new_sim_params = SimParams(ap_params, *sim_params[1:])

fooof/tests/test_core_info.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55
###################################################################################################
66
###################################################################################################
77

8-
def test_get_obj_desc(tfm):
8+
def test_get_description(tfm):
99

10-
desc = get_obj_desc()
10+
desc = get_description()
1111
objs = dir(tfm)
1212

1313
# Test that everything in dict is a valid component of the fooof object
1414
for ke, va in desc.items():
1515
for it in va:
1616
assert it in objs
1717

18-
def test_get_data_indices():
18+
def test_get_indices():
1919

20-
indices_fixed = get_data_indices('fixed')
20+
indices_fixed = get_indices('fixed')
2121
assert indices_fixed
2222
for ke, va in indices_fixed.items():
2323
if ke == 'knee':
2424
assert not va
2525
else:
2626
assert isinstance(va, int)
2727

28-
indices_knee = get_data_indices('knee')
28+
indices_knee = get_indices('knee')
2929
assert indices_knee
3030
for ke, va in indices_knee.items():
3131
assert isinstance(va, int)

fooof/tests/test_core_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pkg_resources as pkg
55

66
from fooof import FOOOF
7-
from fooof.core.info import get_obj_desc
7+
from fooof.core.info import get_description
88

99
from fooof.core.io import *
1010

@@ -142,7 +142,7 @@ def test_load_file_contents():
142142

143143
loaded_data = load_json(file_name, file_path)
144144

145-
desc = get_obj_desc()
145+
desc = get_description()
146146

147147
# Check settings
148148
for setting in desc['settings']:

fooof/tests/test_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tests for the fooof.data."""
22

3-
from fooof.core.info import get_obj_desc
3+
from fooof.core.info import get_description
44

55
from fooof.data import *
66

@@ -13,7 +13,7 @@ def test_fooof_settings():
1313
assert settings
1414

1515
# Check that the object has the correct fields, given the object description
16-
settings_fields = get_obj_desc()['settings']
16+
settings_fields = get_description()['settings']
1717
for field in settings_fields:
1818
getattr(settings, field)
1919
assert True
@@ -24,7 +24,7 @@ def test_fooof_results():
2424
assert results
2525

2626
# Check that the object has the correct fields, given the object description
27-
results_fields = get_obj_desc()['results']
27+
results_fields = get_description()['results']
2828
for field in results_fields:
2929
getattr(results, field.strip('_'))
3030
assert True

fooof/tests/test_fit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from fooof.data import FOOOFSettings, FOOOFMetaData, FOOOFResults
1616
from fooof.sim import gen_power_spectrum
1717
from fooof.core.utils import group_three
18-
from fooof.core.info import get_obj_desc
18+
from fooof.core.info import get_description
1919

2020
from fooof.tests.utils import get_tfm, plot_test
2121

@@ -125,19 +125,19 @@ def test_adds():
125125
# Test adding settings
126126
fooof_settings = FOOOFSettings([1, 4], 6, 0, 2, 'fixed')
127127
tfm.add_settings(fooof_settings)
128-
for setting in get_obj_desc()['settings']:
128+
for setting in get_description()['settings']:
129129
assert getattr(tfm, setting) == getattr(fooof_settings, setting)
130130

131131
# Test adding meta data
132132
fooof_meta_data = FOOOFMetaData([3, 40], 0.5)
133133
tfm.add_meta_data(fooof_meta_data)
134-
for meta_dat in get_obj_desc()['meta_data']:
134+
for meta_dat in get_description()['meta_data']:
135135
assert getattr(tfm, meta_dat) == getattr(fooof_meta_data, meta_dat)
136136

137137
# Test adding results
138138
fooof_results = FOOOFResults([1, 1], [10, 0.5, 0.5], 0.95, 0.02, [10, 0.5, 0.25])
139139
tfm.add_results(fooof_results)
140-
for setting in get_obj_desc()['results']:
140+
for setting in get_description()['results']:
141141
assert getattr(tfm, setting) == getattr(fooof_results, setting.strip('_'))
142142

143143
def test_obj_gets(tfm):
@@ -200,7 +200,7 @@ def test_fooof_resets():
200200
tfm._reset_data_results()
201201
tfm._reset_internal_settings()
202202

203-
desc = get_obj_desc()
203+
desc = get_description()
204204

205205
for data in ['data', 'results', 'model_components']:
206206
for field in desc[data]:
@@ -230,6 +230,6 @@ def raise_runtime_error(*args, **kwargs):
230230
tfm.fit(*gen_power_spectrum([3, 50], [50, 2], [10, 0.5, 2, 20, 0.3, 4]))
231231

232232
# Check after failing out of fit, all results are reset
233-
for result in get_obj_desc()['results']:
233+
for result in get_description()['results']:
234234
cur_res = getattr(tfm, result)
235235
assert cur_res is None or np.all(np.isnan(cur_res))

fooof/tests/test_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from fooof.group import *
1414
from fooof.fit import FOOOFResults
1515
from fooof.sim import gen_group_power_spectra
16-
from fooof.core.info import get_obj_desc
16+
from fooof.core.info import get_description
1717

1818
from fooof.tests.utils import default_group_params, plot_test
1919

@@ -129,7 +129,7 @@ def test_fg_report(skip_if_no_mpl):
129129
def test_fg_get_fooof(tfg):
130130
"""Check return of an individual model fit to a FOOOF object from FOOOFGroup."""
131131

132-
desc = get_obj_desc()
132+
desc = get_description()
133133

134134
# Check without regenerating
135135
tfm0 = tfg.get_fooof(0, False)

0 commit comments

Comments
 (0)