Populations, Views and Assemblies

Populations

class Population(size, cellclass, cellparams=None, structure=None, initial_values={}, label=None)[source]

Bases: pyNN.common.populations.Population, pyNN.neuron.populations.PopulationMixin

A group of neurons all of the same type. “Population” is used as a generic term intended to include layers, columns, nuclei, etc., of cells.

Arguments:
size:
number of cells in the Population. For backwards-compatibility, size may also be a tuple giving the dimensions of a grid, e.g. size=(10,10) is equivalent to size=100 with structure=Grid2D().
cellclass:
a cell type (a class inheriting from pyNN.models.BaseCellType).
cellparams:
a dict, or other mapping, containing parameters, which is passed to the neuron model constructor.
structure:
a pyNN.space.Structure instance, used to specify the positions of neurons in space.
initial_values:
a dict, or other mapping, containing initial values for the neuron state variables.
label:
a name for the population. One will be auto-generated if this is not supplied.
size

The total number of neurons in the Population.

label

A label for the Population.

celltype

The type of neurons making up the Population.

initial_values

A dict containing the initial values of the state variables.

all_cells

An array containing the cell ids of all neurons in the Population (all MPI nodes)

__add__(other)

A Population/PopulationView can be added to another Population, PopulationView or Assembly, returning an Assembly.

__getitem__(index)

Return either a single cell (ID object) from the Population, if index is an integer, or a subset of the cells (PopulationView object), if index is a slice or array.

Note that __getitem__ is called when using [] access, e.g.
p = Population(…) p[2] is equivalent to p.__getitem__(2). p[3:6] is equivalent to p.__getitem__(slice(3, 6))
__iter__()

Iterator over cell ids on the local node.

__len__()

Return the total number of cells in the population (all nodes).

all()

Iterator over cell ids on all MPI nodes.

annotate(**annotations)[source]
can_record(variable)

Determine whether variable can be recorded from this population.

conductance_based

Indicates whether the post-synaptic response is modelled as a change in conductance or a change in current.

describe(template='population_default.txt', engine='default')[source]

Returns a human-readable description of the population.

The output may be customized by specifying a different template together with an associated template engine (see pyNN.descriptions).

If template is None, then a dictionary containing the template context will be returned.

find_units(variable)
get(parameter_names, gather=False, simplify=True)

Get the values of the given parameters for every local cell in the population, or, if gather=True, for all cells in the population.

Values will be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

getSpikes(*args, **kwargs)

Deprecated. Use get_data('spikes') instead.

get_data(variables='all', gather=True, clear=False)

Return a Neo Block containing the data (spikes, state variables) recorded from the Population.

variables - either a single variable name or a list of variable names
Variables must have been previously recorded, otherwise an Exception will be raised.

For parallel simulators, if gather is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

If clear is True, recorded data will be deleted from the Population.

get_gsyn(*args, **kwargs)

Deprecated. Use get_data(['gsyn_exc', 'gsyn_inh']) instead.

get_spike_counts(gather=True)

Returns a dict containing the number of spikes for each neuron.

The dict keys are neuron IDs, not indices.

get_v(*args, **kwargs)

Deprecated. Use get_data('v') instead.

id_to_index(id)[source]

Given the ID(s) of cell(s) in the Population, return its (their) index (order in the Population).

>>> assert p.id_to_index(p[5]) == 5
id_to_local_index(id)[source]

Given the ID(s) of cell(s) in the Population, return its (their) index (order in the Population), counting only cells on the local MPI node.

initialize(**initial_values)

Set initial values of state variables, e.g. the membrane potential.

Values passed to initialize() may be:
  1. single numeric values (all neurons set to the same value)
  2. RandomDistribution objects
  3. lists/arrays of numbers of the same size as the population
  4. mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single number.

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.initialize(v=-70.0)
p.initialize(v=rand_distr, gsyn_exc=0.0)
p.initialize(v=lambda i: -65 + i/10.0)
inject(current_source)

Connect a current source to all cells in the Population.

is_local(id)

Indicates whether the cell with the given ID exists on the local MPI node.

local_cells

An array containing cell ids for the local node.

local_size

Return the number of cells in the population on the local MPI node

meanSpikeCount(*args, **kwargs)

Deprecated. Use mean_spike_count() instead.

mean_spike_count(gather=True)

Returns the mean number of spikes per neuron.

nearest(position)

Return the neuron closest to the specified position.

position_generator
positions

A 3xN array (where N is the number of neurons in the Population) giving the x,y,z coordinates of all the neurons (soma, in the case of non-point models).

printSpikes(*args, **kwargs)

Deprecated. Use write_data(file, 'spikes') instead.

print_gsyn(*args, **kwargs)

Deprecated. Use write_data(file, ['gsyn_exc', 'gsyn_inh']) instead.

print_v(*args, **kwargs)

Deprecated. Use write_data(file, 'v') instead.

receptor_types
record(variables, to_file=None, sampling_interval=None)

Record the specified variable or variables for all cells in the Population or view.

variables may be either a single variable name or a list of variable names. For a given celltype class, celltype.recordable contains a list of variables that can be recorded for that celltype.

If specified, to_file should be a Neo IO instance and write_data() will be automatically called when end() is called.

sampling_interval should be a value in milliseconds, and an integer multiple of the simulation timestep.

record_gsyn(*args, **kwargs)

Deprecated. Use record(['gsyn_exc', 'gsyn_inh']) instead.

record_v(*args, **kwargs)

Deprecated. Use record('v') instead.

rset(*args, **kwargs)

Deprecated. Use set(parametername=rand_distr) instead.

sample(n, rng=None)

Randomly sample n cells from the Population, and return a PopulationView object.

save_positions(file)

Save positions to file. The output format is index x y z

set(**parameters)

Set one or more parameters for every cell in the population.

Values passed to set() may be:
  1. single values
  2. RandomDistribution objects
  3. lists/arrays of values of the same size as the population
  4. mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single value.

Here, a “single value” may be either a single number or a list/array of numbers (e.g. for spike times). Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.set(tau_m=20.0, v_rest=-65).
p.set(spike_times=[0.3, 0.7, 0.9, 1.4])
p.set(cm=rand_distr, tau_m=lambda i: 10 + i/10.0)
structure

The spatial structure of the Population.

tset(*args, **kwargs)

Deprecated. Use set(parametername=value_array) instead.

write_data(io, variables='all', gather=True, clear=False, annotations=None)

Write recorded data to file, using one of the file formats supported by Neo.

io:
a Neo IO instance
variables:
either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

For parallel simulators, if gather is True, all data will be gathered to the master node and a single output file created there. Otherwise, a file will be written on each node, containing only data from the cells simulated on that node.

If clear is True, recorded data will be deleted from the Population.

annotations should be a dict containing simple data types such as numbers and strings. The contents will be written into the output data file as metadata.

create(cellclass, cellparams=None, n=1)

Create n cells all of the same type.

Returns a Population object.

Views (sub-populations)

class PopulationView(parent, selector, label=None)[source]

Bases: pyNN.common.populations.PopulationView, pyNN.neuron.populations.PopulationMixin

A view of a subset of neurons within a Population.

In most ways, Populations and PopulationViews have the same behaviour, i.e. they can be recorded, connected with Projections, etc. It should be noted that any changes to neurons in a PopulationView will be reflected in the parent Population and vice versa.

It is possible to have views of views.

Arguments:
selector:

a slice or numpy mask array. The mask array should either be a boolean array of the same size as the parent, or an integer array containing cell indices, i.e. if p.size == 5:

PopulationView(p, array([False, False, True, False, True]))
PopulationView(p, array([2,4]))
PopulationView(p, slice(2,5,2))

will all create the same view.

size

The total number of neurons in the Population.

label

A label for the Population.

celltype

The type of neurons making up the Population.

initial_values

A dict containing the initial values of the state variables.

parent

A reference to the parent Population (that this is a view of).

mask

The selector mask that was used to create this view.

all_cells

An array containing the cell ids of all neurons in the Population (all MPI nodes).

local_cells

An array containing the cell ids of those neurons in the Population that exist on the local MPI node.

__add__(other)

A Population/PopulationView can be added to another Population, PopulationView or Assembly, returning an Assembly.

__getitem__(index)

Return either a single cell (ID object) from the Population, if index is an integer, or a subset of the cells (PopulationView object), if index is a slice or array.

Note that __getitem__ is called when using [] access, e.g.
p = Population(…) p[2] is equivalent to p.__getitem__(2). p[3:6] is equivalent to p.__getitem__(slice(3, 6))
__iter__()

Iterator over cell ids on the local node.

__len__()

Return the total number of cells in the population (all nodes).

all()

Iterator over cell ids on all MPI nodes.

can_record(variable)

Determine whether variable can be recorded from this population.

conductance_based

Indicates whether the post-synaptic response is modelled as a change in conductance or a change in current.

describe(template='populationview_default.txt', engine='default')[source]

Returns a human-readable description of the population view.

The output may be customized by specifying a different template togther with an associated template engine (see pyNN.descriptions).

If template is None, then a dictionary containing the template context will be returned.

find_units(variable)
get(parameter_names, gather=False, simplify=True)

Get the values of the given parameters for every local cell in the population, or, if gather=True, for all cells in the population.

Values will be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

getSpikes(*args, **kwargs)

Deprecated. Use get_data('spikes') instead.

get_data(variables='all', gather=True, clear=False)

Return a Neo Block containing the data (spikes, state variables) recorded from the Population.

variables - either a single variable name or a list of variable names
Variables must have been previously recorded, otherwise an Exception will be raised.

For parallel simulators, if gather is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

If clear is True, recorded data will be deleted from the Population.

get_gsyn(*args, **kwargs)

Deprecated. Use get_data(['gsyn_exc', 'gsyn_inh']) instead.

get_spike_counts(gather=True)

Returns a dict containing the number of spikes for each neuron.

The dict keys are neuron IDs, not indices.

get_v(*args, **kwargs)

Deprecated. Use get_data('v') instead.

grandparent

Returns the parent Population at the root of the tree (since the immediate parent may itself be a PopulationView).

The name “grandparent” is of course a little misleading, as it could be just the parent, or the great, great, great, …, grandparent.

id_to_index(id)[source]

Given the ID(s) of cell(s) in the PopulationView, return its/their index/indices (order in the PopulationView).

>>> assert pv.id_to_index(pv[3]) == 3
index_in_grandparent(indices)[source]

Given an array of indices, return the indices in the parent population at the root of the tree.

initial_values
initialize(**initial_values)

Set initial values of state variables, e.g. the membrane potential.

Values passed to initialize() may be:
  1. single numeric values (all neurons set to the same value)
  2. RandomDistribution objects
  3. lists/arrays of numbers of the same size as the population
  4. mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single number.

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.initialize(v=-70.0)
p.initialize(v=rand_distr, gsyn_exc=0.0)
p.initialize(v=lambda i: -65 + i/10.0)
inject(current_source)

Connect a current source to all cells in the Population.

is_local(id)

Indicates whether the cell with the given ID exists on the local MPI node.

local_size

Return the number of cells in the population on the local MPI node

meanSpikeCount(*args, **kwargs)

Deprecated. Use mean_spike_count() instead.

mean_spike_count(gather=True)

Returns the mean number of spikes per neuron.

nearest(position)

Return the neuron closest to the specified position.

position_generator
positions
printSpikes(*args, **kwargs)

Deprecated. Use write_data(file, 'spikes') instead.

print_gsyn(*args, **kwargs)

Deprecated. Use write_data(file, ['gsyn_exc', 'gsyn_inh']) instead.

print_v(*args, **kwargs)

Deprecated. Use write_data(file, 'v') instead.

receptor_types
record(variables, to_file=None, sampling_interval=None)

Record the specified variable or variables for all cells in the Population or view.

variables may be either a single variable name or a list of variable names. For a given celltype class, celltype.recordable contains a list of variables that can be recorded for that celltype.

If specified, to_file should be a Neo IO instance and write_data() will be automatically called when end() is called.

sampling_interval should be a value in milliseconds, and an integer multiple of the simulation timestep.

record_gsyn(*args, **kwargs)

Deprecated. Use record(['gsyn_exc', 'gsyn_inh']) instead.

record_v(*args, **kwargs)

Deprecated. Use record('v') instead.

rset(*args, **kwargs)

Deprecated. Use set(parametername=rand_distr) instead.

sample(n, rng=None)

Randomly sample n cells from the Population, and return a PopulationView object.

save_positions(file)

Save positions to file. The output format is index x y z

set(**parameters)

Set one or more parameters for every cell in the population.

Values passed to set() may be:
  1. single values
  2. RandomDistribution objects
  3. lists/arrays of values of the same size as the population
  4. mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single value.

Here, a “single value” may be either a single number or a list/array of numbers (e.g. for spike times). Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.set(tau_m=20.0, v_rest=-65).
p.set(spike_times=[0.3, 0.7, 0.9, 1.4])
p.set(cm=rand_distr, tau_m=lambda i: 10 + i/10.0)
structure

The spatial structure of the parent Population.

tset(*args, **kwargs)

Deprecated. Use set(parametername=value_array) instead.

write_data(io, variables='all', gather=True, clear=False, annotations=None)

Write recorded data to file, using one of the file formats supported by Neo.

io:
a Neo IO instance
variables:
either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

For parallel simulators, if gather is True, all data will be gathered to the master node and a single output file created there. Otherwise, a file will be written on each node, containing only data from the cells simulated on that node.

If clear is True, recorded data will be deleted from the Population.

annotations should be a dict containing simple data types such as numbers and strings. The contents will be written into the output data file as metadata.

Assemblies

class Assembly(*populations, **kwargs)[source]

Bases: pyNN.common.populations.Assembly

A group of neurons, may be heterogeneous, in contrast to a Population where all the neurons are of the same type.

Arguments:
populations:
Populations or PopulationViews
kwargs:
May contain a keyword argument ‘label’
__add__(other)[source]

An Assembly may be added to a Population, PopulationView or Assembly with the ‘+’ operator, returning a new Assembly, e.g.:

a2 = a1 + p
__iadd__(other)[source]

A Population, PopulationView or Assembly may be added to an existing Assembly using the ‘+=’ operator, e.g.:

a += p
__getitem__(index)[source]

Where index is an integer, return an ID. Where index is a slice, tuple, list or numpy array, return a new Assembly consisting of appropriate populations and (possibly newly created) population views.

__iter__()[source]

Iterator over cells in all populations within the Assembly, for cells on the local MPI node.

__len__()[source]

Return the total number of cells in the population (all nodes).

all()[source]

Iterator over cell ids on all nodes.

all_cells
conductance_based

True if the post-synaptic response is modelled as a change in conductance, False if a change in current.

describe(template='assembly_default.txt', engine='default')[source]

Returns a human-readable description of the assembly.

The output may be customized by specifying a different template togther with an associated template engine (see pyNN.descriptions).

If template is None, then a dictionary containing the template context will be returned.

find_units(variable)[source]
first_id
get(parameter_names, gather=False, simplify=True)[source]

Get the values of the given parameters for every local cell in the Assembly, or, if gather=True, for all cells in the Assembly.

getSpikes(*args, **kwargs)

Deprecated. Use get_data('spikes') instead.

get_data(variables='all', gather=True, clear=False, annotations=None)[source]

Return a Neo Block containing the data (spikes, state variables) recorded from the Assembly.

variables - either a single variable name or a list of variable names
Variables must have been previously recorded, otherwise an Exception will be raised.

For parallel simulators, if gather is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

If clear is True, recorded data will be deleted from the Assembly.

get_gsyn(*args, **kwargs)

Deprecated. Use get_data(['gsyn_exc', 'gsyn_inh']) instead.

get_population(label)[source]

Return the Population/PopulationView from within the Assembly that has the given label. If no such Population exists, raise KeyError.

get_spike_counts(gather=True)[source]

Returns the number of spikes for each neuron.

get_v(*args, **kwargs)

Deprecated. Use get_data('v') instead.

id_to_index(id)[source]

Given the ID(s) of cell(s) in the Assembly, return its (their) index (order in the Assembly):

>>> assert p.id_to_index(p[5]) == 5
>>> assert p.id_to_index(p.index([1, 2, 3])) == [1, 2, 3]
initialize(**initial_values)[source]

Set the initial values of the state variables of the neurons in this assembly.

inject(current_source)[source]

Connect a current source to all cells in the Assembly.

last_id
local_cells
mean_spike_count(gather=True)[source]

Returns the mean number of spikes per neuron.

position_generator
positions
printSpikes(*args, **kwargs)

Deprecated. Use write_data(file, 'spikes') instead.

print_gsyn(*args, **kwargs)

Deprecated. Use write_data(['gsyn_exc', 'gsyn_inh']) instead.

print_v(*args, **kwargs)

Deprecated. Use write_data(file, 'v') instead.

receptor_types

Return a list of receptor types that are common to all populations within the assembly.

record(variables, to_file=None, sampling_interval=None)[source]

Record the specified variable or variables for all cells in the Assembly.

variables may be either a single variable name or a list of variable names. For a given celltype class, celltype.recordable contains a list of variables that can be recorded for that celltype.

If specified, to_file should be a Neo IO instance and write_data() will be automatically called when end() is called.

record_gsyn(*args, **kwargs)

Deprecated. Use record(['gsyn_exc', 'gsyn_inh']) instead.

record_v(*args, **kwargs)

Deprecated. Use record('v') instead.

rset(*args, **kwargs)

Deprecated. Use set(parametername=rand_distr) instead.

sample(n, rng=None)[source]

Randomly sample n cells from the Assembly, and return a Assembly object.

save_positions(file)[source]

Save positions to file. The output format is id x y z

set(**parameters)[source]

Set one or more parameters for every cell in the Assembly.

Values passed to set() may be:
  1. single values
  2. RandomDistribution objects
  3. mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single value.

Here, a “single value” may be either a single number or a list/array of numbers (e.g. for spike times).

size
write_data(io, variables='all', gather=True, clear=False, annotations=None)[source]

Write recorded data to file, using one of the file formats supported by Neo.

io:
a Neo IO instance
variables:
either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

For parallel simulators, if gather is True, all data will be gathered to the master node and a single output file created there. Otherwise, a file will be written on each node, containing only data from the cells simulated on that node.

If clear is True, recorded data will be deleted from the Population.