Skip to content

Commit

Permalink
Fix spectrogram inversion for GUI and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asoplata committed Feb 5, 2025
1 parent 23812e8 commit 266f1d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 4 additions & 5 deletions hnn_core/gui/_viz_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,13 @@ def _update_ax(fig, ax, single_simulation, sim_name, plot_type, plot_config):
if len(dpls_copied) > 0:
min_f = plot_config['min_spectral_frequency']
max_f = plot_config['max_spectral_frequency']
step_f = 1.0
if max_f > min_f:
step_f = 1
elif min_f > max_f:
step_f = -1
freqs = np.arange(min_f, max_f, step_f)
n_cycles = freqs / 2.

if freqs[0] > freqs[-1]:
freqs = freqs[::-1]
ax.invert_yaxis()

try:
dpls_copied[0].plot_tfr_morlet(
freqs,
Expand Down
20 changes: 20 additions & 0 deletions hnn_core/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,26 @@ def test_gui_visualization(setup_gui):
assert any(['_cbar-ax-' in attr
for attr in dir(gui.viz_manager.figs[figid])]) is False
assert len(gui.viz_manager.figs[figid].axes) == 1
assert not gui.viz_manager.figs[figid].axes[0].has_data()

# Test that frequency inversion works
# First, test no inversion
gui._simulate_viz_action("edit_figure", figname, axname, 'default',
'spectrogram', {
'min_spectral_frequency': 10,
'max_spectral_frequency': 100,
}, 'plot')
assert gui.viz_manager.figs[figid].axes[0].has_data()
gui._simulate_viz_action("edit_figure", figname, axname, 'default',
'spectrogram', {}, 'clear')
assert not gui.viz_manager.figs[figid].axes[0].has_data()
# Next, test inversion
gui._simulate_viz_action("edit_figure", figname, axname, 'default',
'spectrogram', {
'min_spectral_frequency': 100,
'max_spectral_frequency': 10,
}, 'plot')
assert gui.viz_manager.figs[figid].axes[0].has_data()

else:
# Check if the correct number of axes are present
Expand Down

0 comments on commit 266f1d5

Please sign in to comment.