pymt package

Subpackages

Submodules

pymt.errors module

exception pymt.errors.BadUnitError(unit)[source]

Bases: PymtError

exception pymt.errors.BmiError(fname, status)[source]

Bases: PymtError

exception pymt.errors.IncompatibleUnitsError(src, dst)[source]

Bases: PymtError

exception pymt.errors.PymtError[source]

Bases: Exception

pymt.model_collection module

class pymt.model_collection.ModelCollection[source]

Bases: object

property errors
items()[source]
keys()[source]
static load_entry_point(entry_point)[source]
values()[source]
exception pymt.model_collection.ModelLoadError(name, reason=None)[source]

Bases: Exception

pymt.models module

pymt.timeline module

Execute events along a timeline.

Examples

>>> timeline = Timeline()
>>> timeline.add_recurring_event('event 1', 1.)
>>> timeline.add_recurring_event('event 2', .3)
>>> timeline.pop()
'event 2'
>>> timeline.pop()
'event 2'
>>> timeline.pop()
'event 2'
>>> timeline.pop()
'event 1'
>>> timeline.time
1.0
>>> for event in timeline.iter_until(2.0): print(event)
event 2
event 2
event 2
event 1
>>> timeline.pop()
'event 2'

When events occur at the same time, events are popped in as first-in, first-out.

>>> timeline = Timeline([('event 1', 1.), ('event 2', .5)])
>>> for event in timeline.iter_until(1.0): print(event)
event 2
event 1
event 2
>>> timeline = Timeline([('event 2', .5), ('event 1', 1.)])
>>> timeline.pop_until(1.05)
['event 2', 'event 1', 'event 2']
>>> timeline.time
1.05
>>> for event in timeline.iter_until(1.05): print(event)
>>> timeline.time
1.05
>>> for event in timeline.iter_until(1.06): print(event)
>>> timeline.time
1.06

The event key can be any object, even a tuple.

>>> timeline = Timeline([(('event', 2), .5), (('event', 0), 1.)])
>>> for event in timeline.iter_until(1.05): print(event)
('event', 2)
('event', 0)
('event', 2)

Events do not have to be recurring.

>>> timeline = Timeline([(('event', 2), .5), (('event', 0), 1.)])
>>> timeline.add_one_time_event('one-timer', .1)
>>> for event in timeline.iter_until(1.05): print(event)
one-timer
('event', 2)
('event', 0)
('event', 2)
class pymt.timeline.Timeline(events=None, start=0.0)[source]

Bases: object

Create a timeline of events.

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

  • start (float, optional) – Start time for the timeline.

Examples

Create a timeline with two recurring events. Events can be any old object. In this case they are two strings.

>>> timeline = Timeline([('hello', 1.), ('world', 1.5)], start=3.)
>>> sorted(timeline.events) # The events are returned as a set.
['hello', 'world']

The first events will not occur at the starting time.

>>> timeline.time
3.0
>>> timeline.next_event
'hello'
>>> timeline.time_of_next_event
4.0

To advance the timeline forward to the next event, use the pop method.

>>> timeline.pop()
'hello'
>>> timeline.time
4.0
>>> timeline.pop()
'world'
>>> timeline.time
4.5

The timeline keeps track of objects, without making copies. The objects don’t even need to be hashable.

>>> hello = ['hello', 'world']
>>> timeline = Timeline([(hello, 1.)])
>>> event = timeline.pop()
>>> event is hello
True
>>> event.append('!')
>>> hello
['hello', 'world', '!']
add_one_time_event(event, time)[source]

Add an event that will only happen once.

Parameters:
  • event (event-like) – Event to add to the timeline.

  • time (float) – Time for the event to execute.

Examples

>>> timeline = Timeline()
>>> timeline.add_one_time_event('say hello', 1.)
>>> timeline.time_of_next_event
1.0
>>> timeline.pop()
'say hello'
>>> timeline.time_of_next_event  
Traceback (most recent call last):
IndexError: empty timeline
add_recurring_event(event, interval)[source]

Add a recurring event to the timeline.

Adds a single recurring event to the timeline. event is the event object, and interval is recurrence interval.

Parameters:
  • event (event-like) – Event to add to the timeline.

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

Examples

>>> timeline = Timeline()
>>> timeline.add_recurring_event('say hello', 1.)
>>> timeline.events == {'say hello'}
True
add_recurring_events(events)[source]

Add a series of recurring events to the timeline.

Adds recurring events to the timeline. events is a list where each element is tuple that gives the event object followed by the event recurrence interval.

Parameters:

events (dict-like) – Events object/interval pairs to add to the timeline.

Examples

>>> timeline = Timeline()
>>> len(timeline.events)
0
>>> timeline.add_recurring_events([('hello', 1.), ('world', 1.)])
>>> sorted(timeline.events)
['hello', 'world']

Events pop as first-in, first-out.

>>> timeline.pop()
'hello'
>>> timeline.pop()
'world'

The same event can be added multiple times.

>>> timeline = Timeline()
>>> timeline.add_recurring_events([('hello', 1.), ('world', 1.),
...     ('hello', 1.)])
>>> sorted(timeline.events)
['hello', 'world']
>>> timeline.pop_until(2.)
['hello', 'world', 'hello', 'hello', 'world', 'hello']
property events

All of the event objects in the timeline.

Examples

>>> timeline = Timeline([('an event', 1.), ('another event', 1.)])
>>> events = timeline.events
>>> isinstance(events, set)
True
>>> sorted(events)
['an event', 'another event']
iter_until(stop)[source]

Iterate the timeline until a given time.

Iterate the timeline until stop, popping events along the way.

Parameters:

stop (float) – Time to iterate until.

Returns:

The next event object as the timeline advances to stop.

Return type:

event

property next_event

Next event object.

Return the next event object but don’t advance the timeline forward in time.

Examples

>>> timeline = Timeline([('an event', 1.)])
>>> timeline.next_event
'an event'
>>> timeline.time
0.0
pop()[source]

Pop the next event from the timeline.

Examples

>>> timeline = Timeline(dict(hello=1.))
>>> timeline.pop()
'hello'
pop_until(stop)[source]

Advance the timeline, popping events along the way.

Advance the timeline to stop, popping events along the way. Returns a list of the event objects that were popped to advance the timeline to stop.

Parameters:

stop (float) – Time to iterate until.

Returns:

The events popped to get to the stop time.

Return type:

list

Examples

>>> timeline = Timeline([('a', 1.), ('b', 1.), ('c', 1.)])
>>> timeline.pop_until(2.)
['a', 'b', 'c', 'a', 'b', 'c']
property time

Current time along the timeline.

Examples

>>> timeline = Timeline(start=0)
>>> timeline.time
0.0
>>> timeline = Timeline(start=2)
>>> timeline.time
2.0
property time_of_next_event

Time when the next event will happen.

Examples

>>> timeline = Timeline([('an event', 1.)])
>>> timeline.time_of_next_event
1.0

pymt.units module

pymt.units.transform_azimuth_to_math(angle, units='rad')[source]
pymt.units.transform_math_to_azimuth(angle, units='rad')[source]

Module contents

class pymt.UnitSystem(filepath=None)

Bases: _UnitSystem

A system of units.

A unit-system is a set of units that are all defined in terms of the same set of base units. In the SI system of units, for example, the base units are the meter, kilogram, second, ampere, kelvin, mole, and candela. (For definitions of these base units, see http://physics.nist.gov/cuu/Units/current.html)

In the UDUNITS-2 package, every accessible unit belongs to one and only one unit-system. It is not possible to convert numeric values between units of different unit-systems. Similarly, units belonging to different unit-systems always compare unequal.

Parameters:

filepath (str, optional) – Path to a udunits2 xml-formatted unit database. If not provided, a default system of units is used.