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

[MRG] Add ability to index individual trials when plotting rasters/histograms #472

Merged
merged 8 commits into from Mar 12, 2022

Conversation

ntolley
Copy link
Contributor

@ntolley ntolley commented Mar 3, 2022

Closes #471 Implements the ability to filter out specific trials either through lists or integers:

net.cell_response.plot_spikes_raster(trial_idx=0)
net.cell_response.plot_spikes_raster(trial_idx=[0, 1])

@ntolley
Copy link
Contributor Author

ntolley commented Mar 3, 2022

I think it will be necessary to add this to plot_spikes_hist as well

hnn_core/viz.py Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2022

Codecov Report

Merging #472 (bc37bb7) into master (0db52fa) will decrease coverage by 0.09%.
The diff coverage is 90.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #472      +/-   ##
==========================================
- Coverage   90.46%   90.36%   -0.10%     
==========================================
  Files          18       18              
  Lines        3378     3395      +17     
==========================================
+ Hits         3056     3068      +12     
- Misses        322      327       +5     
Impacted Files Coverage Δ
hnn_core/viz.py 83.47% <88.88%> (+0.17%) ⬆️
hnn_core/cell_response.py 84.53% <100.00%> (ø)
hnn_core/parallel_backends.py 81.49% <0.00%> (-0.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0db52fa...bc37bb7. Read the comment docs.

@jasmainak
Copy link
Collaborator

does this do the job for you @wagdy88 @mkhalil8 ? You can try by doing:

$ git fetch upstream pull/472/head:trial_plots
$ git checkout trial_plots

Once it's merged, just switch to master

$ git checkout master

@jasmainak
Copy link
Collaborator

okay set the PR to [MRG] when ready and don't forget to update whats_new !

@ntolley ntolley changed the title [WIP] Add ability to index individual trials when plotting rasters/histograms [MRG] Add ability to index individual trials when plotting rasters/histograms Mar 11, 2022
@ntolley
Copy link
Contributor Author

ntolley commented Mar 11, 2022

All set on my end!

@@ -322,14 +322,15 @@ def mean_rates(self, tstart, tstop, gid_ranges, mean_type='all'):

return spike_rates

def plot_spikes_raster(self, ax=None, show=True):
def plot_spikes_raster(self, trial_idx=None, ax=None, show=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an API breaking change. It will break code which does:

plot_spikes_raster(ax)

as a general rule, you want to put new arguments towards the end, but maybe before show so API is consistent. Anyhow, I don't think we are doing deprecations at this point, so I'll let this pass but something to remember for the future :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, might be worth discussing the mechanics of deprecation warnings at some point. Especially identifying functions that are the most likely to change in the near future

hnn_core/viz.py Outdated Show resolved Hide resolved
hnn_core/viz.py Outdated
_validate_type(trial_idx, list, 'trial_idx', 'int, list of int')

# Extract desired trials
if cell_response._spike_times[0]:
Copy link
Collaborator

@jasmainak jasmainak Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean to check the length > 0 or do you want to compare against None? Better to be explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

ntolley and others added 2 commits March 11, 2022 17:55
Co-authored-by: Mainak Jas <jasmainak@users.noreply.github.com>
@jasmainak jasmainak merged commit 52620b2 into jonescompneurolab:master Mar 12, 2022
@jasmainak
Copy link
Collaborator

Thanks @ntolley !

@wagdy88
Copy link

wagdy88 commented Mar 17, 2022

Thank you!!

@mkhalil8
Copy link
Contributor

mkhalil8 commented Mar 19, 2022

Dipole_unsync_vs_syncd1_sigma_0 25(1)
Dipole_unsync_vs_syncd1_sigma_0 25(2)

I have re-installed hnn-core to test plotting single results, (I believe multiple other pulls also have been merged).
I used the same code before re-installing and I encountered this difference, any thoughts what might be causing that? @jasmainak @rythorpe @ntolley

@jasmainak
Copy link
Collaborator

@mkhalil8 we have changed the way seeding is done. I suspect that's what causes the difference. See #462 #454. You will have to adjust your seeds if you want to get the previous results.

@ntolley ntolley deleted the trial_plots branch March 20, 2022 07:14
@mkhalil8
Copy link
Contributor

@jasmainak I played around with the seeding and re-produced the exact results from before. Thank you

@mkhalil8
Copy link
Contributor

mkhalil8 commented Mar 22, 2022

As for plotting rasters of single trials, Yeah it is great. It is working well but I get this warning which does not affect the outcome:

hnn_core/viz.py:439: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  np.array(cell_response._spike_gids)[trial_idx]

@jasmainak
Copy link
Collaborator

@ntolley do you know if it's safe to fix this by providing dtype='object'? We should ideally not have any deprecation warnings with our code unless intended explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plot raster for individual trials
5 participants