Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Refactor dipole visualization to invert y-axis when min_freq > max_freq #903

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Bug
- Fix scaling and smoothing of loaded data dipoles to the GUI, by `George Dang`_
in :gh:`892`

- Refactor dipole visualization to support reversed y-axis in plot_tfr_morlet
for min_freq greater than max_freq, by `Abdul Samad Siddiqui`_ in :gh:`903`

API
~~~
- Add :func:`~hnn_core.CellResponse.spike_times_by_type` to get cell spiking times
Expand Down
7 changes: 7 additions & 0 deletions hnn_core/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ def test_dipole_visualization(setup_net):
# multiple TFRs get averaged
fig = plot_tfr_morlet(dpls, freqs=np.arange(23, 26, 1.), n_cycles=3,
show=False)
# when min_freq > max_freq (y-axis inversion)
fig = plot_tfr_morlet(dpls, freqs=np.array([30, 20, 10]),
n_cycles=3, show=False)
ax = fig.get_axes()[0]
y_limits = ax.get_ylim()
assert y_limits[0] > y_limits[1], \
"Y-axis should be inverted when min_freq > max_freq"

with pytest.raises(RuntimeError,
match="All dipoles must be scaled equally!"):
Expand Down
5 changes: 5 additions & 0 deletions hnn_core/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,11 @@ def plot_tfr_morlet(dpl, freqs, *, n_cycles=7., tmin=None, tmax=None,
power = np.mean(trial_power, axis=0)
im = ax.pcolormesh(times, freqs, power[0, 0, ...], cmap=colormap,
shading='auto')

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

ax.set_xlabel('Time (ms)')
ax.set_ylabel('Frequency (Hz)')

Expand Down
Loading