Utility classes and functions

init_logging(logfile, debug=False, num_processes=1, rank=0, level=None)[source]

Simple configuration of logging.


Import and return a PyNN simulator backend module based on command-line arguments.

The simulator name should be the first positional argument. If your script needs additional arguments, you can specify them as (name, help_text) tuples. If you need more complex argument handling, you should use argparse directly.

Returns (simulator, command-line arguments)

class Timer[source]

For timing script execution.

Timing starts on creation of the timer.


Return the time since the last time elapsed_time() or diff() was called.

If called with format='long', return a text representation of the time.

elapsedTime(*args, **kwargs)

Deprecated. Use elapsed_time() instead.


Return the elapsed time in seconds but keep the clock running.

If called with format="long", return a text representation of the time. Examples:

>>> timer.elapsed_time()
>>> timer.elapsed_time(format='long')
16 minutes, 27 seconds

Store the time since the last time since the last time elapsed_time(), diff() or mark() was called, together with the provided label, in the attribute ‘marks’.


Reset the time to zero, and start the clock.


Start/restart timing.

static time_in_words(s)[source]

Formats a time in seconds as a string containing the time in days, hours, minutes, seconds. Examples:

>>> Timer.time_in_words(1)
1 second
>>> Timer.time_in_words(123)
2 minutes, 3 seconds
>>> Timer.time_in_words(24*3600)
1 day
class ProgressBar(width=77, char='#', mode='fixed')[source]

Create a progress bar in the shell.


Rebuild the bar string based on level, which should be a number between 0 and 1.

notify(msg='Simulation finished.', subject='Simulation finished.', smtphost=None, address=None)[source]

Send an e-mail stating that the simulation has finished.

save_population(population, filename, variables=None)[source]

Saves the spike_times of a population and the size, structure, labels such that one can load it back into a SpikeSourceArray population using the load_population() function.

load_population(filename, sim)[source]

Loads a population that was saved with the save_population() function into SpikeSourceArray.

Basic plotting

class Figure(*panels, **options)[source]

Provide simple, declarative specification of multi-panel figures.


    Panel(segment.filter(name="v")[0], ylabel="Membrane potential (mV)")
    Panel(segment.spiketrains, xlabel="Time (ms)"),
    title="Network activity",
Valid options are:
for figure settings, e.g. {‘font.size’: 9}
a (multi-line) string to be printed at the bottom of the figure.
a string to be printed at the top of the figure.

Save the figure to file. The format is taken from the file extension.

class Panel(*data, **options)[source]

Represents a single panel in a multi-panel figure.

A panel is a Matplotlib Axes or Subplot instance. A data item may be an AnalogSignal, AnalogSignal, or a list of SpikeTrains. The Panel will automatically choose an appropriate representation. Multiple data items may be plotted in the same panel.

Valid options are any valid Matplotlib formatting options that should be applied to the Axes/Subplot, plus in addition:

a list of strings of the same length as the number of data items.
a list of dicts containing Matplotlib formatting options, of the same length as the number of data items.

Plot the Panel’s data in the provided Axes/Subplot instance.

comparison_plot(segments, labels, title='', annotations=None, fig_settings=None, with_spikes=True)[source]

Given a list of segments, plot all the data they contain so as to be able to compare them.

Return a Figure instance.