Python tutorial

In this tutorial, we demonstrate how the FastLZeroSpikeInference package can be used to deconvolve calcium imaging data from a single neuron. All demos require the FastLZeroSpikeInference package; installation instructions are provided here.

from FastLZeroSpikeInference import fast
import numpy as np
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

To illustratre the software, we use the following toy dataset.

gam = 0.98
y = np.power(gam, np.concatenate([np.arange(100), np.arange(100)]))
plt.plot(y)

png

The estimate_spikes function estimates spikes based on the calcium trace, exponential decay parameter $\gamma$, and a tuning parameter $\lambda$. This function solves

if the constraint parameter is set to false (default), and

if the constraint parameter is set to true. Here’s an example of the function applied to the toy data.

fit = fast.estimate_spikes(y, gam, 1, False)

By default, and to save computation time, the calcium concentration is not automatically estimated. However, the estimate_calcium function can be used to estimate the calcium concentration based on a prior fit.

# Determine calcium concentration from fit
fit = fast.estimate_calcium(fit)
plt.plot(fit['estimated_calcium'])

png

With estimated spike(s)

fit['spikes'][0]
101

Alternatively, both spikes and calcium concentrations can be computed with the estimate_spikes function with estimate_calcium parameter set to true.

fit = fast.estimate_spikes(y, gam, 1, False, True)

To solve the constrained problem

we set the constraint parameter to true in the estimate_spikes function. Consider the following example.

fit = fast.estimate_spikes(y, gam, 1, True, True)