Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature to generate frequency domain waveforms at reduced frequencies #4948

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion bin/bank/pycbc_brute_bank
Original file line number Diff line number Diff line change
Expand Up @@ -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('--full-resolution-buffer-length', default=None, type=float,
help='size of waveform buffer in seconds')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this help message needs to be clear, e.g. how is this different from buffer-length? Otherwise the PR looks fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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,
Expand Down Expand Up @@ -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
decimation_factor = int(target_df / template.delta_f)

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 'decimation_factor'-th point
decimated_signal = template.data[::decimation_factor]

# Create a new FrequencySeries object with the decimated data and the target delta_f
decimated_template = pycbc.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
Expand Down Expand Up @@ -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.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)
# 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)
if args.use_cross:
hp = hc
Expand Down
Loading