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

calcium refactoring #54

Merged
merged 6 commits into from
Dec 1, 2017
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
61 changes: 61 additions & 0 deletions examples/plot_calcium_deconvolve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python
"""
Deconvolve synthetic calcium traces
==============================

This is an example of how to infer spike events

"""

#######################################################
# First, we'll generate some fake data

import numpy as np
import pandas as pd
from oasis.functions import gen_data

neuron_ids = ['a', 'b', 'c']
sampling_rate = 30.0

traces, _, spikes = map(np.squeeze, gen_data(N=3, b=2, seed=0))

time = np.arange(0, traces.shape[1]/sampling_rate, 1/sampling_rate)

traces = pd.DataFrame(traces.T, index=time, columns=neuron_ids)
spikes = pd.DataFrame(spikes.T, index=time, columns=neuron_ids)

########################################################
# let's plot the data

import matplotlib.pyplot as plt
traces.plot()
plt.show()

##########################################################
# Now, we'll deconvolve the data

from neuroglia.calcium import CalciumDeconvolver

deconvolver = CalciumDeconvolver()
detected_events = deconvolver.transform(traces)

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

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))
Loading