30__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
31from .git_version
import date
as __date__
32from .git_version
import version
as __version__
46 Subclass of the dict built-in type for storing mappings of
47 instrument to time offset.
51 >>> x = offsetvector({"H1": 0, "L1": 10, "V1": 20})
54 >>> not any(x.values()) # check for "zero-lag"
62 Raises ValueError if the offsetvector
is empty.
69 raise ValueError(
"offsetvector is empty")
75 Dictionary of relative offsets. The keys in the result are
76 pairs of keys
from the offset vector, (a, b),
and the
77 values are the relative offsets, (offset[b] - offset[a]).
78 Raises ValueError
if the offsetvector
is empty (WARNING:
79 this behaviour might change
in the future).
84 >>>
assert x.deltas == {(
'H1',
'L1'): 10, (
'H1',
'V1'): 20, (
'H1',
'H1'): 0}
86 >>> y.deltas == x.deltas
89 Note that the result always includes a
"dummy" entry,
90 giving the relative offset of self.
refkey with respect to
91 itself, which
is always 0.
95 BUGS: I think the keys
in each tuple should be reversed.
96 I can
't remember why I put them in the way they are.
97 Expect them to change in the future.
109 refoffset = self[refkey]
110 return dict(((refkey, key), self[key] - refoffset)
for key
in self)
112 def __str__(self, compact = False):
114 Return a human-readable string representation of an offset
121 'H1 = -10.1234567 s, L1 = +0.125 s'
122 >>> a.__str__(compact =
True)
123 'H1=-10.123,L1=0.125'
126 return ",".join((
"%s=%.5g" % x)
for x
in sorted(self.items()))
127 return ", ".join((
"%s = %+.16g s" % x)
for x
in sorted(self.items()))
131 Return a string representation of the offset vector.
132 Running eval() on the result reconstructs the offsetvector.
137 >>> b = eval(repr(a))
144 "offsetvector({'H1': -10.1234567})"
146 return "%s(%s)" % (self.__class__.__name__, dict.__repr__(self))
150 Returns max(offset) - min(offset).
154 >>> abs(offsetvector({"H1": 0.0,
"H2": 0.0,
"L1": 0.0}))
156 >>> abs(
offsetvector({
"H1": 10.0,
"H2": 10.0,
"L1": 10.0}))
158 >>> abs(
offsetvector({
'H1': 10.0,
'L1': 0.0,
'V1': -10.0}))
161 return max(self.values()) -
min(self.values())
165 Returns True if offset vector other can be found
in self,
166 False otherwise. An offset vector
is "found in" another
167 offset vector
if the latter contains all of the former
's
168 instruments and the relative offsets among those
169 instruments are equal (the absolute offsets need
not be).
178 Note the distinction between this
and the
"in" operator:
183 return offsetvector((key, offset)
for key, offset
in self.items()
if key
in other).deltas == other.deltas
187 Adjust the offsetvector so that a particular instrument has
188 the desired offset. All other instruments have their
189 offsets adjusted so that the relative offsets are
190 preserved. The instrument to noramlize, and the offset one
191 wishes it to have, are provided
as a key-word argument.
192 The
return value
is the time slide dictionary, which
is
195 If more than one key-word argument
is provided the keys are
196 sorted
and considered
in order until a key
is found that
is
197 in the offset vector. The offset vector
is normalized to
198 that value. This function
is a no-op
if no key-word
199 argument
is found that applies.
204 >>>
assert a.normalize(L1 = 0) ==
offsetvector({
'H2': 0,
'H1': 0,
'L1': 0})
206 >>>
assert a.normalize(L1 = 0, H2 = 5) ==
offsetvector({
'H2': 5,
'H1': 5})
210 for key, offset
in sorted(kwargs.items()):
212 delta = offset - self[key]
213 for key
in self.keys():
221 Construct an offsetvector from a dictionary of offset
222 deltas
as returned by the .deltas attribute.
227 >>> y = offsetvector.fromdeltas(x.deltas)
231 See also .deltas, .fromkeys()
233 return cls((key, value)
for (refkey, key), value
in deltas.items())
247 Given an iterable of offset vectors, return the shortest list of
248 the unique n-instrument offset vectors from which all the vectors
249 in the input iterable can be constructed. This can be used to
250 determine the minimal set of n-instrument coincs required to
251 construct all of the coincs for all of the requested instrument
and
252 offset combinations
in a set of offset vectors.
254 It
is assumed that the coincs
for the vector {
"H1": 0,
"H2": 10,
255 "L1": 20} can be constructed
from the coincs
for the vectors {
"H1":
256 0,
"H2": 10}
and {
"H2": 0,
"L1": 10}, that
is only the relative
257 offsets are significant
in determining
if two events are
258 coincident,
not the absolute offsets.
261 # collect unique instrument set / deltas combinations
265 for vect in offsetvectors:
266 for instruments
in itertools.combinations(sorted(vect), n):
272 delta_sets.setdefault(instruments, set()).add(tuple(vect[instrument] - vect[instruments[0]]
for instrument
in instruments))
278 return [
offsetvector(zip(instruments, deltas))
for instruments, delta_set
in delta_sets.items()
for deltas
in delta_set]
static double max(double a, double b)
static double min(double a, double b)
Subclass of the dict built-in type for storing mappings of instrument to time offset.
def __abs__(self)
Returns max(offset) - min(offset).
def refkey(self)
= min(self)
def normalize(self, **kwargs)
Adjust the offsetvector so that a particular instrument has the desired offset.
def __str__(self, compact=False)
Return a human-readable string representation of an offset vector.
def fromdeltas(cls, deltas)
Construct an offsetvector from a dictionary of offset deltas as returned by the .deltas attribute.
def contains(self, other)
Returns True if offset vector other can be found in self, False otherwise.
def __repr__(self)
Return a string representation of the offset vector.
def deltas(self)
Dictionary of relative offsets.
def component_offsetvectors(offsetvectors, n)
Given an iterable of offset vectors, return the shortest list of the unique n-instrument offset vecto...