Skip to content

Commit

Permalink
Add source/target to the available properties for edges (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdele committed Jul 3, 2020
1 parent a81f40a commit f90fc4f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
23 changes: 18 additions & 5 deletions bluepysnap/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import libsonata
import numpy as np
import pandas as pd

import six
from cached_property import cached_property

from bluepysnap.exceptions import BluepySnapError
Expand Down Expand Up @@ -137,17 +137,26 @@ def target(self):
return self._nodes(self._population.target)

@cached_property
def _property_names(self):
def _attribute_names(self):
return set(self._population.attribute_names)

@cached_property
def _dynamics_params_names(self):
return set(utils.add_dynamic_prefix(self._population.dynamics_attribute_names))

@property
def _topology_property_names(self):
return {six.text_type(Edge.SOURCE_NODE_ID), six.text_type(Edge.TARGET_NODE_ID)}

@property
def property_names(self):
"""Set of available edge properties."""
return self._property_names | self._dynamics_params_names
"""Set of available edge properties.
Notes:
Properties are a combination of the group attributes, the dynamics_params and the
topology properties.
"""
return self._attribute_names | self._dynamics_params_names | self._topology_property_names

@cached_property
def property_dtypes(self):
Expand Down Expand Up @@ -185,7 +194,7 @@ def _get_property(self, prop, selection):
result = self._population.source_nodes(selection)
elif prop == Edge.TARGET_NODE_ID:
result = self._population.target_nodes(selection)
elif prop in self._property_names:
elif prop in self._attribute_names:
result = self._population.get_attribute(prop, selection)
elif prop in self._dynamics_params_names:
result = self._population.get_dynamics_attribute(
Expand Down Expand Up @@ -231,6 +240,10 @@ def properties(self, edge_ids, properties):
pandas.Series/pandas.DataFrame:
A pandas Series indexed by edge IDs if ``properties`` is scalar.
A pandas DataFrame indexed by edge IDs if ``properties`` is list.
Notes:
The EdgePopulation.property_names function will give you all the usable properties
for the `properties` argument.
"""
selection = libsonata.Selection(edge_ids)
return self._get(selection, properties)
Expand Down
10 changes: 9 additions & 1 deletion bluepysnap/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ def _dynamics_params_names(self):

@property
def property_names(self):
"""Set of available node properties."""
"""Set of available node properties.
Notes:
Properties are a combination of the group attributes and the dynamics_params.
"""
return self._property_names | self._dynamics_params_names

def container_property_names(self, container):
Expand Down Expand Up @@ -420,6 +424,10 @@ def get(self, group=None, properties=None):
pandas.Series/pandas.DataFrame:
If single node ID is passed as ``group`` returns a pandas Series.
Otherwise return a pandas DataFrame indexed by node IDs.
Notes:
The NodePopulation.property_names function will give you all the usable properties
for the `properties` argument.
"""
result = self._data
if properties is not None:
Expand Down
11 changes: 8 additions & 3 deletions tests/test_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def test_basic(self):
assert (
sorted(self.test_obj.property_names) ==
sorted([
Synapse.SOURCE_NODE_ID,
Synapse.TARGET_NODE_ID,
Synapse.AXONAL_DELAY,
Synapse.G_SYNX,
Synapse.POST_X_CENTER,
Expand Down Expand Up @@ -134,7 +136,8 @@ def test_container_properties(self):
['PRE_Y_SURFACE', 'PRE_Z_SURFACE', 'PRE_X_CENTER', 'POST_Y_CENTER', 'AXONAL_DELAY',
'POST_X_CENTER', 'POST_Y_SURFACE', 'POST_Z_SURFACE', 'PRE_Y_CENTER', 'POST_Z_CENTER',
'PRE_Z_CENTER', 'PRE_X_SURFACE', 'POST_X_SURFACE', 'POST_SECTION_ID', 'PRE_SECTION_ID',
'POST_SECTION_POS', 'PRE_SECTION_POS', 'SYN_WEIGHT'])
'POST_SECTION_POS', 'PRE_SECTION_POS', 'SYN_WEIGHT',
'SOURCE_NODE_ID', 'TARGET_NODE_ID'])
assert sorted(self.test_obj.container_property_names(Edge)) == expected
with pytest.raises(BluepySnapError):
mapping = {"X": "x"}
Expand Down Expand Up @@ -164,7 +167,8 @@ def test_property_dtypes(self):
'float32'), dtype('float64'), dtype('float32'), dtype('float64'), dtype(
'int64'), dtype('int64'), dtype('float64'), dtype('float64'), dtype(
'float64'), dtype('float64'), dtype('float64'), dtype('float64'), dtype(
'float32'), dtype('float32'), dtype('float64'), dtype('float64')]
'float32'), dtype('float32'), dtype('float64'), dtype('float64'),
dtype('uint64'), dtype('uint64')]
, index=['syn_weight', '@dynamics:param1', 'afferent_surface_y',
'afferent_surface_z', 'conductance', 'efferent_center_x',
'delay', 'afferent_center_z', 'efferent_section_id',
Expand All @@ -173,7 +177,8 @@ def test_property_dtypes(self):
'afferent_center_y', 'afferent_surface_x',
'efferent_surface_x', 'afferent_section_pos',
'efferent_section_pos', 'efferent_surface_y',
'efferent_center_z']).sort_index()
'efferent_center_z',
'@source_node', '@target_node']).sort_index()

pdt.assert_series_equal(expected, self.test_obj.property_dtypes)

Expand Down

0 comments on commit f90fc4f

Please sign in to comment.