From 1ea27cb4c7323572bc20420bf7154309aeb76d5d Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Thu, 29 Jun 2023 10:43:20 -0700 Subject: [PATCH 1/4] add settings for group report --- fooof/core/reports.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fooof/core/reports.py b/fooof/core/reports.py index 20323b1ce..1ce6fd400 100644 --- a/fooof/core/reports.py +++ b/fooof/core/reports.py @@ -82,7 +82,7 @@ def save_report_fg(fg, file_name, file_path=None): # Initialize figure _ = plt.figure(figsize=REPORT_FIGSIZE) - grid = gridspec.GridSpec(3, 2, wspace=0.4, hspace=0.25, height_ratios=[0.8, 1.0, 1.0]) + grid = gridspec.GridSpec(4, 2, wspace=0.4, hspace=0.25, height_ratios=[0.8, 1.0, 1.0, 0.5]) # First / top: text results ax0 = plt.subplot(grid[0, :]) @@ -92,6 +92,8 @@ def save_report_fg(fg, file_name, file_path=None): ax0.set_xticks([]) ax0.set_yticks([]) + # Second - data plots + # Aperiodic parameters plot ax1 = plt.subplot(grid[1, 0]) plot_fg_ap(fg, ax1) @@ -104,6 +106,14 @@ def save_report_fg(fg, file_name, file_path=None): ax3 = plt.subplot(grid[2, :]) plot_fg_peak_cens(fg, ax3) + # Third - Model settings + ax4 = plt.subplot(grid[3, :]) + settings_str = gen_settings_str(fg, False) + ax4.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center') + ax4.set_frame_on(False) + ax4.set_xticks([]) + ax4.set_yticks([]) + # Save out the report plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT))) plt.close() From 172f9e23e7f58d5bab5b148e4b97fc8099847709 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Thu, 29 Jun 2023 11:02:41 -0700 Subject: [PATCH 2/4] add option for saving settings to reports --- fooof/core/reports.py | 50 ++++++++++++++++++++++++++----------------- fooof/objs/fit.py | 4 ++-- fooof/objs/group.py | 4 ++-- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/fooof/core/reports.py b/fooof/core/reports.py index 1ce6fd400..87170d666 100644 --- a/fooof/core/reports.py +++ b/fooof/core/reports.py @@ -22,7 +22,7 @@ ################################################################################################### @check_dependency(plt, 'matplotlib') -def save_report_fm(fm, file_name, file_path=None, plt_log=False): +def save_report_fm(fm, file_name, file_path=None, plt_log=False, add_settings=True): """Generate and save out a PDF report for a power spectrum model fit. Parameters @@ -35,31 +35,36 @@ def save_report_fm(fm, file_name, file_path=None, plt_log=False): Path to directory to save to. If None, saves to current directory. plt_log : bool, optional, default: False Whether or not to plot the frequency axis in log space. + add_settings : bool, optional, default: True + Whether to add a print out of the model settings to the end of the report. """ + # Define grid settings based on what is to be plotted + n_rows = 3 if add_settings else 2 + height_ratios = [0.45, 1.0, 0.25] if add_settings else [0.45, 1.0] + # Set up outline figure, using gridspec _ = plt.figure(figsize=REPORT_FIGSIZE) - grid = gridspec.GridSpec(3, 1, height_ratios=[0.45, 1.0, 0.25]) + grid = gridspec.GridSpec(n_rows, 1, height_ratios=height_ratios) # First - text results ax0 = plt.subplot(grid[0]) results_str = gen_results_fm_str(fm) ax0.text(0.5, 0.7, results_str, REPORT_FONT, ha='center', va='center') ax0.set_frame_on(False) - ax0.set_xticks([]) - ax0.set_yticks([]) + ax0.set(xticks=[], yticks=[]) # Second - data plot ax1 = plt.subplot(grid[1]) fm.plot(plt_log=plt_log, ax=ax1) # Third - FOOOF settings - ax2 = plt.subplot(grid[2]) - settings_str = gen_settings_str(fm, False) - ax2.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center') - ax2.set_frame_on(False) - ax2.set_xticks([]) - ax2.set_yticks([]) + if add_settings: + ax2 = plt.subplot(grid[2]) + settings_str = gen_settings_str(fm, False) + ax2.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center') + ax2.set_frame_on(False) + ax2.set(xticks=[], yticks=[]) # Save out the report plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT))) @@ -67,7 +72,7 @@ def save_report_fm(fm, file_name, file_path=None, plt_log=False): @check_dependency(plt, 'matplotlib') -def save_report_fg(fg, file_name, file_path=None): +def save_report_fg(fg, file_name, file_path=None, add_settings=True): """Generate and save out a PDF report for a group of power spectrum models. Parameters @@ -78,19 +83,24 @@ def save_report_fg(fg, file_name, file_path=None): Name to give the saved out file. file_path : str, optional Path to directory to save to. If None, saves to current directory. + add_settings : bool, optional, default: True + Whether to add a print out of the model settings to the end of the report. """ + # Define grid settings based on what is to be plotted + n_rows = 4 if add_settings else 3 + height_ratios = [0.8, 1.0, 1.0, 0.5] if add_settings else [0.8, 1.0, 1.0] + # Initialize figure _ = plt.figure(figsize=REPORT_FIGSIZE) - grid = gridspec.GridSpec(4, 2, wspace=0.4, hspace=0.25, height_ratios=[0.8, 1.0, 1.0, 0.5]) + grid = gridspec.GridSpec(n_rows, 2, wspace=0.4, hspace=0.25, height_ratios=height_ratios) # First / top: text results ax0 = plt.subplot(grid[0, :]) results_str = gen_results_fg_str(fg) ax0.text(0.5, 0.7, results_str, REPORT_FONT, ha='center', va='center') ax0.set_frame_on(False) - ax0.set_xticks([]) - ax0.set_yticks([]) + ax0.set(xticks=[], yticks=[]) # Second - data plots @@ -107,12 +117,12 @@ def save_report_fg(fg, file_name, file_path=None): plot_fg_peak_cens(fg, ax3) # Third - Model settings - ax4 = plt.subplot(grid[3, :]) - settings_str = gen_settings_str(fg, False) - ax4.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center') - ax4.set_frame_on(False) - ax4.set_xticks([]) - ax4.set_yticks([]) + if add_settings: + ax4 = plt.subplot(grid[3, :]) + settings_str = gen_settings_str(fg, False) + ax4.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center') + ax4.set_frame_on(False) + ax4.set(xticks=[], yticks=[]) # Save out the report plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT))) diff --git a/fooof/objs/fit.py b/fooof/objs/fit.py index 438926081..377006816 100644 --- a/fooof/objs/fit.py +++ b/fooof/objs/fit.py @@ -642,9 +642,9 @@ def plot(self, plot_peaks=None, plot_aperiodic=True, plt_log=False, @copy_doc_func_to_method(save_report_fm) - def save_report(self, file_name, file_path=None, plt_log=False): + def save_report(self, file_name, file_path=None, plt_log=False, add_settings=True): - save_report_fm(self, file_name, file_path, plt_log) + save_report_fm(self, file_name, file_path, plt_log, add_settings) @copy_doc_func_to_method(save_fm) diff --git a/fooof/objs/group.py b/fooof/objs/group.py index e26213fbd..f77edee5f 100644 --- a/fooof/objs/group.py +++ b/fooof/objs/group.py @@ -402,9 +402,9 @@ def plot(self, save_fig=False, file_name=None, file_path=None, **plot_kwargs): @copy_doc_func_to_method(save_report_fg) - def save_report(self, file_name, file_path=None): + def save_report(self, file_name, file_path=None, add_settings=True): - save_report_fg(self, file_name, file_path) + save_report_fg(self, file_name, file_path, add_settings) @copy_doc_func_to_method(save_fg) From f9b6e7e64537fafbe8ce4c5e20afa14e73f8a795 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Thu, 29 Jun 2023 12:08:22 -0700 Subject: [PATCH 3/4] tweak height ratios --- fooof/core/reports.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fooof/core/reports.py b/fooof/core/reports.py index 87170d666..1084c740f 100644 --- a/fooof/core/reports.py +++ b/fooof/core/reports.py @@ -41,11 +41,11 @@ def save_report_fm(fm, file_name, file_path=None, plt_log=False, add_settings=Tr # Define grid settings based on what is to be plotted n_rows = 3 if add_settings else 2 - height_ratios = [0.45, 1.0, 0.25] if add_settings else [0.45, 1.0] + height_ratios = [0.5, 1.0, 0.25] if add_settings else [0.45, 1.0] # Set up outline figure, using gridspec _ = plt.figure(figsize=REPORT_FIGSIZE) - grid = gridspec.GridSpec(n_rows, 1, height_ratios=height_ratios) + grid = gridspec.GridSpec(n_rows, 1, hspace=0.25, height_ratios=height_ratios) # First - text results ax0 = plt.subplot(grid[0]) @@ -89,7 +89,7 @@ def save_report_fg(fg, file_name, file_path=None, add_settings=True): # Define grid settings based on what is to be plotted n_rows = 4 if add_settings else 3 - height_ratios = [0.8, 1.0, 1.0, 0.5] if add_settings else [0.8, 1.0, 1.0] + height_ratios = [1.0, 1.0, 1.0, 0.5] if add_settings else [0.8, 1.0, 1.0] # Initialize figure _ = plt.figure(figsize=REPORT_FIGSIZE) From 2642a8a9e7f99c0791edd67f5078546b3004aec2 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Thu, 29 Jun 2023 12:09:49 -0700 Subject: [PATCH 4/4] allow for passing in figsize model plots --- fooof/plts/fg.py | 2 +- fooof/plts/fm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fooof/plts/fg.py b/fooof/plts/fg.py index d750e165a..8259268b8 100644 --- a/fooof/plts/fg.py +++ b/fooof/plts/fg.py @@ -43,7 +43,7 @@ def plot_fg(fg, save_fig=False, file_name=None, file_path=None, **plot_kwargs): if not fg.has_model: raise NoModelError("No model fit results are available, can not proceed.") - fig = plt.figure(figsize=PLT_FIGSIZES['group']) + fig = plt.figure(figsize=plot_kwargs.pop('figsize', PLT_FIGSIZES['group'])) gs = gridspec.GridSpec(2, 2, wspace=0.4, hspace=0.25, height_ratios=[1, 1.2]) # Apply scatter kwargs to all subplots diff --git a/fooof/plts/fm.py b/fooof/plts/fm.py index 77fc9e1e3..0cbd168f2 100644 --- a/fooof/plts/fm.py +++ b/fooof/plts/fm.py @@ -62,7 +62,7 @@ def plot_fm(fm, plot_peaks=None, plot_aperiodic=True, plt_log=False, add_legend= the y-axis (power) is plotted in log spacing by default. """ - ax = check_ax(ax, PLT_FIGSIZES['spectral']) + ax = check_ax(ax, plot_kwargs.pop('figsize', PLT_FIGSIZES['spectral'])) # Log settings - note that power values in FOOOF objects are already logged log_freqs = plt_log