Home | Trees | Indices | Help |
|
---|
|
object --+ | dict --+ | offsetvector
Subclass of the dict built-in type for storing mappings of instrument to time offset.
Examples:
>>> x = offsetvector({"H1": 0, "L1": 10, "V1": 20}) >>> x["H1"] 0 >>> not any(x.values()) # check for "zero-lag" False
The motivation for introducing this class, instead of using dictionaries, is that it provides a number of tools for comparing offset vectors besides strict value-for-value equality. For example the Python cmp() operation compares two offset vectors by the relative offsets between instruments rather than their absolute offsets, whereas the == operation compares two offset vectors by demanding strict equality. There is also the ability to check if one offset vector is a subset of another one.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
|
|||
|
|
|||
Inherited from |
|
|||
deltas Dictionary of relative offsets. |
|||
refkey = min(self) |
|||
Inherited from |
|
Returns max(offset) - min(offset). Example: >>> abs(offsetvector({"H1": 0.0, "H2": 0.0, "L1": 0.0})) 0.0 >>> abs(offsetvector({"H1": 10.0, "H2": 10.0, "L1": 10.0})) 0.0 >>> abs(offsetvector({'H1': 10.0, 'L1': 0.0, 'V1': -10.0})) 20.0 |
Compare two offset vectors by their relative offsets. The return value is 0 if the relative offsets are all equal, nonzero otherwise. Example: >>> a = offsetvector({"H1": 0.0, "H2": 0.0, "L1": 0.0}) >>> b = offsetvector({"H1": 10.0, "H2": 10.0, "L1": 10.0}) >>> cmp(a, b) 0 >>> a == b False Note that cmp() and testing for equality are different tests! The equality test returns False because the offset vectors are not identical, however the cmp() function returns 0 because the relative offsets are all equal.
|
Return a string representation of the offset vector. Running eval() on the result reconstructs the offsetvector. Example: >>> a = offsetvector({"H1": -10.1234567, "L1": 0.1}) >>> repr(a) "offsetvector({'H1': -10.1234567, 'L1': 0.1})" >>> b = eval(repr(a)) >>> b offsetvector({'H1': -10.1234567, 'L1': 0.1}) >>> b == a True >>> b is a False
|
Return a human-readable string representation of an offset vector. Example: >>> a = offsetvector({"H1": -10.1234567, "L1": 0.125}) >>> str(a) 'H1 = -10.1234567 s, L1 = +0.125 s' >>> a.__str__(compact = True) 'H1=-10.123,L1=0.125'
|
Returns True if offset vector @other can be found in @self, False otherwise. An offset vector is "found in" another offset vector if the latter contains all of the former's instruments and the relative offsets among those instruments are equal (the absolute offsets need not be). Example: >>> a = offsetvector({"H1": 10, "L1": 20, "V1": 30}) >>> b = offsetvector({"H1": 20, "V1": 40}) >>> a.contains(b) True Note the distinction between this and the "in" operator: >>> "H1" in a True |
Construct an offsetvector from a dictionary of offset deltas as returned by the .deltas attribute. Example: >>> x = offsetvector({"H1": 0, "L1": 10, "V1": 20}) >>> y = offsetvector.fromdeltas(x.deltas) >>> y offsetvector({'V1': 20, 'H1': 0, 'L1': 10}) >>> y == x True See also .deltas, .fromkeys() |
Adjust the offsetvector so that a particular instrument has the desired offset. All other instruments have their offsets adjusted so that the relative offsets are preserved. The instrument to noramlize, and the offset one wishes it to have, are provided as a key-word argument. The return value is the time slide dictionary, which is modified in place. If more than one key-word argument is provided the keys are sorted and considered in order until a key is found that is in the offset vector. The offset vector is normalized to that value. This function is a no-op if no key-word argument is found that applies. Example: >>> a = offsetvector({"H1": -10, "H2": -10, "L1": -10}) >>> a.normalize(L1 = 0) offsetvector({'H2': 0, 'H1': 0, 'L1': 0}) >>> a = offsetvector({"H1": -10, "H2": -10}) >>> a.normalize(L1 = 0, H2 = 5) offsetvector({'H2': 5, 'H1': 5}) |
|
deltasDictionary of relative offsets. The keys in the result are pairs of keys from the offset vector, (a, b), and the values are the relative offsets, (offset[b] - offset[a]). Raises ValueError if the offsetvector is empty (WARNING: this behaviour might change in the future). Example: >>> x = offsetvector({"H1": 0, "L1": 10, "V1": 20}) >>> x.deltas {('H1', 'L1'): 10, ('H1', 'V1'): 20, ('H1', 'H1'): 0} >>> y = offsetvector({'H1': 100, 'L1': 110, 'V1': 120}) >>> y.deltas == x.deltas True Note that the result always includes a "dummy" entry, giving the relative offset of self.refkey with respect to itself, which is always 0. See also .fromdeltas(). BUGS: I think the keys in each tuple should be reversed. I can't remember why I put them in the way they are. Expect them to change in the future.
|
refkey= min(self) Raises ValueError if the offsetvector is empty.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Dec 12 00:34:20 2017 | http://epydoc.sourceforge.net |