Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# group cells by 'groupBy' feature (eg. 'y') in intervals of 'groupByInterval')
cellValuesPre = [cell['tags'][groupBy] for cell in cellsPre]
minValuePre = _roundFigures(groupByIntervalPre * np.floor(min(cellValuesPre) / groupByIntervalPre), 3)
maxValuePre = _roundFigures(groupByIntervalPre * np.ceil(max(cellValuesPre) / groupByIntervalPre), 3)
groupsPre = np.arange(minValuePre, maxValuePre, groupByIntervalPre)
groupsPre = [_roundFigures(x,3) for x in groupsPre]
if includePre == includePost:
groupsPost = groupsPre
else:
cellValuesPost = [cell['tags'][groupBy] for cell in cellsPost]
minValuePost = _roundFigures(groupByIntervalPost * np.floor(min(cellValuesPost) / groupByIntervalPost), 3)
maxValuePost = _roundFigures(groupByIntervalPost * np.ceil(max(cellValuesPost) / groupByIntervalPost), 3)
groupsPost = np.arange(minValuePost, maxValuePost, groupByIntervalPost)
groupsPost = [_roundFigures(x,3) for x in groupsPost]
# only allow matrix sizes >= 2x2 [why?]
# if len(groupsPre) < 2 or len(groupsPost) < 2:
# print 'groupBy %s with groupByIntervalPre %s and groupByIntervalPost %s results in <2 groups'%(str(groupBy), str(groupByIntervalPre), str(groupByIntervalPre))
# return
# set indices for pre and post groups
groupIndsPre = {group: ind for ind,group in enumerate(groupsPre)}
groupIndsPost = {group: ind for ind,group in enumerate(groupsPost)}
# initialize matrices
if feature in ['weight', 'strength']:
weightMatrix = np.zeros((len(groupsPre), len(groupsPost)))
elif feature == 'delay':
delayMatrix = np.zeros((len(groupsPre), len(groupsPost)))
cellConns = list_of_dict_unique_by_key(cell['conns'], preGidIndex)
if synMech:
cellConns = [conn for conn in cellConns if conn[synMechIndex] in synMech]
for conn in cellConns:
if conn[preGidIndex] == 'NetStim':
prePopLabel = -1 # maybe add in future
else:
preCell = next((c for c in cellsPre if c['gid']==conn[preGidIndex]), None)
if preCell:
preGroup = _roundFigures(groupByIntervalPre * np.floor(preCell['tags'][groupBy] / groupByIntervalPre), 3)
else:
preGroup = None
postGroup = _roundFigures(groupByIntervalPost * np.floor(cell['tags'][groupBy] / groupByIntervalPost), 3)
if preGroup in groupIndsPre:
if feature in ['weight', 'strength']:
weightMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += conn[weightIndex]
elif feature == 'delay':
delayMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += conn[delayIndex]
countMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += 1
pre, post = groupsPre, groupsPost
# no valid groupBy
else:
print('groupBy (%s) is not valid'%(str(groupBy)))
return
# normalize by number of postsyn cells
for cell in cellsPost: # for each postsyn cell
if synOrConn=='syn':
cellConns = cell['conns'] # include all synapses
else:
cellConns = list_of_dict_unique_by_key(cell['conns'], preGidIndex)
if synMech:
cellConns = [conn for conn in cellConns if conn[synMechIndex] in synMech]
for conn in cellConns:
if conn[preGidIndex] == 'NetStim':
prePopLabel = -1 # maybe add in future
else:
preCell = next((c for c in cellsPre if c['gid']==conn[preGidIndex]), None)
if preCell:
preGroup = _roundFigures(groupByIntervalPre * np.floor(preCell['tags'][groupBy] / groupByIntervalPre), 3)
else:
preGroup = None
postGroup = _roundFigures(groupByIntervalPost * np.floor(cell['tags'][groupBy] / groupByIntervalPost), 3)
if preGroup in groupIndsPre:
if feature in ['weight', 'strength']:
weightMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += conn[weightIndex]
elif feature == 'delay':
delayMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += conn[delayIndex]
countMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += 1
pre, post = groupsPre, groupsPost
# no valid groupBy
else:
weightMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += conn[weightIndex]
elif feature == 'delay':
delayMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += conn[delayIndex]
countMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += 1
pre, post = popsPre, popsPost
# Calculate matrix if grouped by numeric tag (eg. 'y')
elif groupBy in sim.net.allCells[0]['tags'] and isinstance(sim.net.allCells[0]['tags'][groupBy], Number):
if not isinstance(groupByIntervalPre, Number) or not isinstance(groupByIntervalPost, Number):
print 'groupByIntervalPre or groupByIntervalPost not specified'
return
# group cells by 'groupBy' feature (eg. 'y') in intervals of 'groupByInterval')
cellValuesPre = [cell['tags'][groupBy] for cell in cellsPre]
minValuePre = _roundFigures(groupByIntervalPre * np.floor(min(cellValuesPre) / groupByIntervalPre), 3)
maxValuePre = _roundFigures(groupByIntervalPre * np.ceil(max(cellValuesPre) / groupByIntervalPre), 3)
groupsPre = np.arange(minValuePre, maxValuePre, groupByIntervalPre)
groupsPre = [_roundFigures(x,3) for x in groupsPre]
if includePre == includePost:
groupsPost = groupsPre
else:
cellValuesPost = [cell['tags'][groupBy] for cell in cellsPost]
minValuePost = _roundFigures(groupByIntervalPost * np.floor(min(cellValuesPost) / groupByIntervalPost), 3)
maxValuePost = _roundFigures(groupByIntervalPost * np.ceil(max(cellValuesPost) / groupByIntervalPost), 3)
groupsPost = np.arange(minValuePost, maxValuePost, groupByIntervalPost)
groupsPost = [_roundFigures(x,3) for x in groupsPost]
# only allow matrix sizes >= 2x2 [why?]
# if len(groupsPre) < 2 or len(groupsPost) < 2:
countMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += 1
pre, post = popsPre, popsPost
# Calculate matrix if grouped by numeric tag (eg. 'y')
elif groupBy in sim.net.allCells[0]['tags'] and isinstance(sim.net.allCells[0]['tags'][groupBy], Number):
if not isinstance(groupByIntervalPre, Number) or not isinstance(groupByIntervalPost, Number):
print 'groupByIntervalPre or groupByIntervalPost not specified'
return
# group cells by 'groupBy' feature (eg. 'y') in intervals of 'groupByInterval')
cellValuesPre = [cell['tags'][groupBy] for cell in cellsPre]
minValuePre = _roundFigures(groupByIntervalPre * np.floor(min(cellValuesPre) / groupByIntervalPre), 3)
maxValuePre = _roundFigures(groupByIntervalPre * np.ceil(max(cellValuesPre) / groupByIntervalPre), 3)
groupsPre = np.arange(minValuePre, maxValuePre, groupByIntervalPre)
groupsPre = [_roundFigures(x,3) for x in groupsPre]
if includePre == includePost:
groupsPost = groupsPre
else:
cellValuesPost = [cell['tags'][groupBy] for cell in cellsPost]
minValuePost = _roundFigures(groupByIntervalPost * np.floor(min(cellValuesPost) / groupByIntervalPost), 3)
maxValuePost = _roundFigures(groupByIntervalPost * np.ceil(max(cellValuesPost) / groupByIntervalPost), 3)
groupsPost = np.arange(minValuePost, maxValuePost, groupByIntervalPost)
groupsPost = [_roundFigures(x,3) for x in groupsPost]
# only allow matrix sizes >= 2x2 [why?]
# if len(groupsPre) < 2 or len(groupsPost) < 2:
# print 'groupBy %s with groupByIntervalPre %s and groupByIntervalPost %s results in <2 groups'%(str(groupBy), str(groupByIntervalPre), str(groupByIntervalPre))
# return
weightMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += conn[weightIndex]
elif feature == 'delay':
delayMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += conn[delayIndex]
countMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += 1
pre, post = popsPre, popsPost
# Calculate matrix if grouped by numeric tag (eg. 'y')
elif groupBy in sim.net.allCells[0]['tags'] and isinstance(sim.net.allCells[0]['tags'][groupBy], Number):
if not isinstance(groupByIntervalPre, Number) or not isinstance(groupByIntervalPost, Number):
print('groupByIntervalPre or groupByIntervalPost not specified')
return
# group cells by 'groupBy' feature (eg. 'y') in intervals of 'groupByInterval')
cellValuesPre = [cell['tags'][groupBy] for cell in cellsPre]
minValuePre = _roundFigures(groupByIntervalPre * np.floor(min(cellValuesPre) / groupByIntervalPre), 3)
maxValuePre = _roundFigures(groupByIntervalPre * np.ceil(max(cellValuesPre) / groupByIntervalPre), 3)
groupsPre = np.arange(minValuePre, maxValuePre, groupByIntervalPre)
groupsPre = [_roundFigures(x,3) for x in groupsPre]
if includePre == includePost:
groupsPost = groupsPre
else:
cellValuesPost = [cell['tags'][groupBy] for cell in cellsPost]
minValuePost = _roundFigures(groupByIntervalPost * np.floor(min(cellValuesPost) / groupByIntervalPost), 3)
maxValuePost = _roundFigures(groupByIntervalPost * np.ceil(max(cellValuesPost) / groupByIntervalPost), 3)
groupsPost = np.arange(minValuePost, maxValuePost, groupByIntervalPost)
groupsPost = [_roundFigures(x,3) for x in groupsPost]
# only allow matrix sizes >= 2x2 [why?]
# if len(groupsPre) < 2 or len(groupsPost) < 2:
for cell in cellsPost: # for each postsyn cell
if synOrConn=='syn':
cellConns = cell['conns'] # include all synapses
else:
cellConns = list_of_dict_unique_by_key(cell['conns'], preGidIndex)
if synMech:
cellConns = [conn for conn in cellConns if conn[synMechIndex] in synMech]
for conn in cellConns:
if conn[preGidIndex] == 'NetStim':
prePopLabel = -1 # maybe add in future
else:
preCell = next((c for c in cellsPre if c['gid']==conn[preGidIndex]), None)
if preCell:
preGroup = _roundFigures(groupByIntervalPre * np.floor(preCell['tags'][groupBy] / groupByIntervalPre), 3)
else:
preGroup = None
postGroup = _roundFigures(groupByIntervalPost * np.floor(cell['tags'][groupBy] / groupByIntervalPost), 3)
if preGroup in groupIndsPre:
if feature in ['weight', 'strength']:
weightMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += conn[weightIndex]
elif feature == 'delay':
delayMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += conn[delayIndex]
countMatrix[groupIndsPre[preGroup], groupIndsPost[postGroup]] += 1
pre, post = groupsPre, groupsPost
# no valid groupBy
else:
elif feature == 'delay':
delayMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += conn[delayIndex]
countMatrix[popIndsPre[prePopLabel], popIndsPost[cell['tags']['pop']]] += 1
pre, post = popsPre, popsPost
# Calculate matrix if grouped by numeric tag (eg. 'y')
elif groupBy in sim.net.allCells[0]['tags'] and isinstance(sim.net.allCells[0]['tags'][groupBy], Number):
if not isinstance(groupByIntervalPre, Number) or not isinstance(groupByIntervalPost, Number):
print 'groupByIntervalPre or groupByIntervalPost not specified'
return
# group cells by 'groupBy' feature (eg. 'y') in intervals of 'groupByInterval')
cellValuesPre = [cell['tags'][groupBy] for cell in cellsPre]
minValuePre = _roundFigures(groupByIntervalPre * np.floor(min(cellValuesPre) / groupByIntervalPre), 3)
maxValuePre = _roundFigures(groupByIntervalPre * np.ceil(max(cellValuesPre) / groupByIntervalPre), 3)
groupsPre = np.arange(minValuePre, maxValuePre, groupByIntervalPre)
groupsPre = [_roundFigures(x,3) for x in groupsPre]
if includePre == includePost:
groupsPost = groupsPre
else:
cellValuesPost = [cell['tags'][groupBy] for cell in cellsPost]
minValuePost = _roundFigures(groupByIntervalPost * np.floor(min(cellValuesPost) / groupByIntervalPost), 3)
maxValuePost = _roundFigures(groupByIntervalPost * np.ceil(max(cellValuesPost) / groupByIntervalPost), 3)
groupsPost = np.arange(minValuePost, maxValuePost, groupByIntervalPost)
groupsPost = [_roundFigures(x,3) for x in groupsPost]
# only allow matrix sizes >= 2x2 [why?]
# if len(groupsPre) < 2 or len(groupsPost) < 2:
# print 'groupBy %s with groupByIntervalPre %s and groupByIntervalPost %s results in <2 groups'%(str(groupBy), str(groupByIntervalPre), str(groupByIntervalPre))
print('groupByIntervalPre or groupByIntervalPost not specified')
return
# group cells by 'groupBy' feature (eg. 'y') in intervals of 'groupByInterval')
cellValuesPre = [cell['tags'][groupBy] for cell in cellsPre]
minValuePre = _roundFigures(groupByIntervalPre * np.floor(min(cellValuesPre) / groupByIntervalPre), 3)
maxValuePre = _roundFigures(groupByIntervalPre * np.ceil(max(cellValuesPre) / groupByIntervalPre), 3)
groupsPre = np.arange(minValuePre, maxValuePre, groupByIntervalPre)
groupsPre = [_roundFigures(x,3) for x in groupsPre]
if includePre == includePost:
groupsPost = groupsPre
else:
cellValuesPost = [cell['tags'][groupBy] for cell in cellsPost]
minValuePost = _roundFigures(groupByIntervalPost * np.floor(min(cellValuesPost) / groupByIntervalPost), 3)
maxValuePost = _roundFigures(groupByIntervalPost * np.ceil(max(cellValuesPost) / groupByIntervalPost), 3)
groupsPost = np.arange(minValuePost, maxValuePost, groupByIntervalPost)
groupsPost = [_roundFigures(x,3) for x in groupsPost]
# only allow matrix sizes >= 2x2 [why?]
# if len(groupsPre) < 2 or len(groupsPost) < 2:
# print 'groupBy %s with groupByIntervalPre %s and groupByIntervalPost %s results in <2 groups'%(str(groupBy), str(groupByIntervalPre), str(groupByIntervalPre))
# return
# set indices for pre and post groups
groupIndsPre = {group: ind for ind,group in enumerate(groupsPre)}
groupIndsPost = {group: ind for ind,group in enumerate(groupsPost)}
# initialize matrices
if feature in ['weight', 'strength']:
weightMatrix = np.zeros((len(groupsPre), len(groupsPost)))