LALBurst 2.0.7.1-eeff03c
lalburst.offsetvector.offsetvector Class Reference

Detailed Description

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

Definition at line 56 of file offsetvector.py.

Inherits dict.

Public Member Functions

def refkey (self)
 = min(self) More...
 
def deltas (self)
 Dictionary of relative offsets. More...
 
def __str__ (self, compact=False)
 Return a human-readable string representation of an offset vector. More...
 
def __repr__ (self)
 Return a string representation of the offset vector. More...
 
def __abs__ (self)
 Returns max(offset) - min(offset). More...
 
def contains (self, other)
 Returns True if offset vector other can be found in self, False otherwise. More...
 
def normalize (self, **kwargs)
 Adjust the offsetvector so that a particular instrument has the desired offset. More...
 
def fromdeltas (cls, deltas)
 Construct an offsetvector from a dictionary of offset deltas as returned by the .deltas attribute. More...
 

Member Function Documentation

◆ refkey()

def lalburst.offsetvector.offsetvector.refkey (   self)

= min(self)

Raises ValueError if the offsetvector is empty.

Definition at line 63 of file offsetvector.py.

◆ deltas()

def lalburst.offsetvector.offsetvector.deltas (   self)

Dictionary 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}) assert 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.

Definition at line 98 of file offsetvector.py.

◆ __str__()

def lalburst.offsetvector.offsetvector.__str__ (   self,
  compact = 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'

Definition at line 124 of file offsetvector.py.

◆ __repr__()

def lalburst.offsetvector.offsetvector.__repr__ (   self)

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}) b = eval(repr(a)) b == a True b is a False c = offsetvector({"H1": -10.1234567}) repr(c) "offsetvector({'H1': -10.1234567})"

Definition at line 145 of file offsetvector.py.

◆ __abs__()

def lalburst.offsetvector.offsetvector.__abs__ (   self)

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

Definition at line 160 of file offsetvector.py.

◆ contains()

def lalburst.offsetvector.offsetvector.contains (   self,
  other 
)

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

Definition at line 182 of file offsetvector.py.

◆ normalize()

def lalburst.offsetvector.offsetvector.normalize (   self,
**  kwargs 
)

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}) assert a.normalize(L1 = 0) == offsetvector({'H2': 0, 'H1': 0, 'L1': 0}) a = offsetvector({"H1": -10, "H2": -10}) assert a.normalize(L1 = 0, H2 = 5) == offsetvector({'H2': 5, 'H1': 5})

Definition at line 207 of file offsetvector.py.

◆ fromdeltas()

def lalburst.offsetvector.offsetvector.fromdeltas (   cls,
  deltas 
)

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 == x True

See also .deltas, .fromkeys()

Definition at line 232 of file offsetvector.py.