Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] ENH: add option to delete a drive #550

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor

@ntolley ntolley Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I wonder if we should just combine this with the pick_connection API? Then you could flexibly specify which ones to delete

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but for now I made it private so I don't need to answer that question ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have two options: expose all the arguments that are in pick_connection. But this needs to be done in a consistent way. The other is to allow passing keyword arguments but then the documentation is not so nice because user will have to go to pick_connection function to check the documentation of clear_connectivity. But for now it's private ...

"""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