Skip to content

Commit

Permalink
Merge pull request #19 from mj-will/add-mf-min-argument
Browse files Browse the repository at this point in the history
Add option to specify `mf_min`
  • Loading branch information
WuShichao authored Aug 22, 2024
2 parents 51b0a4f + dad01f8 commit aaf6478
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions BBHX_Phenom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
from warnings import warn


def get_waveform_genner(log_mf_min, run_phenomd=True):
def get_waveform_genner(log_mf_min=None, mf_min=None, run_phenomd=True):
# See below where this function is called for description of how we handle
# log_mf_min.
mf_min = math.exp(log_mf_min/25.)
if mf_min is None:
mf_min = math.exp(log_mf_min/25.)
wave_gen = BBHWaveformFD(
amp_phase_kwargs=dict(run_phenomd=run_phenomd, mf_min=mf_min),
amp_phase_kwargs=dict(
run_phenomd=run_phenomd,
mf_min=mf_min,
),
)
return wave_gen


@functools.lru_cache(maxsize=128)
def cached_get_waveform_genner(log_mf_fin, run_phenomd=True):
def cached_get_waveform_genner(*args, **kwargs):
"""Cached version of get_waveform_genner"""
return get_waveform_genner(log_mf_fin, run_phenomd)
return get_waveform_genner(*args, **kwargs)


@functools.lru_cache(maxsize=10)
Expand Down Expand Up @@ -135,6 +139,7 @@ def _bbhx_fd(
num_interp=100,
interp_f_lower=1e-4,
cache_generator=True,
mf_min=None,
**params
):

Expand Down Expand Up @@ -163,8 +168,13 @@ def _bbhx_fd(
interp_f_lower : float
Lower frequency cutoff used for interpolation when computing the
chirp time.
mf_min : float, optional
Minimum frequency used by BBHx when performing interpolation. If
not specified, the value will be set based on the total mass and
minimum frequency.
cache_generator : bool
If true, the BBHx waveform generator is cached based on
If true, the BBHx waveform generator is cached based on the computed
``mf_min``. Must be ``False`` if ``mf_min`` is specfied.
Returns
-------
Expand Down Expand Up @@ -200,6 +210,7 @@ def _bbhx_fd(
num_interp = int(num_interp)
length = int(length) if length is not None else None
interp_f_lower = float(interp_f_lower)


if ref_frame == 'LISA':
t_ref_lisa = np.float64(params['tc']) + t_offset
Expand Down Expand Up @@ -279,14 +290,20 @@ def _bbhx_fd(
# So we round down to the nearest 1/25 of the logarithm of the frequency
log_mf_min = math.log(f_min*MTSUN_SI*(m1+m2)) * 25
if cache_generator:
if mf_min is not None:
raise RuntimeError(
"Cannot use `cache_generator` when `mf_min` is specified"
)
# Use int to round down
wave_gen = cached_get_waveform_genner(
int(log_mf_min),
mf_min=None,
run_phenomd=run_phenomd,
)
else:
wave_gen = get_waveform_genner(
log_mf_min,
mf_min=mf_min,
run_phenomd=run_phenomd,
)

Expand Down

0 comments on commit aaf6478

Please sign in to comment.