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
[MRG] ENH: Add function to search for specific connections #367
Merged
jasmainak
merged 22 commits into
jonescompneurolab:master
from
ntolley:pick_connectivity
Jul 28, 2021
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ab580a2
Draft of tests for pick_connection
ntolley affbcc7
Look up range from net in viz.py
ntolley 789ed74
WIP: First pass at pick connectivity
ntolley fa41c78
Better notes
ntolley e90deba
Add tests for correct inputs
ntolley 8745c3e
Add more tests for bad parameters
ntolley 6f127b2
Use net.pick_connection in example
ntolley 46f6d1d
Fix conn attribute
ntolley 4983ad4
Fix rebase issues
ntolley f994e68
Fix rebase problems
ntolley 2bb9f9a
Use 'src_gids' attr in examples
ntolley 4198607
Create check.py and move input conversion from add_connection
ntolley 64938f0
Use check functions in pick_connection
ntolley 47fd3db
Remove warning from pick_connection
ntolley 2d3b5cf
Use pick connection in example
ntolley d5ca28f
DOC: Update whats_new.rst
ntolley fce349e
Update hnn_core/network.py
ntolley 73b15b0
Less weird example?
ntolley a48b265
Apply suggestions from code review
ntolley 2c1877e
Misc code review suggestions
ntolley ceca802
Make pick_connection a function separate from Network
ntolley fb99c9c
Remove unecessary function
ntolley File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Input check functions.""" | ||
|
||
# Authors: Nick Tolley <nicholas_tolley@brown.edu> | ||
|
||
from .params import _long_name | ||
from .externals.mne import _validate_type, _check_option | ||
|
||
|
||
def _check_gids(gids, gid_ranges, valid_cells, arg_name): | ||
"""Format different gid specifications into list of gids""" | ||
_validate_type(gids, (int, list, range, str, None), arg_name, | ||
'int list, range, str, or None') | ||
|
||
# Convert gids to list | ||
if gids is None: | ||
return list() | ||
if isinstance(gids, int): | ||
gids = [gids] | ||
elif isinstance(gids, str): | ||
_check_option(arg_name, gids, valid_cells) | ||
gids = gid_ranges[_long_name(gids)] | ||
|
||
cell_type = _gid_to_type(gids[0], gid_ranges) | ||
for gid in gids: | ||
_validate_type(gid, int, arg_name) | ||
gid_type = _gid_to_type(gid, gid_ranges) | ||
if gid_type is None: | ||
raise AssertionError( | ||
f'{arg_name} {gid} not in net.gid_ranges') | ||
if gid_type != cell_type: | ||
raise AssertionError(f'All {arg_name} must be of the same type') | ||
|
||
return gids | ||
|
||
|
||
def _gid_to_type(gid, gid_ranges): | ||
"""Reverse lookup of gid to type.""" | ||
for gidtype, gids in gid_ranges.items(): | ||
if gid in gids: | ||
return gidtype | ||
|
||
|
||
def _string_input_to_list(input_str, valid_str, arg_name): | ||
"""Convert input strings to list""" | ||
if input_str is None: | ||
input_str = list() | ||
elif isinstance(input_str, str): | ||
input_str = [input_str] | ||
for str_item in input_str: | ||
_check_option(arg_name, str_item, valid_str) | ||
|
||
return input_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better! now only thing is that you shouldn't have to do this:
so
plot_connectivity_matrix
accepts a list. Can be a separate PR though. Are there other functions which benefit frompick_connection
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that'd be a bit nicer, but what do you think the alternate behavior should be with a list? Returning multiple plots or subplots?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
umm ... either is fine. Maybe subplots is better so user is not overwhelmed by plot windows. Each row is one connectivity matrix if multiple subplots. And you can even implement a scrollbar if there are too many subplots