Skip to content

Commit

Permalink
fix: added a function to check for existing averaged dipoles
Browse files Browse the repository at this point in the history
-The GUI can average and append the average to the dipole list at an earlier stage than plotting with "data to compare" specified. This solution checks for an existing average, if not it will return an average.
-This fixes an issue where the average_dipoles function was throwing an error because it was passed a list with an averaged dipole already.
  • Loading branch information
gtdang committed Aug 21, 2024
1 parent 80d78f2 commit f7ac50e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hnn_core/gui/_viz_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ def _dynamic_rerender(fig):
fig.tight_layout()


def _avg_dipole_check(dpls):
"""Check for averaged dipole, else average the trials"""
# Check if there is an averaged dipole already
avg_dpls = [d for d in dpls if d.nave > 1]
if avg_dpls:
dpl = avg_dpls[0]
else:
dpl = average_dipoles(dpls)
return dpl


def _plot_on_axes(b, simulations_widget, widgets_plot_type,
data_widget,
spectrogram_colormap_selection, max_spectral_frequency,
Expand Down Expand Up @@ -427,7 +438,7 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type,
t0 = 0.0
tstop = dpls_processed[-1].times[-1]
if len(dpls_processed) > 1:
dpl = average_dipoles(dpls_processed)
dpl = _avg_dipole_check(dpls_processed)
else:
dpl = dpls_processed
rmse = _rmse(dpl, target_dpl_processed, t0, tstop)
Expand Down

0 comments on commit f7ac50e

Please sign in to comment.