Skip to content

Commit

Permalink
Add source_in_edges/target_in_edges to NodePopulations (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdele committed Jul 8, 2020
1 parent 92e836d commit 35d6458
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bluepysnap/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ def _property_names(self):
def _dynamics_params_names(self):
return set(utils.add_dynamic_prefix(self._population.dynamics_attribute_names))

def source_in_edges(self):
"""Set of edge population names that use this node population as source.
Returns:
set: a set containing the names of edge populations using this NodePopulation as
source.
"""
return set(edge.name for edge in self._node_storage.circuit.edges.values() if
self.name == edge.source.name)

def target_in_edges(self):
"""Set of edge population names that use this node population as target.
Returns:
set: a set containing the names of edge populations using this NodePopulation as
target.
"""
return set(edge.name for edge in self._node_storage.circuit.edges.values() if
self.name == edge.target.name)

@property
def property_names(self):
"""Set of available node properties.
Expand Down
23 changes: 23 additions & 0 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from bluepysnap.bbp import Cell
from bluepysnap.sonata_constants import Node
from bluepysnap.circuit import Circuit
from bluepysnap.node_sets import NodeSets
from bluepysnap.exceptions import BluepySnapError

Expand Down Expand Up @@ -131,6 +132,28 @@ def test_container_properties(self):
with pytest.raises(BluepySnapError):
self.test_obj.container_property_names(int)

def test_as_edge_source_target(self):
circuit = Circuit(str(TEST_DATA_DIR / 'circuit_config.json'))
assert circuit.nodes['default'].source_in_edges() == {"default"}
assert circuit.nodes['default'].target_in_edges() == {"default"}

def test_as_edge_source_target_mock(self):
def _mock_edge(name, source, target):
edges = Mock()
edges.source.name = source
edges.target.name = target
edges.name = name
return edges

circuit = Mock()
circuit.edges = {"edge1": _mock_edge('edge1', "default", "nodeother"),
"edge2": _mock_edge('edge2', "nodeother", "default"),
"edge3": _mock_edge('edge3', "default", "nodeother")}
create_node_population(str(TEST_DATA_DIR / 'nodes.h5'), "default", circuit=circuit)

assert circuit.nodes['default'].source_in_edges() == {"edge1", "edge3"}
assert circuit.nodes['default'].target_in_edges() == {"edge2"}

def test__positional_mask(self):
npt.assert_array_equal(self.test_obj._positional_mask([1, 2]), [False, True, True])
npt.assert_array_equal(self.test_obj._positional_mask([0, 2]), [True, False, True])
Expand Down

0 comments on commit 35d6458

Please sign in to comment.