Skip to content

Commit 23bc864

Browse files
committed
Separate generating the fiducial waveform from laying out the bins
Relative binning does both in one loop in the constructor, with the data the bins are built from held in a local. Neither can be redone, so anything that wants a different resolution, or a different fiducial waveform, has to build the whole model again. Split the loop in two. setup_fiducial generates the fiducial waveform and leaves behind the shifted data and frequency range that the bins are laid out from; setup_bin_layout does the laying out. Each can now be called on its own. No change in behaviour. Log likelihood ratios agree with what they were to five parts in a thousand billion, the shifted data having moved from a temporary to a kept array and so being summed in a different order.
1 parent f6eaed2 commit 23bc864

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

pycbc/inference/models/relbin.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,23 @@ def __init__(
220220
if self.fid_params[k] == 'REPLACE':
221221
self.fid_params.pop(k)
222222

223-
for ifo in data:
223+
# the data with the fiducial waveform's timing taken out, and the
224+
# frequency range it covers. Both are what the bins are laid out
225+
# from, and are kept so that can be done again.
226+
self.shifted, self.flimits = {}, {}
227+
228+
self.setup_fiducial()
229+
self.setup_bin_layout(epsilon, gammas, earth_rotation,
230+
int(earth_rotation_mode))
231+
232+
def setup_fiducial(self):
233+
"""Generate the fiducial waveform and the data to compare against it.
234+
235+
Redone when the fiducial parameters change. The bins are laid out
236+
from what this leaves behind, so they have to be laid out again
237+
after it.
238+
"""
239+
for ifo in self.data:
224240
# store data and frequencies
225241
d0 = self.data[ifo]
226242
self.f[ifo] = d0.sample_frequencies.numpy()
@@ -289,7 +305,20 @@ def __init__(
289305
# This makes it easier to compare target signal to reference later
290306
tshift = numpy.exp(-2.0j * numpy.pi * self.f[ifo] * self.ta[ifo])
291307
self.h00[ifo] = numpy.array(curr_wav) # * tshift
292-
data_shifted = self.data[ifo] * numpy.conjugate(tshift)
308+
self.shifted[ifo] = self.data[ifo] * numpy.conjugate(tshift)
309+
self.flimits[ifo] = (f_lo, f_hi)
310+
311+
def setup_bin_layout(self, epsilon, gammas, earth_rotation,
312+
earth_rotation_mode):
313+
"""Place the frequency bins and compute the summary data for them.
314+
315+
Everything this needs is left behind by
316+
:py:meth:`setup_fiducial`, so it can be redone on its own to
317+
change the resolution without generating the fiducial waveform
318+
again.
319+
"""
320+
for ifo in self.data:
321+
f_lo, f_hi = self.flimits[ifo]
293322

294323
logging.info("Computing frequency bins")
295324
fbin_ind = setup_bins(
@@ -300,10 +329,11 @@ def __init__(
300329

301330
self.fedges[ifo] = self.f[ifo][fbin_ind]
302331
self.edges[ifo] = fbin_ind
303-
self.init_from_frequencies(data_shifted, self.h00, fbin_ind, ifo)
332+
self.init_from_frequencies(self.shifted[ifo], self.h00,
333+
fbin_ind, ifo)
304334
self.antenna_time[ifo] = self.setup_antenna(
305335
earth_rotation,
306-
int(earth_rotation_mode),
336+
earth_rotation_mode,
307337
self.fedges[ifo])
308338
self.combine_layout()
309339

0 commit comments

Comments
 (0)