Skip to content

Commit

Permalink
TST with fake clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed Jul 2, 2021
1 parent b29f995 commit 76cee3c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/howto/plot_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

gid_idx = 11
src_gid = net_erp.connectivity[conn_idx]['src_range'][gid_idx]
fig, ax = plot_cell_connectivity(net_erp, conn_idx, src_gid)
fig = plot_cell_connectivity(net_erp, conn_idx, src_gid)

###############################################################################
# Data recorded during simulations are stored under
Expand Down
22 changes: 21 additions & 1 deletion hnn_core/tests/test_viz.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import partial
import os.path as op

import matplotlib
Expand All @@ -13,6 +14,13 @@
matplotlib.use('agg')


def _fake_click(fig, ax, point, button=1):
"""Fake a click at a point within axes."""
x, y = ax.transData.transform_point(point)
func = partial(fig.canvas.button_press_event, x=x, y=y, button=button)
func(guiEvent=None)


def test_network_visualization():
"""Test network visualisations."""
hnn_core_root = op.dirname(hnn_core.__file__)
Expand Down Expand Up @@ -47,9 +55,21 @@ def test_network_visualization():
with pytest.raises(TypeError, match='src_gid must be an instance of'):
plot_cell_connectivity(net, conn_idx, src_gid='blah')

with pytest.raises(ValueError, match='src_gid not in the'):
with pytest.raises(ValueError, match='src_gid not a valid cell ID'):
plot_cell_connectivity(net, conn_idx, src_gid=-1)

# smoke test interactive clicking
del net.connectivity[-1]
conn_idx = 15
net.add_connection(net.gid_ranges['L2_pyramidal'][::2],
'L5_basket', 'soma',
'ampa', 0.00025, 1.0, lamtha=3.0,
probability=0.8)
fig = plot_cell_connectivity(net, conn_idx)
ax_src = fig.axes[0]
pos = net.pos_dict['L2_pyramidal'][2]
_fake_click(fig, ax_src, [pos[0], pos[1]])


def test_dipole_visualization():
"""Test dipole visualisations."""
Expand Down
4 changes: 2 additions & 2 deletions hnn_core/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def plot_cell_connectivity(net, conn_idx, src_gid=None, axes=None,
f" ({conn['loc']}, {conn['receptor']})")

def _onclick(event):
if event.inaxes in [ax]:
if event.inaxes in [ax] or event.inaxes is None:
return

dist = np.linalg.norm(src_type_pos[:, :2] -
Expand Down Expand Up @@ -997,4 +997,4 @@ def _onclick(event):
fig.canvas.mpl_connect('button_press_event', _onclick)

plt_show(show)
return ax.get_figure(), ax
return ax.get_figure()

0 comments on commit 76cee3c

Please sign in to comment.