Skip to content

Commit f81ee12

Browse files
authored
[MNT] - Update peak extraction array & describe index column (#197)
* update array mechanics * update docstrings for get_params * update docstrings for get_params
1 parent d21c535 commit f81ee12

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

fooof/objs/fit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,7 @@ def get_params(self, name, col=None):
586586
587587
Notes
588588
-----
589-
For further description of the data you can extract, check the FOOOFResults documentation.
590-
591-
If there is no data on periodic features, this method will return NaN.
589+
If there are no fit peak (no peak parameters), this method will return NaN.
592590
"""
593591

594592
if not self.has_model:

fooof/objs/group.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def get_params(self, name, col=None):
354354
355355
Notes
356356
-----
357-
For further description of the data you can extract, check the FOOOFResults documentation.
357+
When extracting peak information ('peak_params' or 'gaussian_params'), an additional column
358+
is appended to the returned array, indicating the index of the model that the peak came from.
358359
"""
359360

360361
if not self.has_model:
@@ -375,21 +376,18 @@ def get_params(self, name, col=None):
375376
# As a special case, peak_params are pulled out in a way that appends
376377
# an extra column, indicating which FOOOF run each peak comes from
377378
if name in ('peak_params', 'gaussian_params'):
378-
out = np.array([np.insert(getattr(data, name), 3, index, axis=1)
379-
for index, data in enumerate(self.group_results)])
379+
380+
# Collect peak data, appending the index of the model it comes from
381+
out = np.vstack([np.insert(getattr(data, name), 3, index, axis=1)
382+
for index, data in enumerate(self.group_results)])
383+
380384
# This updates index to grab selected column, and the last column
381385
# This last column is the 'index' column (FOOOF object source)
382386
if col is not None:
383387
col = [col, -1]
384388
else:
385389
out = np.array([getattr(data, name) for data in self.group_results])
386390

387-
# Some data can end up as a list of separate arrays
388-
# If so, concatenate it all into one 2d array
389-
if isinstance(out[0], np.ndarray):
390-
out = np.concatenate([arr.reshape(1, len(arr)) \
391-
if arr.ndim == 1 else arr for arr in out], 0)
392-
393391
# Select out a specific column, if requested
394392
if col is not None:
395393
out = out[:, col]

0 commit comments

Comments
 (0)