Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise TypeError(
"The sampling period must be a time quantity!\n"
" Found: %s, value %s" % (type(sampling_period), str(sampling_period)))
if sampling_period.magnitude < 0:
raise ValueError("The sampling period must be larger than zero.")
if kernel == 'auto':
kernel_width_sigma = sskernel(
spiketrain.magnitude, tin=None, bootstrap=False)['optw']
if kernel_width_sigma is None:
raise ValueError(
"Unable to calculate optimal kernel width for "
"instantaneous rate from input data.")
kernel = kernels.GaussianKernel(kernel_width_sigma * spiketrain.units)
elif not isinstance(kernel, kernels.Kernel):
raise TypeError(
"kernel must be either instance of :class:`Kernel` "
"or the string 'auto'!\n"
" Found: %s, value %s" % (type(kernel), str(kernel)))
if not (isinstance(cutoff, float) or isinstance(cutoff, int)):
raise TypeError("cutoff must be float or integer!")
if not (t_start is None or (isinstance(t_start, pq.Quantity) and
t_start.dimensionality.simplified ==
pq.Quantity(1, "s").dimensionality)):
raise TypeError("t_start must be a time quantity!")
if not (t_stop is None or (isinstance(t_stop, pq.Quantity) and
t_stop.dimensionality.simplified ==
pq.Quantity(1, "s").dimensionality)):
raise TypeError("Spike trains must have a time unit.")
if not (isinstance(q, pq.quantity.Quantity) and
q.dimensionality.simplified ==
pq.Quantity(1, "Hz").dimensionality.simplified):
raise TypeError("q must be a rate quantity.")
if kernel is None:
if q == 0.0:
num_spikes = np.atleast_2d([st.size for st in trains])
return np.absolute(num_spikes.T - num_spikes)
elif q == np.inf:
num_spikes = np.atleast_2d([st.size for st in trains])
return num_spikes.T + num_spikes
else:
kernel = kernels.TriangularKernel(2.0 / (np.sqrt(6.0) * q))
if sort:
trains = [np.sort(st.view(type=pq.Quantity)) for st in trains]
def compute(i, j):
if i == j:
return 0.0
else:
if algorithm == 'fast':
return _victor_purpura_dist_for_st_pair_fast(
trains[i], trains[j], kernel)
elif algorithm == 'intuitive':
return _victor_purpura_dist_for_st_pair_intuitive(
trains[i], trains[j], q)
else:
raise NameError("algorithm must be either 'fast' "
# -*- coding: utf-8 -*-
"""
Tools for working with Neo objects
"""
import re
import numpy as np
import pandas as pd
import neo
import elephant
from pylttb import lttb
class CausalAlphaKernel(elephant.kernels.AlphaKernel):
"""
This modified version of elephant.kernels.AlphaKernel shifts time such that
convolution of the kernel with spike trains (as in
elephant.statistics.instantaneous_rate) results in alpha functions that
begin rising at the spike time, not before. The entire area of the kernel
comes after the spike, rather than half before and half after, as in
AlphaKernel. Consequently, CausalAlphaKernel can be used in causal filters.
Derived from:
"""
__doc__ += elephant.kernels.AlphaKernel.__doc__
def median_index(self, t):
"""
In CausalAlphaKernel, "median_index" is a misnomer. Instead of returning
the index into t that gives half area above and half below (median), it
import neo
import elephant
from pylttb import lttb
class CausalAlphaKernel(elephant.kernels.AlphaKernel):
"""
This modified version of elephant.kernels.AlphaKernel shifts time such that
convolution of the kernel with spike trains (as in
elephant.statistics.instantaneous_rate) results in alpha functions that
begin rising at the spike time, not before. The entire area of the kernel
comes after the spike, rather than half before and half after, as in
AlphaKernel. Consequently, CausalAlphaKernel can be used in causal filters.
Derived from:
"""
__doc__ += elephant.kernels.AlphaKernel.__doc__
def median_index(self, t):
"""
In CausalAlphaKernel, "median_index" is a misnomer. Instead of returning
the index into t that gives half area above and half below (median), it
returns the index for the first non-negative time, which always
corresponds to the start of the rise phase of the alpha function. This
hack ensures that, when the kernel is convolved with a spike train, the
entire alpha function is located to the right of each spike time.
Overrides the following:
"""
return np.nonzero(t >= 0)[0].min()
median_index.__doc__ += elephant.kernels.AlphaKernel.median_index.__doc__
def DownsampleNeoSignal(sig, decimation_factor):
pq.Quantity(1, "s").dimensionality):
raise TypeError(
"The sampling period must be a time quantity!\n"
" Found: %s, value %s" % (type(sampling_period), str(sampling_period)))
if sampling_period.magnitude < 0:
raise ValueError("The sampling period must be larger than zero.")
if kernel == 'auto':
kernel_width_sigma = sskernel(
spiketrain.magnitude, tin=None, bootstrap=False)['optw']
if kernel_width_sigma is None:
raise ValueError(
"Unable to calculate optimal kernel width for "
"instantaneous rate from input data.")
kernel = kernels.GaussianKernel(kernel_width_sigma * spiketrain.units)
elif not isinstance(kernel, kernels.Kernel):
raise TypeError(
"kernel must be either instance of :class:`Kernel` "
"or the string 'auto'!\n"
" Found: %s, value %s" % (type(kernel), str(kernel)))
if not (isinstance(cutoff, float) or isinstance(cutoff, int)):
raise TypeError("cutoff must be float or integer!")
if not (t_start is None or (isinstance(t_start, pq.Quantity) and
t_start.dimensionality.simplified ==
pq.Quantity(1, "s").dimensionality)):
raise TypeError("t_start must be a time quantity!")
if not (t_stop is None or (isinstance(t_stop, pq.Quantity) and
t_stop.dimensionality.simplified ==