Skip to content

Commit d36d5c1

Browse files
committed
add FOOOFGroup.save_model_report()
and remove reports.save_report_fg_i
1 parent 60f3295 commit d36d5c1

File tree

2 files changed

+21
-56
lines changed

2 files changed

+21
-56
lines changed

fooof/core/reports.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -109,59 +109,3 @@ def save_report_fg(fg, file_name, file_path=None):
109109
# Save out the report
110110
plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT)))
111111
plt.close()
112-
113-
114-
def save_report_fg_i(fg, i_model, file_name, file_path=None, plot_peaks=None,
115-
plot_aperiodic=True, plt_log=True, add_legend=True, data_kwargs=None,
116-
model_kwargs=None, aperiodic_kwargs=None, peak_kwargs=None):
117-
"""Generate and save out a PDF report for a single model fit within a FOOOFGroup object.
118-
119-
Parameters
120-
----------
121-
fg : FOOOFGroup
122-
Object with results from fitting a group of power spectra.
123-
i_model : int
124-
Index of the model for which to generate a report.
125-
file_name : str
126-
Name to give the saved out file.
127-
file_path : str, optional
128-
Path to directory to save to. If None, saves to current directory.
129-
plot_peaks : None or {'shade', 'dot', 'outline', 'line'}, optional
130-
What kind of approach to take to plot peaks. If None, peaks are not specifically plotted.
131-
Can also be a combination of approaches, separated by '-', for example: 'shade-line'.
132-
plot_aperiodic : boolean, optional, default: True
133-
Whether to plot the aperiodic component of the model fit.
134-
plt_log : bool, optional, default: False
135-
Whether or not to plot the frequency axis in log space.
136-
add_legend : boolean, optional, default: False
137-
Whether to add a legend describing the plot components.
138-
data_kwargs, model_kwargs, aperiodic_kwargs, peak_kwargs : None or dict, optional
139-
Keyword arguments to pass into the plot call for each plot element.
140-
"""
141-
142-
# imports
143-
import numpy as np
144-
from fooof import FOOOF
145-
from fooof.sim.gen import gen_aperiodic, gen_periodic
146-
147-
# create fooof object and add settings
148-
fm = FOOOF()
149-
fm.add_settings(fg.get_settings())
150-
151-
# Copy results for model of interest and additional data needed for plotting
152-
fm.add_results(fg[i_model])
153-
fm.power_spectrum = fg.power_spectra[i_model]
154-
fm.freq_range = fg.freq_range
155-
fm.freq_res = fg.freq_res
156-
fm.freqs = fg.freqs
157-
158-
# generate and perioidc/aperiodic fits from parameters
159-
fm._ap_fit = gen_aperiodic(fg.freqs, fg[i_model].aperiodic_params)
160-
fm._peak_fit = gen_periodic(fg.freqs, np.ndarray.flatten(fg[i_model].gaussian_params))
161-
fm.fooofed_spectrum_ = fm._ap_fit + fm._peak_fit
162-
163-
# save report
164-
save_report_fm(fm, file_name, file_path=file_path, plot_peaks=plot_peaks,
165-
plot_aperiodic=plot_aperiodic, plt_log=plt_log, add_legend=add_legend,
166-
data_kwargs=data_kwargs, model_kwargs=model_kwargs,
167-
aperiodic_kwargs=aperiodic_kwargs, peak_kwargs=peak_kwargs)

fooof/objs/group.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,27 @@ def print_results(self, concise=False):
541541
print(gen_results_fg_str(self, concise))
542542

543543

544+
def save_model_report(self, index, file_name, file_path=None, plt_log=False, **plot_kwargs):
545+
""""Save out an individual model report for a specified model fit.
546+
547+
Parameters
548+
----------
549+
index : int
550+
Index of the model fit to save out.
551+
file_name : str
552+
Name to give the saved out file.
553+
file_path : str, optional
554+
Path to directory to save to. If None, saves to current directory.
555+
plt_log : bool, optional, default: False
556+
Whether or not to plot the frequency axis in log space.
557+
plot_kwargs : keyword arguments
558+
Keyword arguments to pass into the plot method.
559+
560+
"""
561+
562+
self.get_fooof(ind=index, regenerate=True).save_report(file_name, file_path, plt_log, **plot_kwargs)
563+
564+
544565
def _fit(self, *args, **kwargs):
545566
"""Create an alias to FOOOF.fit for FOOOFGroup object, for internal use."""
546567

0 commit comments

Comments
 (0)