diff options
-rw-r--r-- | .github/workflows/python-package.yml | 51 | ||||
-rw-r--r-- | .travis.yml | 22 | ||||
-rw-r--r-- | Changelog | 6 | ||||
-rw-r--r-- | Readme.rst | 9 | ||||
-rw-r--r-- | doc/tutorial.rst | 1 | ||||
-rw-r--r-- | pyspike/DiscreteFunc.py | 6 | ||||
-rw-r--r-- | pyspike/PieceWiseConstFunc.py | 8 | ||||
-rw-r--r-- | pyspike/PieceWiseLinFunc.py | 8 | ||||
-rw-r--r-- | pyspike/cython/cython_add.pyx | 1 | ||||
-rw-r--r-- | pyspike/cython/cython_directionality.pyx | 1 | ||||
-rw-r--r-- | pyspike/cython/cython_distances.pyx | 1 | ||||
-rw-r--r-- | pyspike/cython/cython_profiles.pyx | 1 | ||||
-rw-r--r-- | pyspike/cython/cython_simulated_annealing.pyx | 1 | ||||
-rw-r--r-- | setup.py | 12 | ||||
-rw-r--r-- | test/test_distance.py | 70 | ||||
-rw-r--r-- | test/test_empty.py | 36 | ||||
-rw-r--r-- | test/test_function.py | 52 | ||||
-rw-r--r-- | test/test_generic_interfaces.py | 18 | ||||
-rw-r--r-- | test/test_regression/test_regression_15.py | 20 | ||||
-rw-r--r-- | test/test_spikes.py | 10 | ||||
-rw-r--r-- | test/test_sync_filter.py | 32 |
21 files changed, 204 insertions, 162 deletions
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..6585af4 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,51 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python package + +on: + push: + branches: [ master, develop ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] + cython: ['python -m pip install -q cython', 'echo "No Cython"'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install libblas-dev + sudo apt-get install liblapack-dev + sudo apt-get install gfortran + python -m pip install --upgrade pip + python -m pip install flake8 pytest nose numpy scipy + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install Cython + run: | + ${{ matrix.cython }} + - name: Install package + run: | + python setup.py build_ext --inplace + # - name: Lint with flake8 + # run: | + # # stop the build if there are Python syntax errors or undefined names + # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with PyTest + run: | + python -m pytest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2877331..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: python -python: - - "2.7" - - "3.4" - - "3.5" - - "3.6" -env: - - CYTHON_INSTALL="pip install -q cython" - - CYTHON_INSTALL="" -before_install: - - sudo apt-get update - - sudo apt-get install libblas-dev - - sudo apt-get install liblapack-dev - - sudo apt-get install gfortran -install: - - pip install scipy - - $CYTHON_INSTALL - -script: - - python setup.py build_ext --inplace - - nosetests - - travis_wait 30 nosetests test/numeric @@ -1,3 +1,9 @@ +PySpike v0.7: + * Python 3.10 compatible + * Dropped support for Python2 + * Small fixes in tests + * Fixed documentation links + PySpike v0.6: * Support for computing spike directionality and spike train order @@ -22,15 +22,18 @@ If you use PySpike in your research, please cite our SoftwareX publication on Py Additionally, depending on the used methods: ISI-distance [1], SPIKE-distance [2] or SPIKE-Synchronization [3], please cite one or more of the following publications: -.. [#] Kreuz T, Haas JS, Morelli A, Abarbanel HDI, Politi A, *Measuring spike train synchrony.* J Neurosci Methods 165, 151 (2007) `[pdf] <http://wwwold.fi.isc.cnr.it/users/thomas.kreuz/images/Kreuz_JNeurosciMethods_2007_Spike-Train-Synchrony.pdf>`_ +.. [#] Kreuz T, Haas JS, Morelli A, Abarbanel HDI, Politi A, *Measuring spike train synchrony.* J Neurosci Methods 165, 151 (2007) `[pdf] <https://drive.google.com/file/d/113cr1xUhKe0rMIiFc1vMoIQ7j9noobKW/view>`_ -.. [#] Kreuz T, Chicharro D, Houghton C, Andrzejak RG, Mormann F, *Monitoring spike train synchrony.* J Neurophysiol 109, 1457 (2013) `[pdf] <http://wwwold.fi.isc.cnr.it/users/thomas.kreuz/images/Kreuz_JNeurophysiol_2013_SPIKE-distance.pdf>`_ +.. [#] Kreuz T, Chicharro D, Houghton C, Andrzejak RG, Mormann F, *Monitoring spike train synchrony.* J Neurophysiol 109, 1457 (2013) `[pdf] <https://drive.google.com/file/d/1oppf86V4cBVakPiv6Mbn_WaoKoKWzmIl/view>`_ .. [#] Kreuz T, Mulansky M and Bozanic N, *SPIKY: A graphical user interface for monitoring spike train synchrony*, J Neurophysiol, JNeurophysiol 113, 3432 (2015) Important Changelog ----------------------------- +With version 0.7.0, support for Python 2 was dropped, PySpike now officially supports +Python 3.7, 3.8, 3.9, 3.10. + With version 0.6.0, the spike directionality and spike train order function have been added. With version 0.5.0, the interfaces have been unified and the specific functions for multivariate computations have become deprecated. @@ -135,5 +138,5 @@ Curie Initial Training Network* `Neural Engineering Transformative Technologies .. _SPIKE: http://www.scholarpedia.org/article/SPIKE-distance .. _SPIKE-Synchronization: http://www.scholarpedia.org/article/Measures_of_spike_train_synchrony#SPIKE_synchronization .. _cython: http://www.cython.org -.. _SPIKY: http://wwwold.fi.isc.cnr.it/users/thomas.kreuz/Source-Code/SPIKY.html +.. _SPIKY: https://thomas-kreuz.complexworld.net/source-codes/spiky .. _BSD_License: http://opensource.org/licenses/BSD-2-Clause diff --git a/doc/tutorial.rst b/doc/tutorial.rst index 377c0a2..7c3e9b6 100644 --- a/doc/tutorial.rst +++ b/doc/tutorial.rst @@ -245,6 +245,7 @@ The following example computes the Spike Order profile and Synfire Indicator of two Poissonian spike trains. .. code:: python + import numpy as np from matplotlib import pyplot as plt import pyspike as spk diff --git a/pyspike/DiscreteFunc.py b/pyspike/DiscreteFunc.py index caad290..48bc787 100644 --- a/pyspike/DiscreteFunc.py +++ b/pyspike/DiscreteFunc.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, print_function import numpy as np -import collections +import collections.abc import pyspike @@ -155,11 +155,11 @@ class DiscreteFunc(object): multiplicity = np.sum(self.mp[1:-1]) else: # check if interval is as sequence - assert isinstance(interval, collections.Sequence), \ + assert isinstance(interval, collections.abc.Sequence), \ "Invalid value for `interval`. None, Sequence or Tuple \ expected." # check if interval is a sequence of intervals - if not isinstance(interval[0], collections.Sequence): + if not isinstance(interval[0], collections.abc.Sequence): # find the indices corresponding to the interval start_ind, end_ind = get_indices(interval) value = np.sum(self.y[start_ind:end_ind]) diff --git a/pyspike/PieceWiseConstFunc.py b/pyspike/PieceWiseConstFunc.py index 17fdd3f..e33c61d 100644 --- a/pyspike/PieceWiseConstFunc.py +++ b/pyspike/PieceWiseConstFunc.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, print_function import numpy as np -import collections +import collections.abc import pyspike @@ -39,7 +39,7 @@ class PieceWiseConstFunc(object): ind = np.searchsorted(self.x, t, side='right') - if isinstance(t, collections.Sequence): + if isinstance(t, collections.abc.Sequence): # t is a sequence of values # correct the cases t == x[0], t == x[-1] ind[ind == 0] = 1 @@ -173,10 +173,10 @@ class PieceWiseConstFunc(object): return self.integral() / (self.x[-1]-self.x[0]) # check if interval is as sequence - assert isinstance(interval, collections.Sequence), \ + assert isinstance(interval, collections.abc.Sequence), \ "Invalid value for `interval`. None, Sequence or Tuple expected." # check if interval is a sequence of intervals - if not isinstance(interval[0], collections.Sequence): + if not isinstance(interval[0], collections.abc.Sequence): # just one interval a = self.integral(interval) / (interval[1]-interval[0]) else: diff --git a/pyspike/PieceWiseLinFunc.py b/pyspike/PieceWiseLinFunc.py index 8faaec4..b3b503b 100644 --- a/pyspike/PieceWiseLinFunc.py +++ b/pyspike/PieceWiseLinFunc.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, print_function import numpy as np -import collections +import collections.abc import pyspike @@ -46,7 +46,7 @@ class PieceWiseLinFunc: ind = np.searchsorted(self.x, t, side='right') - if isinstance(t, collections.Sequence): + if isinstance(t, collections.abc.Sequence): # t is a sequence of values # correct the cases t == x[0], t == x[-1] ind[ind == 0] = 1 @@ -211,10 +211,10 @@ class PieceWiseLinFunc: return self.integral() / (self.x[-1]-self.x[0]) # check if interval is as sequence - assert isinstance(interval, collections.Sequence), \ + assert isinstance(interval, collections.abc.Sequence), \ "Invalid value for `interval`. None, Sequence or Tuple expected." # check if interval is a sequence of intervals - if not isinstance(interval[0], collections.Sequence): + if not isinstance(interval[0], collections.abc.Sequence): # just one interval a = self.integral(interval) / (interval[1]-interval[0]) else: diff --git a/pyspike/cython/cython_add.pyx b/pyspike/cython/cython_add.pyx index 25f1181..f38406a 100644 --- a/pyspike/cython/cython_add.pyx +++ b/pyspike/cython/cython_add.pyx @@ -1,3 +1,4 @@ +#cython: language_level=3 #cython: boundscheck=False #cython: wraparound=False #cython: cdivision=True diff --git a/pyspike/cython/cython_directionality.pyx b/pyspike/cython/cython_directionality.pyx index ac37690..40450cd 100644 --- a/pyspike/cython/cython_directionality.pyx +++ b/pyspike/cython/cython_directionality.pyx @@ -1,3 +1,4 @@ +#cython: language_level=3 #cython: boundscheck=False #cython: wraparound=False #cython: cdivision=True diff --git a/pyspike/cython/cython_distances.pyx b/pyspike/cython/cython_distances.pyx index d4070ae..f049718 100644 --- a/pyspike/cython/cython_distances.pyx +++ b/pyspike/cython/cython_distances.pyx @@ -1,3 +1,4 @@ +#cython: language_level=3 #cython: boundscheck=False #cython: wraparound=False #cython: cdivision=True diff --git a/pyspike/cython/cython_profiles.pyx b/pyspike/cython/cython_profiles.pyx index aa24db4..a83e4f7 100644 --- a/pyspike/cython/cython_profiles.pyx +++ b/pyspike/cython/cython_profiles.pyx @@ -1,3 +1,4 @@ +#cython: language_level=3 #cython: boundscheck=False #cython: wraparound=False #cython: cdivision=True diff --git a/pyspike/cython/cython_simulated_annealing.pyx b/pyspike/cython/cython_simulated_annealing.pyx index be9423c..53ecde7 100644 --- a/pyspike/cython/cython_simulated_annealing.pyx +++ b/pyspike/cython/cython_simulated_annealing.pyx @@ -1,3 +1,4 @@ +#cython: language_level=3 #cython: boundscheck=False #cython: wraparound=False #cython: cdivision=True @@ -72,7 +72,7 @@ elif use_c: # c files are there, compile to binaries setup( name='pyspike', packages=find_packages(exclude=['doc']), - version='0.6.0', + version='0.7.0', cmdclass=cmdclass, ext_modules=ext_modules, include_dirs=[numpy_include()], @@ -98,13 +98,11 @@ train similarity', 'License :: OSI Approved :: BSD License', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6' + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], package_data={ 'pyspike': ['cython/cython_add.c', 'cython/cython_profiles.c', diff --git a/test/test_distance.py b/test/test_distance.py index fe09f34..7ec3a72 100644 --- a/test/test_distance.py +++ b/test/test_distance.py @@ -11,7 +11,7 @@ Distributed under the BSD License from __future__ import print_function import numpy as np from copy import copy -from numpy.testing import assert_equal, assert_almost_equal, \ +from numpy.testing import assert_allclose, assert_almost_equal, \ assert_array_almost_equal import pyspike as spk @@ -41,10 +41,10 @@ def test_isi(): # print("ISI: ", f.y) print("ISI value:", expected_isi_val) - assert_equal(f.x, expected_times) + assert_allclose(f.x, expected_times) assert_array_almost_equal(f.y, expected_isi, decimal=15) - assert_equal(f.avrg(), expected_isi_val) - assert_equal(spk.isi_distance(t1, t2), expected_isi_val) + assert_allclose(f.avrg(), expected_isi_val) + assert_allclose(spk.isi_distance(t1, t2), expected_isi_val) # check with some equal spike times t1 = SpikeTrain([0.2, 0.4, 0.6], [0.0, 1.0]) @@ -60,10 +60,10 @@ def test_isi(): f = spk.isi_profile(t1, t2) - assert_equal(f.x, expected_times) + assert_allclose(f.x, expected_times) assert_array_almost_equal(f.y, expected_isi, decimal=15) - assert_equal(f.avrg(), expected_isi_val) - assert_equal(spk.isi_distance(t1, t2), expected_isi_val) + assert_allclose(f.avrg(), expected_isi_val) + assert_allclose(spk.isi_distance(t1, t2), expected_isi_val) def test_spike(): @@ -75,7 +75,7 @@ def test_spike(): f = spk.spike_profile(t1, t2) - assert_equal(f.x, expected_times) + assert_allclose(f.x, expected_times) # from SPIKY: y_all = np.array([0.000000000000000000, 0.555555555555555580, @@ -89,7 +89,7 @@ def test_spike(): assert_array_almost_equal(f.y2, y_all[1::2]) assert_almost_equal(f.avrg(), 0.186309523809523814, decimal=15) - assert_equal(spk.spike_distance(t1, t2), f.avrg()) + assert_allclose(spk.spike_distance(t1, t2), f.avrg()) t1 = SpikeTrain([0.2, 0.4, 0.6, 0.7], 1.0) t2 = SpikeTrain([0.3, 0.45, 0.8, 0.9, 0.95], 1.0) @@ -118,7 +118,7 @@ def test_spike(): f = spk.spike_profile(t1, t2) - assert_equal(f.x, expected_times) + assert_allclose(f.x, expected_times) assert_array_almost_equal(f.y1, expected_y1, decimal=15) assert_array_almost_equal(f.y2, expected_y2, decimal=15) assert_almost_equal(f.avrg(), expected_spike_val, decimal=15) @@ -157,7 +157,7 @@ def test_spike(): f = spk.spike_profile(t1, t2) - assert_equal(f.x, expected_times) + assert_allclose(f.x, expected_times) assert_array_almost_equal(f.y1, expected_y1, decimal=14) assert_array_almost_equal(f.y2, expected_y2, decimal=14) assert_almost_equal(f.avrg(), expected_spike_val, decimal=16) @@ -236,8 +236,8 @@ def test_spike_sync(): f.add(f2) i12 = f.integral() - assert_equal(i1[0]+i2[0], i12[0]) - assert_equal(i1[1]+i2[1], i12[1]) + assert_allclose(i1[0]+i2[0], i12[0]) + assert_allclose(i1[1]+i2[1], i12[1]) def check_multi_profile(profile_func, profile_func_multi, dist_func_multi): @@ -258,7 +258,7 @@ def check_multi_profile(profile_func, profile_func_multi, dist_func_multi): f_multi = profile_func_multi(spike_trains, [0, 1]) assert f_multi.almost_equal(f12, decimal=14) d = dist_func_multi(spike_trains, [0, 1]) - assert_equal(f_multi.avrg(), d) + assert_allclose(f_multi.avrg(), d) f_multi1 = profile_func_multi(spike_trains, [1, 2, 3]) f_multi2 = profile_func_multi(spike_trains[1:]) @@ -329,11 +329,11 @@ def test_multi_spike_sync(): f = spk.spike_sync_profile_multi(spike_trains) - assert_equal(spike_times, f.x[1:-1]) - assert_equal(len(f.x), len(f.y)) + assert_allclose(spike_times, f.x[1:-1]) + assert_allclose(len(f.x), len(f.y)) - assert_equal(np.sum(f.y[1:-1]), 39932) - assert_equal(np.sum(f.mp[1:-1]), 85554) + assert_allclose(np.sum(f.y[1:-1]), 39932) + assert_allclose(np.sum(f.mp[1:-1]), 85554) # example with 2 empty spike trains sts = [] @@ -365,16 +365,16 @@ def check_dist_matrix(dist_func, dist_matrix_func): f_matrix = dist_matrix_func(spike_trains) # check zero diagonal for i in range(4): - assert_equal(0.0, f_matrix[i, i]) + assert_allclose(0.0, f_matrix[i, i]) for i in range(4): for j in range(i+1, 4): - assert_equal(f_matrix[i, j], f_matrix[j, i]) - assert_equal(f12, f_matrix[1, 0]) - assert_equal(f13, f_matrix[2, 0]) - assert_equal(f14, f_matrix[3, 0]) - assert_equal(f23, f_matrix[2, 1]) - assert_equal(f24, f_matrix[3, 1]) - assert_equal(f34, f_matrix[3, 2]) + assert_allclose(f_matrix[i, j], f_matrix[j, i]) + assert_allclose(f12, f_matrix[1, 0]) + assert_allclose(f13, f_matrix[2, 0]) + assert_allclose(f14, f_matrix[3, 0]) + assert_allclose(f23, f_matrix[2, 1]) + assert_allclose(f24, f_matrix[3, 1]) + assert_allclose(f34, f_matrix[3, 2]) def test_isi_matrix(): @@ -397,13 +397,13 @@ def test_regression_spiky(): isi_dist = spk.isi_distance(st1, st2) assert_almost_equal(isi_dist, 9.0909090909090939e-02, decimal=15) isi_profile = spk.isi_profile(st1, st2) - assert_equal(isi_profile.y, 0.1/1.1 * np.ones_like(isi_profile.y)) + assert_allclose(isi_profile.y, 0.1/1.1 * np.ones_like(isi_profile.y)) spike_dist = spk.spike_distance(st1, st2) - assert_equal(spike_dist, 0.211058782487353908) + assert_allclose(spike_dist, 0.211058782487353908) spike_sync = spk.spike_sync(st1, st2) - assert_equal(spike_sync, 8.6956521739130432e-01) + assert_allclose(spike_sync, 8.6956521739130432e-01) # multivariate check @@ -414,7 +414,7 @@ def test_regression_spiky(): assert_almost_equal(isi_dist, 0.17051816816999129656, decimal=15) spike_profile = spk.spike_profile_multi(spike_trains) - assert_equal(len(spike_profile.y1)+len(spike_profile.y2), 1252) + assert_allclose(len(spike_profile.y1)+len(spike_profile.y2), 1252) spike_dist = spk.spike_distance_multi(spike_trains) # get the full precision from SPIKY @@ -422,7 +422,7 @@ def test_regression_spiky(): spike_sync = spk.spike_sync_multi(spike_trains) # get the full precision from SPIKY - assert_equal(spike_sync, 0.7183531505298066) + assert_allclose(spike_sync, 0.7183531505298066) # Eero's edge correction example st1 = SpikeTrain([0.5, 1.5, 2.5], 6.0) @@ -439,7 +439,7 @@ def test_regression_spiky(): expected_y1 = y_all[::2] expected_y2 = y_all[1::2] - assert_equal(f.x, expected_times) + assert_allclose(f.x, expected_times) assert_array_almost_equal(f.y1, expected_y1, decimal=14) assert_array_almost_equal(f.y2, expected_y2, decimal=14) @@ -452,15 +452,15 @@ def test_multi_variate_subsets(): v1 = spk.isi_distance_multi(spike_trains_sub_set) v2 = spk.isi_distance_multi(spike_trains, sub_set) - assert_equal(v1, v2) + assert_allclose(v1, v2) v1 = spk.spike_distance_multi(spike_trains_sub_set) v2 = spk.spike_distance_multi(spike_trains, sub_set) - assert_equal(v1, v2) + assert_allclose(v1, v2) v1 = spk.spike_sync_multi(spike_trains_sub_set) v2 = spk.spike_sync_multi(spike_trains, sub_set) - assert_equal(v1, v2) + assert_allclose(v1, v2) if __name__ == "__main__": diff --git a/test/test_empty.py b/test/test_empty.py index 4d0a5cf..93fd2c1 100644 --- a/test/test_empty.py +++ b/test/test_empty.py @@ -10,7 +10,7 @@ Distributed under the BSD License from __future__ import print_function import numpy as np -from numpy.testing import assert_equal, assert_almost_equal, \ +from numpy.testing import assert_allclose, assert_almost_equal, \ assert_array_equal, assert_array_almost_equal import pyspike as spk @@ -33,18 +33,18 @@ def test_isi_empty(): st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([], edges=(0.0, 1.0)) d = spk.isi_distance(st1, st2) - assert_equal(d, 0.0) + assert_allclose(d, 0.0) prof = spk.isi_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 1.0]) assert_array_equal(prof.y, [0.0, ]) st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([0.4, ], edges=(0.0, 1.0)) d = spk.isi_distance(st1, st2) - assert_equal(d, 0.6*0.4+0.4*0.6) + assert_allclose(d, 0.6*0.4+0.4*0.6) prof = spk.isi_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 0.4, 1.0]) assert_array_equal(prof.y, [0.6, 0.4]) @@ -53,7 +53,7 @@ def test_isi_empty(): d = spk.isi_distance(st1, st2) assert_almost_equal(d, 0.2/0.6*0.4 + 0.0 + 0.2/0.6*0.4, decimal=15) prof = spk.isi_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.4, 0.6, 1.0], decimal=15) assert_array_almost_equal(prof.y, [0.2/0.6, 0.0, 0.2/0.6], decimal=15) @@ -62,9 +62,9 @@ def test_spike_empty(): st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([], edges=(0.0, 1.0)) d = spk.spike_distance(st1, st2) - assert_equal(d, 0.0) + assert_allclose(d, 0.0) prof = spk.spike_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 1.0]) assert_array_equal(prof.y1, [0.0, ]) assert_array_equal(prof.y2, [0.0, ]) @@ -75,7 +75,7 @@ def test_spike_empty(): d_expect = 2*0.4*0.4*1.0/(0.4+1.0)**2 + 2*0.6*0.4*1.0/(0.6+1.0)**2 assert_almost_equal(d, d_expect, decimal=15) prof = spk.spike_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 0.4, 1.0]) assert_array_almost_equal(prof.y1, [2*0.4*1.0/(0.4+1.0)**2, 2*0.4*1.0/(0.6+1.0)**2], @@ -100,7 +100,7 @@ def test_spike_empty(): assert_almost_equal(d, expected_spike_val, decimal=15) prof = spk.spike_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.4, 0.6, 1.0], decimal=15) assert_array_almost_equal(prof.y1, expected_y1, decimal=15) assert_array_almost_equal(prof.y2, expected_y2, decimal=15) @@ -110,18 +110,18 @@ def test_spike_sync_empty(): st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) - assert_equal(d, 1.0) + assert_allclose(d, 1.0) prof = spk.spike_sync_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 1.0]) assert_array_equal(prof.y, [1.0, 1.0]) st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([0.4, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) - assert_equal(d, 0.0) + assert_allclose(d, 0.0) prof = spk.spike_sync_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 0.4, 1.0]) assert_array_equal(prof.y, [0.0, 0.0, 0.0]) @@ -130,7 +130,7 @@ def test_spike_sync_empty(): d = spk.spike_sync(st1, st2) assert_almost_equal(d, 1.0, decimal=15) prof = spk.spike_sync_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.4, 0.6, 1.0], decimal=15) assert_array_almost_equal(prof.y, [1.0, 1.0, 1.0, 1.0], decimal=15) @@ -139,7 +139,7 @@ def test_spike_sync_empty(): d = spk.spike_sync(st1, st2) assert_almost_equal(d, 0.0, decimal=15) prof = spk.spike_sync_profile(st1, st2) - assert_equal(d, prof.avrg()) + assert_allclose(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.2, 0.8, 1.0], decimal=15) assert_array_almost_equal(prof.y, [0.0, 0.0, 0.0, 0.0], decimal=15) @@ -148,9 +148,9 @@ def test_spike_sync_empty(): st2 = SpikeTrain([2.1, 7.0], [0, 10.0]) st3 = SpikeTrain([5.1, 6.0], [0, 10.0]) res = spk.spike_sync_profile(st1, st2).avrg(interval=[3.0, 4.0]) - assert_equal(res, 1.0) + assert_allclose(res, 1.0) res = spk.spike_sync(st1, st2, interval=[3.0, 4.0]) - assert_equal(res, 1.0) + assert_allclose(res, 1.0) sync_matrix = spk.spike_sync_matrix([st1, st2, st3], interval=[3.0, 4.0]) assert_array_equal(sync_matrix, np.ones((3, 3)) - np.diag(np.ones(3))) diff --git a/test/test_function.py b/test/test_function.py index 6c04839..ba10ae7 100644 --- a/test/test_function.py +++ b/test/test_function.py @@ -11,7 +11,7 @@ from __future__ import print_function import numpy as np from copy import copy from nose.tools import raises -from numpy.testing import assert_equal, assert_almost_equal, \ +from numpy.testing import assert_allclose, assert_almost_equal, \ assert_array_equal, assert_array_almost_equal import pyspike as spk @@ -24,14 +24,14 @@ def test_pwc(): f = spk.PieceWiseConstFunc(x, y) # function values - assert_equal(f(0.0), 1.0) - assert_equal(f(0.5), 1.0) - assert_equal(f(1.0), 0.25) - assert_equal(f(2.0), 0.5) - assert_equal(f(2.25), 1.5) - assert_equal(f(2.5), 2.25/2) - assert_equal(f(3.5), 0.75) - assert_equal(f(4.0), 0.75) + assert_allclose(f(0.0), 1.0) + assert_allclose(f(0.5), 1.0) + assert_allclose(f(1.0), 0.25) + assert_allclose(f(2.0), 0.5) + assert_allclose(f(2.25), 1.5) + assert_allclose(f(2.5), 2.25/2) + assert_allclose(f(3.5), 0.75) + assert_allclose(f(4.0), 0.75) assert_array_equal(f([0.0, 0.5, 1.0, 2.0, 2.25, 2.5, 3.5, 4.0]), [1.0, 1.0, 0.25, 0.5, 1.5, 2.25/2, 0.75, 0.75]) @@ -131,21 +131,21 @@ def test_pwc_integral(): # test full interval full = 1.0*1.0 + 1.0*-0.5 + 0.5*1.5 + 1.5*0.75; - assert_equal(f1.integral(), full) - assert_equal(f1.integral((np.min(x),np.max(x))), full) + assert_allclose(f1.integral(), full) + assert_allclose(f1.integral((np.min(x),np.max(x))), full) # test part interval, spanning an edge - assert_equal(f1.integral((0.5,1.5)), 0.5*1.0 + 0.5*-0.5) + assert_allclose(f1.integral((0.5,1.5)), 0.5*1.0 + 0.5*-0.5) # test part interval, just over two edges assert_almost_equal(f1.integral((1.0-1e-16,2+1e-16)), 1.0*-0.5, decimal=14) # test part interval, between two edges - assert_equal(f1.integral((1.0,2.0)), 1.0*-0.5) - assert_equal(f1.integral((1.2,1.7)), (1.7-1.2)*-0.5) + assert_allclose(f1.integral((1.0,2.0)), 1.0*-0.5) + assert_allclose(f1.integral((1.2,1.7)), (1.7-1.2)*-0.5) # test part interval, start to before and after edge - assert_equal(f1.integral((0.0,0.7)), 0.7*1.0) - assert_equal(f1.integral((0.0,1.1)), 1.0*1.0+0.1*-0.5) + assert_allclose(f1.integral((0.0,0.7)), 0.7*1.0) + assert_allclose(f1.integral((0.0,1.1)), 1.0*1.0+0.1*-0.5) # test part interval, before and after edge till end - assert_equal(f1.integral((2.6,4.0)), (4.0-2.6)*0.75) - assert_equal(f1.integral((2.4,4.0)), (2.5-2.4)*1.5+(4-2.5)*0.75) + assert_allclose(f1.integral((2.6,4.0)), (4.0-2.6)*0.75) + assert_allclose(f1.integral((2.4,4.0)), (2.5-2.4)*1.5+(4-2.5)*0.75) @raises(ValueError) def test_pwc_integral_bad_bounds_inv(): @@ -178,14 +178,14 @@ def test_pwl(): f = spk.PieceWiseLinFunc(x, y1, y2) # function values - assert_equal(f(0.0), 1.0) - assert_equal(f(0.5), 1.25) - assert_equal(f(1.0), 0.5) - assert_equal(f(2.0), 1.1/2) - assert_equal(f(2.25), 1.5) - assert_equal(f(2.5), 2.25/2) - assert_equal(f(3.5), 0.75-0.5*1.0/1.5) - assert_equal(f(4.0), 0.25) + assert_allclose(f(0.0), 1.0) + assert_allclose(f(0.5), 1.25) + assert_allclose(f(1.0), 0.5) + assert_allclose(f(2.0), 1.1/2) + assert_allclose(f(2.25), 1.5) + assert_allclose(f(2.5), 2.25/2) + assert_allclose(f(3.5), 0.75-0.5*1.0/1.5) + assert_allclose(f(4.0), 0.25) assert_array_equal(f([0.0, 0.5, 1.0, 2.0, 2.25, 2.5, 3.5, 4.0]), [1.0, 1.25, 0.5, 0.55, 1.5, 2.25/2, 0.75-0.5/1.5, 0.25]) diff --git a/test/test_generic_interfaces.py b/test/test_generic_interfaces.py index 7f08067..553f3f4 100644 --- a/test/test_generic_interfaces.py +++ b/test/test_generic_interfaces.py @@ -9,7 +9,7 @@ Distributed under the BSD License """ from __future__ import print_function -from numpy.testing import assert_equal +from numpy.testing import assert_allclose import pyspike as spk from pyspike import SpikeTrain @@ -43,33 +43,33 @@ def check_func(dist_func): isi12 = dist_func(t1, t2) isi12_ = dist_func([t1, t2]) - assert_equal(isi12, isi12_) + assert_allclose(isi12, isi12_) isi12_ = dist_func(spike_trains, indices=[0, 1]) - assert_equal(isi12, isi12_) + assert_allclose(isi12, isi12_) isi123 = dist_func(t1, t2, t3) isi123_ = dist_func([t1, t2, t3]) - assert_equal(isi123, isi123_) + assert_allclose(isi123, isi123_) isi123_ = dist_func(spike_trains, indices=[0, 1, 2]) - assert_equal(isi123, isi123_) + assert_allclose(isi123, isi123_) # run the same test with an additional interval parameter isi12 = dist_func(t1, t2, interval=[0.0, 0.5]) isi12_ = dist_func([t1, t2], interval=[0.0, 0.5]) - assert_equal(isi12, isi12_) + assert_allclose(isi12, isi12_) isi12_ = dist_func(spike_trains, indices=[0, 1], interval=[0.0, 0.5]) - assert_equal(isi12, isi12_) + assert_allclose(isi12, isi12_) isi123 = dist_func(t1, t2, t3, interval=[0.0, 0.5]) isi123_ = dist_func([t1, t2, t3], interval=[0.0, 0.5]) - assert_equal(isi123, isi123_) + assert_allclose(isi123, isi123_) isi123_ = dist_func(spike_trains, indices=[0, 1, 2], interval=[0.0, 0.5]) - assert_equal(isi123, isi123_) + assert_allclose(isi123, isi123_) def test_isi_profile(): diff --git a/test/test_regression/test_regression_15.py b/test/test_regression/test_regression_15.py index 54adf23..81b5bb0 100644 --- a/test/test_regression/test_regression_15.py +++ b/test/test_regression/test_regression_15.py @@ -11,7 +11,7 @@ Distributed under the BSD License from __future__ import division import numpy as np -from numpy.testing import assert_equal, assert_almost_equal, \ +from numpy.testing import assert_allclose, assert_almost_equal, \ assert_array_almost_equal import pyspike as spk @@ -28,15 +28,15 @@ def test_regression_15_isi(): N = len(spike_trains) dist_mat = spk.isi_distance_matrix(spike_trains) - assert_equal(dist_mat.shape, (N, N)) + assert_allclose(dist_mat.shape, (N, N)) ind = np.arange(N//2) dist_mat = spk.isi_distance_matrix(spike_trains, ind) - assert_equal(dist_mat.shape, (N//2, N//2)) + assert_allclose(dist_mat.shape, (N//2, N//2)) ind = np.arange(N//2, N) dist_mat = spk.isi_distance_matrix(spike_trains, ind) - assert_equal(dist_mat.shape, (N//2, N//2)) + assert_allclose(dist_mat.shape, (N//2, N//2)) def test_regression_15_spike(): @@ -46,15 +46,15 @@ def test_regression_15_spike(): N = len(spike_trains) dist_mat = spk.spike_distance_matrix(spike_trains) - assert_equal(dist_mat.shape, (N, N)) + assert_allclose(dist_mat.shape, (N, N)) ind = np.arange(N//2) dist_mat = spk.spike_distance_matrix(spike_trains, ind) - assert_equal(dist_mat.shape, (N//2, N//2)) + assert_allclose(dist_mat.shape, (N//2, N//2)) ind = np.arange(N//2, N) dist_mat = spk.spike_distance_matrix(spike_trains, ind) - assert_equal(dist_mat.shape, (N//2, N//2)) + assert_allclose(dist_mat.shape, (N//2, N//2)) def test_regression_15_sync(): @@ -64,15 +64,15 @@ def test_regression_15_sync(): N = len(spike_trains) dist_mat = spk.spike_sync_matrix(spike_trains) - assert_equal(dist_mat.shape, (N, N)) + assert_allclose(dist_mat.shape, (N, N)) ind = np.arange(N//2) dist_mat = spk.spike_sync_matrix(spike_trains, ind) - assert_equal(dist_mat.shape, (N//2, N//2)) + assert_allclose(dist_mat.shape, (N//2, N//2)) ind = np.arange(N//2, N) dist_mat = spk.spike_sync_matrix(spike_trains, ind) - assert_equal(dist_mat.shape, (N//2, N//2)) + assert_allclose(dist_mat.shape, (N//2, N//2)) if __name__ == "__main__": diff --git a/test/test_spikes.py b/test/test_spikes.py index ee505b5..579f8e1 100644 --- a/test/test_spikes.py +++ b/test/test_spikes.py @@ -9,7 +9,7 @@ Distributed under the BSD License from __future__ import print_function import numpy as np -from numpy.testing import assert_equal +from numpy.testing import assert_allclose import pyspike as spk @@ -29,7 +29,7 @@ def test_load_from_txt(): spike_times = [64.886, 305.81, 696, 937.77, 1059.7, 1322.2, 1576.1, 1808.1, 2121.5, 2381.1, 2728.6, 2966.9, 3223.7, 3473.7, 3644.3, 3936.3] - assert_equal(spike_times, spike_trains[0].spikes) + assert_allclose(spike_times, spike_trains[0].spikes) # check auxiliary spikes for spike_train in spike_trains: @@ -47,9 +47,9 @@ def test_load_time_series(): # check spike trains for n in range(len(spike_trains)): - assert_equal(spike_trains[n].spikes, spike_trains_check[n].spikes) - assert_equal(spike_trains[n].t_start, 0) - assert_equal(spike_trains[n].t_end, 4000) + assert_allclose(spike_trains[n].spikes, spike_trains_check[n].spikes) + assert_allclose(spike_trains[n].t_start, 0) + assert_allclose(spike_trains[n].t_end, 4000) def check_merged_spikes(merged_spikes, spike_trains): diff --git a/test/test_sync_filter.py b/test/test_sync_filter.py index e259903..0b915db 100644 --- a/test/test_sync_filter.py +++ b/test/test_sync_filter.py @@ -10,7 +10,7 @@ Distributed under the BSD License from __future__ import print_function import numpy as np -from numpy.testing import assert_equal, assert_almost_equal, \ +from numpy.testing import assert_allclose, assert_almost_equal, \ assert_array_almost_equal import pyspike as spk @@ -36,21 +36,21 @@ def test_single_prof(): coincidences = np.array(coincidence_impl(st1, st2, 0, 5.0, 0.0)) print(coincidences) for i, t in enumerate(st1): - assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], - "At index %d" % i) + assert_allclose(coincidences[i], sync_prof.y[sync_prof.x == t], + err_msg="At index %d" % i) coincidences = np.array(coincidence_impl(st2, st1, 0, 5.0, 0.0)) for i, t in enumerate(st2): - assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], - "At index %d" % i) + assert_allclose(coincidences[i], sync_prof.y[sync_prof.x == t], + err_msg="At index %d" % i) sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), SpikeTrain(st3, 5.0)) coincidences = np.array(coincidence_impl(st1, st3, 0, 5.0, 0.0)) for i, t in enumerate(st1): - assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], - "At index %d" % i) + assert_allclose(coincidences[i], sync_prof.y[sync_prof.x == t], + err_msg="At index %d" % i) st1 = np.array([1.0, 2.0, 3.0, 4.0]) st2 = np.array([1.0, 2.0, 4.0]) @@ -61,8 +61,8 @@ def test_single_prof(): coincidences = np.array(coincidence_impl(st1, st2, 0, 5.0, 0.0)) for i, t in enumerate(st1): expected = sync_prof.y[sync_prof.x == t]/sync_prof.mp[sync_prof.x == t] - assert_equal(coincidences[i], expected, - "At index %d" % i) + assert_allclose(coincidences[i], expected, + err_msg="At index %d" % i) def test_filter(): @@ -72,22 +72,22 @@ def test_filter(): # filtered_spike_trains = spk.filter_by_spike_sync([st1, st2], 0.5) - # assert_equal(filtered_spike_trains[0].spikes, [1.0, 2.0, 4.0]) - # assert_equal(filtered_spike_trains[1].spikes, [1.1, 2.1, 3.8]) + # assert_allclose(filtered_spike_trains[0].spikes, [1.0, 2.0, 4.0]) + # assert_allclose(filtered_spike_trains[1].spikes, [1.1, 2.1, 3.8]) # filtered_spike_trains = spk.filter_by_spike_sync([st2, st1], 0.5) - # assert_equal(filtered_spike_trains[0].spikes, [1.1, 2.1, 3.8]) - # assert_equal(filtered_spike_trains[1].spikes, [1.0, 2.0, 4.0]) + # assert_allclose(filtered_spike_trains[0].spikes, [1.1, 2.1, 3.8]) + # assert_allclose(filtered_spike_trains[1].spikes, [1.0, 2.0, 4.0]) filtered_spike_trains = spk.filter_by_spike_sync([st1, st2, st3], 0.75) for st in filtered_spike_trains: print(st.spikes) - assert_equal(filtered_spike_trains[0].spikes, [1.0, 4.0]) - assert_equal(filtered_spike_trains[1].spikes, [1.1, 3.8]) - assert_equal(filtered_spike_trains[2].spikes, [0.9, 4.1]) + assert_allclose(filtered_spike_trains[0].spikes, [1.0, 4.0]) + assert_allclose(filtered_spike_trains[1].spikes, [1.1, 3.8]) + assert_allclose(filtered_spike_trains[2].spikes, [0.9, 4.1]) if __name__ == "main": |