@@ -84,6 +84,32 @@ def model_to_dataframe(fit_results, peak_org):
84
84
return pd .Series (model_to_dict (fit_results , peak_org ))
85
85
86
86
87
+ def group_to_dict (fit_results , peak_org ):
88
+ """Convert a group of model fit results into a dictionary.
89
+
90
+ Parameters
91
+ ----------
92
+ fit_results : list of FOOOFResults
93
+ List of FOOOFResults objects.
94
+ peak_org : int or Bands
95
+ How to organize peaks.
96
+ If int, extracts the first n peaks.
97
+ If Bands, extracts peaks based on band definitions.
98
+
99
+ Returns
100
+ -------
101
+ dict
102
+ Model results organized into a dictionary.
103
+ """
104
+
105
+ fr_dict = {ke : [] for ke in model_to_dict (fit_results [0 ], peak_org ).keys ()}
106
+ for f_res in fit_results :
107
+ for key , val in model_to_dict (f_res , peak_org ).items ():
108
+ fr_dict [key ].append (val )
109
+
110
+ return fr_dict
111
+
112
+
87
113
@check_dependency (pd , 'pandas' )
88
114
def group_to_dataframe (fit_results , peak_org ):
89
115
"""Convert a group of model fit results into a dataframe.
@@ -103,4 +129,4 @@ def group_to_dataframe(fit_results, peak_org):
103
129
Model results organized into a dataframe.
104
130
"""
105
131
106
- return pd .DataFrame ([ model_to_dataframe ( f_res , peak_org ) for f_res in fit_results ] )
132
+ return pd .DataFrame (group_to_dict ( fit_results , peak_org ))
0 commit comments