Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def plotEPSPAmp(include=None, trace=None, start=0, interval=50, number=2, amp='absolute', polarity='exc', saveFig=False, showFig=True):
from .. import sim
print('Plotting EPSP amplitudes...')
if include is None: include = [] # If not defined, initialize as empty list
cells, cellGids, _ = getCellsInclude(include)
gidPops = {cell['gid']: cell['tags']['pop'] for cell in cells}
if not trace:
print('Error: Missing trace to to plot EPSP amplitudes')
return
step = sim.cfg.recordStep
peaksAbs = np.zeros((number, len(cellGids)))
peaksRel = np.zeros((number, len(cellGids)))
for icell, gid in enumerate(cellGids):
vsoma = sim.allSimData[trace]['cell_'+str(gid)]
for ipeak in range(number):
if polarity == 'exc':
peakAbs = max(vsoma[int(start/step+(ipeak*interval/step)):int(start/step+(ipeak*interval/step)+(interval-1)/step)])
elif polarity == 'inh':
peakAbs = min(vsoma[int(start/step+(ipeak*interval/step)):int(start/step+(ipeak*interval/step)+(interval-1)/step)])
preLabelIndex = connsFormat.index('preLabel') if 'preLabel' in connsFormat else -1
if len(missing) > 0:
print(" Error: cfg.compactConnFormat missing:")
print(missing)
return None, None, None
else:
# using long conn format (dict)
preGidIndex = 'preGid'
synMechIndex = 'synMech'
weightIndex = 'weight'
delayIndex = 'delay'
preLabelIndex = 'preLabel'
# Calculate pre and post cells involved
cellsPre, cellGidsPre, netStimPopsPre = getCellsInclude(includePre)
if includePre == includePost:
cellsPost, cellGidsPost, netStimPopsPost = cellsPre, cellGidsPre, netStimPopsPre
else:
cellsPost, cellGidsPost, netStimPopsPost = getCellsInclude(includePost)
if isinstance(synMech, basestring): synMech = [synMech] # make sure synMech is a list
# Calculate matrix if grouped by cell
if groupBy == 'cell':
if feature in ['weight', 'delay', 'numConns']:
connMatrix = np.zeros((len(cellGidsPre), len(cellGidsPost)))
countMatrix = np.zeros((len(cellGidsPre), len(cellGidsPost)))
else:
print('Conn matrix with groupBy="cell" only supports features= "weight", "delay" or "numConns"')
return fig
cellIndsPre = {cell['gid']: ind for ind,cell in enumerate(cellsPre)}
print missing
return None, None, None
else:
# using long conn format (dict)
preGidIndex = 'preGid'
synMechIndex = 'synMech'
weightIndex = 'weight'
delayIndex = 'delay'
preLabelIndex = 'preLabel'
# Calculate pre and post cells involved
cellsPre, cellGidsPre, netStimPopsPre = getCellsInclude(includePre)
if includePre == includePost:
cellsPost, cellGidsPost, netStimPopsPost = cellsPre, cellGidsPre, netStimPopsPre
else:
cellsPost, cellGidsPost, netStimPopsPost = getCellsInclude(includePost)
if isinstance(synMech, basestring): synMech = [synMech] # make sure synMech is a list
# Calculate matrix if grouped by cell
if groupBy == 'cell':
if feature in ['weight', 'delay', 'numConns']:
connMatrix = np.zeros((len(cellGidsPre), len(cellGidsPost)))
countMatrix = np.zeros((len(cellGidsPre), len(cellGidsPost)))
else:
print 'Conn matrix with groupBy="cell" only supports features= "weight", "delay" or "numConns"'
return fig
cellIndsPre = {cell['gid']: ind for ind,cell in enumerate(cellsPre)}
cellIndsPost = {cell['gid']: ind for ind,cell in enumerate(cellsPost)}
# Order by
if len(cellsPre) > 0 and len(cellsPost) > 0:
preLabelIndex = connsFormat.index('preLabel') if 'preLabel' in connsFormat else -1
if len(missing) > 0:
print " Error: cfg.compactConnFormat missing:"
print missing
return None, None, None
else:
# using long conn format (dict)
preGidIndex = 'preGid'
synMechIndex = 'synMech'
weightIndex = 'weight'
delayIndex = 'delay'
preLabelIndex = 'preLabel'
# Calculate pre and post cells involved
cellsPre, cellGidsPre, netStimPopsPre = getCellsInclude(includePre)
if includePre == includePost:
cellsPost, cellGidsPost, netStimPopsPost = cellsPre, cellGidsPre, netStimPopsPre
else:
cellsPost, cellGidsPost, netStimPopsPost = getCellsInclude(includePost)
if isinstance(synMech, basestring): synMech = [synMech] # make sure synMech is a list
# Calculate matrix if grouped by cell
if groupBy == 'cell':
if feature in ['weight', 'delay', 'numConns']:
connMatrix = np.zeros((len(cellGidsPre), len(cellGidsPost)))
countMatrix = np.zeros((len(cellGidsPre), len(cellGidsPost)))
else:
print 'Conn matrix with groupBy="cell" only supports features= "weight", "delay" or "numConns"'
return fig
cellIndsPre = {cell['gid']: ind for ind,cell in enumerate(cellsPre)}
else:
yaxisLabel = 'Spike count'
figs=[]
if overlay:
figs.append(figure(title="Spike Historgram", tools=TOOLS, x_axis_label="Time (ms)", y_axis_label=yaxisLabel, toolbar_location='above'))
fig = figs[0]
legendItems = []
for iplot, subset in enumerate(include):
if not overlay:
figs.append(figure(title=str(subset), tools=TOOLS, x_axis_label="Time (ms)", y_axis_label=yaxisLabel))
fig = figs[iplot]
if isinstance(subset, list):
cells, cellGids, netStimLabels = getCellsInclude(subset)
else:
cells, cellGids, netStimLabels = getCellsInclude([subset])
numNetStims = 0
# Select cells to include
if len(cellGids) > 0:
try:
spkinds,spkts = list(zip(*[(spkgid,spkt) for spkgid,spkt in zip(sim.allSimData['spkid'],sim.allSimData['spkt']) if spkgid in cellGids]))
except:
spkinds,spkts = [],[]
else:
spkinds,spkts = [],[]
spkts, spkinds = list(spkts), list(spkinds)
numNetStims = 0
if 'stims' in sim.allSimData:
legendItems = []
figs=[]
if overlay:
figs.append(figure(title="PSD Rate Plot", tools=TOOLS, x_axis_label="Frequncy (Hz)", y_axis_label="Power Spectral Density (db/Hz)", toolbar_location='above'))
fig = figs[0]
legendItems = []
# Plot separate line for each entry in include
for iplot, subset in enumerate(include):
if not overlay:
figs.append(figure(title=str(subset), tools=TOOLS, x_axis_label="Frequency (HZ)", y_axis_label="Power Spectral Density (db/Hz)"))
fig = figs[iplot]
cells, cellGids, netStimLabels = getCellsInclude([subset])
numNetStims = 0
# Select cells to include
if len(cellGids) > 0:
try:
spkinds,spkts = list(zip(*[(spkgid,spkt) for spkgid,spkt in zip(sim.allSimData['spkid'],sim.allSimData['spkt']) if spkgid in cellGids]))
except:
spkinds,spkts = [],[]
else:
spkinds,spkts = [],[]
# Add NetStim spikes
spkts, spkinds = list(spkts), list(spkinds)
numNetStims = 0
if 'stims' in sim.allSimData:
if 'nte' not in dir(h):
try:
print(' Warning: support/nte.mod not compiled; attempting to compile from %s via "nrnivmodl support"'%(root))
os.system('cd ' + root + '; nrnivmodl support')
from neuron import load_mechanisms
load_mechanisms(root)
print(' Compilation of support folder mod files successful')
except:
print(' Error compiling support folder mod files')
return
h.load_file(root+'/support/nte.hoc') # nTE code (also requires support/net.mod)
if not spks1: # if doesnt contain a list of spk times, obtain from cells specified
cells, cellGids, netStimPops = getCellsInclude(cells1)
numNetStims = 0
# Select cells to include
if len(cellGids) > 0:
try:
spkts = [spkt for spkgid,spkt in zip(sim.allSimData['spkid'],sim.allSimData['spkt']) if spkgid in cellGids]
except:
spkts = []
else:
spkts = []
# Add NetStim spikes
spkts = list(spkts)
numNetStims = 0
for netStimPop in netStimPops:
if 'stims' in sim.allSimData:
if not set(prePreGids).isdisjoint(preGidsAll):
numDis += 1
else:
if sim.cfg.compactConnFormat:
if 'preGid' in sim.cfg.compactConnFormat:
preGidIndex = sim.cfg.compactConnFormat.index('preGid') # using compact conn format (list)
else:
print ' Error: cfg.compactConnFormat does not include "preGid"'
return -1
else:
preGidIndex = 'preGid' # using long conn format (dict)
_, cellsPreGids, _ = getCellsInclude(includePre)
_, cellsPrePreGids, _ = getCellsInclude(includePrePre)
cellsPost, _, _ = getCellsInclude(includePost)
for postCell in cellsPost:
print postCell['gid']
preGidsAll = [conn[preGidIndex] for conn in postCell['conns'] if isinstance(conn[preGidIndex], Number) and conn[preGidIndex] in cellsPreGids+cellsPrePreGids]
preGids = [gid for gid in preGidsAll if gid in cellsPreGids]
for preGid in preGids:
preCell = sim.net.allCells[preGid]
prePreGids = [conn[preGidIndex] for conn in preCell['conns'] if conn[preGidIndex] in cellsPrePreGids]
totCon += 1
if not set(prePreGids).isdisjoint(preGidsAll):
numDis += 1
print ' Total disynaptic connections: %d / %d (%.2f%%)' % (numDis, totCon, float(numDis)/float(totCon)*100 if totCon>0 else 0.0)
try:
sim.allSimData['disynConns'] = numDis
except: