Skip to content

Commit

Permalink
semantic changes to network examples (#124)
Browse files Browse the repository at this point in the history
* semantic changes to network examples

* retuned parameters for extrinsic inputs, fixed py3 issue

* use standalone parameters module

* pip requirements file pointing to freestanding Neurotools parameters module

* pip requirements file pointing to freestanding Neurotools parameters module

* removed unused imports, fixed h5py and mpl DeprecationWarnings
  • Loading branch information
espenhgn committed Mar 1, 2019
1 parent 8a4eb45 commit afd5ea9
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 55 deletions.
4 changes: 2 additions & 2 deletions examples/bioRxiv281717/example_parallel_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
GNU General Public License for more details.
'''
from __future__ import division
from mpi4py import MPI
import neuron
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
Expand All @@ -150,8 +152,6 @@
h5py.version.hdf5_version))
import os
from time import time
from mpi4py import MPI
import neuron
import LFPy
from example_parallel_network_plotting import decimate

Expand Down
40 changes: 31 additions & 9 deletions examples/bioRxiv281717/example_parallel_network_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@
neuron.h.load_file("import3d.hoc")


#######################
# Functions
#######################
def get_pre_m_type(post):
'''little helper function to return the most populuous excitatory m_type
within the layer of m_type post, assuming this is representative for
excitatory external connections onto postsynaptic cells '''
if post.startswith('L23'):
return 'L23_PC'
elif post.startswith('L4'):
return 'L4_PC'
elif post.startswith('L5'):
return 'L5_TTPC1'
elif post.startswith('L6'):
return 'L6_IPC'

#######################
# Parameters
#######################


# test mode (1 cell per pop, all-to-all connectivity)
TESTING = False

Expand Down Expand Up @@ -202,21 +223,21 @@
# Excitatory
('L4_PC', 'cAD', 'L4_PC_cADpyr230_1', 2674,
dict(radius=210, loc=PSET.layer_data[3]['center'], scale=100., cap=[1078., 97.]),
dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.05, 5.),
dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.125, 5.),
# Inhibitory
('L4_LBC', 'dNAC', 'L4_LBC_dNAC222_1', 122,
dict(radius=210, loc=PSET.layer_data[3]['center'], scale=100., cap=[938., 670]),
dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.05, 5.),
dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.125, 5.),

# Layer 5
# Excitatory
('L5_TTPC1', 'cAD', 'L5_TTPC1_cADpyr232_1', 2403,
dict(radius=210, loc=PSET.layer_data[4]['center'], scale=125., cap=[719, 73.]),
dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.045, 5.),
dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.1, 5.),
# Inhibitory
('L5_MC', 'bAC', 'L5_MC_bAC217_1', 395,
dict(radius=210, loc=PSET.layer_data[4]['center'], scale=125., cap=[378., 890]),
dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.05, 5.),
dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.125, 5.),
],
dtype = [('m_type', '|{}32'.format(stringType)), ('e_type', '|{}32'.format(stringType)),
('me_type', '|{}32'.format(stringType)), ('POP_SIZE', 'i8'), ('pop_args', dict),
Expand All @@ -228,6 +249,7 @@
# names as used to denote individual cell types
# POP_SIZE : number of neurons for each morphological type as given on https://bbp.epfl.ch/nmc-portal/microcircuit


# pop_args : dict, radius, mean position (loc) and standard deviation (scale) of the soma positions
# rotation_args : dict, default rotations around x and y axis applied to each cell in the population using LFPy.NetworkCell.set_rotation() method.

Expand Down Expand Up @@ -651,13 +673,13 @@
PSET.connParamsExtrinsic = dict(
# synapse type
syntype = 'ProbAMPANMDA_EMS',
# synapse parameters (chosen using pre==post)
# synapse parameters (assumes parameters of excitatory population in the layer)
synparams = [dict(
Use = syn_param_stats['{}:{}'.format(post, post)]['Use_mean'],
Dep = syn_param_stats['{}:{}'.format(post, post)]['Dep_mean'],
Fac = syn_param_stats['{}:{}'.format(post, post)]['Fac_mean'],
Use = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['Use_mean'],
Dep = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['Dep_mean'],
Fac = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['Fac_mean'],
tau_r_AMPA = 0.2,
tau_d_AMPA = syn_param_stats['{}:{}'.format(pre, post)]['tau_d_mean'],
tau_d_AMPA = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['tau_d_mean'],
tau_r_NMDA = 0.29,
tau_d_NMDA = 43,
e=0,
Expand Down
11 changes: 5 additions & 6 deletions examples/bioRxiv281717/figure_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from mpl_toolkits.axes_grid.axislines import SubplotZero
from matplotlib.collections import PolyCollection, LineCollection, PatchCollection
from matplotlib import colors, patches
from mpl_toolkits.axisartist.axislines import SubplotZero
from matplotlib.collections import PolyCollection
import neuron

# set some plotting parameters
Expand Down Expand Up @@ -258,7 +257,7 @@ def draw_lineplot(


def remove_axis_junk(ax, lines=['right', 'top']):
for loc, spine in ax.spines.iteritems():
for loc, spine in ax.spines.items():
if loc in lines:
spine.set_color('none')
ax.xaxis.set_ticks_position('bottom')
Expand Down Expand Up @@ -305,7 +304,7 @@ def remove_axis_junk(ax, lines=['right', 'top']):
zips = []
xz = cell.get_idx_polygons()
for x, z in xz:
zips.append(zip(x, z))
zips.append(list(zip(x, z)))
for ax in [ax0]:
polycol = PolyCollection(zips,
linewidths=(0.5),
Expand Down Expand Up @@ -336,7 +335,7 @@ def remove_axis_junk(ax, lines=['right', 'top']):
zips = []
offset = 0.
for x, z in cell.get_pt3d_polygons():
zips.append(zip(x-offset, z+offset))
zips.append(list(zip(x-offset, z+offset)))
polycol = PolyCollection(zips,
edgecolors='none',
facecolors='gray',
Expand Down
1 change: 0 additions & 1 deletion examples/bioRxiv281717/figure_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from matplotlib.ticker import MaxNLocator
import os
import numpy as np
import scipy.signal as ss
import h5py
from LFPy import NetworkCell
import example_parallel_network_plotting as plotting
Expand Down
18 changes: 7 additions & 11 deletions examples/bioRxiv281717/figure_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
from __future__ import division
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec
from matplotlib.collections import PolyCollection
from mpl_toolkits.axes_grid.axislines import SubplotZero
import mpl_toolkits.axes_grid.axes_size as Size
from mpl_toolkits.axes_grid import Divider
from mpl_toolkits.axisartist.axislines import SubplotZero
import os
import numpy as np
import scipy.signal as ss
import h5py
from LFPy import NetworkCell, FourSphereVolumeConductor, MEG
from LFPy import FourSphereVolumeConductor, MEG
import example_parallel_network_plotting as plotting
from mpi4py import MPI

Expand All @@ -53,7 +49,7 @@ def plot_spike_raster(ax, PSET, T):
for i, (m_name, name) in enumerate(zip(PSET.populationParameters['m_type'], PSET.populationParameters['me_type'])):
x = []
y = []
ax.hlines(f['SPIKES'][name]['gids'].value.min(), T[0], T[1], 'k', lw=0.25)
ax.hlines(f['SPIKES'][name]['gids'][()].min(), T[0], T[1], 'k', lw=0.25)
for gid, spt in zip(f['SPIKES'][name]['gids'], f['SPIKES'][name]['times']):
if len(spt) > 0:
y += [gid]*spt.size
Expand Down Expand Up @@ -121,7 +117,7 @@ def plot_spike_raster(ax, PSET, T):
for i, (m_name, name) in enumerate(zip(PSET.populationParameters['m_type'], PSET.populationParameters['me_type'])):
ax = axes[i]
plotting.remove_axis_junk(ax)
data = np.hstack(f['SPIKES'][name]['times'].value.flat)
data = np.hstack(f['SPIKES'][name]['times'][()].flat)
ax.hist(data, bins=bins, color=colors[i][:-1], label=m_name)
ax.axis(ax.axis('tight'))
ax.set_xlim(PSET.TRANSIENT, PSET.TRANSIENT+1000.)
Expand All @@ -146,7 +142,7 @@ def plot_spike_raster(ax, PSET, T):
ax = fig.add_subplot(gs0[:-2])
f = h5py.File(os.path.join(PSET.OUTPUTPATH, 'example_parallel_network_output.h5'), 'r')
for data, title, color in zip(
[f['SUMMED_OUTPUT'].value['imem']],
[f['SUMMED_OUTPUT'][()]['imem']],
['extracellular potentials, summed'],
['k']):
ax.set_title(title)
Expand All @@ -169,12 +165,12 @@ def plot_spike_raster(ax, PSET, T):
# PANEL D ECoG potential
ax = fig.add_subplot(gs0[-1])
f = h5py.File(os.path.join(PSET.OUTPUTPATH, 'example_parallel_network_output.h5'), 'r')
data = f['SUMMED_ECOG'].value['imem']
data = f['SUMMED_ECOG'][()]['imem']
title = 'ECoG potential, summed'
color = 'k'
ax.set_title(title)
vlimround = plotting.draw_lineplot(ax=ax,
data=plotting.decimate(f['SUMMED_OUTPUT'].value['imem'][0, ].reshape((1, -1)),
data=plotting.decimate(f['SUMMED_OUTPUT'][()]['imem'][0, ].reshape((1, -1)),
q=PSET.decimate_q),
dt=PSET.dt*PSET.decimate_q,
scalebar=False,
Expand Down
10 changes: 2 additions & 8 deletions examples/bioRxiv281717/figure_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@
from __future__ import division
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from matplotlib.collections import PolyCollection
from mpl_toolkits.axes_grid.axislines import SubplotZero
import mpl_toolkits.axes_grid.axes_size as Size
from mpl_toolkits.axes_grid import Divider
import os
import numpy as np
import scipy.signal as ss
import h5py
from LFPy import NetworkCell, FourSphereVolumeConductor, MEG
import example_parallel_network_plotting as plotting
from mpi4py import MPI

Expand Down Expand Up @@ -69,7 +63,7 @@
ax = fig.add_subplot(gs[:8, j])
f = h5py.File(os.path.join(PSET.OUTPUTPATH, 'example_parallel_network_output.h5'), 'r')
for data, title, color in zip(
[f['SUMMED_OUTPUT'].value[me_type]],
[f['SUMMED_OUTPUT'][()][me_type]],
[m_type],
['k']):
ax.set_title(title)
Expand Down Expand Up @@ -127,7 +121,7 @@
f = h5py.File(os.path.join(PSET.OUTPUTPATH, 'example_parallel_network_output.h5'), 'r')

for m_type, me_type, color in zip(list(PSET.populationParameters['m_type'])+['summed'], list(PSET.populationParameters['me_type'])+['imem'], colors+['k']):
data = f['SUMMED_OUTPUT'].value[me_type]
data = f['SUMMED_OUTPUT'][()][me_type]
ax.semilogx(data[:, tind:].var(axis=1), y, lw=2, label=m_type, color=color)
f.close()
ax.set_yticks(y)
Expand Down
9 changes: 4 additions & 5 deletions examples/bioRxiv281717/figure_7_8/example_parallel_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
GNU General Public License for more details.
'''
from __future__ import division
from mpi4py import MPI
import neuron
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
Expand All @@ -139,12 +141,10 @@
h5py.version.hdf5_version))
import os
from time import time
from mpi4py import MPI
import neuron
import LFPy
from example_parallel_network_plotting import decimate
import sys
import NeuroTools.parameters as ps
import parameters as ps


# set up MPI environment
Expand Down Expand Up @@ -263,7 +263,7 @@
if RANK == 0:
parameters_time = time() - tic
# open file object for writing
logfile = file(os.path.join(PSET.OUTPUTPATH, 'log.txt'), 'w', 0)
logfile = open(os.path.join(PSET.OUTPUTPATH, 'log.txt'), 'w')
logfile.write('initialization {}\n'.format(initialization_time))
print('Parameters in {} seconds'.format(parameters_time))
logfile.write('parameters {}\n'.format(parameters_time))
Expand Down Expand Up @@ -574,7 +574,6 @@
label=name,
)
ax.add_collection(polycol)
ax.axis(ax.axis('equal'))
ax.set_xlim(-400, 400)
axis = ax.axis()
ax.hlines(np.r_[0., -PSET.layer_data['thickness'].cumsum()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
RANK = COMM.Get_rank()


#######################
# Functions
#######################
def get_pre_m_type(post):
'''little helper function to return the most populuous excitatory m_type
within the layer of m_type post, assuming this is representative for
excitatory external connections onto postsynaptic cells '''
if post.startswith('L23'):
return 'L23_PC'
elif post.startswith('L4'):
return 'L4_PC'
elif post.startswith('L5'):
return 'L5_TTPC1'
elif post.startswith('L6'):
return 'L6_IPC'

#######################
# Parameters
#######################


# load some neuron-interface files needed for the EPFL cell types
neuron.h.load_file("stdrun.hoc")
neuron.h.load_file("import3d.hoc")
Expand Down Expand Up @@ -205,21 +226,21 @@
# # Excitatory
# ('L4_PC', 'cAD', 'L4_PC_cADpyr230_1', 2674,
# dict(radius=210, loc=PSET.layer_data[3]['center'], scale=100., cap=[1078., 97.]),
# dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.05, 5.),
# dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.125, 5.),
# # Inhibitory
# ('L4_LBC', 'dNAC', 'L4_LBC_dNAC222_1', 122,
# dict(radius=210, loc=PSET.layer_data[3]['center'], scale=100., cap=[938., 670]),
# dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.05, 5.),
# dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.125, 5.),

# Layer 5
# Excitatory
('L5_TTPC1', 'cAD', 'L5_TTPC1_cADpyr232_1', 2403,
dict(radius=210, loc=PSET.layer_data[4]['center'], scale=125., cap=[719, 73.]),
dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.045, 5.),
dict(x=np.pi/2, y=0.), ['dend', 'apic'], ['dend', 'apic'], 0.1, 5.),
# Inhibitory
('L5_MC', 'bAC', 'L5_MC_bAC217_1', 395,
dict(radius=210, loc=PSET.layer_data[4]['center'], scale=125., cap=[378., 890]),
dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.05, 5.),
dict(x=np.pi/2, y=0.), ['soma', 'dend', 'apic'], ['dend', 'apic'], 0.125, 5.),
],
dtype = [('m_type', '|{}32'.format(stringType)), ('e_type', '|{}32'.format(stringType)),
('me_type', '|{}32'.format(stringType)), ('POP_SIZE', 'i8'), ('pop_args', dict),
Expand Down Expand Up @@ -654,13 +675,13 @@
PSET.connParamsExtrinsic = dict(
# synapse type
syntype = 'ProbAMPANMDA_EMS',
# synapse parameters (chosen using pre==post)
# synapse parameters (assumes parameters of excitatory population in the layer)
synparams = [dict(
Use = syn_param_stats['{}:{}'.format(post, post)]['Use_mean'],
Dep = syn_param_stats['{}:{}'.format(post, post)]['Dep_mean'],
Fac = syn_param_stats['{}:{}'.format(post, post)]['Fac_mean'],
Use = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['Use_mean'],
Dep = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['Dep_mean'],
Fac = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['Fac_mean'],
tau_r_AMPA = 0.2,
tau_d_AMPA = syn_param_stats['{}:{}'.format(pre, post)]['tau_d_mean'],
tau_d_AMPA = syn_param_stats['{}:{}'.format(get_pre_m_type(post), post)]['tau_d_mean'],
tau_r_NMDA = 0.29,
tau_d_NMDA = 43,
e=0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import operator
import pickle
import hashlib
import NeuroTools.parameters as ps
import parameters as ps


def sort_deep_dict(d):
Expand Down
1 change: 0 additions & 1 deletion examples/bioRxiv281717/figure_7_8/figure_7_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os
import numpy as np
import example_parallel_network_parameterspace as ps
#from example_parallel_network_parameterspace import *
from example_parallel_network_parameters import PSET
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
Expand Down
1 change: 1 addition & 0 deletions examples/bioRxiv281717/figure_7_8/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e git+git@github.com:espenhgn/parameters.git@fix_py3#egg=parameters
3 changes: 1 addition & 2 deletions examples/bioRxiv281717/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#essential
parameters>=0.2.1
-e git+git@github.com:espenhgn/parameters.git@fix_py3#egg=parameters

0 comments on commit afd5ea9

Please sign in to comment.