HWRF  trunk@4391
Public Member Functions | List of all members
hwrf.numerics.TimeContainer Class Reference

Abstract base class that maps from time to objects. More...

Detailed Description

Abstract base class that maps from time to objects.

This is the abstract base class of any class that represents a mapping from a set of times to a set of data. It provides the underlying implementation of TimeArray and TimeMapping. This is not exported by "from hwrf.numerics import *" to prevent accidental use.

Definition at line 493 of file numerics.py.

Inheritance diagram for hwrf.numerics.TimeContainer:
hwrf.numerics.TimeArray hwrf.numerics.TimeMapping

Public Member Functions

def __init__
 TimeContainer constructor. More...
 
def at_index (self, index)
 Returns the data at the given index, or raises KeyError if no data exists. More...
 
def index_of (self, when)
 This virtual function should be implemented in a subclass. More...
 
def lasttime (self)
 Returns the last time in the array or list of times, even if it has no data. More...
 
def firsttime (self)
 Returns the first time in the array or list of times, even if it has no data. More...
 
def __getitem__ (self, when)
 Returns the item at the latest time that is not later than "when". More...
 
def neartime
 Returns a tuple containing the time nearest to "when" without going over, and the index of that time. More...
 
def get (self, when, default)
 Returns the item at the latest time that is not later than "when.". More...
 
def __setitem__ (self, when, val)
 Finds the latest time that is not later than "when" in self._times. More...
 
def __iter__ (self)
 Iterates over all data. More...
 
def itervalues (self)
 Iterates over data for all known times that have data. More...
 
def iterkeys (self)
 Iterates over all times that have data. More...
 
def iteritems (self)
 Iterates over all known times that have data, returning a tuple containing the time and the data at that time. More...
 
def __reversed__ (self)
 Iterates over all known times that have data, in reverse order. More...
 
def __delitem__ (self, when)
 Finds the latest time that is not later than "when" and removes the data it is mapped to. More...
 
def __contains__ (self, when)
 Finds the latest time that is not later than "when" in self._times. More...
 
def __len__ (self)
 Returns the number of times that have data. More...
 
def times (self)
 Iterates over all times in this TimeContainer.
 
def datatimes (self)
 Iterates over all times in this TimeContainer that map to data. More...
 
def __str__ (self)
 Returns a string representation of this object. More...
 
def datatimes_reversed (self)
 Iterates in reverse order over all times in this TimeContainer that map to data. More...
 

Constructor & Destructor Documentation

def hwrf.numerics.TimeContainer.__init__ (   self,
  times,
  init = None 
)

TimeContainer constructor.

Initializes the internal arrays for the given list of times, which must not be empty. Note that strange, potentially bad things will happen if there are duplicate times.

Implementation notes:

1 self._times[N]: a list of times
2 self._data[N]: the data for each time
3 self._assigned[N]: True if there is data for this time,
4  False otherwise

where N is the length of the input times array. The _data will be filled with init() and _assigned filled with True if init is present and not None, otherwise _assigned will be False.

Parameters
timesthe times to map from
inita constructor or function that creates initial values for all uninitialized array elements

Definition at line 502 of file numerics.py.

Member Function Documentation

def hwrf.numerics.TimeContainer.__contains__ (   self,
  when 
)

Finds the latest time that is not later than "when" in self._times.

Returns True if there is data mapped to that time and False otherwise.

Parameters
whenthe time of interest

Definition at line 645 of file numerics.py.

def hwrf.numerics.TimeContainer.__delitem__ (   self,
  when 
)

Finds the latest time that is not later than "when" and removes the data it is mapped to.

Later calls to getitem, get, iter and so on, will not return any data for this time.

Parameters
whenthe time of disinterest

Definition at line 636 of file numerics.py.

def hwrf.numerics.TimeContainer.__getitem__ (   self,
  when 
)

Returns the item at the latest time that is not later than "when".

If there is no data assigned at that time, then KeyError is raised.

Parameters
whenthe time of interest

Definition at line 557 of file numerics.py.

def hwrf.numerics.TimeContainer.__iter__ (   self)

Iterates over all data.

Definition at line 607 of file numerics.py.

def hwrf.numerics.TimeContainer.__len__ (   self)

Returns the number of times that have data.

Definition at line 655 of file numerics.py.

def hwrf.numerics.TimeContainer.__reversed__ (   self)

Iterates over all known times that have data, in reverse order.

Definition at line 628 of file numerics.py.

def hwrf.numerics.TimeContainer.__setitem__ (   self,
  when,
  val 
)

Finds the latest time that is not later than "when" in self._times.

Assigns "val" to that time.

Parameters
whenthe time of interest
valthe value to assign to that time

Definition at line 597 of file numerics.py.

def hwrf.numerics.TimeContainer.__str__ (   self)

Returns a string representation of this object.

Definition at line 667 of file numerics.py.

def hwrf.numerics.TimeContainer.at_index (   self,
  index 
)

Returns the data at the given index, or raises KeyError if no data exists.

Parameters
indexthe desired index

Definition at line 534 of file numerics.py.

def hwrf.numerics.TimeContainer.datatimes (   self)

Iterates over all times in this TimeContainer that map to data.

Definition at line 662 of file numerics.py.

def hwrf.numerics.TimeContainer.datatimes_reversed (   self)

Iterates in reverse order over all times in this TimeContainer that map to data.

Definition at line 678 of file numerics.py.

def hwrf.numerics.TimeContainer.firsttime (   self)

Returns the first time in the array or list of times, even if it has no data.

Definition at line 553 of file numerics.py.

def hwrf.numerics.TimeContainer.get (   self,
  when,
  default 
)
def hwrf.numerics.TimeContainer.index_of (   self,
  when 
)

This virtual function should be implemented in a subclass.

It should return the index of the time to use for the given time.

Parameters
whenthe time of interest

Definition at line 540 of file numerics.py.

Referenced by hwrf.numerics.TimeContainer.__contains__(), hwrf.numerics.TimeContainer.__delitem__(), hwrf.numerics.TimeContainer.__getitem__(), hwrf.numerics.TimeContainer.__setitem__(), hwrf.numerics.TimeContainer.get(), and hwrf.numerics.TimeContainer.neartime().

def hwrf.numerics.TimeContainer.iteritems (   self)

Iterates over all known times that have data, returning a tuple containing the time and the data at that time.

Definition at line 622 of file numerics.py.

def hwrf.numerics.TimeContainer.iterkeys (   self)

Iterates over all times that have data.

Definition at line 617 of file numerics.py.

def hwrf.numerics.TimeContainer.itervalues (   self)

Iterates over data for all known times that have data.

Definition at line 612 of file numerics.py.

def hwrf.numerics.TimeContainer.lasttime (   self)

Returns the last time in the array or list of times, even if it has no data.

Definition at line 548 of file numerics.py.

def hwrf.numerics.TimeContainer.neartime (   self,
  when,
  epsilon = None 
)

Returns a tuple containing the time nearest to "when" without going over, and the index of that time.

Parameters
epsilonIf specified, raise hwrf.exceptions.NoNearbyValues if no times are near that value.
whenthe time of interest

Definition at line 566 of file numerics.py.


The documentation for this class was generated from the following file: