From 01bc4ae4b277f5506ea757e2fee14b256716cc78 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Thu, 27 Jun 2024 21:07:46 -0400 Subject: [PATCH 1/5] add ability to cache detect response to marginalize time model and use alternate sampler rate than data --- .../models/marginalized_gaussian_noise.py | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pycbc/inference/models/marginalized_gaussian_noise.py b/pycbc/inference/models/marginalized_gaussian_noise.py index 0a1342d0432..391d387b4d2 100644 --- a/pycbc/inference/models/marginalized_gaussian_noise.py +++ b/pycbc/inference/models/marginalized_gaussian_noise.py @@ -19,6 +19,7 @@ """ import itertools +import logging import numpy from scipy import special @@ -207,6 +208,7 @@ class MarginalizedTime(DistMarg, BaseGaussianNoise): def __init__(self, variable_params, data, low_frequency_cutoff, psds=None, high_frequency_cutoff=None, normalize=False, + sample_rate=None, **kwargs): self.kwargs = kwargs @@ -240,6 +242,13 @@ def __init__(self, variable_params, gates=self.gates, **kwargs['static_params']) self.dets = {} + + if sample_rate is not None: + logging.info("Using %s sample rate for marginalization", sample_rate) + for det in self._whitened_data: + tlen = int(round(float(sample_rate) * self.whitened_data[det].duration)) + flen = tlen // 2 + 1 + self._whitened_data[det].resize(flen) def _nowaveform_loglr(self): """Convenience function to set loglr values if no waveform generated. @@ -325,15 +334,20 @@ def _loglr(self): for det in wfs: if det not in self.dets: self.dets[det] = Detector(det) - fp, fc = self.dets[det].antenna_pattern( - params['ra'], - params['dec'], - params['polarization'], - params['tc']) - dt = self.dets[det].time_delay_from_earth_center(params['ra'], - params['dec'], - params['tc']) + + if self.precalc_antenna_factors: + fp, fc, dt = self.get_precalc_antenna_factors(det) + else: + fp, fc = self.dets[det].antenna_pattern( + params['ra'], + params['dec'], + params['polarization'], + params['tc']) + dt = self.dets[det].time_delay_from_earth_center(params['ra'], + params['dec'], + params['tc']) dtc = params['tc'] + dt + cplx_hd = fp * cplx_hpd[det].at_time(dtc, interpolate='quadratic') cplx_hd += fc * cplx_hcd[det].at_time(dtc, From 5a9d151dd9d013c1bb651770688f589eb84f8965 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Tue, 2 Jul 2024 15:40:55 -0400 Subject: [PATCH 2/5] cc --- .../models/marginalized_gaussian_noise.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pycbc/inference/models/marginalized_gaussian_noise.py b/pycbc/inference/models/marginalized_gaussian_noise.py index 391d387b4d2..39573d856af 100644 --- a/pycbc/inference/models/marginalized_gaussian_noise.py +++ b/pycbc/inference/models/marginalized_gaussian_noise.py @@ -242,13 +242,15 @@ def __init__(self, variable_params, gates=self.gates, **kwargs['static_params']) self.dets = {} - + if sample_rate is not None: - logging.info("Using %s sample rate for marginalization", sample_rate) + logging.info("Using %s sample rate for marginalization", + sample_rate) for det in self._whitened_data: - tlen = int(round(float(sample_rate) * self.whitened_data[det].duration)) + tlen = int(round(float(sample_rate) * + self.whitened_data[det].duration)) flen = tlen // 2 + 1 - self._whitened_data[det].resize(flen) + self._whitened_data[det].resize(flen) def _nowaveform_loglr(self): """Convenience function to set loglr values if no waveform generated. @@ -334,7 +336,7 @@ def _loglr(self): for det in wfs: if det not in self.dets: self.dets[det] = Detector(det) - + if self.precalc_antenna_factors: fp, fc, dt = self.get_precalc_antenna_factors(det) else: @@ -347,7 +349,7 @@ def _loglr(self): params['dec'], params['tc']) dtc = params['tc'] + dt - + cplx_hd = fp * cplx_hpd[det].at_time(dtc, interpolate='quadratic') cplx_hd += fc * cplx_hcd[det].at_time(dtc, From ffa34788593fc3491c1b0fe20a5a73e52ecfe124 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Mon, 22 Jul 2024 12:28:48 -0400 Subject: [PATCH 3/5] update --- examples/inference/margtime/margtime.ini | 3 +++ .../models/marginalized_gaussian_noise.py | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/inference/margtime/margtime.ini b/examples/inference/margtime/margtime.ini index ce2bf7bebbd..9bea5471691 100644 --- a/examples/inference/margtime/margtime.ini +++ b/examples/inference/margtime/margtime.ini @@ -3,6 +3,9 @@ name = marginalized_time low-frequency-cutoff = 30.0 +# This is the sample rate used for the model and marginalization +sample_rate = 2048 + marginalize_vector_params = tc, ra, dec, polarization marginalize_vector_samples = 500 diff --git a/pycbc/inference/models/marginalized_gaussian_noise.py b/pycbc/inference/models/marginalized_gaussian_noise.py index 39573d856af..9052a5018ed 100644 --- a/pycbc/inference/models/marginalized_gaussian_noise.py +++ b/pycbc/inference/models/marginalized_gaussian_noise.py @@ -211,6 +211,7 @@ def __init__(self, variable_params, sample_rate=None, **kwargs): + self.sample_rate = float(sample_rate) self.kwargs = kwargs variable_params, kwargs = self.setup_marginalization( variable_params, @@ -244,13 +245,12 @@ def __init__(self, variable_params, self.dets = {} if sample_rate is not None: + for ifo in self.data: + if self.sample_rate < self.data[ifo].sample_rate: + raise ValueError("Model sample rate was set less than the" + " data. ") logging.info("Using %s sample rate for marginalization", sample_rate) - for det in self._whitened_data: - tlen = int(round(float(sample_rate) * - self.whitened_data[det].duration)) - flen = tlen // 2 + 1 - self._whitened_data[det].resize(flen) def _nowaveform_loglr(self): """Convenience function to set loglr values if no waveform generated. @@ -307,8 +307,15 @@ def _loglr(self): hp[self._kmin[det]:kmax] *= self._weight[det][slc] hc[self._kmin[det]:kmax] *= self._weight[det][slc] - hp.resize(len(self._whitened_data[det])) - hc.resize(len(self._whitened_data[det])) + # Use a higher sample rate if requested + if self.sample_rate is not None: + tlen = int(round(self.sample_rate * + self.whitened_data[det].duration)) + flen = tlen // 2 + 1 + hp.resize(flen) + hc.resize(flen) + self._whitened_data[det].resize(flen) + cplx_hpd[det], _, _ = matched_filter_core( hp, self._whitened_data[det], From 9540ec7dd80323e35e2884e40778da444eae2311 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Mon, 22 Jul 2024 15:10:24 -0400 Subject: [PATCH 4/5] update example --- examples/inference/margtime/margtime.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/inference/margtime/margtime.ini b/examples/inference/margtime/margtime.ini index 9bea5471691..fd17c0e7e5a 100644 --- a/examples/inference/margtime/margtime.ini +++ b/examples/inference/margtime/margtime.ini @@ -4,10 +4,10 @@ name = marginalized_time low-frequency-cutoff = 30.0 # This is the sample rate used for the model and marginalization -sample_rate = 2048 +sample_rate = 4096 marginalize_vector_params = tc, ra, dec, polarization -marginalize_vector_samples = 500 +marginalize_vector_samples = 2000 ; You shouldn't use phase marginalization if the approximant has ; higher-order modes From ffdeb304fe72e09c3123d31a7ee655733f68c8e0 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Mon, 22 Jul 2024 16:26:22 -0400 Subject: [PATCH 5/5] update example --- examples/inference/margtime/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/inference/margtime/run.sh b/examples/inference/margtime/run.sh index 383d348ef29..3d9a7f32a73 100644 --- a/examples/inference/margtime/run.sh +++ b/examples/inference/margtime/run.sh @@ -1,6 +1,6 @@ OMP_NUM_THREADS=1 pycbc_inference \ --config-file `dirname "$0"`/margtime.ini \ ---nprocesses 2 \ +--nprocesses 1 \ --processing-scheme mkl \ --output-file marg_150914.hdf \ --seed 0 \ @@ -23,4 +23,5 @@ pycbc_inference_plot_posterior \ "primary_mass(mass1, mass2) / (1 + redshift(distance)):srcmass1" \ "secondary_mass(mass1, mass2) / (1 + redshift(distance)):srcmass2" \ ra dec tc inclination coa_phase polarization distance \ +--vmin 23.2 \ --z-arg snr