Giter Site home page Giter Site logo

spykes's Introduction

spykes

License Join the chat at https://gitter.im/KordingLab/spykes Travis Circle Coverage Status

Spykes!

Almost any electrophysiology study of neural spiking data relies on a battery of standard analyses. Raster plots and peri-stimulus time histograms aligned to stimuli and behavior provide a snapshot visual description of neural activity. Similarly, tuning curves are the most standard way to characterize how neurons encode stimuli or behavioral preferences. With increasing popularity of population recordings, maximum-likelihood decoders based on tuning models are becoming part of this standard.

Yet, virtually every lab relies on a set of in-house analysis scripts to go from raw data to summaries. We want to improve this status quo in order to enable easier sharing, better reproducibility and fewer bugs.

Spykes is a collection of Python tools to make the visualization and analysis of neural data easy and reproducible.

For more, see the documentation.

Installation

Spykes can be installed using

pip install spykes

For more detailed installation options, see the documentation.

Authors

Acknowledgments

spykes's People

Contributors

codekansas avatar gitter-badger avatar hugoguh avatar jasmainak avatar neuromusic avatar pavanramkumar avatar timshell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spykes's Issues

Improvements to example notebooks

List of possible improvements for example notebooks:

reaching_example:

  • color code by reaching direction the circular plots in decoding from pop

simul_example:

  • use new simulated spike data (in a restricted angular direction) for evaluation of decoding performance and plotting

spykes.mplstyle not found on import

from neurovis import NeuroVis
---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-11-c37dd3c942ac> in <module>()
----> 1 from neurovis import NeuroVis

/usr/local/home/jkiggins/Code/spykes/neurovis/__init__.py in <module>()
----> 1 from .neurovis import NeuroVis
      2 __version__ = '0.1.dev'

/usr/local/home/jkiggins/Code/spykes/neurovis/neurovis.py in <module>()
      2 import matplotlib.pyplot as plt
      3 
----> 4 plt.style.use('../mpl_styles/spykes.mplstyle')
      5 
      6 

/home/jkiggins/envs/jkiggins/lib/python2.7/site-packages/matplotlib/style/core.pyc in use(style)
     88                        "not a valid URL or path. See `style.available` for "
     89                        "list of available styles.")
---> 90                 raise IOError(msg % style)
     91 
     92 

IOError: '../mpl_styles/spykes.mplstyle' not found in the style library and input is not a valid URL or path. See `style.available` for list of available styles.

plot PSTHs of population as rasters/ heat maps

Suggestion from Lee Miller's Beer & Brainstorm:

"We often plot mean PSTHs of neurons in a population as a raster or heat map. We may sort these by

  • preferred stimulus
  • firing rate
  • peak latency of PSTH"

Takeaway:

Write a new class called PopVis() which

  • takes a population of spike counts
  • computes preferred stimuli
  • computes PSTHs
  • plots them as a heat map (rows = neurons, cols = time)
  • takes a sortby argument that sorts neurons by one of above three ways

add vanilla von mises method for tuning curve fit and decoding in NeuroPop

Currently, the $$b + g*\exp(\cos(\theta - \theta_0))$$ model works, but it's non-convex and very slow.

I think we should add a simple $$\exp(b_0 + b_cos_\cos(\theta) + b_sin_\sin(\theta))$$ model for tunefit(), encode() and decode().

We can give the user the option of choosing the model they prefer

improving precision of event rasters

The method of generating the rasters strikes me as incredibly imprecise. Please correct me if my understanding of the algorithm is wrong.

We create a single bins vector that spans the spiketimes, then...

# bin the spikes into time bins
spike_counts = np.histogram(self.spiketimes, bins)[0]

# bin the events into time bins
event_counts = np.histogram(selected_events, bins)[0]
event_bins = np.where(event_counts > 0)[0]

raster = np.array([(spike_counts[(i+window[0]/binsize): \
                                 (i+window[1]/binsize+1)]) \
                   for i in event_bins])

Spikes AND events are binned in this vector and the raster is built from the counts aligned to the bins that contain events.

This approach means that any spike that lands in the same bin as the event is counted in that bin, no matter whether it occurred before the event of after.

Further, if events are not regular, then sometimes the event will happen early in the bin and the bin will consist mostly of spikes that happen after the event and other times, visa versa.

I expected that a unique bins vector would be constructed for each event, spanning the window so that spikes were clearly assigned before or after the event.

suggested improvements to the API

This is a somewhat long feature request.

I'm really excited about these packages and I think it's a major step in the right direction for getting plotting functions of neural time-series data. However, I think the current API is severely limited, especially with respect to the features and conditions arguments.

I would love to see an API which bears more similarity to @mwaskom's seaborn.

Seaborn's plotting functionality is amazing. For pretty much all of seaborn's plotting functions, you pass in a pandas dataframe as well as the column names you want plotted against each other. Then, you can split the data into colors by passing a column name for the hue argument, or break out the plot into an array of subplots where each col/row is defined according to a different factor.

The utility of this approach is more clear looking at the factorplot examples: https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.factorplot.html

Since I use seaborn extensively for data exploration already, wrote up a few functions that wrap the neurovis plotting functions in something more seaborn-like so you can see what I mean. Here's a notebook that demonstrates (a) getting the features and conditions into a friendly pandas dataframe and (b) plotting with seaborn style.

https://gist.github.com/neuromusic/f6fe2c5d7c1101811b5cd497b98a516c

Currently, by treating features and conditions as separate arguments, neurovis is incredibly limited. For one, the dictionary format of the conditions is not intuitive. Second, it's hard to compute complex conditions from the dictionary format that is currently used -- it seems largely limited to performing "AND" operations between factors and only filtering factors with ranges. It is better, I think, to let the user use pandas to construct factors with whatever logic they want.

In my above example, I only used "hue" since neurovis already supports this. Along with fixing #22, it would not be too hard to add a col or row factor. Then, in my example in the gist above, one could quickly plot the same plot as above but breaking out plots for correct and incorrect trials into rows like so...

trials = events_df[(events_df['GoodTrials']==True)]

# plot the PSTH
psthplot('RealCueTimes',trials,
         spike_times,nid=neuron_n,
         hue='response',
         row='correct',
         window=window,
         binsize=100)

One could also then also address #42 and/or other PSTH-like computations (e.g. gaussian kernels, poisson GLM models, etc) by setting a style argument or passing in some standardized estimation function.

See also seaborn's tsplot function https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.tsplot.html and discussion on it's future: mwaskom/seaborn#896

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.