# 3.11. Monitoring¶

Recording of neural or synaptic variables during the simulation is possible through a Monitor object.

## 3.11.1. Monitor class¶

class ANNarchy.Monitor(obj, variables=[], period=None, period_offset=None, start=True, net_id=0)[source]

Monitoring class allowing to record easily parameters or variables from Population, PopulationView and Dendrite objects.

Parameters: obj – object to monitor. Must be a Population, PopulationView, Dendrite or Projection object. variables – single variable name or list of variable names to record (default: []). period – delay in ms between two recording (default: dt). Not valid for the spike variable of a Population(View). period_offset – determine the moment in ms of recording within the period (default 0). Must be smaller than period. start – defines if the recording should start immediately (default: True). If not, you should later start the recordings with the start() method.

Example:

m = Monitor(pop, ['g_exc', 'v', 'spike'], period=10.0)


It is also possible to record the sum of inputs to each neuron in a rate-coded population:

m = Monitor(pop, ['sum(exc)', 'r'])

get(variables=None, keep=False, reshape=False, force_dict=False)[source]

Returns the recorded variables as a Numpy array (first dimension is time, second is neuron index).

If a single variable name is provided, the recorded values for this variable are directly returned. If a list is provided or the argument left empty, a dictionary with all recorded variables is returned.

The spike variable of a population will be returned as a dictionary of lists, where the spike times (in steps) for each recorded neurons are returned.

Parameters: variables – (list of) variables. By default, a dictionary with all variables is returned. keep – defines if the content in memory for each variable should be kept (default: False). reshape – transforms the second axis of the array to match the population’s geometry (default: False).
histogram(spikes=None, bins=None)[source]

Returns a histogram for the recorded spikes in the population.

Parameters: spikes – the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. bins – the bin size in ms (default: dt).

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
histo = m.histogram()
plot(histo)


or:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
histo = m.histogram(spikes)
plot(histo)

mean_fr(spikes=None)[source]

Computes the mean firing rate in the population during the recordings.

Parameters: spikes – the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory.

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
fr = m.mean_fr()


or:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
fr = m.mean_fr(spikes)

pause()[source]

Pauses the recordings.

population_rate(spikes=None, smooth=0.0)[source]

Takes the recorded spikes of a population and returns a smoothed firing rate for the population of recorded neurons.

This method is faster than calling smoothed_rate and then averaging.

The first axis is the neuron index, the second is time.

Parameters: spikes – the dictionary of spikes returned by get('spike'). smooth – smoothing time constant. Default: 0.0 (no smoothing).

If spikes is left empty, get('spike') will be called. Beware: this erases the data from memory.

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
r = m.population_rate(smooth=100.)

raster_plot(spikes=None)[source]

Returns two vectors representing for each recorded spike 1) the spike times and 2) the ranks of the neurons.

Parameters: spikes – the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory.

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spike_times, spike_ranks = m.raster_plot()
plot(spike_times, spike_ranks, '.')


or:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
spike_times, spike_ranks = m.raster_plot(spikes)
plot(spike_times, spike_ranks, '.')

resume()[source]

Resumes the recordings.

size_in_bytes()[source]

Get the size of allocated memory on C++ side. Please note, this is only valid if compile() was invoked.

Returns: size in bytes of all allocated C++ data.
smoothed_rate(spikes=None, smooth=0.0)[source]

Computes the smoothed firing rate of the recorded spiking neurons.

The first axis is the neuron index, the second is time.

Parameters: spikes – the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. smooth – smoothing time constant. Default: 0.0 (no smoothing).

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
r = m.smoothed_rate(smooth=100.)

start(variables=None, period=None)[source]

Starts recording the variables. It is called automatically after compile() if the flag start was not passed to the constructor.

Parameters: variables – single variable name or list of variable names to start recording (default: the variables argument passed to the constructor). period – delay in ms between two recording (default: dt). Not valid for the spike variable of a Population(View).
stop()[source]

Stops the recordings.

times(variables=None)[source]

Returns the start and stop times of the recorded variables.

Parameters: variables – (list of) variables. By default, the times for all variables is returned.
period

Period of recording in ms

period_offset

Shift of moment of time of recording in ms within a period

## 3.11.2. Offline methods¶

ANNarchy.raster_plot(spikes)[source]

Returns two vectors representing for each recorded spike 1) the spike times and 2) the ranks of the neurons.

Parameters: spikes – the dictionary of spikes returned by get('spike').

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
spike_times, spike_ranks = raster_plot(spikes)
plot(spike_times, spike_ranks, '.')

ANNarchy.histogram(spikes, bins=None)[source]

Returns a histogram for the recorded spikes in the population.

Parameters: spikes – the dictionary of spikes returned by get('spike'). bins – the bin size in ms (default: dt).

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
histo = histogram(spikes)
plot(histo)

ANNarchy.mean_fr(spikes, duration=None)[source]

Computes the mean firing rate in the population during the recordings.

Parameters: spikes – the dictionary of spikes returned by get('spike'). duration – duration of the recordings. By default, the mean firing rate is computed between the first and last spikes of the recordings.

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
fr = mean_fr(spikes)

ANNarchy.smoothed_rate(spikes, smooth=0.0)[source]

Computes the smoothed firing rate of the recorded spiking neurons.

The first axis is the neuron index, the second is time.

Parameters: spikes – the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. smooth – smoothing time constant. Default: 0.0 (no smoothing).

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
r = smoothed_rate(smooth=100.)

ANNarchy.population_rate(spikes, smooth=0.0)[source]

Takes the recorded spikes of a population and returns a smoothed firing rate for the population of recorded neurons.

This method is faster than calling smoothed_rate and then averaging.

The first axis is the neuron index, the second is time.

Parameters: spikes – the dictionary of spikes returned by get('spike'). smooth – smoothing time constant. Default: 0.0 (no smoothing).

Example:

m = Monitor(P[:1000], 'spike')
simulate(1000.0)
spikes = m.get('spike')
r = population_rate(smooth=100.)