Reference 〉Decorator

@Helipad.event( str name = None, bool repeat = False, mixed **kwargs )

A function decorator used to register an Event. When triggered, an event marks the plot area with a vertical line and stores the data output at that time. The image to the right shows two events, marking the increase and leveling off of population.

This decorator can be used bare (i.e. without parentheses) on a function whose name will be used as the event name. It can also take arguments, which are passed to model.addEvent().

The decorated function will run at the end of each period, immediately after data collection but before the modelPostStep hook.


  • name str, optional

    An optional reference name, to override the function name.

    Default value: None

  • repeat bool, optional

    Whether the event should trigger once, or every time the criterion is satisfied.

    Default value: False

  • **kwargs mixed, optional

    Further options to be passed to the visualizer's event() method. TimeSeries.event(), for example, draws a vertical line on the plot area, and takes color, linestyle, and linewidth arguments to customize its appearance.

    Default value: {}

Notes and Examples

  1. charwick

    Dec 14, 2020 at 22:05

    The image above is generated by the following two events, the first of which fires when the increase in population over the last 20 periods is greater than 3, and the second when the first has triggered and the increase in population over the last period.

    def exp1(model): return sum(diff('ruralPop', 20))) > 3
    def taper2(model): return['exp1'].triggered and sum(diff('ruralPop', 20))) < -1

    The second is an example of ordering events: the second will only fire after the first.

  2. charwick

    Dec 14, 2020 at 22:08

    The decorated function can be written so as to take an action when the event is triggered, as in the following:

    def stab4(model):
    	go =['cull3'].triggered and sum(diff('ruralPop', 400))) > 0
    	if go:
    		#Do some task when the event fires
    	return go
  3. charwick

    Dec 14, 2020 at 22:12

    Models can be set to stop at an event, by setting the stopafter parameter to the name of an event, as in this example from the walkthrough, which terminates the model once the volume of trade for each good is under 20.

    #Stop the model when we're basically equilibrated
    def stopCondition(model):
    	return model.t > 1 and'demand-shmoo') < 20 and'demand-soma') < 20
    heli.param('stopafter', 'stopCondition')
  4. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.