Skip to content

Commit

Permalink
Check if nodes are biophysical before calling .morph (#68)
Browse files Browse the repository at this point in the history
* Check if nodes are biophysical before calling .morph
  • Loading branch information
tomdele committed Jul 1, 2020
1 parent 717f2b8 commit a81f40a
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 160 deletions.
8 changes: 8 additions & 0 deletions bluepysnap/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from bluepysnap.settings import MORPH_CACHE_SIZE
from bluepysnap.sonata_constants import Node
from bluepysnap.exceptions import BluepySnapError


class MorphHelper(object):
Expand All @@ -41,6 +42,10 @@ def __init__(self, morph_dir, nodes):
"""
self._morph_dir = morph_dir
self._nodes = nodes

# all nodes from a population must have the same model type
if not self._is_biophysical(0):
raise BluepySnapError("Node population does not contain biophysical nodes.")
self._load = nm.load_neuron
if MORPH_CACHE_SIZE is not None:
try:
Expand All @@ -49,6 +54,9 @@ def __init__(self, morph_dir, nodes):
from functools32 import lru_cache
self._load = lru_cache(maxsize=MORPH_CACHE_SIZE)(self._load)

def _is_biophysical(self, node_id):
return self._nodes.get(node_id, Node.MODEL_TYPE) == "biophysical"

def get_filepath(self, node_id):
"""Return path to SWC morphology file corresponding to `node_id`."""
name = self._nodes.get(node_id, Node.MORPHOLOGY)
Expand Down
35 changes: 35 additions & 0 deletions tests/data/morphologies/morph-A.swc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# index type X Y Z radius parent
1 1 -0.320000 1.000000 0.000000 0.725000 -1
2 1 -0.320000 0.900000 0.000000 0.820000 1
3 1 -0.320000 0.800000 0.000000 0.820000 2
4 1 -0.320000 0.700000 0.000000 0.820000 3
5 1 -0.320000 0.600000 0.000000 0.820000 4
6 1 -0.320000 0.500000 0.000000 0.820000 5
7 1 -0.320000 0.400000 0.000000 0.820000 6
8 1 -0.320000 0.300000 0.000000 0.820000 7
9 1 -0.320000 0.200000 0.000000 0.820000 8
10 1 -0.320000 0.100000 0.000000 0.820000 9
11 1 -0.320000 0.000000 0.000000 0.820000 10
12 1 -0.320000 -0.100000 0.000000 0.820000 11
13 1 -0.320000 -0.200000 0.000000 0.820000 12
14 1 -0.320000 -0.300000 0.000000 0.820000 13
15 1 -0.320000 -0.400000 0.000000 0.820000 14
16 1 -0.320000 -0.500000 0.000000 0.820000 15
17 1 -0.320000 -0.600000 0.000000 0.820000 16
18 1 -0.320000 -0.700000 0.000000 0.820000 17
19 1 -0.320000 -0.800000 0.000000 0.820000 18
20 1 -0.320000 -0.900000 0.000000 0.820000 19
21 1 -0.320000 -1.000000 0.000000 0.430000 20
22 2 0.000000 5.000000 0.000000 1.000000 1
23 2 2.000000 9.000000 0.000000 1.000000 22
24 2 0.000000 13.000000 0.000000 1.000000 23
25 2 2.000000 13.000000 0.000000 1.000000 24
26 2 4.000000 13.000000 0.000000 1.000000 25
27 3 3.000000 -4.000000 0.000000 1.000000 1
28 3 3.000000 -6.000000 0.000000 1.000000 27
29 3 3.000000 -8.000000 0.000000 1.000000 28
30 3 3.000000 -10.000000 0.000000 1.000000 29
31 3 0.000000 -10.000000 0.000000 1.000000 30
32 3 6.000000 -10.000000 0.000000 1.000000 30

# Created by MorphIO v2.0.4
35 changes: 0 additions & 35 deletions tests/data/morphologies/small_morph.swc

This file was deleted.

Binary file modified tests/data/nodes_quaternions.h5
Binary file not shown.

0 comments on commit a81f40a

Please sign in to comment.