Skip to content

Commit

Permalink
add presence plot to event plots / reports
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Mar 27, 2024
1 parent b6de612 commit 508c0ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions specparam/core/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ def save_event_report(event_model, file_name, file_path=None, add_settings=True)
has_knee = 'knee' in event_model.event_time_results.keys()

# Initialize figure, defining number of axes based on model + what is to be plotted
n_rows = 1 + (4 if has_knee else 3) + (n_bands * 4) + 2 + (1 if add_settings else 0)
n_rows = 1 + (4 if has_knee else 3) + (n_bands * 5) + 2 + (1 if add_settings else 0)
height_ratios = [2.75] + [1] * (3 if has_knee else 2) + \
[0.25, 1, 1, 1] * n_bands + [0.25] + [1, 1] + ([1.5] if add_settings else [])
[0.25, 1, 1, 1, 1] * n_bands + [0.25] + [1, 1] + ([1.5] if add_settings else [])
_, axes = plt.subplots(n_rows, 1,
gridspec_kw={'hspace' : 0.1, 'height_ratios' : height_ratios},
figsize=(REPORT_FIGSIZE[0], REPORT_FIGSIZE[1] + 6))
figsize=(REPORT_FIGSIZE[0], REPORT_FIGSIZE[1] + 7))

# First / top: text results
plot_text(gen_event_results_str(event_model), 0.5, 0.7, ax=axes[0])
Expand Down
11 changes: 8 additions & 3 deletions specparam/plts/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from itertools import cycle

from specparam.data.utils import get_periodic_labels, get_band_labels
from specparam.utils.data import compute_presence
from specparam.plts.utils import savefig
from specparam.plts.templates import plot_param_over_time_yshade
from specparam.plts.settings import PARAM_COLORS
Expand Down Expand Up @@ -45,13 +46,13 @@ def plot_event_model(event_model, **plot_kwargs):
n_bands = len(pe_labels['cf'])

has_knee = 'knee' in event_model.event_time_results.keys()
height_ratios = [1] * (3 if has_knee else 2) + [0.25, 1, 1, 1] * n_bands + [0.25] + [1, 1]
height_ratios = [1] * (3 if has_knee else 2) + [0.25, 1, 1, 1, 1] * n_bands + [0.25] + [1, 1]

axes = plot_kwargs.pop('axes', None)
if axes is None:
_, axes = plt.subplots((4 if has_knee else 3) + (n_bands * 4) + 2, 1,
_, axes = plt.subplots((4 if has_knee else 3) + (n_bands * 5) + 2, 1,
gridspec_kw={'hspace' : 0.1, 'height_ratios' : height_ratios},
figsize=plot_kwargs.pop('figsize', [10, 4 + 4 * n_bands]))
figsize=plot_kwargs.pop('figsize', [10, 4 + 5 * n_bands]))
axes = cycle(axes)

xlim = [0, event_model.n_time_windows - 1]
Expand All @@ -74,6 +75,10 @@ def plot_event_model(event_model, **plot_kwargs):
label=plabel.upper(), drop_xticks=True, add_xlabel=False, xlim=xlim,
title='Periodic Parameters - ' + band_labels[band_ind] if plabel == 'cf' else None,
color=PARAM_COLORS[plabel], ax=next(axes))
plot_param_over_time_yshade(\
None, compute_presence(event_model.event_time_results[pe_labels[plabel][band_ind]]),
label='Presence', drop_xticks=True, add_xlabel=False, xlim=xlim,
color=PARAM_COLORS['presence'], ax=next(axes))
next(axes).axis('off')

# 03: goodness of fit
Expand Down
1 change: 1 addition & 0 deletions specparam/plts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'cf' : '#acc918',
'pw' : '#28a103',
'bw' : '#0fd197',
'presence' : '#095407',
'error' : '#940000',
'r_squared' : '#ab7171',
}
Expand Down

0 comments on commit 508c0ba

Please sign in to comment.