Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ out/
# C files are always generated by Cython
*.c
*.C
test-env/
*.egg-info/
__pycache__/
*.so
15 changes: 11 additions & 4 deletions examples/distance_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
from __future__ import print_function

import matplotlib.pyplot as plt

import numpy as np
import pyspike as spk

# first load the data, interval ending time = 4000, start=0 (default)
spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt", 4000)

print(len(spike_trains))

# plot the spike times
plt.figure()
for (i, spike_train) in enumerate(spike_trains):
plt.scatter(spike_train, i*np.ones_like(spike_train), marker='|',color='black')
plt.title("raster plot")


plt.figure()
isi_distance = spk.isi_distance_matrix(spike_trains)
isi_distance = spk.isi_distance_matrix(spike_trains,interval=(0, 1000))
plt.imshow(isi_distance, interpolation='none')
plt.title("ISI-distance")

Expand All @@ -31,8 +38,8 @@
plt.title("SPIKE-distance, T=0-1000")

plt.figure()
spike_sync = spk.spike_sync_matrix(spike_trains, interval=(2000, 4000))
spike_sync = spk.spike_sync_matrix(spike_trains, interval=(0, 1000))
plt.imshow(spike_sync, interpolation='none')
plt.title("SPIKE-Sync, T=2000-4000")
plt.title("SPIKE-Sync, T=0-1000")

plt.show()
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "numpy", "cython"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion pyspike/PieceWiseConstFunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def integral(self, interval=None):
return a

def avrg(self, interval=None):
""" Computes the average of the piece-wise const function:
r""" Computes the average of the piece-wise const function:
:math:`a = 1/T \int_0^T f(x) dx` where T is the length of the interval.

:param interval: averaging interval given as a pair of floats, a
Expand Down
2 changes: 1 addition & 1 deletion pyspike/PieceWiseLinFunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def intermediate_value(x0, x1, y0, y1, x):
return integral

def avrg(self, interval=None):
""" Computes the average of the piece-wise linear function:
r""" Computes the average of the piece-wise linear function:
:math:`a = 1/T \int_0^T f(x) dx` where T is the interval length.

:param interval: averaging interval given as a pair of floats, a
Expand Down
17 changes: 4 additions & 13 deletions pyspike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,13 @@

# define the __version__ following
# http://stackoverflow.com/questions/17583443
from pkg_resources import get_distribution, DistributionNotFound
import os.path
from importlib.metadata import version, PackageNotFoundError

try:
_dist = get_distribution('pyspike')
# Normalize case for Windows systems
dist_loc = os.path.normcase(_dist.location)
here = os.path.normcase(__file__)
if not here.startswith(os.path.join(dist_loc, 'pyspike')):
# not installed, but there is another version that *is*
raise DistributionNotFound
except DistributionNotFound:
__version__ = version('pyspike')
except PackageNotFoundError:
__version__ = 'Please install this project with setup.py'
else:
__version__ = _dist.version


disable_backend_warning = False

def NoCythonWarn():
Expand Down
2 changes: 1 addition & 1 deletion pyspike/spike_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _spike_sync_values(spike_train1, spike_train2, interval, max_tau, **kwargs):
# spike_sync
############################################################
def spike_sync(*args, **kwargs):
""" Computes the spike synchronization value of the given spike
r""" Computes the spike synchronization value of the given spike
trains. The spike synchronization value is the computed as the total number
of coincidences divided by the total number of spikes:

Expand Down
112 changes: 28 additions & 84 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,40 @@
"""
from setuptools import setup, find_packages
from distutils.extension import Extension
from Cython.Build import cythonize
import os.path

try:
from Cython.Distutils import build_ext
except ImportError:
use_cython = False
else:
use_cython = True


class numpy_include(os.PathLike):
"""Defers import of numpy until install_requires is through"""
def __str__(self):
import numpy
return numpy.get_include()

def __fspath__(self):
return str(self)


if os.path.isfile("pyspike/cython/cython_add.c") and \
os.path.isfile("pyspike/cython/cython_get_tau.c") and \
os.path.isfile("pyspike/cython/cython_profiles.c") and \
os.path.isfile("pyspike/cython/cython_distances.c") and \
os.path.isfile("pyspike/cython/cython_directionality.c") and \
os.path.isfile("pyspike/cython/cython_simulated_annealing.c"):
use_c = True
else:
use_c = False

if not use_cython and not use_c:
print('Cython not installed. Programs will be slow.')
# Ans = input('Abort? (Y/N)\n')
# if len(Ans)>0 and (Ans[0]=='Y' or Ans[0]=='y'):
# print("\nAborting\n")
# raise RuntimeError('User termination')
"""Defers import of numpy until install_requires is through"""
def __str__(self):
import numpy
return numpy.get_include()

def __fspath__(self):
return str(self)


ext_modules = cythonize([
Extension("pyspike.cython.cython_add",
["pyspike/cython/cython_add.pyx"]),
Extension("pyspike.cython.cython_get_tau",
["pyspike/cython/cython_get_tau.pyx"]),
Extension("pyspike.cython.cython_profiles",
["pyspike/cython/cython_profiles.pyx"]),
Extension("pyspike.cython.cython_distances",
["pyspike/cython/cython_distances.pyx"]),
Extension("pyspike.cython.cython_directionality",
["pyspike/cython/cython_directionality.pyx"]),
Extension("pyspike.cython.cython_simulated_annealing",
["pyspike/cython/cython_simulated_annealing.pyx"])
])

cmdclass = {}
ext_modules = []

if use_cython: # Cython is available, compile .pyx -> .c
ext_modules += [
Extension("pyspike.cython.cython_add",
["pyspike/cython/cython_add.pyx"]),
Extension("pyspike.cython.cython_get_tau",
["pyspike/cython/cython_get_tau.pyx"]),
Extension("pyspike.cython.cython_profiles",
["pyspike/cython/cython_profiles.pyx"]),
Extension("pyspike.cython.cython_distances",
["pyspike/cython/cython_distances.pyx"]),
Extension("pyspike.cython.cython_directionality",
["pyspike/cython/cython_directionality.pyx"]),
Extension("pyspike.cython.cython_simulated_annealing",
["pyspike/cython/cython_simulated_annealing.pyx"])
]
cmdclass.update({'build_ext': build_ext})
elif use_c: # c files are there, compile to binaries
ext_modules += [
Extension("pyspike.cython.cython_add",
["pyspike/cython/cython_add.c"]),
Extension("pyspike.cython.cython_get_tau",
["pyspike/cython/cython_get_tau.c"]),
Extension("pyspike.cython.cython_profiles",
["pyspike/cython/cython_profiles.c"]),
Extension("pyspike.cython.cython_distances",
["pyspike/cython/cython_distances.c"]),
Extension("pyspike.cython.cython_directionality",
["pyspike/cython/cython_directionality.c"]),
Extension("pyspike.cython.cython_simulated_annealing",
["pyspike/cython/cython_simulated_annealing.c"])
]
# neither cython nor c files available -> automatic fall-back to python backend

setup(
name='pyspike',
packages=find_packages(exclude=['doc', 'test*']),
version='0.8.0',
cmdclass=cmdclass,
ext_modules=ext_modules,
include_dirs=[numpy_include()],
description='A Python library for the numerical analysis of spike\
Expand All @@ -98,34 +54,22 @@ def __fspath__(self):
license='BSD',
url='https://github.com/mariomulansky/PySpike',
install_requires=['numpy'],
keywords=['data analysis', 'spike', 'neuroscience'], # arbitrary keywords
keywords=['data analysis', 'spike', 'neuroscience'],
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',

# Indicate who your project is intended for
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Information Analysis',

'License :: OSI Approved :: BSD License',

'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
package_data={
'pyspike': ['cython/cython_add.c',
'cython/cython_profiles.c',
'cython/cython_get_tau.c',
'cython/cython_distances.c',
'cython/cython_directionality.c',
'cython/cython_simulated_annealing.c'],
'test': ['Spike_testdata.txt']
}
)
)