Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elephant dir packages are back #239

Merged
merged 9 commits into from
Jul 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ nosetests.xml
.pydevproject
.settings
*.tmp*
.idea
.idea/
venv/
env/
.pytest_cache/

# Compiled source #
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ install:

- pip -V
- pip install coverage coveralls nose
- pip install .
- python setup.py install
- python -c "from elephant.spade import HAVE_FIM; assert HAVE_FIM"
- pip list
- python --version

Expand Down
9 changes: 5 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
recursive-include elephant *.py
include requirements*.txt
dizcza marked this conversation as resolved.
Show resolved Hide resolved
include README.rst
include LICENSE.txt
include AUTHORS.txt
include elephant/VERSION
include elephant/current_source_density_src/README.md
include elephant/current_source_density_src/test_data.mat
include elephant/spade_src/LICENCE
include elephant/spade_src/LICENSE
recursive-include elephant/spade_src *.so *.pyd
dizcza marked this conversation as resolved.
Show resolved Hide resolved
include elephant/test/spike_extraction_test_data.txt
recursive-include doc *

# special care for the files, used in setup.py
include elephant/spade_src/fim_manager.py
prune doc/_build
dizcza marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions elephant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@
:license: Modified BSD, see LICENSE.txt for details.
"""

from . import (statistics,
spike_train_generation,
spike_train_correlation,
unitary_event_analysis,
cubic,
spectral,
kernels,
spike_train_dissimilarity,
spike_train_surrogates,
signal_processing,
current_source_density,
change_point_detection,
phase_analysis,
sta,
conversion,
neo_tools,
spade,
cell_assembly_detection,
waveform_features)

try:
from . import pandas_bridge
from . import asset
except ImportError:
# requirements-extras are missing
pass


def _get_version():
import os
Expand Down
4 changes: 0 additions & 4 deletions elephant/spade.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,9 @@
import quantities as pq
import warnings
from elephant.spade_src import fast_fca
from elephant.spade_src.fim_manager import download_spade_fim

warnings.simplefilter('once', UserWarning)

# if not downloaded during the install, do it now
download_spade_fim()


try:
from mpi4py import MPI # for parallelized routines
Expand Down
41 changes: 0 additions & 41 deletions elephant/spade_src/fim_manager.py

This file was deleted.

21 changes: 5 additions & 16 deletions elephant/test/test_spade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from __future__ import division

import os
import unittest

import neo
Expand All @@ -18,8 +17,6 @@
import elephant.spade as spade
import elephant.spike_train_generation as stg
from elephant.spade import HAVE_FIM
from elephant.spade_src.fim_manager import download_spade_fim, \
_get_fim_lib_path


class SpadeTestCase(unittest.TestCase):
Expand Down Expand Up @@ -110,6 +107,7 @@ def setUp(self):
self.patt_psr = self.patt3 + [self.patt3[-1][:3]]

# Testing cpp
@unittest.skipUnless(HAVE_FIM, "Time consuming with pythonic FIM")
def test_spade_cpp(self):
output_cpp = spade.spade(self.cpp, self.binsize, 1,
n_subsets=self.n_subset,
Expand Down Expand Up @@ -243,7 +241,7 @@ def test_parameters(self):
# check the lags
assert_array_equal([len(lags) < self.max_spikes for lags in
lags_msip_max_spikes], [True] * len(
lags_msip_max_spikes))
lags_msip_max_spikes))

# test max_occ parameter
output_msip_max_occ = spade.spade(self.msip, self.binsize, self.winlen,
Expand Down Expand Up @@ -371,12 +369,11 @@ def test_spectrum(self):
self.winlen, report='3d#')[0]
assert_array_equal(spectrum_3d, [
[len(self.lags3) + 1, self.n_occ3, max(self.lags3), 1]])
# test the errors raised

def test_spade_raise_error(self):
# Test list not using neo.Spiketrain
self.assertRaises(TypeError, spade.spade, [
[1, 2, 3], [3, 4, 5]], 1 * pq.ms, 4)
[1, 2, 3], [3, 4, 5]], 1 * pq.ms, 4)
# Test neo.Spiketrain with different t_stop
self.assertRaises(AttributeError, spade.spade, [neo.SpikeTrain(
[1, 2, 3] * pq.s, t_stop=5 * pq.s), neo.SpikeTrain(
Expand All @@ -385,7 +382,7 @@ def test_spade_raise_error(self):
self.assertRaises(ValueError, spade.spade, [neo.SpikeTrain(
[1, 2, 3] * pq.s, t_stop=6 * pq.s), neo.SpikeTrain(
[3, 4, 5] * pq.s, t_stop=6 * pq.s)], 1 * pq.ms, 4, n_surr=1,
spectrum='try')
spectrum='try')
# Test negative minimum number of spikes
self.assertRaises(AttributeError, spade.spade, [neo.SpikeTrain(
[1, 2, 3] * pq.s, t_stop=5 * pq.s), neo.SpikeTrain(
Expand All @@ -394,14 +391,13 @@ def test_spade_raise_error(self):
self.assertRaises(AttributeError, spade.pvalue_spectrum, [
neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s), neo.SpikeTrain(
[3, 4, 5] * pq.s, t_stop=5 * pq.s)], 1 * pq.ms, 4, 3 * pq.ms,
n_surr=-3)
n_surr=-3)
# Test wrong correction parameter
self.assertRaises(AttributeError, spade.test_signature_significance, (
(2, 3, 0.2), (2, 4, 0.1)), 0.01, corr='try')
# Test negative number of subset for stability
self.assertRaises(AttributeError, spade.approximate_stability, (),
np.array([]), n_subsets=-3)
# test psr

def test_pattern_set_reduction(self):
output_msip = spade.spade(self.patt_psr, self.binsize, self.winlen,
Expand All @@ -426,13 +422,6 @@ def test_pattern_set_reduction(self):
# check the occurrences time of the patters
assert_array_equal(len(occ_msip[0]), self.n_occ3)

def test_download_spade_fim(self):
fim_lib_path = _get_fim_lib_path()
if os.path.exists(fim_lib_path):
os.unlink(fim_lib_path)
download_spade_fim()
assert os.path.exists(fim_lib_path)


def suite():
suite = unittest.makeSuite(SpadeTestCase, 'test')
Expand Down
47 changes: 42 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# -*- coding: utf-8 -*-

import os
import platform
import struct
import sys

from setuptools import setup

from elephant import __version__
from elephant.spade_src.fim_manager import download_spade_fim

python_version_major = sys.version_info.major

if python_version_major == 2:
from urllib import urlretrieve
else:
from urllib.request import urlretrieve

with open(os.path.join(os.path.dirname(__file__),
"elephant", "VERSION")) as version_file:
version = version_file.read().strip()

with open("README.rst") as f:
long_description = f.read()
with open('requirements.txt') as fp:
Expand All @@ -18,11 +27,39 @@
with open('requirements-{0}.txt'.format(extra)) as fp:
extras_require[extra] = fp.read()

download_spade_fim()

def download_spade_fim():
"""
Downloads SPADE specific PyFIM binary file.
"""
if platform.system() == "Windows":
fim_filename = "fim.pyd"
else:
# Linux
fim_filename = "fim.so"
spade_src_dir = os.path.join(os.path.dirname(__file__), "elephant",
"spade_src")
fim_lib_path = os.path.join(spade_src_dir, fim_filename)
if os.path.exists(fim_lib_path):
return

arch_bits = struct.calcsize("P") * 8
url_fim = "http://www.borgelt.net/bin{arch}/py{py_ver}/{filename}". \
format(arch=arch_bits, py_ver=python_version_major,
filename=fim_filename)
try:
urlretrieve(url_fim, filename=fim_lib_path)
print("Successfully downloaded fim lib to {}".format(fim_lib_path))
except Exception:
print("Unable to download {url} module.".format(url=url_fim))


if len(sys.argv) > 1 and sys.argv[1].lower() != 'sdist':
download_spade_fim()

setup(
name="elephant",
version=__version__,
version=version,
packages=['elephant', 'elephant.test'],
include_package_data=True,

Expand Down