31from .
import offsetvector
34__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
35from .git_version
import date
as __date__
36from .git_version
import version
as __version__
50 Accepts a string in the format
51 instrument=first:last:step[,first:last:step]... and returns the
52 tuple (instrument, [offset1, offset2, ....]) where the offsets are
53 the sorted list of unique numbers described by the ranges. A range
54 with a positive step describes the offsets (first + n * step) where
55 n
is an integer such that first <= offset <= last. A range
with a
56 negative step describes the offsets (first + n * step) where n
is
57 an integer such that last <= offset <= first.
62 (
'H1', [-5.0, -4.5, -4.0, -3.5, -3.0, -2.5, -2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0])
64 (
'H1', [-5.0, -4.5, -4.0, -3.5, -3.0, -2.5, -2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0])
69 instrument, rangespec = slidespec.split("=")
71 raise ValueError(
"cannot parse time slide '%s'" % slidespec)
73 for rng
in [s.strip()
for s
in rangespec.split(
",")]:
75 first, last, step = map(float, rng.split(
":"))
77 raise ValueError(
"malformed range '%s' in '%s'" % (rng, rangespec))
80 raise ValueError(
"divide by zero in range '%s'" % rng)
83 elif last > first
if step < 0
else last < first:
84 raise ValueError(
"step has wrong sign in range '%s'" % rng)
86 for i
in itertools.count():
88 if not min(first, last) <= x <=
max(first, last):
91 return instrument.strip(), sorted(offsets)
96 Accepts a list of strings of the format understood by
97 parse_slidespec(), and returns a dictionary mapping instrument
98 names to sorted lists of unique offsets.
102 >>> parse_slides(["H1=-1:+1:+1", "H2=-1:+1:+1", "L1=0:0:0"])
103 {'H2': [-1.0, 0.0, 1.0], 'H1': [-1.0, 0.0, 1.0], 'L1': [0.0]}
108 for slidespec
in slides:
111 d[instrument] |= set(offsets)
113 d[instrument] = set(offsets)
115 return dict((instrument, sorted(offsets))
for instrument, offsets
in d.items())
120 Accepts a string in the format
121 count:instrument=offset[,instrument=offset...] and returns the
122 tuple (count, {instrument: offset, ...})
126 >>> parse_inspiral_num_slides_slidespec("3:H1=0,H2=5,L1=10")
127 (3, offsetvector({'H2': 5.0, 'H1': 0.0, 'L1': 10.0}))
129 count, offsets = slidespec.strip().split(
":")
130 offsetvect =
offsetvector.offsetvector((instrument.strip(), float(offset))
for instrument, offset
in (token.strip().split(
"=")
for token
in offsets.strip().split(
",")))
131 return int(count), offsetvect
145 Accepts a dictionary mapping instrument --> list-of-offsets (for
146 example, as returned by parse_slides()), and iterates over the
147 cartesian (outer) product of the offset lists, yielding all
148 possible N-way instrument --> offset mappings.
152 >>> slides = {"H1": [-1, 0, 1], "H2": [-1, 0, 1], "L1": [0]}
153 >>> list(SlidesIter(slides))
154 [offsetvector({'H2': -1, 'H1': -1, 'L1': 0}), offsetvector({'H2': -1, 'H1': 0, 'L1': 0}), offsetvector({'H2': -1, 'H1': 1, 'L1': 0}), offsetvector({'H2': 0, 'H1': -1, 'L1': 0}), offsetvector({'H2': 0, 'H1': 0, 'L1': 0}), offsetvector({'H2': 0, 'H1': 1, 'L1': 0}), offsetvector({'H2': 1, 'H1': -1, 'L1': 0}), offsetvector({'H2': 1, 'H1': 0, 'L1': 0}), offsetvector({'H2': 1, 'H1': 1, 'L1': 0})]
166 instruments = slides.keys()
167 for slide
in itertools.product(*slides.values()):
173 This generator yields a sequence of time slide dictionaries in the
174 style of lalapps_thinca's time slides. Each resulting dictionary
175 maps instrument to offset. The input is a count of time slides (an
176 integer),
and a dictionary mapping instrument to offset. The
177 output dictionaries describe time slides that are integer multiples
178 of the input time shifts.
183 [offsetvector({
'H2': -15.0,
'H1': -0.0,
'L1': -30.0}), offsetvector({
'H2': -10.0,
'H1': -0.0,
'L1': -20.0}), offsetvector({
'H2': -5.0,
'H1': -0.0,
'L1': -10.0}), offsetvector({
'H2': 0.0,
'H1': 0.0,
'L1': 0.0}), offsetvector({
'H2': 5.0,
'H1': 0.0,
'L1': 10.0}), offsetvector({
'H2': 10.0,
'H1': 0.0,
'L1': 20.0}), offsetvector({
'H2': 15.0,
'H1': 0.0,
'L1': 30.0})]
185 The output time slides are all integer multiples of the input time
186 shift vector
in the range [-count, +count],
and are returned
in
187 increasing order of mupltiplier.
189 offsets = offsets.items()
190 for n in range(-count, +count + 1):
194def vacuum(time_slides, verbose = False):
196 Given a dictionary mapping time slide ID to offsetvector, for
197 example as returned by the .as_dict() method of the TimeSlideTable
198 class in ligolw.lsctables, construct and return a mapping
199 indicating time slide equivalences. This can be used to delete
200 redundant time slides from a time slide table,
and then also used
201 via the .applyKeyMapping() method of ligolw.table.Table instances
202 to update cross references (
for example
in the coinc_event table).
206 >>> slides = {0: offsetvector({
"H1": 0,
"H2": 0}), 1: offsetvector({
"H1": 10,
"H2": 10}), 2: offsetvector({
"H1": 0,
"H2": 10})}
210 indicating that time slide ID 1 describes a time slide that
is
211 equivalent to time slide ID 0. The calling code could use this
212 information to delete time slide ID 1
from the time_slide table,
213 and replace references to that ID
in other tables
with references
216 # convert offsets to deltas
217 time_slides = dict((time_slide_id, offsetvect.deltas) for time_slide_id, offsetvect in time_slides.items())
218 with tqdm(total = len(time_slides), disable = not verbose) as progressbar:
224 id1, deltas1 = time_slides.popitem()
228 ids_to_delete = [id2
for id2, deltas2
in time_slides.items()
if deltas2 == deltas1]
229 for id2
in ids_to_delete:
234 progressbar.update(1 + len(ids_to_delete))
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 vacuum(time_slides, verbose=False)
Given a dictionary mapping time slide ID to offsetvector, for example as returned by the ....
def Inspiral_Num_Slides_Iter(count, offsets)
This generator yields a sequence of time slide dictionaries in the style of lalapps_thinca's time sli...
def parse_inspiral_num_slides_slidespec(slidespec)
Accepts a string in the format count:instrument=offset[,instrument=offset...] and returns the tuple (...
def parse_slides(slides)
Accepts a list of strings of the format understood by parse_slidespec(), and returns a dictionary map...
def SlidesIter(slides)
Accepts a dictionary mapping instrument --> list-of-offsets (for example, as returned by parse_slides...
def parse_slidespec(slidespec)
Accepts a string in the format instrument=first:last:step[,first:last:step]... and returns the tuple ...