Source code for gwModels.waveforms.circular_models

#! /usr/bin/env python
#-*- coding: utf-8 -*-
#==============================================================================
#
#    FILE: circular_models.py
#
#    AUTHOR: Tousif Islam
#    CREATED: 11-01-2024
#    LAST MODIFIED: 05-28-2026
#    REVISION: ---
#==============================================================================
__author__ = "Tousif Islam"

import logging
import numpy as np

logger = logging.getLogger(__name__)

try:
    import gwsurrogate
except ImportError:
    gwsurrogate = None
    logger.info("gwsurrogate not installed; NRHybSur3dq8 will not be available")

try:
    import BHPTNRSurrogate
except ImportError:
    BHPTNRSurrogate = None
    logger.info("BHPTNRSurrogate not installed; BHPTNRSur1dq1e4 will not be available")


[docs] class genBHPTNRSur1dq1e4: """ Class to generate waveforms using the BHPTNRSur1dq1e4 model. """
[docs] def __init__(self, model): """ Initialize the genBHPTNRSur1dq1e4 object. Parameters: model: An instance of the BHPTNRSur1dq1e4 surrogate model. """ self.model = model
def _generate_raw_BHPTNRSur1dq1e4(self, model, params): """ Generate raw BHPTNRSur1dq1e4 waveforms directly from the surrogate library. Parameters: model: The surrogate model to be used for generating waveforms. params (dict): Dictionary containing parameters for the waveform generation, including mass ratio 'q'. Returns: tuple: (modes, times, hp, hc) """ modes, times, hp, hc = model(q=params["q"], ell=[2, 2, 3, 3, 4, 4], m=[2, 1, 3, 2, 4, 3], mode_sum=False, fake_neg_modes=False) return modes, times, hp, hc def _process_BHPTNRSur1dq1e4_output(self, modes, hp, hc): """ Process the output of BHPTNRSur1dq1e4 waveforms into a format compatible with gwNRHME. Parameters: modes (list): List of modes generated by the waveform model. hp (ndarray): Plus polarization waveforms. hc (ndarray): Cross polarization waveforms. Returns: dict: A dictionary mapping mode labels to the complex strain waveforms. """ hdict = {} flag = 0 for mode in modes: hdict['h_l%dm%d' % (mode[0], mode[1])] = hp[:, flag] + 1j * hc[:, flag] flag += 1 return hdict
[docs] def generate_BHPTNRSur1dq1e4(self, model, params): """ Generate BHPTNRSur1dq1e4 waveforms from the surrogate library. Parameters: model: The surrogate model used for generating waveforms. params (dict): Dictionary containing parameters for the waveform generation. Returns: tuple: (t_sur, h_sur) — time array and dictionary of waveform modes. """ modes, times, hp, hc = self._generate_raw_BHPTNRSur1dq1e4(model, params) t_sur = times h_sur = self._process_BHPTNRSur1dq1e4_output(modes, hp, hc) return t_sur, h_sur
[docs] class genNRHybSur3dq8: """ Class to generate waveforms using the NRHybSur3dq8 model. """
[docs] def __init__(self): """ Initialize the genNRHybSur3dq8 object and load the surrogate model. """ if gwsurrogate is None: raise ImportError("gwsurrogate is required for NRHybSur3dq8. " "Install via: pip install gwsurrogate") self.sur = gwsurrogate.LoadSurrogate('NRHybSur3dq8')
def _generate_raw_NRHybSur3dq8(self, params): """ Generate raw NRHybSur3dq8 waveforms from gwsurrogate. Parameters: params (dict): Dictionary containing parameters for waveform generation, including mass ratio 'q' and spins 's1z' and 's2z'. Returns: tuple: (t, h) — time array and dictionary of generated waveforms. """ q = params["q"] for key in ["s1z", "s2z"]: if key not in params: params[key] = 0 chiA = [0, 0, params["s1z"]] chiB = [0, 0, params["s2z"]] dt = 0.1 # 0.99 ensures the circular waveform is slightly longer than the eccentric one f_low = 0.99 * params['omega0'] / (np.pi) t, h, dyn = self.sur(q, chiA, chiB, dt=dt, f_low=f_low) return t, h def _process_NRHybSur3dq8_output(self, t, h): """ Process the output of NRHybSur3dq8 waveforms into a format compatible with gwNRHME. Parameters: t (ndarray): Time array of the generated waveforms. h (dict): Dictionary of waveforms generated by the NRHybSur3dq8 model. Returns: tuple: (t_sur, h_sur) — time array and dictionary of processed waveform modes. """ t_sur = t h_sur = {} h_sur['h_l2m1'] = h[(2, 1)] for mode in h.keys(): if mode != (2, 1) and mode[1] > 0: h_sur['h_l%dm%d' % (mode[0], mode[1])] = h[mode] return t_sur, h_sur
[docs] def generate_NRHybSur3dq8(self, params): """ Generate NRHybSur3dq8 waveforms from gwsurrogate. Parameters: params (dict): Dictionary containing parameters for waveform generation. Returns: tuple: (t_sur, h_sur) — time array and dictionary of generated waveform modes. """ t, h = self._generate_raw_NRHybSur3dq8(params) t_sur, h_sur = self._process_NRHybSur3dq8_output(t, h) return t_sur, h_sur