Skip to content

Commit

Permalink
Start system for warning invalid connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ntolley committed Aug 26, 2021
1 parent 4fde7c6 commit 41f2e7b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
31 changes: 27 additions & 4 deletions hnn_core/network.py
Expand Up @@ -11,6 +11,7 @@
from copy import deepcopy

import numpy as np
from numpy.testing._private.utils import raises

from .drives import _drive_cell_event_times
from .drives import _get_target_properties, _add_drives_from_params
Expand Down Expand Up @@ -1043,12 +1044,34 @@ def add_connection(self, src_gids, target_gids, loc, receptor,
_validate_type(loc, str, 'loc')
_validate_type(receptor, str, 'receptor')

valid_loc = ['proximal', 'distal', 'soma']
_check_option('loc', loc, valid_loc)
valid_loc = list(self.cell_types[target_type].p_secs.keys())
for item in self.cell_types[target_type].sect_loc.values():
valid_loc.extend(item)

valid_loc = list(set(valid_loc))
# Separation ecessary to identify valid receptors
if loc in self.cell_types[target_type].sect_loc and \
self.cell_types[target_type].sect_loc[loc]:
sect_list = self.cell_types[target_type].sect_loc[loc]
elif loc in self.cell_types[target_type].p_secs:
sect_list = [loc]
else:
raise ValueError(
f"The loc '{loc}' is not defined for '{target_type}' "
f"cells. Valid locations include {valid_loc}")

conn['loc'] = loc

valid_receptor = ['ampa', 'nmda', 'gabaa', 'gabab']
_check_option('receptor', receptor, valid_receptor)
valid_receptors = set(np.concatenate([
self.cell_types[target_type].p_secs[sect_name]['syns'] for
sect_name in sect_list]))

if receptor not in valid_receptors:
raise ValueError(
f"The receptor'{receptor}' is not defined for the loc '{loc}'"
f" on '{target_type}' cells. Valid receptors include"
f"{valid_receptors}")

conn['receptor'] = receptor

# Create and validate nc_dict
Expand Down
22 changes: 22 additions & 0 deletions hnn_core/tests/test_network.py
Expand Up @@ -314,6 +314,28 @@ def test_network():
kwargs[arg] = string_arg
net.add_connection(**kwargs)

# Test warnings for undefined loc
with pytest.raises(
ValueError,
match=r"The loc \'distal\' is not defined for L5_basket"
r"cells. Valid locations include \[\'soma\'\]"):
kwargs = kwargs_default.copy()
kwargs['target_gids'] = 'L5_basket'
kwargs['loc'] = 'distal'
net.add_connection(**kwargs)

# Test warnings for undefined synapse for specific loc
with pytest.raises(
ValueError,
match=r"The receptor \'ampa\' is not defined for the loc \'soma\'"
r" on \'L5_pyramidal\' cells. Valid receptors include "
r"\[\'gabaa\', \'gabab\'\]"):
kwargs = kwargs_default.copy()
kwargs['target_gids'] = 'L5_pyramidal'
kwargs['loc'] = 'soma'
kwargs['receptor'] = 'ampa'
net.add_connection(**kwargs)

# Check probability=0.5 produces half as many connections as default
net.add_connection(**kwargs_default)
kwargs = kwargs_default.copy()
Expand Down

0 comments on commit 41f2e7b

Please sign in to comment.