# NeuronGroup class

(Shortest import: `from brian2 import NeuronGroup)`

class brian2.groups.neurongroup.NeuronGroup(*args, **kw)

  Bases: `Group`, `SpikeSource`

  A group of neurons.

  Parameters:

    N : int

    > Number of neurons in the group.

    model : str, `Equations`

    > The differential equations defining the group

    method : (str, function), optional

    > The numerical integration method. Either a string with the name of a registered method (e.g. “euler”) or a function that receives an `Equations` object and returns the corresponding abstract code. If no method is specified, a suitable method will be chosen automatically.

    threshold : str, optional

    > The condition which produces spikes. Should be a single line boolean expression.

    reset : str, optional

    > The (possibly multi-line) string with the code to execute on reset.

    refractory : {str, `Quantity`}, optional

    > Either the length of the refractory period (e.g. `2*ms`), a string expression that evaluates to the length of the refractory period after each spike (e.g. `'(1 + rand())*ms'`), or a string expression evaluating to a boolean value, given the condition under which the neuron stays refractory after a spike (e.g. `'v > -20*mV'`)

    events : dict, optional

    > User-defined events in addition to the “spike” event defined by the `threshold`. Has to be a mapping of strings (the event name) to strings (the condition) that will be checked.

    namespace: dict, optional :

    > A dictionary mapping identifier names to objects. If not given, the namespace will be filled in at the time of the call of `Network.run`, with either the values from the `namespace` argument of the `Network.run` method or from the local context, if no such argument is given.

    dtype : (`dtype`, `dict`), optional

    > The `numpy.dtype` that will be used to store the values, or a dictionary specifying the type for variable names. If a value is not provided for a variable (or no value is provided at all), the preference setting core.default_float_dtype is used.

    codeobj_class : class, optional

    > The `CodeObject` class to run code with.

    dt : `Quantity`, optional

    > The time step to be used for the simulation. Cannot be combined with the `clock` argument.

    clock : `Clock`, optional

    > The update clock to be used. If neither a clock, nor the `dt` argument is specified, the `defaultclock` will be used.

    order : int, optional

    > The priority of of this group for operations occurring at the same time step and in the same scheduling slot. Defaults to 0.

    name : str, optional

    > A unique name for the group, otherwise use `neurongroup_0`, etc.

  Notes

  `NeuronGroup` contains a `StateUpdater`, `Thresholder` and `Resetter`, and these are run at the ‘groups’, ‘thresholds’ and ‘resets’ slots (i.e. the values of their `when` attribute take these values). The `order` attribute will be passed down to the contained objects but can be set individually by setting the `order` attribute of the `state_updater`, `thresholder` and `resetter` attributes, respectively.

  Attributes

  `_refractory` | The refractory condition or timespan
  `event_codes` | Code that is triggered on events (e.g. reset).
  `events` | Events supported by this group
  `method_choice` | The state update method selected by the user
  `resetter` | Reset neurons which have spiked (or perform arbitrary actions for user-defined events)
  `spikes` | The spikes returned by the most recent thresholding operation.
  `state_updater` | Performs numerical integration step
  `subexpression_updater` | Update the "constant over a time step" subexpressions
  `thresholder` | Checks the spike threshold (or abitrary user-defined events)
  `user_equations` | The original equations as specified by the user (i.e. without the multiplied `int(not_refractory)` term for equations marked as `(unless refractory)`).

  Methods

  `before_run`([run_namespace]) | Optional method to prepare the object before a run.
  `run_on_event`(event, code[, when, order]) | Run code triggered by a custom-defined event (see `NeuronGroup` documentation for the specification of events).The created `Resetter` object will be automatically added to the group, it therefore does not need to be added to the network manually.
  `set_event_schedule`(event[, when, order]) | Change the scheduling slot for checking the condition of an event.
  `state`(name[, use_units, level]) | Return the state variable in a way that properly supports indexing in the context of this group

  Details

  _refractory

    The refractory condition or timespan

  event_codes

    Code that is triggered on events (e.g. reset)

  events

    Events supported by this group

  method_choice

    The state update method selected by the user

  resetter

    Reset neurons which have spiked (or perform arbitrary actions for user-defined events)

  spikes

    The spikes returned by the most recent thresholding operation.

  state_updater

    Performs numerical integration step

  subexpression_updater

    Update the “constant over a time step” subexpressions

  thresholder

    Checks the spike threshold (or abitrary user-defined events)

  user_equations

    The original equations as specified by the user (i.e. without the multiplied `int(not_refractory)` term for equations marked as `(unless refractory)`)

  before_run(run_namespace=None)

    Optional method to prepare the object before a run.

    Called by `Network.after_run` before the main simulation loop starts.

  run_on_event(event, code, when='after_resets', order=None)

    Run code triggered by a custom-defined event (see `NeuronGroup` documentation for the specification of events).The created `Resetter` object will be automatically added to the group, it therefore does not need to be added to the network manually. However, a reference to the object will be returned, which can be used to later remove it from the group or to set it to inactive.

    Parameters:

      event : str

      > The name of the event that should trigger the code

      code : str

      > The code that should be executed

      when : str, optional

      > The scheduling slot that should be used to execute the code. Defaults to `'after_resets'`. See Scheduling for possible values.

      order : int, optional

      > The order for operations in the same scheduling slot. Defaults to the order of the `NeuronGroup`.

    Returns:

      obj : `Resetter`

      > A reference to the object that will be run.

  set_event_schedule(event, when='after_thresholds', order=None)

    Change the scheduling slot for checking the condition of an event.

    Parameters:

      event : str

      > The name of the event for which the scheduling should be changed

      when : str, optional

      > The scheduling slot that should be used to check the condition. Defaults to `'after_thresholds'`. See Scheduling for possible values.

      order : int, optional

      > The order for operations in the same scheduling slot. Defaults to the order of the `NeuronGroup`.

  state(name, use_units=True, level=0)

    Return the state variable in a way that properly supports indexing in the context of this group

    Parameters:

      name : str

      > The name of the state variable

      use_units : bool, optional

      > Whether to use the state variable’s unit.

      level : int, optional

      > How much farther to go down in the stack to find the namespace.

      Returns :

      ——- :

      var : `VariableView` or scalar value

      > The state variable’s value that can be indexed (for non-scalar values).

## Tutorials and examples using this

- Tutorial 1-intro-to-brian-neurons

- Tutorial 2-intro-to-brian-synapses

- Tutorial 3-intro-to-brian-simulations

- Example COBAHH

- Example CUBA

- Example IF_curve_Hodgkin_Huxley

- Example IF_curve_LIF

- Example adaptive_threshold

- Example advanced/COBAHH_approximated

- Example advanced/Ornstein_Uhlenbeck

- Example advanced/compare_GSL_to_conventional

- Example advanced/custom_events

- Example advanced/exprel_function

- Example advanced/float_32_64_benchmark

- Example advanced/modelfitting_sbi

- Example advanced/opencv_movie

- Example advanced/stochastic_odes

- Example compartmental/bipolar_with_inputs

- Example compartmental/bipolar_with_inputs2

- Example compartmental/lfp

- Example coupled_oscillators

- Example frompapers/Brette_2004

- Example frompapers/Brette_Gerstner_2005

- Example frompapers/Brette_Guigon_2003

- Example frompapers/Brunel_2000

- Example frompapers/Brunel_Hakim_1999

- Example frompapers/Brunel_Wang_2001

- Example frompapers/Clopath_et_al_2010_homeostasis

- Example frompapers/Clopath_et_al_2010_no_homeostasis

- Example frompapers/Diehl_Cook_2015

- Example frompapers/Diesmann_et_al_1999

- Example frompapers/Graupner_Brunel_2012

- Example frompapers/Hindmarsh_Rose_1984

- Example frompapers/Izhikevich_2003

- Example frompapers/Izhikevich_2007

- Example frompapers/Jansen_Rit_1995_single_column

- Example frompapers/Kremer_et_al_2011_barrel_cortex

- Example frompapers/Maass_Natschlaeger_Markram_2002

- Example frompapers/Morris_Lecar_1981

- Example frompapers/Naud_et_al_2008_adex_firing_patterns

- Example frompapers/Nicola_Clopath_2017

- Example frompapers/Platkiewicz_Brette_2011

- Example frompapers/Rossant_et_al_2011bis

- Example frompapers/Rothman_Manis_2003

- Example frompapers/Spreizer_et_al_2019/Spreizer_et_al_2019

- Example frompapers/Stimberg_et_al_2018/example_1_COBA

- Example frompapers/Stimberg_et_al_2018/example_2_gchi_astrocyte

- Example frompapers/Stimberg_et_al_2018/example_3_io_synapse

- Example frompapers/Stimberg_et_al_2018/example_4_rsmean

- Example frompapers/Stimberg_et_al_2018/example_4_synrel

- Example frompapers/Stimberg_et_al_2018/example_5_astro_ring

- Example frompapers/Stimberg_et_al_2018/example_6_COBA_with_astro

- Example frompapers/Stimberg_et_al_2019/example_3_bisection

- Example frompapers/Stimberg_et_al_2019/example_3_bisection_standalone

- Example frompapers/Sturzl_et_al_2000

- Example frompapers/Tetzlaff_2015

- Example frompapers/Touboul_Brette_2008

- Example frompapers/Tsodyks_Pawelzik_Markram_1998

- Example frompapers/Tsodyks_Uziel_Markram_2000

- Example frompapers/Vogels_et_al_2011

- Example frompapers/Wang_2002

- Example frompapers/Wang_Buszaki_1996

- Example multiprocessing/01_using_cython

- Example multiprocessing/02_using_standalone

- Example multiprocessing/03_standalone_joblib

- Example network_operation_stop

- Example non_reliability

- Example phase_locking

- Example reliability

- Example standalone/STDP_standalone

- Example standalone/cuba_openmp

- Example standalone/simple_case

- Example standalone/simple_case_build

- Example standalone/standalone_multiple_processes

- Example standalone/standalone_multiplerun

- Example synapses/STDP

- Example synapses/continuous_interaction

- Example synapses/efficient_gaussian_connectivity

- Example synapses/gapjunctions

- Example synapses/homeostatic_stdp_at_inhibitory_synapes

- Example synapses/jeffress

- Example synapses/licklider

- Example synapses/nonlinear

- Example synapses/spatial_connections

- Example synapses/spike_based_homeostasis

- Example synapses/state_variables

- Example synapses/synapses