Skip to content

Commit

Permalink
Merge pull request #251 from Neurosim-lab/development
Browse files Browse the repository at this point in the history
PR from development to master - VERSION 0.7.2
  • Loading branch information
salvadord authored Aug 11, 2017
2 parents 95cdb5d + 7c27e33 commit 078e708
Show file tree
Hide file tree
Showing 18 changed files with 1,827 additions and 360 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ virtualenv:
system_site_packages: true

install:
- pip install scipy
# Install OMV to facilitate installation of packages below
- pip install git+https://github.com/OpenSourceBrain/osb-model-validation
# Need to pre install NEURON so nrnivmodl can be run targeting mod files in a different directory
Expand Down
29 changes: 29 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# Version 0.7.2

- Improved NeuroML importing/exporting

- Added error checking for simConfig

- Added popColors option to plotSpikeHist and plotRatePSD

- Added support to load params, cfg, net and simData from .mat files

- Made root section (with no parents) the source of spikes by default (issue #246)

- Added option to set initial cfg in batch sims

- Added option to set grouped params in Batch constructor

- Added option to not record time (to reduce output file size)

- Fixed bug: synMechFraction had no effect; replaced with synMechWeightFactor

- Fixed bug in modifyStims for NetStim 'interval' and 'rate'

- Fixed bug importing cell -- use h.pop_section() to avoid stack overflow

- Fixed bug when adding stim NetStim where sec is a list

- Fixed bug when adding stim NetStim with multiple synMechs and synsPerConn>1


# Version 0.7.1

- Updates and bug fixes of NeuroML importer/exporter
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Requires NEURON with Python and MPI support.
```
import HHTut
from netpyne import sim
sim.createAndSimulate(
sim.createSimulateAnalyze(
simConfig = HHTut.simConfig,
netParams = HHTut.netParams)
```
Expand Down
2 changes: 1 addition & 1 deletion doc/source/code/tut2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0} # excitatory synaptic mechanism

# Stimulation parameters
netParams.stimSourceParams['bkg'] = {'type': 'NetStim', 'rate': 10, 'noise': 0.5,}
netParams.stimSourceParams['bkg'] = {'type': 'NetStim', 'rate': 10, 'noise': 0.5}
netParams.stimTargetParams['bkg->PYR'] = {'source': 'bkg', 'conds': {'cellType': 'PYR'}, 'weight': 0.01, 'delay': 5, 'synMech': 'exc'}

## Cell connectivity rules
Expand Down
1 change: 1 addition & 0 deletions examples/batchCell/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def runBatch(b, label):
def batchNa():
b = createBatch({'dendNa': [0.025, 0.03, 0.035, 0.4],
('IClamp1', 'amp'): list(np.arange(-2.0, 8.0, 0.5)/10.0)})
b.initCfg = {'duration': 1.1, 'tau1NMDA': 15}
runBatch(b, 'batchNa')


Expand Down
154 changes: 102 additions & 52 deletions examples/sandbox/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,103 @@
from neuron import h, gui

pc = h.ParallelContext()
pc.set_maxstep(10)
idhost = int(pc.id())
nhost = int(pc.nhost())

# Create presyn cell 1
pre1_gid = 0
pre1_host = 0
if idhost == pre1_host:
pre1 = h.Section(name='pre1')
pc.set_gid2node(pre1_gid, pre1_host)
nc = h.NetCon(pre1(0.5)._ref_v, None, sec = pre1)
nc.threshold = 20.0
pc.cell(pre1_gid, nc)

# Create presyn cell 2
pre2_gid = 1
pre2_host = 1 if nhost>1 else 0
if idhost == pre2_host:
pre2 = h.Section(name='pre2')
pc.set_gid2node(pre2_gid, pre2_host)
nc = h.NetCon(pre2(0.5)._ref_v, None, sec = pre2)
nc.threshold = 20.0
pc.cell(pre2_gid, nc)

# Create postsyn cell
post_gid = 2
post_host = 0
if idhost == post_host:
post = h.Section(name='post')
postsyn = h.Exp2Syn(post(0.5))
pc.set_gid2node(post_gid, post_host)
nc = h.NetCon(post(0.5)._ref_v, None, sec = post)
pc.cell(post_gid, nc) # Associate the cell with this host and gid


# Connect pre to post cells
if pc.gid_exists(post_gid):
nc1 = pc.gid_connect(pre1_gid, postsyn)
nc1.threshold = 5.0
nc2 = pc.gid_connect(pre2_gid, postsyn)
nc2.threshold = 5.0


# run sim
h.stdinit()

for i in range(3):
if pc.gid_exists(i):
print '\ngid: %d, pc.threshold: %.1f' % (i, pc.threshold(i))
"""
params.py
netParams is a dict containing a set of network parameters using a standardized structure
simConfig is a dict containing a set of simulation configurations using a standardized structure
Contributors: [email protected]
"""

from netpyne import specs, sim

netParams = specs.NetParams() # object of class NetParams to store the network parameters
simConfig = specs.SimConfig() # object of class SimConfig to store the simulation configuration


###############################################################################
#
# MPI HH TUTORIAL PARAMS
#
###############################################################################

###############################################################################
# NETWORK PARAMETERS
###############################################################################

# Population parameters
netParams.popParams['PYR'] = {'cellModel': 'HH', 'cellType': 'PYR', 'numCells': 5} # add dict with params for this pop
netParams.popParams['PYR2'] = {'cellModel': 'HH', 'cellType': 'PYR2', 'numCells': 5} # add dict with params for this pop


# Cell parameters
## PYR cell properties
cellRule = {'conds': {'cellModel': 'HH', 'cellType': 'PYR'}, 'secs': {}} # cell rule dict
cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict
cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry
cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism
cellRule['secs']['soma']['vinit'] = -71
netParams.cellParams['PYR'] = cellRule # add dict to list of cell params


cellRule = {'conds': {'cellModel': 'HH', 'cellType': 'PYR2'}, 'secs': {}} # cell rule dict
cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict
cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry
cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism
cellRule['secs']['soma']['vinit'] = -71
netParams.cellParams['PYR2'] = cellRule # add dict to list of cell params

# Synaptic mechanism parameters
netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0}


# Stimulation parameters
netParams.stimSourceParams['bkg'] = {'type': 'NetStim', 'rate': 10, 'noise': 0.5, 'start': 1}
netParams.stimSourceParams['bkg2'] = {'type': 'NetStim', 'rate': 10, 'noise': 0.5, 'start': 1}

netParams.stimTargetParams['bkg->PYR1'] = {'source': 'bkg', 'conds': {'pop': 'PYR'}, 'weight': 0.1, 'delay': 'uniform(1,5)'}


# Connectivity parameters
netParams.connParams['PYR->PYR'] = {
'preConds': {'pop': 'PYR'}, 'postConds': {'pop': ['PYR','PYR2']},
'weight': 0.002, # weight of each connection
'delay': '0.2+normal(13.0,1.4)', # delay min=0.2, mean=13.0, var = 1.4
'threshold': 10, # threshold
'convergence': 'uniform(1,15)'} # convergence (num presyn targeting postsyn) is uniformly distributed between 1 and 15


###############################################################################
# SIMULATION PARAMETERS
###############################################################################

# Simulation parameters
simConfig.duration = 1*1e3 # Duration of the simulation, in ms
simConfig.dt = 'a' # Internal integration timestep to use
simConfig.seeds = {'con': 1, 'stim': 1, 'loc': 1} # Seeds for randomizers (connectivity, input stimulation and cell locations)
simConfig.createNEURONObj = 1 # create HOC objects when instantiating network
simConfig.createPyStruct = 1 # create Python structure (simulator-independent) when instantiating network
simConfig.verbose = False # show detailed messages

simConfig.checkErrors = 0

# Recording
simConfig.recordCells = [] # which cells to record from
simConfig.recordTraces = {'Vsoma':{'se':'soma','loc':0.5,'var':'v','conds': {'cellType': 'PYR2'}}}
simConfig.recordStim = True # record spikes of cell stims
simConfig.recordStep = 0.1 # Step size in ms to save data (eg. V traces, LFP, etc)

# Saving
simConfig.filename = 'HHTut' # Set file output name
simConfig.saveFileStep = 1000 # step size in ms to save data to disk
simConfig.savePickle = False # Whether or not to write spikes etc. to a .mat file
simConfig.saveMat = True

# Analysis and plotting
simConfig.analysis['plotRaster'] = {'bla':1}
#simConfig.analysis['plotTraces'] = {'include': ['all'], 'oneFigPer':'trace'}

sim.createSimulateAnalyze()

#data=sim.loadSimData('HHTut.mat')


2 changes: 1 addition & 1 deletion netpyne/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__version__ = '0.7.1'
__version__ = '0.7.2'
__gui__ = True # global option to enable/disable graphics
35 changes: 10 additions & 25 deletions netpyne/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,6 @@ def plotRaster (include = ['allCells'], timeRange = None, maxSpikes = 1e8, order

print('Plotting raster...')

# colorList = [[0.42,0.67,0.84], [0.90,0.76,0.00], [0.42,0.83,0.59], [0.90,0.32,0.00],
# [0.34,0.67,0.67], [0.90,0.59,0.00], [0.42,0.82,0.83], [1.00,0.85,0.00],
# [0.33,0.67,0.47], [1.00,0.38,0.60], [0.57,0.67,0.33], [0.5,0.2,0.0],
# [0.71,0.82,0.41], [0.0,0.2,0.5]]

# Select cells to include
cells, cellGids, netStimLabels = getCellsInclude(include)
selectedPops = [cell['tags']['pop'] for cell in cells]
Expand Down Expand Up @@ -477,7 +472,7 @@ def plotSpikeHist (include = ['allCells', 'eachPop'], timeRange = None, binSize
- overlay (True|False): Whether to overlay the data lines or plot in separate subplots (default: True)
- graphType ('line'|'bar'): Type of graph to use (line graph or bar plot) (default: 'line')
- yaxis ('rate'|'count'): Units of y axis (firing rate in Hz, or spike count) (default: 'rate')
- popColors (dict): TO DO!
- popColors (dict): Dictionary with color (value) used for each population (key) (default: None)
- figSize ((width, height)): Size of figure (default: (10,8))
- saveData (None|True|'fileName'): File name where to save the final data used to generate the figure;
if set to True uses filename from simConfig (default: None)
Expand All @@ -490,12 +485,6 @@ def plotSpikeHist (include = ['allCells', 'eachPop'], timeRange = None, binSize

print('Plotting spike histogram...')

# colorList = [[0.42,0.67,0.84], [0.90,0.76,0.00], [0.42,0.83,0.59], [0.90,0.32,0.00],
# [0.34,0.67,0.67], [0.90,0.59,0.00], [0.42,0.82,0.83], [1.00,0.85,0.00],
# [0.33,0.67,0.47], [1.00,0.38,0.60], [0.57,0.67,0.33], [0.5,0.2,0.0],
# [0.71,0.82,0.41], [0.0,0.2,0.5]]


# Replace 'eachPop' with list of pops
if 'eachPop' in include:
include.remove('eachPop')
Expand Down Expand Up @@ -555,7 +544,7 @@ def plotSpikeHist (include = ['allCells', 'eachPop'], timeRange = None, binSize

if yaxis=='rate': histoCount = histoCount * (1000.0 / binSize) / (len(cellGids)+numNetStims) # convert to firing rate

color = colorList[iplot%len(colorList)]
color = popColors[subset] if subset in popColors else colorList[i%len(colorList)]

if not overlay:
plt.subplot(len(include),1,iplot+1) # if subplot, create new subplot
Expand All @@ -581,7 +570,8 @@ def plotSpikeHist (include = ['allCells', 'eachPop'], timeRange = None, binSize
# Add legend
if overlay:
for i,subset in enumerate(include):
plt.plot(0,0,color=colorList[i%len(colorList)],label=str(subset))
color = popColors[subset] if subset in popColors else colorList[i%len(colorList)]
plt.plot(0,0,color=color,label=str(subset))
plt.legend(fontsize=fontsiz, bbox_to_anchor=(1.04, 1), loc=2, borderaxespad=0.)
maxLabelLen = min(10,max([len(str(l)) for l in include]))
plt.subplots_adjust(right=(0.9-0.012*maxLabelLen))
Expand Down Expand Up @@ -613,7 +603,7 @@ def plotSpikeHist (include = ['allCells', 'eachPop'], timeRange = None, binSize
## Plot spike histogram
######################################################################################################################################################
def plotRatePSD (include = ['allCells', 'eachPop'], timeRange = None, binSize = 5, Fs = 200, smooth = 0, overlay=True,
figSize = (10,8), saveData = None, saveFig = None, showFig = True):
popColors = None, figSize = (10,8), saveData = None, saveFig = None, showFig = True):
'''
Plot firing rate power spectral density (PSD)
- include (['all',|'allCells','allNetStims',|,120,|,'E1'|,('L2', 56)|,('L5',[4,5,6])]): List of data series to include.
Expand All @@ -625,6 +615,7 @@ def plotRatePSD (include = ['allCells', 'eachPop'], timeRange = None, binSize =
- overlay (True|False): Whether to overlay the data lines or plot in separate subplots (default: True)
- graphType ('line'|'bar'): Type of graph to use (line graph or bar plot) (default: 'line')
- yaxis ('rate'|'count'): Units of y axis (firing rate in Hz, or spike count) (default: 'rate')
- popColors (dict): Dictionary with color (value) used for each population (key) (default: None)
- figSize ((width, height)): Size of figure (default: (10,8))
- saveData (None|True|'fileName'): File name where to save the final data used to generate the figure;
if set to True uses filename from simConfig (default: None)
Expand All @@ -636,12 +627,6 @@ def plotRatePSD (include = ['allCells', 'eachPop'], timeRange = None, binSize =
'''

print('Plotting firing rate power spectral density (PSD) ...')

# colorList = [[0.42,0.67,0.84], [0.90,0.76,0.00], [0.42,0.83,0.59], [0.90,0.32,0.00],
# [0.34,0.67,0.67], [0.90,0.59,0.00], [0.42,0.82,0.83], [1.00,0.85,0.00],
# [0.33,0.67,0.47], [1.00,0.38,0.60], [0.57,0.67,0.33], [0.5,0.2,0.0],
# [0.71,0.82,0.41], [0.0,0.2,0.5]]


# Replace 'eachPop' with list of pops
if 'eachPop' in include:
Expand Down Expand Up @@ -695,7 +680,7 @@ def plotRatePSD (include = ['allCells', 'eachPop'], timeRange = None, binSize =

histData.append(histoCount)

color = colorList[iplot%len(colorList)]
color = popColors[subset] if subset in popColors else colorList[iplot%len(colorList)]

if not overlay:
plt.subplot(len(include),1,iplot+1) # if subplot, create new subplot
Expand Down Expand Up @@ -727,7 +712,8 @@ def plotRatePSD (include = ['allCells', 'eachPop'], timeRange = None, binSize =
# Add legend
if overlay:
for i,subset in enumerate(include):
plt.plot(0,0,color=colorList[i%len(colorList)],label=str(subset))
color = popColors[subset] if subset in popColors else colorList[i%len(colorList)]
plt.plot(0,0,color=color,label=str(subset))
plt.legend(fontsize=fontsiz, bbox_to_anchor=(1.04, 1), loc=2, borderaxespad=0.)
maxLabelLen = min(10,max([len(str(l)) for l in include]))
plt.subplots_adjust(right=(0.9-0.012*maxLabelLen))
Expand Down Expand Up @@ -784,10 +770,9 @@ def plotTraces (include = None, timeRange = None, overlay = False, oneFigPer = '
print('Plotting recorded cell traces ...')

if include is None: include = [] # If not defined, initialize as empty list
global colorList
if isinstance(colors, list):
colorList = colors
else:
global colorList

# rerun simulation so new include cells get recorded from
if rerun:
Expand Down
Loading

0 comments on commit 078e708

Please sign in to comment.