-
Notifications
You must be signed in to change notification settings - Fork 354
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
ahnitz
merged 5 commits into
gwastro:master
from
Kanchan-05:add_reduced_freq_match_func
Nov 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
003bb36
added a feature to generate frequency domain waveforms at reduced fre…
2fbc5ee
Mofified the input argument --full-resolution-buffer-length and fixed…
ccc8068
Minor change
eae8e88
Minor change
7e08bea
updated the help message for --buffer-high-pass-length
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name / help might be clearer. Maybe --full-resolution-buffer-length or maybe you have a better idea? Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--full-resolution-buffer-length sounds good! If it feels too lengthy, perhaps --full-res-buffer-length could be a more concise alternative.