Skip to content

Commit

Permalink
Rationalize some calls to waveform properties (#4540)
Browse files Browse the repository at this point in the history
* rationalize some calls to waveform properties

* Only allow explictly listed names

* don't try to change function name

* g

g
  • Loading branch information
tdent authored Oct 19, 2023
1 parent f1e16ea commit 68e527b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
14 changes: 3 additions & 11 deletions pycbc/events/coinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@
from .eventmgr_cython import timecoincidence_findidxlen
from .eventmgr_cython import timecluster_cython

# Mapping used in background_bin_from_string to select approximant for
# duration function, if duration-based binning is used.
_APPROXIMANT_DURATION_MAP = {
'SEOBNRv2duration': 'SEOBNRv2',
'SEOBNRv4duration': 'SEOBNRv4',
'SEOBNRv5duration': 'SEOBNRv5_ROM'
}


def background_bin_from_string(background_bins, data):
""" Return template ids for each bin as defined by the format string
Expand Down Expand Up @@ -104,7 +96,7 @@ def background_bin_from_string(background_bins, data):
elif bin_type == 'chi_eff':
vals = pycbc.conversions.chi_eff(data['mass1'], data['mass2'],
data['spin1z'], data['spin2z'])
elif bin_type in ['SEOBNRv2Peak', 'SEOBNRv4Peak']:
elif bin_type.endswith('Peak'):
vals = pycbc.pnutils.get_freq(
'f' + bin_type,
data['mass1'],
Expand All @@ -113,14 +105,14 @@ def background_bin_from_string(background_bins, data):
data['spin2z']
)
cached_values[bin_type] = vals
elif bin_type in _APPROXIMANT_DURATION_MAP:
elif bin_type.endswith('duration'):
vals = pycbc.pnutils.get_imr_duration(
data['mass1'],
data['mass2'],
data['spin1z'],
data['spin2z'],
data['f_lower'],
approximant=_APPROXIMANT_DURATION_MAP[bin_type]
approximant=bin_type.replace('duration', '')
)
cached_values[bin_type] = vals
else:
Expand Down
12 changes: 6 additions & 6 deletions pycbc/pnutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def frequency_cutoff_from_name(name, m1, m2, s1z, s2z):
f : float or numpy.array
Frequency in Hz
"""
params = {"mass1":m1, "mass2":m2, "spin1z":s1z, "spin2z":s2z}
params = {"mass1": m1, "mass2": m2, "spin1z": s1z, "spin2z": s2z}
return named_frequency_cutoffs[name](params)

def _get_imr_duration(m1, m2, s1z, s2z, f_low, approximant="SEOBNRv4"):
Expand All @@ -532,20 +532,20 @@ def _get_imr_duration(m1, m2, s1z, s2z, f_low, approximant="SEOBNRv4"):
chi = lalsim.SimIMRPhenomBComputeChi(m1, m2, s1z, s2z)
time_length = lalsim.SimIMRSEOBNRv2ChirpTimeSingleSpin(
m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, chi, f_low)
elif approximant == 'IMRPhenomXAS':
elif approximant == "IMRPhenomXAS":
time_length = lalsim.SimIMRPhenomXASDuration(
m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, s1z, s2z, f_low)
elif approximant == "IMRPhenomD":
time_length = lalsim.SimIMRPhenomDChirpTime(
m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, s1z, s2z, f_low)
elif approximant == "SEOBNRv4":
# NB for no clear reason this function has f_low as first argument
elif approximant in ["SEOBNRv4", "SEOBNRv4_ROM"]:
# NB the LALSim function has f_low as first argument
time_length = lalsim.SimIMRSEOBNRv4ROMTimeOfFrequency(
f_low, m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, s1z, s2z)
elif approximant == 'SEOBNRv5_ROM':
elif approximant in ["SEOBNRv5", "SEOBNRv5_ROM"]:
time_length = lalsim.SimIMRSEOBNRv5ROMTimeOfFrequency(
f_low, m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, s1z, s2z)
elif approximant == 'SPAtmplt' or approximant == 'TaylorF2':
elif approximant in ["SPAtmplt", "TaylorF2"]:
chi = lalsim.SimInspiralTaylorF2ReducedSpinComputeChi(
m1, m2, s1z, s2z
)
Expand Down

0 comments on commit 68e527b

Please sign in to comment.