spiking_metrics.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import numpy as np
  2. # See also: https://github.com/NeuralEnsemble/NeuroTools/blob/master/src/signals/spikes.py
  3. def mean_firing_rate(spiketrain):
  4. """
  5. spiketrain - an array of spike times in seconds
  6. """
  7. if len(spiketrain) < 5:
  8. return 0
  9. return np.mean(np.diff(spiketrain)) ** (-1)
  10. def isi_cv(spiketrain, outliers=3):
  11. """
  12. ISI Coeff of variation
  13. spiketrain - an array of spike times in seconds
  14. """
  15. if len(spiketrain) < 5:
  16. return 0
  17. isi = np.diff(spiketrain)
  18. #isi = isi[abs(isi - np.mean(isi)) < outliers * np.std(isi)]
  19. return np.std(isi)/np.mean(isi)
  20. def isi_fano(spiketrain, outliers=3):
  21. """
  22. The Fano Factor is defined as the variance of the isi divided by the mean of the isi
  23. http://en.wikipedia.org/wiki/Fano_factor
  24. From https://github.com/NeuralEnsemble/NeuroTools/blob/master/src/signals/spikes.py
  25. spiketrain - an array of spike times in seconds
  26. """
  27. if len(spiketrain) < 5:
  28. return 0
  29. isi = np.diff(spiketrain)
  30. #isi_filt = isi[abs(isi - np.mean(isi)) < outliers * np.std(isi)]
  31. return np.var(isi)/np.mean(isi)
  32. def burstiness(spiketrain, threshold=0.02):
  33. """
  34. spiketrain - an array of spike times in seconds
  35. threshold -
  36. """
  37. pass # Not implemented