Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] - Add support for converting model results, including to DFs #196

Merged
merged 9 commits into from
Jun 29, 2023

Conversation

TomDonoghue
Copy link
Member

@TomDonoghue TomDonoghue commented Feb 23, 2021

Adds fooof.data.conversions that allows for converting model results into alternate forms, including DataFrames.

A key component for doing this is to is to organize how to to organize peaks. Currently, this implementation supports organizing a set number of peaks, or using band definitions.

Note that this is an alternate approach to some other ideas explored in #194

Example usage:

from fooof import FOOOFGroup, Bands
from fooof.sim import gen_group_power_spectra

freqs, pows = gen_group_power_spectra(2, [3, 40], [1, 1], [[10, 1, 1], [20, 1, 1]])

fg = FOOOFGroup(verbose=False)
fg.fit(freqs, pows)
# Convert to DF, extracting 2 peaks per model
fg.to_df(2)

Screen Shot 2021-02-23 at 1 57 14 PM

# Convert to DF, extracting peaks with a specified band definition
bands = Bands({'alpha' : [8, 12], 'beta' : [15, 30]})
fg.to_df(bands)

Screen Shot 2021-02-23 at 1 57 19 PM

@rdgao
Copy link
Contributor

rdgao commented Feb 24, 2021

👍 !!

fooof/data/conversions.py Show resolved Hide resolved
fooof/data/conversions.py Show resolved Hide resolved
@ryanhammonds ryanhammonds mentioned this pull request Apr 6, 2021
3 tasks
@fooof-tools fooof-tools deleted a comment from codecov-io Apr 15, 2021
@matteuler
Copy link

Hello,

Thanks for making FOOOF available, great tool!!

I'm trying to use this dataframe conversion utility and I can't seem to get it to work. When I run the example usage code exactly as above I get the following error.:

image

I also can't seem to import or access documentation for fooof.data.conversions. Are there some simple import steps or documentation I am missing?

@danieltomasz
Copy link

@matteuler the branch containing the code for a data frame conversion is not merged yet into main and released, you probably installed an older version of the package that doesn't contain the method for conversion, I would recommend waiting until the authors make the new release

@ryanhammonds
Copy link
Contributor

ryanhammonds commented Jul 6, 2021

@matteuler, you may get this feature early via cloning, checking out the df branch, and running pip install -e . from within the cloned directory. Otherwise, as @danieltomasz mentioned, you can wait until this PR is merged and released.

@matteuler
Copy link

@danieltomasz @ryanhammonds Thanks very much for these responses! I was able to use "get_params' to get the aperiodic and fit info directly (ignoring peaks for the time being) which made converting to a dataframe easy via pandas utilities.

@danieltomasz
Copy link

danieltomasz commented Jul 6, 2021

@matteuler you may really easily join peaks into dataframe with aperiodic and periodic parameters, 'temp_df` is the dataframe with aperiodic parameters

temp_df.insert(0, 'ID', temp_df.index)
peaks = fg.get_params('peak_params') # prepare peaks dataframe
peaks_df = pd.DataFrame(peaks)
peaks_df.columns = ['CF', 'PW', 'BW', 'ID']
peaks_df['ID'] = peaks_df['ID'].astype(int)
peaks_df = peaks_df.join(temp_df.set_index('ID'), on='ID')

@TomDonoghue TomDonoghue added 2.0 Targetted for the specparam 2.0 release. 1.1 Targetted for a fooof 1.1 release. and removed 2.0 Targetted for the specparam 2.0 release. labels Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.1 Targetted for a fooof 1.1 release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants