Skip to content

Commit

Permalink
ENH: add option to delete a drive
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed Aug 19, 2022
1 parent df833b4 commit 3c18ac7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/howto/plot_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# directly.
def get_network(probability=1.0):
net = jones_2009_model(add_drives_from_params=True)
net.clear_connectivity()
net.connectivity = list()

# Pyramidal cell connections
location, receptor = 'distal', 'ampa'
Expand Down
30 changes: 19 additions & 11 deletions hnn_core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,23 +1253,31 @@ def add_connection(self, src_gids, target_gids, loc, receptor,

self.connectivity.append(deepcopy(conn))

def clear_connectivity(self):
"""Remove all connections defined in Network.connectivity
"""
def _clear_connectivity(self, src_types=None):
"""Remove connections with src_type in Network.connectivity."""
if src_types is None:
src_types = self.external_drives.keys()
connectivity = list()
for conn in self.connectivity:
if conn['src_type'] in self.external_drives.keys():
if conn['src_type'] in src_types:
connectivity.append(conn)
self.connectivity = connectivity

def clear_drives(self):
"""Remove all drives defined in Network.connectivity"""
def clear_drives(self, drive_name='all'):
"""Remove all drives defined in Network.connectivity.
Parameters
----------
drive_names : list | 'all'
The drive_names to remove
"""
if drive_names == 'all':
drive_names = list(self.external_drives.keys())
_validate_type(drive_names, (list,))
connectivity = list()
for conn in self.connectivity:
if conn['src_type'] not in self.external_drives.keys():
connectivity.append(conn)
self.external_drives = dict()
self.connectivity = connectivity
for drive_name in drive_names:
del self.external_drives[drive_name]
self._clear_connectivity(src_type=drive_names)

def add_electrode_array(self, name, electrode_pos, *, conductivity=0.3,
method='psa', min_distance=0.5):
Expand Down
2 changes: 0 additions & 2 deletions hnn_core/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ def test_network():

# Test removing connections from net.connectivity
# Needs to be updated if number of drives change in preceeding tests
net.clear_connectivity()
assert len(net.connectivity) == 50
net.clear_drives()
assert len(net.connectivity) == 0

Expand Down

0 comments on commit 3c18ac7

Please sign in to comment.