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

Fix get length in time #15

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
66 changes: 42 additions & 24 deletions BBHX_Phenom.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,48 @@ def chirptime(m1, m2, f_lower, m_mode=None):
return duration


def imr_duration(**params):
# More accurate duration (within LISA frequency band) of the waveform,
# including merge, ringdown, and aligned spin effects.
# This is used in the time-domain signal injection in PyCBC.
import warnings

nparams = {'mass1':params['mass1'], 'mass2':params['mass2'],
'spin1z':params['spin1z'], 'spin2z':params['spin2z'],
'f_lower':params['f_lower']}

if params['approximant'] == 'BBHX_PhenomD':
from pycbc.waveform.waveform import imrphenomd_length_in_time
time_length = np.float64(imrphenomd_length_in_time(**nparams))
elif params['approximant'] == 'BBHX_PhenomHM':
from pycbc.waveform.waveform import imrphenomhm_length_in_time
time_length = np.float64(imrphenomhm_length_in_time(**nparams))

if time_length < 2678400:
warnings.warn("Waveform duration is too short! Setting it to 1 month (2678400 s).")
time_length = 2678400
if time_length >= params['t_obs_start']:
warnings.warn("Waveform duration is longer than data length! Setting it to `t_obs_start`.")
time_length = params['t_obs_start']
return time_length * 1.1
def validate_length_in_time(length_in_time, t_obs_start):
"""Validate the estimate length in time compared to t_obs_start.

Parameters
----------
length_in_time : float
Estimated length in time.
t_obs_start
Observation start time.

Returns
-------
float
Valid length in time.
"""
if length_in_time < 2678400:
warn("Waveform duration is too short! Setting it to 1 month (2678400 s).")
length_in_time = 2678400
if length_in_time >= t_obs_start:
warn("Waveform duration is longer than data length! Setting it to `t_obs_start`.")
length_in_time = t_obs_start
return length_in_time * 1.1


def bbhx_phenomd_length_in_time(**params):
"""Compute the length in for BBHx PhenomD"""
from pycbc.waveform.waveform import get_imr_length

time_length = np.float64(get_imr_length("IMRPhenomD", **params))
return validate_length_in_time(time_length, params["t_obs_start"])


def bbhx_phenomhm_length_in_time(**params):
"""Compute the length in for BBHx PhenomHM"""
from pycbc.waveform.waveform import get_hm_length_in_time

# Max m mode is 4 for BBHx PhenomHM, use if the `mode_array` is not
# specified.
length_in_time = np.float64(
get_hm_length_in_time("IMRPhenomD", 4, **params)
)
return validate_length_in_time(length_in_time, params["t_obs_start"])


def interpolated_tf(m1, m2, m_mode=None, num_interp=100, f_lower=1e-4):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"BBHX_PhenomHM=BBHX_Phenom:waveform_setup",
],
"pycbc.waveform.length": [
"BBHX_PhenomD=BBHX_Phenom:imr_duration",
"BBHX_PhenomHM=BBHX_Phenom:imr_duration",
"BBHX_PhenomD=BBHX_Phenom:bbhx_phenomd_length_in_time",
"BBHX_PhenomHM=BBHX_Phenom:bbhx_phenomhm_length_in_time",
]
},

Expand Down
13 changes: 12 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import numpy as np
from pycbc.waveform import get_fd_det_waveform, get_fd_det_waveform_sequence
from pycbc.waveform import (
get_fd_det_waveform,
get_fd_det_waveform_sequence,
get_waveform_filter_length_in_time,
)
import pytest


Expand Down Expand Up @@ -72,3 +76,10 @@ def test_phenomhm_mode_array(params, mode_array):
params["mode_array"] = mode_array
wf = get_fd_det_waveform(**params)
assert len(wf) == 3


def test_length_in_time(params, approximant):
params["approximant"] = approximant
# print(params)
duration = get_waveform_filter_length_in_time(**params)
assert duration > 0