Examples how to use the plotShape function

A Python package that facilitates development and use of models of biological neural networks

Moderator: tom_morse

Post Reply
Vittorio
Posts: 5
Joined: Mon Aug 28, 2017 12:21 pm

Examples how to use the plotShape function

Post by Vittorio »

Hi all,

can somebody point me towards an example of how to use the plotShape function in netpyne?

Also, is it possible to use this function to create a movie or just single snapshots at different time points to show the spatial distribution of a variable?

Thanks!
salvadord
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Re: Examples how to use the plotShape function

Post by salvadord »

Hi Vittorio,

I've updated the plotShape documentation and added some examples: http://www.neurosimlab.org/netpyne/refe ... -functions

At the moment its not possible to create a movie via netpyne (will add to github list of requests), but you can of course generate multiple snapshots and create movie using e.g. python. Also, I believe it is possible to create a movie using NEURON Interviews.

Please use the Github development version of NetPyNE since I just fixed a couple minor issues in the plotShape() func.

Let me know if you have any other issues/questions using plotShape().

salva
Vittorio
Posts: 5
Joined: Mon Aug 28, 2017 12:21 pm

Re: Examples how to use the plotShape function

Post by Vittorio »

Thanks Salva for the examples!

How do I pull the development version of NetPyNE?
salvadord
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Re: Examples how to use the plotShape function

Post by salvadord »

1) Remove any current version via pip uninstall netpyne
2) cd parent_folder_where_you_want_netpyne_repo
3) git clone https://github.com/Neurosim-lab/netpyne.git
4) cd netpyne
5) git checkout developmnet
6) pip install -e .

pip will add a symlink in the default python packages folder to the cloned netpyne folder. If new changes are available just need to git pull from the cloned repo folder.

Let me know if you have any issues
Vittorio
Posts: 5
Joined: Mon Aug 28, 2017 12:21 pm

Re: Examples how to use the plotShape function

Post by Vittorio »

Thanks!

I pulled the development version and tried a few files (e.g. geom.hoc of the tutorial) but I always get this error:
line 778, in getCellsList
if sim.nhosts > 1 and any(isinstance(cond, tuple) or isinstance(cond,list) for cond in include): # Gather tags from all cells
AttributeError: 'module' object has no attribute 'nhosts'
salvadord
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Re: Examples how to use the plotShape function

Post by salvadord »

So I assume you followed all the steps in prev post?

Can you please run python and include here the output of import netpyne; print netpyne.__file__? Then go to whatever folder shows up and include here the output of git branch and git log -1 ? We need to make sure the development version of netpyne is installed correctly and that you are not using some older version.

Also, can you please include the full error, the source code you are trying and the command to run it? I assume geom.hoc refers to the advanced features importing cells example, but not sure if something else.

Thanks
Vittorio
Posts: 5
Joined: Mon Aug 28, 2017 12:21 pm

Re: Examples how to use the plotShape function

Post by Vittorio »

Hi Salva!

yes, I followed all steps you indicated to pull the development version.

The output of git branch is
* development
master
and, the output of git log -1 is
commit 7b75ba78f48385d4c4467d7926fd08b588fa2a02
Author: salvadord <salvadordura@gmail.com>
Date: Thu Aug 31 11:45:25 2017 -0400

Fixed converting tuples to strings when saving Matlab; now converts to lists
Regarding the code I am running. Yes, the geom.hoc file is the file used for the example showing advanced features for importing cells.
I am running this code (a reduced version of the tut_import.hoc):

Code: Select all

from netpyne import specs, sim

# Network parameters
netParams = specs.NetParams()  # object of class NetParams to store the network parameters

## Population parameters
netParams.popParams['HH3D_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'HH3D'}

### HH3D
cellRule = netParams.importCellParams(label='PYR_HH3D_rule', conds={'cellType': 'PYR', 'cellModel': 'HH3D'},
                                      fileName='geom.hoc', cellName='E21', importSynMechs=True)
cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70}  	# soma hh mechanism
for secName in cellRule['secs']:
    cellRule['secs'][secName]['mechs']['pas'] = {'g': 0.001, 'e': -65}
    cellRule['secs'][secName]['geom']['cm'] = 1

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


# Stimulation parameters
netParams.stimSourceParams['bkg'] = {'type': 'NetStim', 'rate': 50, 'noise': 0.5}
netParams.stimTargetParams['bg1'] = {'source': 'bkg', 'conds': {'cellType': 'PYR', 'cellModel': ['HH3D']},
    'weight': 0.1, 'delay': 5, 'sec': 'soma','synMech': 'AMPA'}


## Connectivity params
netParams.connParams['recurrent'] = {
    'preConds': {'cellType': 'PYR'}, 'postConds': {'cellType': 'PYR'},  #  PYR -> PYR random
        'connFunc': 'convConn', 	# connectivity function (random)
        'convergence': 'uniform(0,10)', 			# max number of incoming conns to cell
        'weight': 0.001, 			# synaptic weight
        'delay': 5,					# transmission delay (ms)
        'sec': 'soma'}				# section to connect to



# Simulation options
simConfig = specs.SimConfig()					# object of class SimConfig to store simulation configuration
simConfig.duration = 1*1e3 			# Duration of the simulation, in ms
simConfig.dt = 0.025 				# Internal integration timestep to use
simConfig.verbose = 0			# Show detailed messages
simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}}  # Dict with traces to record
simConfig.recordStep = 1 			# Step size in ms to save data (eg. V traces, LFP, etc)
simConfig.filename = 'model_output'  # Set file output name
simConfig.savePickle = False 		# Save params, network and sim output to pickle file

simConfig.analysis['plotRaster'] = {'orderInverse': True}			# Plot a raster
simConfig.analysis['plotTraces'] = {'include': [1]} 			# Plot recorded traces for this list of cells

sim.analysis.plotShape(showSyns=1, saveFig=True, showFig=True)
# Create network and run simulation
sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig)    

import pylab; pylab.show()  # this line is only necessary in certain systems where figures appear empty
The code itself works when I comment out sim.analysis.plotShape(showSyns=1, saveFig=True, showFig=True)

Thanks!
salvadord
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Re: Examples how to use the plotShape function

Post by salvadord »

Ah ok! Problem is you are calling the plotShape() function before even creating the network. It should go after sim.createSimulateAnalyze()

Note netpyne is a declarative language so nothing gets executed/created until you call sim.createSimulateAnalyze().

Alternatively, you can include plotShape in a declarative form together with the other analysis function in simConfig (this will have the same effect as if you call the function directly after the net has been created), e.g.:

Code: Select all

simConfig.analysis['plotTraces'] = {'include': [1]}  
simConfig.analysis['plotShape'] = {'showSyns': 1, 'saveFig': True, 'showFig': True} 
# Create network and run simulation
sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig)
hope this helps!
Post Reply