Skip to content

Commit

Permalink
Merge pull request #410 from brian-team/spatialneuron
Browse files Browse the repository at this point in the history
Spatialneuron
  • Loading branch information
mstimberg committed Feb 25, 2015
2 parents 94aa2f3 + 9c2173b commit 716547f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
22 changes: 15 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ language: python
matrix:
include:
- python: "2.6"
env: STANDALONE=no CYTHON=yes
env: STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no
- python: "2.7"
env: STANDALONE=no CYTHON=yes
env: STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no
- python: "2.7"
env: STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=yes
- python: "3.3"
env: STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no
- python: "3.3"
env: STANDALONE=no CYTHON=yes
env: STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=yes
- python: "3.4"
env: STANDALONE=no CYTHON=yes
env: STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no
- python: "2.7"
env: STANDALONE=yes CYTHON=no
env: STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no
- python: "2.7" # test without installed cython
env: STANDALONE=no CYTHON=no
env: STANDALONE=no CYTHON=no MINIMAL_VERSIONS=no

# Use miniconda to install binary versions of numpy etc. from continuum
# analytic's repository. Follows an approach described by Dan Blanchard:
Expand All @@ -28,7 +32,11 @@ before_install:
# command to install dependencies
install:
- conda update --yes conda
- conda create -n travis_conda --yes pip python=$TRAVIS_PYTHON_VERSION numpy scipy nose sphinx ipython sympy pyparsing
- if [[ $MINIMAL_VERSIONS == 'yes' ]]; then
conda create -n travis_conda --yes pip python=$TRAVIS_PYTHON_VERSION numpy==1.8.0 scipy==0.13.3 nose sphinx ipython sympy==0.7.6 jinja2==2.7 pyparsing;
else
conda create -n travis_conda --yes pip python=$TRAVIS_PYTHON_VERSION numpy scipy nose sphinx ipython sympy pyparsing jinja2;
fi
- source activate travis_conda
- if [[ $CYTHON == 'yes' ]]; then conda install --yes cython; SETUP_ARGS=--with-cython; else SETUP_ARGS=""; fi
- pip install -q coveralls --use-mirrors
Expand Down
15 changes: 5 additions & 10 deletions brian2/spatialneuron/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

logger = get_logger(__name__)

try:
from pylab import figure
from mpl_toolkits.mplot3d import Axes3D
except ImportError:
logger.warn('matplotlib 0.99.1 is required for 3D plots', once=True)

__all__ = ['Morphology', 'MorphologyData', 'Cylinder', 'Soma']


Expand Down Expand Up @@ -207,10 +201,6 @@ def create_from_segments(self, segments, origin=0):
self.diameter, self.length, self.area, self.x, self.y, self.z = \
zip(*[(seg['diameter'], seg['length'], seg['area'], seg['x'],
seg['y'], seg['z']) for seg in branch])
(self.diameter, self.length, self.area,
self.x, self.y, self.z) = (array(self.diameter), array(self.length),
array(self.area), array(self.x),
array(self.y), array(self.z))
self.type = segments[n]['T'] # normally same type for all compartments
# in the branch
self.set_distance()
Expand Down Expand Up @@ -463,6 +453,11 @@ def plot(self, axes=None, simple=True, origin=None):
if ``True``, the diameter of branches is ignored
(defaults to ``True``)
"""
try:
from pylab import figure
from mpl_toolkits.mplot3d import Axes3D
except ImportError:
raise ImportError('matplotlib 0.99.1 is required for 3d plots')
if axes is None: # new figure
fig = figure()
axes = Axes3D(fig)
Expand Down
5 changes: 3 additions & 2 deletions brian2/spatialneuron/spatialneuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ def _pre_calc_iteration(self, morphology, counter=0):
self._temp_morph_parent_i[counter] = morphology.parent + 1
self._temp_starts[counter] = morphology._origin
self._temp_ends[counter] = morphology._origin + len(morphology.x) - 1
total_count = 1
for child in morphology.children:
counter += 1
self._pre_calc_iteration(child, counter)
total_count += self._pre_calc_iteration(child, counter+total_count)
return total_count

def number_branches(self, morphology, n=0, parent=-1):
'''
Expand Down
9 changes: 8 additions & 1 deletion brian2/tests/test_spatialneuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from nose.plugins.attrib import attr
from brian2 import *

@attr('codegen-independent')
@with_setup(teardown=restore_initial_state)
def test_construction():
BrianLogger.suppress_name('resolution_conflict')
morpho = Soma(diameter=30*um)
morpho.L = Cylinder(length=10*um, diameter=1*um, n=10)
morpho.LL = Cylinder(length=5*um, diameter=2*um, n=5)
morpho.LR = Cylinder(length=5*um, diameter=2*um, n=10)
morpho.right = Cylinder(length=3*um, diameter=1*um, n=7)
morpho.right.nextone = Cylinder(length=2*um, diameter=1*um, n=3)
gL=1e-4*siemens/cm**2
Expand Down Expand Up @@ -42,6 +44,11 @@ def test_construction():
assert_allclose(neuron.L.main.area,morpho.L.area)
assert_allclose(neuron.L.main.length,morpho.L.length)

# Check basic consistency of the flattened representation
assert len(np.unique(neuron.diffusion_state_updater._morph_i[:])) == len(neuron.diffusion_state_updater._morph_i)
assert all(neuron.diffusion_state_updater._ends[:].flat >=
neuron.diffusion_state_updater._starts[:].flat)


@attr('long')
@with_setup(teardown=restore_initial_state)
Expand Down Expand Up @@ -207,4 +214,4 @@ def test_rall():
test_construction()
test_infinitecable()
test_finitecable()
test_rall()
test_rall()
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ def build_extension(self, ext):
# include default_preferences file
'brian2': ['default_preferences']
},
install_requires=['numpy>=1.4.1',
'scipy>=0.7.0',
install_requires=['numpy>=1.8.0',
'scipy>=0.13.3',
'sympy>=0.7.6',
'pyparsing',
'jinja2>=2.7',
],
setup_requires=['numpy>=1.4.1'],
setup_requires=['numpy>=1.8.0'],
cmdclass={'build_ext': optional_build_ext},
provides=['brian2'],
extras_require={'test': ['nosetests>=1.0'],
Expand Down

0 comments on commit 716547f

Please sign in to comment.