pymt.events package

Submodules

pymt.events.chain module

class pymt.events.chain.ChainEvent(events)[source]

Bases: object

finalize()[source]
initialize()[source]
run(stop_time)[source]
update(stop_time)[source]

pymt.events.empty module

An empty event.

PassEvent implements an event-like interface but doesn’t do anything. This can be a useful event to give to an EventManager if you want to force the manager to stop at particular intervals.

class pymt.events.empty.PassEvent[source]

Bases: object

An event that doesn’t do anything.

finalize(stop_time)[source]
initialize()[source]
run(stop_time)[source]

pymt.events.manager module

Manage the execution of events on a timeline.

The EventManager puts events on a Timeline and then orchestrates the setup, execution, and teardown of the events as the time line advances. Events are classes that implement an event interface. That is, they implement the following methods:

  • initialize()

  • run(time)

  • finalize()

Because the EventManager class itself is event-like, it is able to manage other EventManager instances and even handle recursive events.

Examples

Create an event that prints, “hello”.

>>> class PrintHello:
...     def initialize(self):
...         print("hello from initialize")
...     def run(self, time):
...         print("hello!")
...     def finalize(self):
...         print("hello from finalize")

Add an instance of the event to be run at a regular interval to the manager.

>>> mngr = EventManager([(PrintHello(), 2.)])
>>> mngr.initialize()
hello from initialize
>>> mngr.run(1.)
>>> mngr.run(2.)
hello!
>>> mngr.finalize()
hello from finalize

You can also use an EventManager as a context,

>>> with EventManager([(PrintHello(), 2.)]) as mngr:
...     mngr.run(4.)
hello from initialize
hello!
hello!
hello from finalize
class pymt.events.manager.EventManager(*args)[source]

Bases: object

Parameters:

events (dict-like) – Events as event-object/repeat interval pairs.

Examples

Create an EventManager without any events.

>>> mngr = EventManager()
>>> mngr.time
0.0
>>> len(mngr)
0

Create a manager with one recurring event.

>>> from pymt.events.empty import PassEvent
>>> mngr = EventManager([(PassEvent(), 1.)])
>>> len(mngr)
1

Create a manager with two recurring events.

>>> mngr = EventManager([(PassEvent(), 1.), (PassEvent(), 2.)])
>>> len(mngr)
2
add_recurring_event(event, interval)[source]

Add a managed event.

Add event to the list of managed events and run it with the recurrence interval, interval.

Parameters:
  • event (event-like) – Event to be managed.

  • interval (float) – Recurrence interval for the event.

finalize()[source]

Finalize managed events.

Execute the finalize method for each of the events being managed. Events are finalized in the reverse order in which they were initialized, and only if the manager has not yet been initialized.

classmethod from_path(path, prefix='')[source]

Create an EventManager from a file.

Parameters:
  • path (str) – Path to ini-formatted file.

  • prefix (str) – Prefix for section.

Returns:

A newly-created EventManager.

Return type:

EventManager

See also

from_string()

Alternate constructor that uses a string.

classmethod from_string(source, prefix='')[source]

Create an EventManager from a string.

Parameters:
  • source (str) – Ini-formatted string.

  • prefix (str) – Prefix for section.

Returns:

A newly-created EventManager.

Return type:

EventManager

See also

from_path()

Alternate constructor that uses a path name.

initialize()[source]

Initialize the managed events.

Execute the initialize methods of each of the events that are being managed, making sure the manager is not initialized if it is already in the initialization process. Events are initialized in the order they were given at creation.

run(stop_time)[source]

Run events until some time.

Execute the run method of each of the events being managed until stop_time is reached on the time line.

Parameters:

stop_time (float) – Time to run events until.

property time

Current time along the time line.

pymt.events.port module

Wrap a port as a Timeline event.

class pymt.events.port.PortEvent(*args, **kwds)[source]

Bases: GridMixIn

Wrap a port as an event.

Parameters:
  • port (str) – Name of port.

  • init_args (list, optional) – List of arguments to initialize port.

  • run_dir (str, optional) – Path to directory to execute port.

finalize()[source]

Finalize the event.

Run the finalize method of the underlying port.

initialize()[source]

Initialize the event.

Run the underlying port’s initialization method in its run_dir. The event’s init_args are passed to the initialize method as arguments.

run(time)[source]

Run the event.

Call the run method of the underlying port using time as the run time.

Parameters:

time (float) – Time to run the event to.

update(time)[source]
class pymt.events.port.PortMapEvent(*args, **kwds)[source]

Bases: object

An event that maps values between ports.

Parameters:
  • src_port (str) – Port name that is the data source.

  • dst_port (str) – Port name that is the destination.

  • vars_to_map (list, optional) – Names of variable to map.

  • method ({'direct', 'nearest'}, optional) – Method used to map values.

finalize()[source]
initialize()[source]

Initialize the data mappers.

run(stop_time)[source]

Map values from one port to another.

pymt.events.printer module

class pymt.events.printer.PrintEvent(*args, **kwds)[source]

Bases: object

finalize()[source]
initialize(*args)[source]
run(time)[source]

Module contents