Skip to content

Commit 01ac5a4

Browse files
authored
Make morphio optional (#829)
Fixes #823
1 parent a7f4a20 commit 01ac5a4

9 files changed

Lines changed: 44 additions & 14 deletions

File tree

.github/workflows/full-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Install NEURON
4040
if: startsWith(matrix.os, 'ubuntu')
4141
run: |
42-
python -m pip install "neuron>=9.0.0"
42+
python -m pip install "neuron>=9.0.0" morphio
4343
python -m pip install "nrnutils>0.2.0"
4444
- name: Install NEST
4545
if: startsWith(matrix.os, 'ubuntu')
@@ -53,7 +53,7 @@ jobs:
5353
- name: Install Arbor
5454
if: startsWith(matrix.os, 'ubuntu')
5555
run: |
56-
python -m pip install arbor==0.9.0 libNeuroML
56+
python -m pip install arbor==0.9.0 libNeuroML morphio
5757
- name: Install PyNN itself
5858
run: |
5959
python -m pip install -e ".[test]"

pyNN/arbor/cells.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ..morphology import Morphology, NeuroMLMorphology, MorphIOMorphology, IonChannelDistribution
77
from ..models import BaseCellType
88
from ..parameters import ParameterSpace
9-
from morphio import SectionType
109

1110

1211
def convert_point(p3d: Point3DWithDiam) -> arbor.mpoint:

pyNN/morphology.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
have_neuroml = True
1515
except ImportError:
1616
have_neuroml = False
17-
import morphio
18-
from morphio import SectionType
1917

2018

2119
def _download_file(url):
@@ -68,6 +66,8 @@ class NeuroMLMorphology(Morphology):
6866
"""
6967

7068
def __init__(self, morphology):
69+
from morphio import SectionType
70+
7171
if not have_neuroml:
7272
raise ImportError("Please install libNeuroML to use the NeuroMLMorphology class")
7373
super(NeuroMLMorphology, self).__init__()
@@ -158,6 +158,9 @@ class BrianMorphology(Morphology):
158158
class MorphIOMorphology(Morphology):
159159

160160
def __init__(self, morphology_file):
161+
import morphio
162+
from morphio import SectionType
163+
161164
super().__init__()
162165
self.morphology_file = morphology_file
163166
self._morphology = morphio.Morphology(morphology_file)

pyNN/neuron/cells.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import numpy as np
1515
from neuron import h, nrn, hclass
1616
import numpy.random
17-
from morphio import SectionType
1817

1918
from .. import errors
2019
from ..models import BaseCellType

pyNN/neuron/morphology.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
"""
66

7-
from morphio import SectionType
87
import numpy as np
98
from .. import morphology as base_morphology
109

@@ -38,6 +37,8 @@ class dendrites(base_morphology.dendrites):
3837
def __call__(self, morphology, filter_by_section=False):
3938
"""Return an index (integer NumPy array) that can be used
4039
to retrieve the sections corresponding to the filter. """
40+
from morphio import SectionType
41+
4142
section_index = np.array([], dtype=int)
4243
for label in (SectionType.apical_dendrite, SectionType.basal_dendrite):
4344
if label in morphology.section_groups:
@@ -53,6 +54,8 @@ def __call__(self, morphology, filter_by_section=False):
5354
class apical_dendrites(base_morphology.apical_dendrites):
5455

5556
def __call__(self, morphology, filter_by_section=False):
57+
from morphio import SectionType
58+
5659
if SectionType.apical_dendrite in morphology.section_groups:
5760
section_index = morphology.section_groups[SectionType.apical_dendrite]
5861
if filter_by_section:
@@ -66,6 +69,8 @@ def __call__(self, morphology, filter_by_section=False):
6669
class basal_dendrites(base_morphology.basal_dendrites):
6770

6871
def __call__(self, morphology, filter_by_section=False):
72+
from morphio import SectionType
73+
6974
if SectionType.basal_dendrite in morphology.section_groups:
7075
section_index = morphology.section_groups[SectionType.basal_dendrite]
7176
if filter_by_section:
@@ -79,6 +84,8 @@ def __call__(self, morphology, filter_by_section=False):
7984
class axon(base_morphology.axon):
8085

8186
def __call__(self, morphology, filter_by_section=False):
87+
from morphio import SectionType
88+
8289
if SectionType.axon in morphology.section_groups:
8390
section_index = morphology.section_groups[SectionType.axon]
8491
if filter_by_section:
@@ -92,6 +99,8 @@ def __call__(self, morphology, filter_by_section=False):
9299
class soma(base_morphology.axon):
93100

94101
def __call__(self, morphology, filter_by_section=False):
102+
from morphio import SectionType
103+
95104
if SectionType.soma in morphology.section_groups:
96105
section_index = morphology.section_groups[SectionType.soma]
97106
if filter_by_section:

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ classifiers = [
2929
]
3030
dependencies = [
3131
"lazyarray>=0.5.2",
32-
"neo>=0.13.4",
33-
"morphio"
32+
"neo>=0.13.4"
3433
]
3534

3635
[project.optional-dependencies]
@@ -40,9 +39,10 @@ examples = ["matplotlib", "scipy"]
4039
plotting = ["matplotlib", "scipy"]
4140
MPI = ["mpi4py"]
4241
sonata = ["h5py"]
42+
morphologies = ["morphio"]
4343
neuron = ["neuron", "nrnutils"]
4444
brian2 = ["brian2"]
45-
arbor = ["arbor==0.9.0", "libNeuroML"]
45+
arbor = ["arbor==0.9.0", "libNeuroML", "morphio"]
4646
spiNNaker = ["spyNNaker"]
4747
neuroml = ["libNeuroML"]
4848

test/system/scenarios/test_scenario5.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import sys
22
import numpy as np
33

4+
try:
5+
import morphio
6+
have_morphio = True
7+
except ImportError:
8+
have_morphio = False
9+
410
try:
511
from neuroml import Morphology, Segment, Point3DWithDiam as P
612
have_neuroml = True
@@ -21,6 +27,8 @@ def test_scenario5(sim):
2127
"""
2228
Array of multi-compartment neurons, each injected with a different current.
2329
"""
30+
if not have_morphio:
31+
pytest.skip("morphio not available")
2432
if not have_neuroml:
2533
pytest.skip("libNeuroML not available")
2634

test/system/test_neuron.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
have_neuron = False
1919
import pytest
2020

21+
try:
22+
import morphio
23+
have_morphio = True
24+
except ImportError:
25+
have_morphio = False
2126

2227
try:
2328
from neuroml import Morphology, Segment, Point3DWithDiam as P
@@ -242,8 +247,8 @@ def test_artificial_cells():
242247

243248

244249
def test_2_compartment():
245-
if not (have_neuron and have_neuroml):
246-
pytest.skip("Need neuron and neuroml")
250+
if not (have_neuron and have_neuroml and have_morphio):
251+
pytest.skip("Need neuron, neuroml, and morphio")
247252
sim = pyNN.neuron
248253

249254
sim.setup(timestep=0.025)

test/unittests/test_morphology.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
have_neuroml = True
1818
except ImportError:
1919
have_neuroml = False
20-
from pyNN.morphology import load_morphology, NeuroMLMorphology, SectionType, any as morph_any
20+
try:
21+
from pyNN.morphology import load_morphology, NeuroMLMorphology, any as morph_any
22+
from morphio import SectionType
23+
have_morphio = True
24+
except ImportError:
25+
have_morphio = False
2126
try:
2227
from pyNN.neuron.morphology import (dendrites, apical_dendrites,
2328
basal_dendrites, random_section, with_label,
@@ -53,8 +58,10 @@
5358
def setUpModule():
5459
global neuroml_morph, array_morph
5560

61+
if not have_morphio:
62+
pytest.skip("morphio not installed")
5663
if not have_neuroml:
57-
pytest.skip("libNeuroML not installed")
64+
pytest.skip("libNeuroML not installed")
5865

5966
test_file = "morph_test.swc"
6067
with open(test_file, "w") as fp:

0 commit comments

Comments
 (0)