elephant icon indicating copy to clipboard operation
elephant copied to clipboard

Error in instantaneous rate when passing a 1-dimensional kernel sigma [Bug]

Open Kleinjohann opened this issue 3 years ago • 1 comments

Describe the bug When passing a more than 0-dimensional sigma in the generation of a kernel and using said kernel to calculate the instantaneous firing rate an error is raised somewhere in fftconvolve.

To Reproduce

import neo
import elephant
import quantities as pq

st = neo.SpikeTrain([1]*pq.s, t_stop=2*pq.s)
kernel = elephant.kernels.GaussianKernel(sigma=[20]*pq.ms)

rate = elephant.statistics.instantaneous_rate(st,
                                              sampling_period=1*pq.ms,
                                              kernel=kernel)

returns

Traceback (most recent call last):
  File "reproduce_sigma_error.py", line 9, in <module>
    rate = elephant.statistics.instantaneous_rate(st,
  File "/home/kleinjohann/software/elephant/elephant/utils.py", line 79, in wrapper
    return func(*args, **kwargs)
  File "/home/kleinjohann/software/elephant/elephant/statistics.py", line 868, in instantaneous_rate
    rate = scipy.signal.fftconvolve(time_vectors,
  File "/home/kleinjohann/software/miniconda3/envs/elephant/lib/python3.8/site-packages/scipy/signal/signaltools.py", line 525, in fftconvolve
    raise ValueError("in1 and in2 should have the same dimensionality")
ValueError: in1 and in2 should have the same dimensionality

I tracked this down to https://github.com/NeuralEnsemble/elephant/blob/d0d39206a5a2bff0d57d365a63a30e402dbc597d/elephant/statistics.py#L852 where t_arr gains an extra dimension since cutoff_sigma keeps the extra dimension of sigma.

Expected behavior Either a more helpful error should be raised which tells me to fix the dimensionality of sigma, or different dimensionalities should be accounted for internally and no error should be raised.

Environment

  • OS: Linux
  • How I installed elephant: from source
  • Python version: 3.8.1
  • neo python package version: 0.9.0
  • elephant version: d0d3920
  • scipy version: 1.5.4

Kleinjohann avatar Feb 21 '22 11:02 Kleinjohann

Thanks for reporting this. I get the same error.

We will look into this, currently elephant.statistics.instantaneous_rate is undergoing changes with PR #453 in relation to #374.

Moritz-Alexander-Kern avatar Feb 23 '22 13:02 Moritz-Alexander-Kern