.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_calcium_deconvolve.py: Deconvolve synthetic calcium traces ============================== This is an example of how to infer spike events First, we'll generate some fake data .. code-block:: python import numpy as np import pandas as pd from neuroglia.datasets import make_calcium_traces data = make_calcium_traces(duration=10.0,oscillation=False) traces = data['traces'] spikes = data['spikes'] let's plot the data .. code-block:: python import matplotlib.pyplot as plt traces.plot() plt.show() Now, we'll deconvolve the data .. code-block:: python from neuroglia.calcium import CalciumDeconvolver deconvolver = CalciumDeconvolver() detected_events = deconvolver.transform(traces) neuron_ids = traces.columns for neuron in neuron_ids: y_true = spikes[neuron] y_pred = detected_events[neuron] corr = np.corrcoef(y_pred,y_true)[0,1] print("{}: {:0.2f}".format(neuron,corr)) detected_events.plot() plt.show() Now, we'll predict spikes .. code-block:: python spikes_pred = deconvolver.predict(traces) spikes_true = (spikes>0).astype(int) for neuron in neuron_ids: y_true = spikes_true[neuron] y_pred = spikes_pred[neuron] corr = np.corrcoef(y_pred,y_true)[0,1] print("{}: {:0.2f}".format(neuron,corr)) .. _sphx_glr_download_gallery_calcium_deconvolve.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: calcium_deconvolve.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: calcium_deconvolve.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_