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

Maps from an ordered list of times to arbitrary data. More...

Detailed Description

Maps from an ordered list of times to arbitrary data.

A TimeMapping is a mapping from an ordered list of times to a set of data. The full set of possible times is given in the constructor: it is not possible to add new times to the mapping after creation of the TimeMapping. A TimeMapping is more expensive than a TimeArray since every [] lookup (getitem) has to do a binary search. However, it is more general since the times do not have to be exactly at an interval.

Note that a TimeArray can replace a TimeMapping if a small enough timestep (the greatest common factor) is used since most of the TimeContainer methods only work on the indices that have data. However, if some timespans have dense timesteps and the rest are sparse, there may be significant memory and CPU savings in using a TimeMapping.

Definition at line 746 of file numerics.py.

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

Public Member Functions

def __init__
 TimeMapping constructor. More...
 
def index_of (self, when)
 Returns the index of the specified time in the internal storage arrays or raises NotInTimespan if the time is not in the timespan. More...
 
- Public Member Functions inherited from hwrf.numerics.TimeContainer
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.TimeMapping.__init__ (   self,
  times,
  init = None 
)

TimeMapping constructor.

Parameters
timesA list of times, which will be converted with to_datetime and sorted.
initThe initializer for data values. This is typically a constructor (dict, list, etc.) or a function that calls a constructor.

Definition at line 763 of file numerics.py.

Member Function Documentation

def hwrf.numerics.TimeMapping.index_of (   self,
  when 
)

Returns the index of the specified time in the internal storage arrays or raises NotInTimespan if the time is not in the timespan.

Parameters
whenAnything accepted by to_datetime_rel(when,self._start)

Definition at line 771 of file numerics.py.


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