From d571721516e38506e99898a53e57f28e17d1fe07 Mon Sep 17 00:00:00 2001 From: Connor Date: Tue, 13 Sep 2022 11:23:58 +0200 Subject: [PATCH] Modified cython code with own version of likelihood_parts function for waveforms whcih compute own det response --- pycbc/inference/models/relbin.py | 35 +++++++++++++++++---------- pycbc/inference/models/relbin_cpu.pyx | 32 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/pycbc/inference/models/relbin.py b/pycbc/inference/models/relbin.py index bd451912975..d8281d385cb 100644 --- a/pycbc/inference/models/relbin.py +++ b/pycbc/inference/models/relbin.py @@ -38,7 +38,8 @@ from .gaussian_noise import BaseGaussianNoise from .relbin_cpu import (likelihood_parts, likelihood_parts_v, - likelihood_parts_multi, likelihood_parts_multi_v) + likelihood_parts_multi, likelihood_parts_multi_v, + likelihood_parts_det) from .tools import DistMarg @@ -346,7 +347,10 @@ def setup_antenna(self, earth_rotation, fedges): self.mlik = likelihood_parts_multi_v else: atimes = self.fid_params["tc"] - self.lik = likelihood_parts + if self.det_response: + self.lik = likelihood_parts_det + else: + self.lik = likelihood_parts self.mlik = likelihood_parts_multi return atimes @@ -491,12 +495,19 @@ def _loglr(self): end_time = self.end_time[ifo] times = self.antenna_time[ifo] - # project waveform to detector frame - # FIXME: Don't want to do this for LISA!! + # project waveform to detector frame if waveform does not deal + # with detector response. Otherwise, skip detector response. + + hp, hc = wfs[ifo] if self.det_response: - fp, fc = (1, 0) - dt = 0 + fp = 1 dtc = -end_time + hp, hc = wfs[ifo] + hdp, hhp = self.lik(freqs, fp, dtc, + hp, hc, h00, + sdat['a0'], sdat['a1'], + sdat['b0'], sdat['b1']) + self._current_wf_parts[ifo] = (fp, dtc, hp, hc, h00) else: det = self.det[ifo] fp, fc = det.antenna_pattern(p["ra"], p["dec"], @@ -504,13 +515,11 @@ def _loglr(self): dt = det.time_delay_from_earth_center(p["ra"], p["dec"], times) dtc = p["tc"] + dt - end_time - hp, hc = wfs[ifo] - hdp, hhp = self.lik(freqs, fp, fc, dtc, - hp, hc, h00, - sdat['a0'], sdat['a1'], - sdat['b0'], sdat['b1']) - - self._current_wf_parts[ifo] = (fp, fc, dtc, hp, hc, h00) + hdp, hhp = self.lik(freqs, fp, fc, dtc, + hp, hc, h00, + sdat['a0'], sdat['a1'], + sdat['b0'], sdat['b1']) + self._current_wf_parts[ifo] = (fp, fc, dtc, hp, hc, h00) hd += hdp hh += hhp return self.marginalize_loglr(hd, hh) diff --git a/pycbc/inference/models/relbin_cpu.pyx b/pycbc/inference/models/relbin_cpu.pyx index 88f11f49e11..b5ae87ec833 100644 --- a/pycbc/inference/models/relbin_cpu.pyx +++ b/pycbc/inference/models/relbin_cpu.pyx @@ -107,6 +107,38 @@ cpdef likelihood_parts(double [::1] freqs, x0 = x0n return hd, hh +cpdef likelihood_parts_det(double [::1] freqs, + double fp, + double dtc, + double complex[::1] hp, + double complex[::1] hc, + double complex[::1] h00, + double complex[::1] a0, + double complex[::1] a1, + double [::1] b0, + double [::1] b1, + ) : + cdef size_t i + cdef double complex hd=0, r0, r0n, r1, x0, x1, x0n; + cdef double hh=0 + + N = freqs.shape[0] + for i in range(N): + r0n = (exp(-2.0j * 3.141592653 * dtc * freqs[i]) + * (fp * hp[i])) / h00[i] + r1 = r0n - r0 + + x0n = norm(r0n) + x1 = x0n - x0 + + if i > 0: + hd += a0[i-1] * r0 + a1[i-1] * r1 + hh += real(b0[i-1] * x0 + b1[i-1] * x1) + + r0 = r0n + x0 = x0n + return hd, hh + cpdef likelihood_parts_v(double [::1] freqs, double[::1] fp, double[::1] fc,