-
Notifications
You must be signed in to change notification settings - Fork 52
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
[MRG] Spikes raster plot colors #895
[MRG] Spikes raster plot colors #895
Conversation
Hi @ntolley. I was looking into writing a test for making sure the colors are working expected for this plot. I was looking into the existing tests for the plotter in hnn-core/hnn_core/tests/test_viz.py Lines 124 to 240 in 9cdd05d
Here's a code snip to recreate: from hnn_core import simulate_dipole, jones_2009_model, read_params
from pathlib import Path
hnn_core_root = Path.cwd().parents[0]
params_fname = Path(hnn_core_root, 'param', 'default.json')
params = read_params(params_fname)
net = jones_2009_model(params, mesh_shape=(3, 3))
weights_ampa = {'L2_pyramidal': 5.4e-5, 'L5_pyramidal': 5.4e-5}
syn_delays = {'L2_pyramidal': 0.1, 'L5_pyramidal': 1.}
net.add_bursty_drive(
'beta_prox', tstart=0., burst_rate=25, burst_std=5,
numspikes=1, spike_isi=0, n_drive_cells=11, location='proximal',
weights_ampa=weights_ampa, synaptic_delays=syn_delays,
event_seed=14)
net.add_bursty_drive(
'beta_dist', tstart=0., burst_rate=25, burst_std=5,
numspikes=1, spike_isi=0, n_drive_cells=11, location='distal',
weights_ampa=weights_ampa, synaptic_delays=syn_delays,
event_seed=14)
dpls = simulate_dipole(net, tstop=100., n_trials=2, record_vsec='all')
fig1 = net.cell_response.plot_spikes_raster()
fig1.show() |
@gtdang this test was written for the edge case with the drives are too weak to produce spiking activity in the network There was an earlier bug where the plotting function would throw an error if not spikes occurred, so this test is to make sure that an empty plot is generated (the desired behavior in these simulations) |
If you want spiking just change the weights to a bigger number like |
26c9fa8
to
9717ae7
Compare
hnn_core/viz.py
Outdated
def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): | ||
def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True, | ||
cell_types=['L2_basket', 'L2_pyramidal', | ||
'L5_basket', 'L5_pyramidal'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad idea to have a default list in a function. You will get funky effects in Python ... default should not be a mutable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, we're going to refactor this call to be aligned with the plot_spikes_hist implementation so that it can also take a dict of color assignments. I don't think we need to expose the cell_types as an argument... though I wish there was a way to get it dynamically from the network instead of hard-coding the types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #916 ... it allows you to dynamically extract the cell types
class TestCellResponsePlotters: | ||
|
||
@pytest.fixture(scope='class') | ||
def class_setup_net(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gtdang this comment is not addressed yet, otherwise I can go ahead and merge. Still see some test functions without a one-line docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, do you just want a doc string for these fixtures? Perhaps:
"""Creates a base network from the default json for tests within this class"""
and
"""Adds bursty drives with spikes to the base network for testing visualizations of spikes"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that's good!
events = [] | ||
for cell_type in cell_types: | ||
cell_type_gids = np.unique(spike_gids[spike_types == cell_type]) | ||
cell_type_times, cell_type_ypos = [], [] | ||
color = next(color_iter) | ||
|
||
for gid in cell_type_gids: | ||
gid_time = spike_times[spike_gids == gid] | ||
cell_type_times.append(gid_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you are at it, I am wondering if this could be addressed as well. The following line:
cell_type_ypos.append(-gid)
causes cells that spike with neighboring gids to overlap. I have been staring at these raster plots recently and it's very hard to tell how many times the same cell spiked (important to understand the underlying dynamics). Adding a small offset between nearby cells should address that problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look into this. The overlap is due to both the y-position as you've identified and the line lengths defined during the plot function call on line 568. The y-position is the center of each line and the length is how much it extends from that center point (+-2.5 each way for a value of 5).
Lines 559 to 568 in 27c6fc1
for gid in cell_type_gids: | |
gid_time = spike_times[spike_gids == gid] | |
cell_type_times.append(gid_time) | |
cell_type_ypos.append(-gid) | |
if cell_type_times: | |
events.append( | |
ax.eventplot(cell_type_times, lineoffsets=cell_type_ypos, | |
color=cell_type_colors[cell_type], | |
label=cell_type, linelengths=5)) |
A simple solution is to change the line length to 1. However the lines will look more like dots with this change.
Another solution would be to analyze the cell times and gids, and apply a larger y-offset if they are within an X and Y bounding box of one another.
Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with the spikes looking like dots ... it's just a function of the number of cells in our network. Did a quick google image search of "spike raster plot" and the plots do look dotted when there are more neurons. I guess the y-offset = -gid is helpful since it allows you to identify the cell, so maybe best not to touch that. @ntolley any opinion here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…and use the set color cycle's first 4 colors
So far only added test for the spikes raster plot.
…ted variable names
be192f3
to
4d3a706
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changes
With new colors
With new shorter lines.
Question:
Should the API allow users to be able to specify colors?Yescloses #888