From 95db2f6d99d5ea50f10805cc3cdf6f457ed729aa Mon Sep 17 00:00:00 2001 From: Yifan Wang Date: Thu, 14 Nov 2024 13:52:08 +0100 Subject: [PATCH] add waveform downsample --- pycbc/inference/models/gated_gaussian_noise.py | 8 +++++++- pycbc/inference/models/gaussian_noise.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pycbc/inference/models/gated_gaussian_noise.py b/pycbc/inference/models/gated_gaussian_noise.py index 33e7ecc27e1..311ce579fdd 100644 --- a/pycbc/inference/models/gated_gaussian_noise.py +++ b/pycbc/inference/models/gated_gaussian_noise.py @@ -29,7 +29,7 @@ from pycbc.pnutils import hybrid_meco_frequency from pycbc.waveform.utils import time_from_frequencyseries from pycbc.waveform import generator -from pycbc.filter import highpass +from pycbc.filter import highpass, resample_to_delta_t from .gaussian_noise import (BaseGaussianNoise, create_waveform_generator) from .base_data import BaseDataModel from .data_utils import fd_data_from_strain_dict @@ -207,6 +207,12 @@ def get_waveforms(self): h = highpass( h.to_timeseries(), frequency=self.highpass_waveforms).to_frequencyseries() + if 'waveform_srate' in self.static_params: + logging.warning("Resampling waveform from %f to %f Hz", + self.static_params['waveform_srate'], self.data[det].sample_rate) + h = resample_to_delta_t(h.to_timeseries(), + 1. / self.data[det].sample_rate, + method='ldas').to_frequencyseries() wfs[det] = h self._current_wfs = wfs return self._current_wfs diff --git a/pycbc/inference/models/gaussian_noise.py b/pycbc/inference/models/gaussian_noise.py index 418fdb66cc5..68f0de62968 100644 --- a/pycbc/inference/models/gaussian_noise.py +++ b/pycbc/inference/models/gaussian_noise.py @@ -1215,6 +1215,9 @@ def create_waveform_generator( d.start_time == start_time]): raise ValueError("data must all have the same delta_t, " "delta_f, and start_time") + if 'waveform_srate' in static_params: + delta_t = 1. / static_params['waveform_srate'] + logging.warning("Overriding delta_t to match waveform_srate") waveform_generator = generator_class( generator_function, epoch=start_time, variable_args=variable_params, detectors=list(data.keys()),