The L^p electrode compensation method is implemented, along with a spike detection method and a quality test (Rossant et al 2012).
Lp_compensate(I, Vraw, dt, slice_duration=1.0 * second, p=1.0, criterion=None, full=False, docompensation=True, **initial_params)¶
Perform the L^p electrode compensation technique on a recorded membrane potential.
- I: injected current, 1D vector.
- Vraw: raw (uncompensated) voltage trace, 1D vector, same length as I.
- dt: sampling period (inverse of the sampling frequency), in second.
- slice_duration=1*second: duration of each time slice, where the fit is performed independently
- p=1.0: parameter of the Lp error. p should be less than 2. Experimenting with this parameter is recommended. Use p~1 at first, especially with difficult recordings Use p~0.5 with good recordings (less noise) or with biophysical model simulations without noise.
- criterion: a custom error function used in the optimization. If None, it is the Lp error. Otherwise, it should be a function of the form “lambda raw, model: error”, where raw and model are the raw and linear model membrane potential traces. For instance, the function for the Lp error is: “lambda raw, model: sum(abs(raw-model)**self.p)”. It can also be a function of the form: “lambda raw, model, electrode: error” in the case when one needs the electrode response to compute the error.
- full=False: if False, return a tuple (compensated_trace, parameters) where parameters is an array of the best parameters (one column/slice) If True, return a dict with the following keys: Vcompensated, Vneuron, Velectrode, params=params, instance where instance in the ElectrodeCompensation object.
- docompensation=True: if False, does not perform the optimization and only return an ElectrodeCompensation object instance, to take full control over the optimization procedure.
- params: a list of initial parameters for the optimization, in the following order: R, tau, Vr, Re, taue. Best results are obtained when reasonable estimates of the parameters are given.
find_spikes(v, vc=None, dt=0.1 * msecond, refractory=5.0 * msecond, check_quality=False)¶
Find spikes in an intracellular trace.
- vc=None: separatrix (in volt). If None, a separatrix will be automatically detected using the method described in the paper.
- dt=0.1*ms: timestep in the trace (inverse of the sampling frequency)
- refractory=5*ms: refractory period: minimal duration between two successive spikes
- check_quality=False: if True, will check spike detection quality using signal detection theory. The function then returns a tuple (spikes,scores) where scores is a dict.
get_trace_quality(v, I, full=False)¶
Compute the quality of a compensated trace.
- v: a compensated intracellular trace
- I: injected current
- full=False: if True, return a dict with the following keys: correlation, spikes, coefficients, after_onsets, peaks_prediction, after_onsets, spike_before, spike_onset, spike_after