Skip to content

Commit 172f9e2

Browse files
committed
add option for saving settings to reports
1 parent 1ea27cb commit 172f9e2

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

fooof/core/reports.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
###################################################################################################
2323

2424
@check_dependency(plt, 'matplotlib')
25-
def save_report_fm(fm, file_name, file_path=None, plt_log=False):
25+
def save_report_fm(fm, file_name, file_path=None, plt_log=False, add_settings=True):
2626
"""Generate and save out a PDF report for a power spectrum model fit.
2727
2828
Parameters
@@ -35,39 +35,44 @@ def save_report_fm(fm, file_name, file_path=None, plt_log=False):
3535
Path to directory to save to. If None, saves to current directory.
3636
plt_log : bool, optional, default: False
3737
Whether or not to plot the frequency axis in log space.
38+
add_settings : bool, optional, default: True
39+
Whether to add a print out of the model settings to the end of the report.
3840
"""
3941

42+
# Define grid settings based on what is to be plotted
43+
n_rows = 3 if add_settings else 2
44+
height_ratios = [0.45, 1.0, 0.25] if add_settings else [0.45, 1.0]
45+
4046
# Set up outline figure, using gridspec
4147
_ = plt.figure(figsize=REPORT_FIGSIZE)
42-
grid = gridspec.GridSpec(3, 1, height_ratios=[0.45, 1.0, 0.25])
48+
grid = gridspec.GridSpec(n_rows, 1, height_ratios=height_ratios)
4349

4450
# First - text results
4551
ax0 = plt.subplot(grid[0])
4652
results_str = gen_results_fm_str(fm)
4753
ax0.text(0.5, 0.7, results_str, REPORT_FONT, ha='center', va='center')
4854
ax0.set_frame_on(False)
49-
ax0.set_xticks([])
50-
ax0.set_yticks([])
55+
ax0.set(xticks=[], yticks=[])
5156

5257
# Second - data plot
5358
ax1 = plt.subplot(grid[1])
5459
fm.plot(plt_log=plt_log, ax=ax1)
5560

5661
# Third - FOOOF settings
57-
ax2 = plt.subplot(grid[2])
58-
settings_str = gen_settings_str(fm, False)
59-
ax2.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center')
60-
ax2.set_frame_on(False)
61-
ax2.set_xticks([])
62-
ax2.set_yticks([])
62+
if add_settings:
63+
ax2 = plt.subplot(grid[2])
64+
settings_str = gen_settings_str(fm, False)
65+
ax2.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center')
66+
ax2.set_frame_on(False)
67+
ax2.set(xticks=[], yticks=[])
6368

6469
# Save out the report
6570
plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT)))
6671
plt.close()
6772

6873

6974
@check_dependency(plt, 'matplotlib')
70-
def save_report_fg(fg, file_name, file_path=None):
75+
def save_report_fg(fg, file_name, file_path=None, add_settings=True):
7176
"""Generate and save out a PDF report for a group of power spectrum models.
7277
7378
Parameters
@@ -78,19 +83,24 @@ def save_report_fg(fg, file_name, file_path=None):
7883
Name to give the saved out file.
7984
file_path : str, optional
8085
Path to directory to save to. If None, saves to current directory.
86+
add_settings : bool, optional, default: True
87+
Whether to add a print out of the model settings to the end of the report.
8188
"""
8289

90+
# Define grid settings based on what is to be plotted
91+
n_rows = 4 if add_settings else 3
92+
height_ratios = [0.8, 1.0, 1.0, 0.5] if add_settings else [0.8, 1.0, 1.0]
93+
8394
# Initialize figure
8495
_ = plt.figure(figsize=REPORT_FIGSIZE)
85-
grid = gridspec.GridSpec(4, 2, wspace=0.4, hspace=0.25, height_ratios=[0.8, 1.0, 1.0, 0.5])
96+
grid = gridspec.GridSpec(n_rows, 2, wspace=0.4, hspace=0.25, height_ratios=height_ratios)
8697

8798
# First / top: text results
8899
ax0 = plt.subplot(grid[0, :])
89100
results_str = gen_results_fg_str(fg)
90101
ax0.text(0.5, 0.7, results_str, REPORT_FONT, ha='center', va='center')
91102
ax0.set_frame_on(False)
92-
ax0.set_xticks([])
93-
ax0.set_yticks([])
103+
ax0.set(xticks=[], yticks=[])
94104

95105
# Second - data plots
96106

@@ -107,12 +117,12 @@ def save_report_fg(fg, file_name, file_path=None):
107117
plot_fg_peak_cens(fg, ax3)
108118

109119
# Third - Model settings
110-
ax4 = plt.subplot(grid[3, :])
111-
settings_str = gen_settings_str(fg, False)
112-
ax4.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center')
113-
ax4.set_frame_on(False)
114-
ax4.set_xticks([])
115-
ax4.set_yticks([])
120+
if add_settings:
121+
ax4 = plt.subplot(grid[3, :])
122+
settings_str = gen_settings_str(fg, False)
123+
ax4.text(0.5, 0.1, settings_str, REPORT_FONT, ha='center', va='center')
124+
ax4.set_frame_on(False)
125+
ax4.set(xticks=[], yticks=[])
116126

117127
# Save out the report
118128
plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT)))

fooof/objs/fit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@ def plot(self, plot_peaks=None, plot_aperiodic=True, plt_log=False,
642642

643643

644644
@copy_doc_func_to_method(save_report_fm)
645-
def save_report(self, file_name, file_path=None, plt_log=False):
645+
def save_report(self, file_name, file_path=None, plt_log=False, add_settings=True):
646646

647-
save_report_fm(self, file_name, file_path, plt_log)
647+
save_report_fm(self, file_name, file_path, plt_log, add_settings)
648648

649649

650650
@copy_doc_func_to_method(save_fm)

fooof/objs/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ def plot(self, save_fig=False, file_name=None, file_path=None, **plot_kwargs):
402402

403403

404404
@copy_doc_func_to_method(save_report_fg)
405-
def save_report(self, file_name, file_path=None):
405+
def save_report(self, file_name, file_path=None, add_settings=True):
406406

407-
save_report_fg(self, file_name, file_path)
407+
save_report_fg(self, file_name, file_path, add_settings)
408408

409409

410410
@copy_doc_func_to_method(save_fg)

0 commit comments

Comments
 (0)