Analysis

Autodoc

NeuroTools.analysis

A collection of analysis functions that may be used by NeuroTools.signals or other packages.

Classes

TuningCurve([D]) Class to facilitate working with tuning curves.

Functions

ccf Fast cross correlation function based on fft.
crosscorrelate Cross-correlation between two series of discrete events (e.g.
make_kernel Creates kernel functions for convolution.
simple_frequency_spectrum Simple frequency spectrum.
class NeuroTools.analysis.TuningCurve(D=None)[source]

Class to facilitate working with tuning curves.

add(D)[source]
max()[source]

Return the key of the max value and the max value.

stats()[source]

Return the mean tuning curve with stderrs.

NeuroTools.analysis.ccf(x, y, axis=None)[source]

Fast cross correlation function based on fft.

Computes the cross-correlation function of two series. Note that the computations are performed on anomalies (deviations from average). Returns the values of the cross-correlation at different lags.

x, y : 1D MaskedArrays
The two input arrays.
axis : integer, optional
Axis along which to compute (0 for rows, 1 for cols). If None, the array is flattened first.
>>> z = arange(5)
>>> ccf(z,z)
array([  3.90798505e-16,  -4.00000000e-01,  -4.00000000e-01,
        -1.00000000e-01,   4.00000000e-01,   1.00000000e+00,
         4.00000000e-01,  -1.00000000e-01,  -4.00000000e-01,
        -4.00000000e-01])
NeuroTools.analysis.crosscorrelate(sua1, sua2, lag=None, n_pred=1, predictor=None, display=False, kwargs={})[source]

Cross-correlation between two series of discrete events (e.g. spikes).

Calculates the cross-correlation between two vectors containing event times. Returns (differeces, pred, norm). See below for details.

Adapted from original script written by Martin P. Nawrot for the FIND MATLAB toolbox [1]_.

sua1, sua2 : 1D row or column ndarray or SpikeTrain
Event times. If sua2 == sua1, the result is the autocorrelogram.
lag : float
Lag for which relative event timing is considered with a max difference of +/- lag. A default lag is computed from the inter-event interval of the longer of the two sua arrays.
n_pred : int
Number of surrogate compilations for the predictor. This influences the total length of the predictor output array
predictor : {None, ‘shuffle’}
Determines the type of bootstrap predictor to be used. ‘shuffle’ shuffles interevent intervals of the longer input array and calculates relative differences with the shorter input array. n_pred determines the number of repeated shufflings, resulting differences are pooled from all repeated shufflings.
display : boolean
If True the corresponding plots will be displayed. If False, int, int_ and norm will be returned.
kwargs : dict
Arguments to be passed to np.histogram.
differences : np array
Accumulated differences of events in sua1 minus the events in sua2. Thus positive values relate to events of sua2 that lead events of sua1. Units are the same as the input arrays.
pred : np array
Accumulated differences based on the prediction method. The length of pred is n_pred * length(differences). Units are the same as the input arrays.
norm : float
Normalization factor used to scale the bin heights in differences and pred. differences/norm and pred/norm correspond to the linear correlation coefficient.

>> crosscorrelate(np_array1, np_array2) >> crosscorrelate(spike_train1, spike_train2) >> crosscorrelate(spike_train1, spike_train2, lag = 150.0) >> crosscorrelate(spike_train1, spike_train2, display=True,

kwargs={‘bins’:100})

ccf

[1]Meier R, Egert U, Aertsen A, Nawrot MP, “FIND - a unified framework for neural data analysis”; Neural Netw. 2008 Oct; 21(8):1085-93.
NeuroTools.analysis.make_kernel(form, sigma, time_stamp_resolution, direction=1)[source]

Creates kernel functions for convolution.

Constructs a numeric linear convolution kernel of basic shape to be used for data smoothing (linear low pass filtering) and firing rate estimation from single trial or trial-averaged spike trains.

Exponential and alpha kernels may also be used to represent postynaptic currents / potentials in a linear (current-based) model.

Adapted from original script written by Martin P. Nawrot for the FIND MATLAB toolbox [1]_ [2].

form : {‘BOX’, ‘TRI’, ‘GAU’, ‘EPA’, ‘EXP’, ‘ALP’}
Kernel form. Currently implemented forms are BOX (boxcar), TRI (triangle), GAU (gaussian), EPA (epanechnikov), EXP (exponential), ALP (alpha function). EXP and ALP are aymmetric kernel forms and assume optional parameter direction.
sigma : float
Standard deviation of the distribution associated with kernel shape. This parameter defines the time resolution (in ms) of the kernel estimate and makes different kernels comparable (cf. [1] for symetric kernels). This is used here as an alternative definition to the cut-off frequency of the associated linear filter.
time_stamp_resolution : float
Temporal resolution of input and output in ms.
direction : {-1, 1}
Asymmetric kernels have two possible directions. The values are -1 or 1, default is 1. The definition here is that for direction = 1 the kernel represents the impulse response function of the linear filter. Default value is 1.
kernel : array_like
Array of kernel. The length of this array is always an odd number to represent symmetric kernels such that the center bin coincides with the median of the numeric array, i.e for a triangle, the maximum will be at the center bin with equal number of bins to the right and to the left.
norm : float

For rate estimates. The kernel vector is normalized such that the sum of all entries equals unity sum(kernel)=1. When estimating rate functions from discrete spike data (0/1) the additional parameter norm allows for the normalization to rate in spikes per second.

For example: rate = norm * scipy.signal.lfilter(kernel, 1, spike_data)

m_idx : int
Index of the numerically determined median (center of gravity) of the kernel function.

To obtain single trial rate function of trial one should use:

r = norm * scipy.signal.fftconvolve(sua, kernel)

To obtain trial-averaged spike train one should use:

r_avg = norm * scipy.signal.fftconvolve(sua, np.mean(X,1))

where X is an array of shape (l,n), n is the number of trials and l is the length of each trial.

SpikeTrain.instantaneous_rate SpikeList.averaged_instantaneous_rate

[1]Meier R, Egert U, Aertsen A, Nawrot MP, “FIND - a unified framework for neural data analysis”; Neural Netw. 2008 Oct; 21(8):1085-93.
[2]Nawrot M, Aertsen A, Rotter S, “Single-trial estimation of neuronal firing rates - from single neuron spike trains to population activity”; J. Neurosci Meth 94: 81-92; 1999.
NeuroTools.analysis.simple_frequency_spectrum(x)[source]

Simple frequency spectrum.

Very simple calculation of frequency spectrum with no detrending, windowing, etc, just the first half (positive frequency components) of abs(fft(x))

x : array_like
The input array, in the time-domain.
spec : array_like
The frequency spectrum of x.

Table Of Contents

Previous topic

The parameters module

Next topic

The stgen module

This Page