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

plot Spike-contrast synchrony measure #34

Merged
merged 1 commit into from
Dec 4, 2020
Merged
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
9 changes: 9 additions & 0 deletions doc/bib/viziphant.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@article{Ciba18_136,
title={Spike-contrast: A novel time scale independent and multivariate measure of spike train synchrony},
author={Ciba, M. and Isomura, T. and Jimbo, Y. and Bahmer, A. and Thielemann, C.},
year={2018},
journal={J. Neurosci. Meth.},
volume={293},
pages={136--143},
doi={10.1016/j.jneumeth.2017.09.008}
}
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'sphinx.ext.viewcode',
'sphinx.ext.mathjax',
'matplotlib.sphinxext.plot_directive',
'sphinxcontrib.bibtex',
'numpydoc',
'sphinx_tabs.tabs',
'sphinx.builders.linkcheck',
Expand Down
10 changes: 10 additions & 0 deletions doc/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ Function Reference by Module
.. automodule:: viziphant.gpfa

.. automodule:: viziphant.unitary_event_analysis

.. automodule:: viziphant.spike_train_synchrony


References
----------

.. bibliography:: bib/viziphant.bib
:style: unsrt
:all:
5 changes: 3 additions & 2 deletions requirements/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpydoc>=0.9.2
sphinx>=2.4.2
numpydoc>=1.1.0
sphinx>=3.3.0
sphinx-tabs>=1.1.13
sphinxcontrib-bibtex>=1.0.0
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
neo>=0.9.0
elephant[extras]>=0.9.0
elephant @ git+https://github.com/NeuralEnsemble/elephant.git#egg=elephant[extras]
numpy>=1.18.1
quantities>=0.12.1
six>=1.10.0
Expand Down
2 changes: 1 addition & 1 deletion viziphant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# License: Modified BSD, see LICENSE.txt for details.

from . import (events, gpfa, rasterplot, spade, spike_train_correlation,
statistics, unitary_event_analysis)
spike_train_synchrony, statistics, unitary_event_analysis)


def _get_version():
Expand Down
96 changes: 96 additions & 0 deletions viziphant/spike_train_synchrony.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
Spike train synchrony plots
---------------------------

.. autosummary::
:toctree: toctree/spike_train_synchrony

plot_spike_contrast

"""

import matplotlib.pyplot as plt
import numpy as np

from viziphant.rasterplot import rasterplot


def plot_spike_contrast(trace, spiketrains=None, title=None, lw=1.0,
xscale='log', **kwargs):
"""
Plot Spike-contrast synchrony measure :cite:`Ciba18_136`.

Parameters
----------
trace : SpikeContrastTrace
The trace output from
:func:`elephant.spike_train_synchrony.spike_contrast` function.
spiketrains : list of neo.SpikeTrain or None
Input spike trains, optional. If provided, the raster plot will be
shown at the bottom.
Default: None
title : str or None.
The plot title. If None, an automatic description will be set.
Default: None
lw : float, optional
The curves line width.
Default: 1.0
xscale : str, optional
X axis scale.
Default: 'log'
**kwargs
Additional arguments, passed in :func:`viziphant.rasterplot.rasterplot`

Returns
-------
axes : matplotlib.Axes.axes

Examples
--------
Spike-contrast synchrony of homogenous Poisson processes.

.. plot::
:include-source:

import numpy as np
import quantities as pq
from elephant.spike_train_generation import homogeneous_poisson_process
from elephant.spike_train_synchrony import spike_contrast
import viziphant
np.random.seed(24)
spiketrains = [homogeneous_poisson_process(rate=20 * pq.Hz,
t_stop=10 * pq.s) for _ in range(10)]
synchrony, trace = spike_contrast(spiketrains, return_trace=True)
viziphant.spike_train_synchrony.plot_spike_contrast(trace,
spiketrains=spiketrains, c='gray', s=1)
plt.show()

"""
nrows = 2 if spiketrains is not None else 1
fig, axes = plt.subplots(nrows=nrows)
axes = np.atleast_1d(axes)
units = trace.bin_size.units
bin_sizes = trace.bin_size.magnitude
axes[0].plot(bin_sizes, trace.contrast, lw=lw, label=r'Contrast($\Delta$)',
linestyle='dashed', color='limegreen')
axes[0].plot(bin_sizes, trace.active_spiketrains, lw=lw,
label=r'ActiveST($\Delta$)',
linestyle='dashdot', color='dodgerblue')
axes[0].plot(bin_sizes, trace.synchrony, lw=lw,
label=r'Synchrony($\Delta$)', color='black')
bin_id_max = np.argmax(trace.synchrony)
synchrony_loc = bin_sizes[bin_id_max], trace.synchrony[bin_id_max]
axes[0].scatter(*synchrony_loc, s=20, c='red', marker='x')
axes[0].annotate('S', synchrony_loc, color='red', va='bottom', ha='left')
axes[0].legend()
axes[0].set_xscale(xscale)
axes[0].set_xlabel(fr"Bin size $\Delta$ ({units.dimensionality})")
if title is None:
title = "Spike-contrast synchrony measure"
axes[0].set_title(title)
if spiketrains is not None:
rasterplot(spiketrains, axes=axes[1], **kwargs)
axes[1].set_ylabel('neuron')
axes[1].yaxis.set_label_coords(0, 0.5)
plt.tight_layout()
return axes