Skip to content

Commit 0cd815f

Browse files
committed
get_params col -> field
1 parent d90f945 commit 0cd815f

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

specparam/data/utils.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
###################################################################################################
66
###################################################################################################
77

8-
def _get_params_helper(modes, name, col):
8+
def _get_params_helper(modes, name, field):
99
"""Helper function for get_*_params functions."""
1010

1111
# Allow for shortcut alias, without adding `_params`
1212
if name in ['aperiodic', 'peak', 'gaussian']:
1313
name = name + '_params'
1414

15-
# If col specified as string, get mapping back to integer
16-
if isinstance(col, str):
15+
# If field specified as string, get mapping back to integer
16+
if isinstance(field, str):
1717
if 'aperiodic' in name:
18-
col = modes.aperiodic.params.indices[col.lower()]
18+
field = modes.aperiodic.params.indices[field.lower()]
1919
if 'peak' in name or 'gaussian' in name:
20-
col = modes.periodic.params.indices[col.lower()]
20+
field = modes.periodic.params.indices[field.lower()]
2121

22-
return name, col
22+
return name, field
2323

2424

25-
def get_model_params(fit_results, modes, name, col=None):
25+
def get_model_params(fit_results, modes, name, field=None):
2626
"""Return model fit parameters for specified feature(s).
2727
2828
Parameters
@@ -33,7 +33,7 @@ def get_model_params(fit_results, modes, name, col=None):
3333
Model modes definition.
3434
name : {'aperiodic_params', 'peak_params', 'gaussian_params', 'metrics'}
3535
Name of the data field to extract.
36-
col : str or int, optional
36+
field : str or int, optional
3737
Column name / index to extract from selected data, if requested.
3838
For example, {'CF', 'PW', 'BW'} (periodic) or {'offset', 'knee', 'exponent'} (aperiodic).
3939
@@ -44,31 +44,31 @@ def get_model_params(fit_results, modes, name, col=None):
4444
"""
4545

4646
# Use helper function to sort out name and column selection
47-
name, col = _get_params_helper(modes, name, col)
47+
name, ind = _get_params_helper(modes, name, field)
4848

49-
# Extract the requested data field from object
49+
# Extract the requested data attribute from object
5050
out = getattr(fit_results, name)
5151

5252
# Periodic values can be empty arrays and if so, replace with NaN array
5353
if isinstance(out, np.ndarray) and out.size == 0:
5454
out = np.array([np.nan] * modes.periodic.n_params)
5555

5656
# Select out a specific column, if requested
57-
if col is not None:
57+
if ind is not None:
5858

5959
if name == 'metrics':
60-
out = out[col]
60+
out = out[ind]
6161

6262
else:
6363

6464
# Extract column, & if result is a single value in an array, unpack from array
65-
out = out[col] if out.ndim == 1 else out[:, col]
65+
out = out[ind] if out.ndim == 1 else out[:, ind]
6666
out = out[0] if isinstance(out, np.ndarray) and out.size == 1 else out
6767

6868
return out
6969

7070

71-
def get_group_params(group_results, modes, name, col=None):
71+
def get_group_params(group_results, modes, name, field=None):
7272
"""Extract a specified set of parameters from a set of group results.
7373
7474
Parameters
@@ -79,7 +79,7 @@ def get_group_params(group_results, modes, name, col=None):
7979
Model modes definition.
8080
name : {'aperiodic_params', 'peak_params', 'gaussian_params', 'error', 'r_squared'}
8181
Name of the data field to extract across the group.
82-
col : str or int, optional
82+
field : str or int, optional
8383
Column name / index to extract from selected data, if requested.
8484
For example, {'CF', 'PW', 'BW'} (periodic) or {'offset', 'knee', 'exponent'} (aperiodic).
8585
@@ -90,7 +90,7 @@ def get_group_params(group_results, modes, name, col=None):
9090
"""
9191

9292
# Use helper function to sort out name and column selection
93-
name, col = _get_params_helper(modes, name, col)
93+
name, ind = _get_params_helper(modes, name, field)
9494

9595
# Pull out the requested data field from the group data
9696
# As a special case, peak_params are pulled out in a way that appends
@@ -103,18 +103,18 @@ def get_group_params(group_results, modes, name, col=None):
103103

104104
# This updates index to grab selected column, and the last column
105105
# This last column is the 'index' column (model object source)
106-
if col is not None:
107-
col = [col, -1]
106+
if ind is not None:
107+
ind = [ind, -1]
108108
else:
109109
out = np.array([getattr(data, name) for data in group_results])
110110

111111
# Select out a specific column, if requested
112-
if col is not None:
112+
if ind is not None:
113113

114114
if name == 'metrics':
115-
out = np.array([cdict[col] for cdict in out])
115+
out = np.array([cdict[ind] for cdict in out])
116116
else:
117-
out = out[:, col]
117+
out = out[:, ind]
118118

119119
return out
120120

specparam/objs/results.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ def get_component(self, component='full', space='log'):
196196
return output
197197

198198

199-
def get_params(self, name, col=None):
199+
def get_params(self, name, field=None):
200200
"""Return model fit parameters for specified feature(s).
201201
202202
Parameters
203203
----------
204204
name : {'aperiodic_params', 'peak_params', 'gaussian_params', 'error', 'r_squared'}
205205
Name of the data field to extract.
206-
col : {'CF', 'PW', 'BW', 'offset', 'knee', 'exponent'} or int, optional
206+
field : {'CF', 'PW', 'BW', 'offset', 'knee', 'exponent'} or int, optional
207207
Column name / index to extract from selected data, if requested.
208208
Only used for name of {'aperiodic_params', 'peak_params', 'gaussian_params'}.
209209
@@ -225,7 +225,7 @@ def get_params(self, name, col=None):
225225
if not self.has_model:
226226
raise NoModelError("No model fit results are available to extract, can not proceed.")
227227

228-
return get_model_params(self.get_results(), self.modes, name, col)
228+
return get_model_params(self.get_results(), self.modes, name, field)
229229

230230

231231
def _check_loaded_results(self, data):
@@ -422,14 +422,14 @@ def drop(self, inds):
422422
self.group_results[ind] = null_model
423423

424424

425-
def get_params(self, name, col=None):
425+
def get_params(self, name, field=None):
426426
"""Return model fit parameters for specified feature(s).
427427
428428
Parameters
429429
----------
430430
name : {'aperiodic_params', 'peak_params', 'gaussian_params', 'error', 'r_squared'}
431431
Name of the data field to extract across the group.
432-
col : {'CF', 'PW', 'BW', 'offset', 'knee', 'exponent'} or int, optional
432+
field : {'CF', 'PW', 'BW', 'offset', 'knee', 'exponent'} or int, optional
433433
Column name / index to extract from selected data, if requested.
434434
Only used for name of {'aperiodic_params', 'peak_params', 'gaussian_params'}.
435435
@@ -443,7 +443,7 @@ def get_params(self, name, col=None):
443443
NoModelError
444444
If there are no model fit results available.
445445
ValueError
446-
If the input for the `col` input is not understood.
446+
If the input for the `field` input is not understood.
447447
448448
Notes
449449
-----
@@ -454,7 +454,7 @@ def get_params(self, name, col=None):
454454
if not self.has_model:
455455
raise NoModelError("No model fit results are available, can not proceed.")
456456

457-
return get_group_params(self.group_results, self.modes, name, col)
457+
return get_group_params(self.group_results, self.modes, name, field)
458458

459459

460460
class BaseResults2DT(BaseResults2D):
@@ -629,14 +629,14 @@ def get_results(self):
629629
return self.event_time_results
630630

631631

632-
def get_params(self, name, col=None):
632+
def get_params(self, name, field=None):
633633
"""Return model fit parameters for specified feature(s).
634634
635635
Parameters
636636
----------
637637
name : {'aperiodic_params', 'peak_params', 'gaussian_params', 'error', 'r_squared'}
638638
Name of the data field to extract across the group.
639-
col : {'CF', 'PW', 'BW', 'offset', 'knee', 'exponent'} or int, optional
639+
field : {'CF', 'PW', 'BW', 'offset', 'knee', 'exponent'} or int, optional
640640
Column name / index to extract from selected data, if requested.
641641
Only used for name of {'aperiodic_params', 'peak_params', 'gaussian_params'}.
642642
@@ -650,15 +650,15 @@ def get_params(self, name, col=None):
650650
NoModelError
651651
If there are no model fit results available.
652652
ValueError
653-
If the input for the `col` input is not understood.
653+
If the input for the `field` input is not understood.
654654
655655
Notes
656656
-----
657657
When extracting peak information ('peak_params' or 'gaussian_params'), an additional
658658
column is appended to the returned array, indicating the index that the peak came from.
659659
"""
660660

661-
return [get_group_params(gres, self.modes, name, col) for gres in self.event_group_results]
661+
return [get_group_params(gres, self.modes, name, field) for gres in self.event_group_results]
662662

663663

664664
def convert_results(self, bands=None):

0 commit comments

Comments
 (0)