Skip to content

Commit 15841f7

Browse files
committed
Move info & index related tools to their own internal file
1 parent 848e242 commit 15841f7

File tree

14 files changed

+93
-84
lines changed

14 files changed

+93
-84
lines changed

fooof/core/info.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Internal functions to manage info related to FOOOF objects."""
2+
3+
def get_obj_desc():
4+
"""Get dictionary specifying FOOOF object names and kind of attributes.
5+
6+
Returns
7+
-------
8+
attibutes : dict
9+
Mapping of FOOOF object attributes, and what kind of data they are.
10+
"""
11+
12+
attributes = {'results' : ['aperiodic_params_', 'peak_params_', 'error_',
13+
'r_squared_', '_gaussian_params'],
14+
'settings' : ['peak_width_limits', 'max_n_peaks', 'min_peak_amplitude',
15+
'peak_threshold', 'aperiodic_mode'],
16+
'data' : ['power_spectrum', 'freq_range', 'freq_res'],
17+
'data_info' : ['freq_range', 'freq_res'],
18+
'arrays' : ['freqs', 'power_spectrum', 'aperiodic_params_',
19+
'peak_params_', '_gaussian_params']}
20+
21+
return attributes
22+
23+
24+
def get_data_indices(aperiodic_mode):
25+
"""Get a dictionary mapping the column labels to indices in FOOOF data (FOOOFResults).
26+
27+
Parameters
28+
----------
29+
aperiodic_mode : {'fixed', 'knee'}
30+
Which approach taken to fit the aperiodic component.
31+
32+
Returns
33+
-------
34+
indices : dict
35+
Mapping for data columns to the column indices in which they appear.
36+
"""
37+
38+
indices = {
39+
'CF' : 0,
40+
'Amp' : 1,
41+
'BW' : 2,
42+
'offset' : 0,
43+
'knee' : 1 if aperiodic_mode == 'knee' else None,
44+
'exponent' : 1 if aperiodic_mode == 'fixed' else 2
45+
}
46+
47+
return indices

fooof/core/io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import json
66
from json import JSONDecodeError
77

8-
from fooof.core.utils import dict_array_to_lst, dict_select_keys, dict_lst_to_array, get_obj_desc
8+
from fooof.core.info import get_obj_desc
9+
from fooof.core.utils import dict_array_to_lst, dict_select_keys, dict_lst_to_array
910

1011
###################################################################################################
1112
###################################################################################################

fooof/core/utils.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -100,53 +100,6 @@ def check_array_dim(arr):
100100
return np.empty([0, 3]) if arr.ndim == 1 else arr
101101

102102

103-
def get_obj_desc():
104-
"""Get dictionary specifying FOOOF object names and kind of attributes.
105-
106-
Returns
107-
-------
108-
attibutes : dict
109-
Mapping of FOOOF object attributes, and what kind of data they are.
110-
"""
111-
112-
attributes = {'results' : ['aperiodic_params_', 'peak_params_', 'error_',
113-
'r_squared_', '_gaussian_params'],
114-
'settings' : ['peak_width_limits', 'max_n_peaks', 'min_peak_amplitude',
115-
'peak_threshold', 'aperiodic_mode'],
116-
'data' : ['power_spectrum', 'freq_range', 'freq_res'],
117-
'data_info' : ['freq_range', 'freq_res'],
118-
'arrays' : ['freqs', 'power_spectrum', 'aperiodic_params_',
119-
'peak_params_', '_gaussian_params']}
120-
121-
return attributes
122-
123-
124-
def get_data_indices(aperiodic_mode):
125-
"""Get a dictionary mapping the column labels to indices in FOOOF data (FOOOFResults).
126-
127-
Parameters
128-
----------
129-
aperiodic_mode : {'fixed', 'knee'}
130-
Which approach taken to fit the aperiodic component.
131-
132-
Returns
133-
-------
134-
indices : dict
135-
Mapping for data columns to the column indices in which they appear.
136-
"""
137-
138-
indices = {
139-
'CF' : 0,
140-
'Amp' : 1,
141-
'BW' : 2,
142-
'offset' : 0,
143-
'knee' : 1 if aperiodic_mode == 'knee' else None,
144-
'exponent' : 1 if aperiodic_mode == 'fixed' else 2
145-
}
146-
147-
return indices
148-
149-
150103
def check_iter(obj, length):
151104
"""Check an object to ensure that it is iterable, and make it iterable if not.
152105

fooof/fit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
from fooof.core.io import save_fm, load_json
4141
from fooof.core.reports import save_report_fm
4242
from fooof.core.funcs import gaussian_function, get_ap_func, infer_ap_func
43-
from fooof.core.utils import group_three, check_array_dim, get_obj_desc
43+
from fooof.core.utils import group_three, check_array_dim
44+
from fooof.core.info import get_obj_desc
4445
from fooof.core.modutils import copy_doc_func_to_method
4546
from fooof.core.strings import gen_settings_str, gen_results_str_fm, gen_issue_str, gen_wid_warn_str
4647

fooof/funcs.py

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

55
from fooof import FOOOFGroup
66
from fooof.synth.gen import gen_freqs
7-
from fooof.utils import get_obj_desc, compare_info
7+
from fooof.utils import compare_info
8+
from fooof.core.info import get_obj_desc
89

910
###################################################################################################
1011
###################################################################################################

fooof/group.py

Lines changed: 1 addition & 1 deletion
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_str_fg
1818
from fooof.core.io import save_fg, load_jsonlines
19-
from fooof.core.utils import get_data_indices
19+
from fooof.core.info import get_data_indices
2020
from fooof.core.modutils import copy_doc_func_to_method, copy_doc_class, safe_import
2121

2222
###################################################################################################

fooof/synth/params.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numpy as np
44

55
from fooof.core.funcs import infer_ap_func
6-
from fooof.core.utils import check_flat, get_data_indices
6+
from fooof.core.utils import check_flat
7+
from fooof.core.info import get_data_indices
78
from fooof.data import SynParams
89

910
###################################################################################################

fooof/tests/test_core_info.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Tests for FOOOF core.info."""
2+
3+
from fooof.core.info import *
4+
5+
###################################################################################################
6+
###################################################################################################
7+
8+
def test_get_obj_desc(tfm):
9+
10+
desc = get_obj_desc()
11+
objs = dir(tfm)
12+
13+
# Test that everything in dict is a valid component of the fooof object
14+
for ke, va in desc.items():
15+
for it in va:
16+
assert it in objs
17+
18+
def test_get_data_indices():
19+
20+
indices_fixed = get_data_indices('fixed')
21+
assert indices_fixed
22+
for ke, va in indices_fixed.items():
23+
if ke == 'knee':
24+
assert not va
25+
else:
26+
assert isinstance(va, int)
27+
28+
indices_knee = get_data_indices('knee')
29+
assert indices_knee
30+
for ke, va in indices_knee.items():
31+
assert isinstance(va, int)

fooof/tests/test_core_io.py

Lines changed: 1 addition & 1 deletion
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.utils import get_obj_desc
7+
from fooof.core.info import get_obj_desc
88

99
from fooof.core.io import *
1010

fooof/tests/test_core_utils.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,6 @@ def test_check_array_dim():
5959
out = check_array_dim(np.array([1, 2, 3]))
6060
assert out.shape == (0, 3)
6161

62-
def test_get_obj_desc():
63-
64-
desc = get_obj_desc()
65-
66-
tfm = FOOOF()
67-
objs = dir(tfm)
68-
69-
# Test that everything in dict is a valid component of the fooof object
70-
for ke, va in desc.items():
71-
for it in va:
72-
assert it in objs
73-
74-
def test_get_data_indices():
75-
76-
indices_fixed = get_data_indices('fixed')
77-
assert indices_fixed
78-
for ke, va in indices_fixed.items():
79-
if ke == 'knee':
80-
assert not va
81-
else:
82-
assert isinstance(va, int)
83-
84-
indices_knee = get_data_indices('knee')
85-
assert indices_knee
86-
for ke, va in indices_knee.items():
87-
assert isinstance(va, int)
88-
8962
def test_check_iter():
9063

9164
# Note: generator case not tested

0 commit comments

Comments
 (0)