# PopulationRateMonitor class

(Shortest import: `from brian2 import PopulationRateMonitor)`

class brian2.monitors.ratemonitor.PopulationRateMonitor(*args, **kw)

  Bases: `RateMonitor`

  Record instantaneous firing rates, averaged across neurons from a `NeuronGroup` or other spike source.

  Parameters:

    source : (`NeuronGroup`, `SpikeSource`)

    > The source of spikes to record.

    name : str, optional

    > A unique name for the object, otherwise will use `source.name+'_ratemonitor_0'`, etc.

    codeobj_class : class, optional

    > The `CodeObject` class to run code with.

    dtype : dtype, optional

    > The dtype to use to store the `rate` variable. Defaults to `float64`, i.e. double precision.

  Notes

  Currently, this monitor can only monitor the instantaneous firing rates at each time step of the source clock. Any binning/smoothing of the firing rates has to be done afterwards using the `binned_rate` or `smooth_rate` methods.

  Attributes

  `source` | The group we are recording from

  Methods

  `binned_rate`(bin_size) | Return the population rate binned with the given bin size.
  `reinit`() | Clears all recorded rates
  `resize`(new_size) |

  Details

  source

    The group we are recording from

  binned_rate(bin_size)

    Return the population rate binned with the given bin size.

    Parameters:

      bin_size : `Quantity`

      > The size of the bins in seconds. Should be a multiple of dt.

    Returns:

      bins : `Quantity`

      > The start time of the bins.

      binned_values : `Quantity`

      > The binned population rates as a 1D array in Hz.

    Warning

    This method will give incorrect results if the monitor has recorded values with varying `dt` values.

    Notes

    The returned bin times represent the start of each bin interval, not the center. This is consistent with how Brian2 records spike times and other temporal data. For example, a spike recorded at time `t` occurred during the interval `[t, t+dt)`.

    For plotting purposes, especially with larger bin sizes, you may want to use bin centers instead of bin starts for a more intuitive visualization. You can easily calculate the bin centers by adding half the bin size:

        >> bins, rates = monitor.binned_rate(10*ms)
        >> bin_centers = bins + 10*ms / 2
        >> plt.plot(bin_centers, rates)

    This adjustment is particularly helpful when the bins are large relative to the time scale of interest, as it better represents where the rate measurement applies within each time window.

  reinit()

    Clears all recorded rates

  resize(new_size)

## Tutorials and examples using this

- Example frompapers/Brunel_2000

- Example frompapers/Brunel_Hakim_1999

- Example frompapers/Brunel_Wang_2001

- Example frompapers/Wang_2002

- Example synapses/spike_based_homeostasis