From 003bb360d1295e29ebfafb9659348c47e8cf1354 Mon Sep 17 00:00:00 2001 From: Kanchan Soni Date: Tue, 19 Nov 2024 18:03:14 -0500 Subject: [PATCH 1/5] added a feature to generate frequency domain waveforms at reduced frequencies --- bin/bank/pycbc_brute_bank | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/bin/bank/pycbc_brute_bank b/bin/bank/pycbc_brute_bank index 61626e48832..71b4b3364c8 100755 --- a/bin/bank/pycbc_brute_bank +++ b/bin/bank/pycbc_brute_bank @@ -53,6 +53,8 @@ parser.add_argument('--approximant', required=False, parser.add_argument('--minimal-match', default=0.97, type=float) parser.add_argument('--buffer-length', default=2, type=float, help='size of waveform buffer in seconds') +parser.add_argument('--buffer-high-pass-length', default=None, type=float, + help='size of waveform buffer in seconds') parser.add_argument('--max-signal-length', type= float, help="When specified, it cuts the maximum length of the waveform model to the lengh provided") parser.add_argument('--sample-rate', default=2048, type=float, @@ -275,6 +277,37 @@ class TriangleBank(object): return bank, num_added / total_num +def decimate_frequency_domain(template,target_df): + """ + Returns a frequency-domain waveform resampled to a lower frequency resolution (delta_f) by decimation. + + Parameters + ---------- + template: pycbc.types.FrequencySeries + The input frequency-domain signal to be decimated. + target_df: float + The target frequency resolution (delta_f) for the decimated signal. + + Returns + ---------- + decimated_template: pycbc.types.FrequencySeries + A new FrequencySeries object with the decimated data and the specified target delta_f. + """ + + # Calculate the decimation factor + factor = int(target_df / template.delta_f) + + if factor < 1: + raise ValueError("Target delta_f must be greater than or equal to the original delta_f.") + + # Decimate the data by selecting every 'factor'-th point + decimated_signal = template.data[::factor] + + import pycbc.types as types + # Create a new FrequencySeries object with the decimated data and the target delta_f + decimated_template = types.FrequencySeries(decimated_signal, delta_f=target_df) + return decimated_template + class GenUniformWaveform(object): def __init__(self, buffer_length, sample_rate, f_lower): self.f_lower = f_lower @@ -308,7 +341,15 @@ class GenUniformWaveform(object): kwds['approximant'] = kwds['approximant'].decode() if kwds['approximant'] in pycbc.waveform.fd_approximants(): - hp, hc = pycbc.waveform.get_fd_waveform(delta_f=self.delta_f, + if args.buffer_high_pass_length is not None: + # generate the frequency domain waveform at high frequency + high_hp, high_hc = pycbc.waveform.get_fd_waveform(delta_f= 1 / args.buffer_high_pass_length, + **kwds) + # decimate the generated signal into reduced frequency (equivalent to buffer-length) + hp = decimate_frequency_domain(high_hp,1/ args.buffer_length) + hc = decimate_frequency_domain(high_hp,1/ args.buffer_length) + else: + hp, hc = pycbc.waveform.get_fd_waveform(delta_f=self.delta_f, **kwds) if args.use_cross: hp = hc From 2fbc5ee205785ea65326ec71323fe61cb1d184a9 Mon Sep 17 00:00:00 2001 From: Kanchan Soni Date: Wed, 20 Nov 2024 12:13:11 -0500 Subject: [PATCH 2/5] Mofified the input argument --full-resolution-buffer-length and fixed some bugs --- bin/bank/pycbc_brute_bank | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/bin/bank/pycbc_brute_bank b/bin/bank/pycbc_brute_bank index 71b4b3364c8..aef5d73ede4 100755 --- a/bin/bank/pycbc_brute_bank +++ b/bin/bank/pycbc_brute_bank @@ -53,7 +53,7 @@ parser.add_argument('--approximant', required=False, parser.add_argument('--minimal-match', default=0.97, type=float) parser.add_argument('--buffer-length', default=2, type=float, help='size of waveform buffer in seconds') -parser.add_argument('--buffer-high-pass-length', default=None, type=float, +parser.add_argument('--full-resolution-buffer-length', default=None, type=float, help='size of waveform buffer in seconds') parser.add_argument('--max-signal-length', type= float, help="When specified, it cuts the maximum length of the waveform model to the lengh provided") @@ -277,35 +277,35 @@ class TriangleBank(object): return bank, num_added / total_num -def decimate_frequency_domain(template,target_df): +def decimate_frequency_domain(template, target_df): """ - Returns a frequency-domain waveform resampled to a lower frequency resolution (delta_f) by decimation. + Returns a frequency-domain waveform resampled to a lower frequency resolution + (delta_f) by decimation. Parameters ---------- - template: pycbc.types.FrequencySeries + template : pycbc.types.FrequencySeries The input frequency-domain signal to be decimated. - target_df: float + target_df : float The target frequency resolution (delta_f) for the decimated signal. Returns ---------- - decimated_template: pycbc.types.FrequencySeries - A new FrequencySeries object with the decimated data and the specified target delta_f. + decimated_template : pycbc.types.FrequencySeries + A new FrequencySeries object with the decimated data and the specified + target delta_f. """ - # Calculate the decimation factor - factor = int(target_df / template.delta_f) + decimation_factor = int(target_df / template.delta_f) - if factor < 1: + if decimation_factor < 1: raise ValueError("Target delta_f must be greater than or equal to the original delta_f.") - # Decimate the data by selecting every 'factor'-th point - decimated_signal = template.data[::factor] + # Decimate the data by selecting every 'decimation_factor'-th point + decimated_signal = template.data[::decimation_factor] - import pycbc.types as types # Create a new FrequencySeries object with the decimated data and the target delta_f - decimated_template = types.FrequencySeries(decimated_signal, delta_f=target_df) + decimated_template = pycbc.types.FrequencySeries(decimated_signal, delta_f=target_df) return decimated_template class GenUniformWaveform(object): @@ -342,12 +342,12 @@ class GenUniformWaveform(object): if kwds['approximant'] in pycbc.waveform.fd_approximants(): if args.buffer_high_pass_length is not None: - # generate the frequency domain waveform at high frequency - high_hp, high_hc = pycbc.waveform.get_fd_waveform(delta_f= 1 / args.buffer_high_pass_length, - **kwds) - # decimate the generated signal into reduced frequency (equivalent to buffer-length) - hp = decimate_frequency_domain(high_hp,1/ args.buffer_length) - hc = decimate_frequency_domain(high_hp,1/ args.buffer_length) + # Generate the frequency-domain waveform at high frequency + high_hp, high_hc = pycbc.waveform.get_fd_waveform(delta_f=1 / args.full_resolution_buffer_length, + **kwds) + # Decimate the generated signal to a reduced frequency resolution + hp = decimate_frequency_domain(high_hp, 1 / args.buffer_length) + hc = decimate_frequency_domain(high_hc, 1 / args.buffer_length) else: hp, hc = pycbc.waveform.get_fd_waveform(delta_f=self.delta_f, **kwds) From ccc8068d26b73e1823eaab50040c6fba0cc6a0b5 Mon Sep 17 00:00:00 2001 From: Kanchan Soni Date: Wed, 20 Nov 2024 12:16:17 -0500 Subject: [PATCH 3/5] Minor change --- bin/bank/pycbc_brute_bank | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bank/pycbc_brute_bank b/bin/bank/pycbc_brute_bank index aef5d73ede4..319578e0ee7 100755 --- a/bin/bank/pycbc_brute_bank +++ b/bin/bank/pycbc_brute_bank @@ -342,7 +342,7 @@ class GenUniformWaveform(object): if kwds['approximant'] in pycbc.waveform.fd_approximants(): if args.buffer_high_pass_length is not None: - # Generate the frequency-domain waveform at high frequency + # Generate the frequency-domain waveform at full frequency resolution high_hp, high_hc = pycbc.waveform.get_fd_waveform(delta_f=1 / args.full_resolution_buffer_length, **kwds) # Decimate the generated signal to a reduced frequency resolution From eae8e88d69354bf41868a9e186b9c66c6a8502fa Mon Sep 17 00:00:00 2001 From: Kanchan Soni Date: Wed, 20 Nov 2024 13:26:59 -0500 Subject: [PATCH 4/5] Minor change --- bin/bank/pycbc_brute_bank | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bank/pycbc_brute_bank b/bin/bank/pycbc_brute_bank index 319578e0ee7..a17b1b2df09 100755 --- a/bin/bank/pycbc_brute_bank +++ b/bin/bank/pycbc_brute_bank @@ -341,7 +341,7 @@ class GenUniformWaveform(object): kwds['approximant'] = kwds['approximant'].decode() if kwds['approximant'] in pycbc.waveform.fd_approximants(): - if args.buffer_high_pass_length is not None: + if args.full_resolution_buffer_length is not None: # Generate the frequency-domain waveform at full frequency resolution high_hp, high_hc = pycbc.waveform.get_fd_waveform(delta_f=1 / args.full_resolution_buffer_length, **kwds) From 7e08bea20bea97442e04a2f1c1b94c1e498525a9 Mon Sep 17 00:00:00 2001 From: Kanchan Soni Date: Fri, 22 Nov 2024 13:10:47 -0500 Subject: [PATCH 5/5] updated the help message for --buffer-high-pass-length --- bin/bank/pycbc_brute_bank | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bank/pycbc_brute_bank b/bin/bank/pycbc_brute_bank index a17b1b2df09..ecce65d8ab6 100755 --- a/bin/bank/pycbc_brute_bank +++ b/bin/bank/pycbc_brute_bank @@ -54,7 +54,7 @@ parser.add_argument('--minimal-match', default=0.97, type=float) parser.add_argument('--buffer-length', default=2, type=float, help='size of waveform buffer in seconds') parser.add_argument('--full-resolution-buffer-length', default=None, type=float, - help='size of waveform buffer in seconds') + help='Size of the waveform buffer in seconds for generating time-domain signals at full resolution before conversion to the frequency domain.') parser.add_argument('--max-signal-length', type= float, help="When specified, it cuts the maximum length of the waveform model to the lengh provided") parser.add_argument('--sample-rate', default=2048, type=float,