Skip to content

Foof.group peak_params documentation doesn't mention additional column that is used as a index #192

Closed
@danieltomasz

Description

@danieltomasz

According to the Sphinx documentation on the fooof page (here and here) the code below should work

from fooof import FOOOFGroup
import pandas as pd
from fooof.sim.gen import gen_freqs, gen_group_power_spectra
n_spectra = 2
freq_range = [3, 40]
ap_params = [[0.5, 1], [1, 1.5]]
pe_params = [[10, 0.4, 1], [10, 0.2, 1, 22, 0.1, 3]]
nlv = 0.02
# Simulate a group of power spectra
freqs, powers, sim_params = gen_group_power_spectra(n_spectra, freq_range, ap_params,
                                            pe_params, nlv, return_params=True)
fg = FOOOFGroup(peak_width_limits=[1, 8],min_peak_height=0.05, max_n_peaks=6)
fg.fit(freqs, powers, freq_range=[3, 40],n_jobs=-1, progress='tqdm')
peaks = fg.get_params('peak_params') # prepare peaks dataframe
peaks_df = pd.DataFrame(peaks)
peaks_df.columns = ['CF', 'PW', 'BW']

Code that doesn't work.

ValueError: Length mismatch: Expected axis has 4 elements, new values have 3 elements

Documentation doesn't mention the additional column used as an index.
I was able to run it by changing it after reading this comment in code documentation

 peaks = fg.get_params('peak_params') # prepare peaks dataframe
 peaks_df = pd.DataFrame(peaks)
 peaks_df.columns = ['CF', 'PW', 'BW', 'index']
 peaks_df['index'] = peaks_df['index'].astype(int)

It was probably reworked in fooof 1.0 since my earlier code using the previous version doesn't have that problem (the 1st version worked). And why the index column is not an int?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions