def print_fd_approximants(): """Only list the frequency-domain approximants in lalsimulation. """ napprox = lalsimulation.NumApproximants for i in range(napprox): if lalsimulation.SimInspiralImplementedFDApproximants(i): print i, lalsimulation.GetStringFromApproximant(i)
def _compute_waveform_comps(self, df, f_final): approx = lalsim.GetApproximantFromString(self.approximant) lmbda1 = lmbda2 = 0 # No tidal terms here ampO = -1 # Are these the correct values?? phaseO = -1 # Are these the correct values?? if lalsim.SimInspiralImplementedFDApproximants(approx): hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( self.orb_phase, df, self.m1 * MSUN_SI, self.m2 * MSUN_SI, self.spin1x, self.spin1y, self.spin1z, self.spin2x, self.spin2y, self.spin2z, self.bank.flow, f_final, self.bank.flow, 1e6 * PC_SI, self.iota, lmbda1, lmbda2, # irrelevant parameters for BBH None, None, # non-GR parameters ampO, phaseO, approx) else: hplus_fd, hcross_fd = lalsim.SimInspiralFD( self.orb_phase, df, self.m1 * MSUN_SI, self.m2 * MSUN_SI, self.spin1x, self.spin1y, self.spin1z, self.spin2x, self.spin2y, self.spin2z, self.bank.flow, f_final, self.bank.flow, 1e6 * PC_SI, 0, self.iota, lmbda1, lmbda2, # irrelevant parameters for BBH None, None, # non-GR parameters ampO, phaseO, approx) return hplus_fd, hcross_fd
def _compute_waveform_comps(self, df, f_final): approx = lalsim.GetApproximantFromString(self.approximant) if lalsim.SimInspiralImplementedFDApproximants(approx): hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( self.m1 * MSUN_SI, self.m2 * MSUN_SI, self.spin1x, self.spin1y, self.spin1z, self.spin2x, self.spin2y, self.spin2z, 1.e6 * PC_SI, self.iota, self.orb_phase, 0., 0., 0., df, self.flow, f_final, self.flow, None, approx) else: hplus_fd, hcross_fd = lalsim.SimInspiralFD( self.m1 * MSUN_SI, self.m2 * MSUN_SI, self.spin1x, self.spin1y, self.spin1z, self.spin2x, self.spin2y, self.spin2z, 1.e6 * PC_SI, self.iota, self.orb_phase, 0., 0., 0., df, self.flow, f_final, self.flow, None, approx) return hplus_fd, hcross_fd
def _compute_waveform(self, df, f_final): approx = lalsim.GetApproximantFromString(self.approximant) if lalsim.SimInspiralImplementedFDApproximants(approx): hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0., 0., self.spin1z, 0., 0., self.spin2z, 1e6 * PC_SI, 0., 0., 0., 0., 0., df, self.bank.flow, f_final, self.bank.flow, None, approx) else: hplus_fd, hcross_fd = lalsim.SimInspiralFD( phi0, df, self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0, 0, self.spin1z, 0, 0, self.spin2z, 1.e6 * PC_SI, 0., 0., 0., 0., 0., df, self.bank.flow, f_final, 40., None, approx) return hplus_fd
def _compute_waveform(self, df, f_final): phi0 = 0 # This is a reference phase, and not an intrinsic parameter approx = lalsim.GetApproximantFromString(self.approximant) if lalsim.SimInspiralImplementedFDApproximants(approx): hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0., 0., self.spin1z, 0., 0., self.spin2z, 1e6 * PC_SI, 0., 0., 0., 0., 0., df, self.flow, f_final, self.flow, None, approx) else: hplus_fd, hcross_fd = lalsim.SimInspiralFD( phi0, df, self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0, 0, self.spin1z, 0, 0, self.spin2z, 1.e6 * PC_SI, 0., 0., 0., 0., 0., df, self.flow, f_final, 40., None, approx) return hplus_fd
def _compute_waveform(self, df, f_final): flags = lalsim.SimInspiralCreateWaveformFlags() phi0 = 0 # This is a reference phase, and not an intrinsic parameter lmbda1 = lmbda2 = 0 # No tidal terms here ampO = -1 # Are these the correct values?? phaseO = -1 # Are these the correct values?? approx = lalsim.GetApproximantFromString(self.approximant) if lalsim.SimInspiralImplementedFDApproximants(approx): hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( 0, df, self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0., 0., self.spin1z, 0., 0., self.spin2z, self.bank.flow, f_final, self.bank.flow, 1e6 * PC_SI, 0., 0., 0., flags, None, ampO, phaseO, approx) else: hplus_fd, hcross_fd = lalsim.SimInspiralFD( phi0, df, self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0, 0, self.spin1z, 0, 0, self.spin2z, self.bank.flow, f_final, 40.0, 1e6 * PC_SI, 0, 0, lmbda1, lmbda2, # irrelevant parameters for BBH None, None, # non-GR parameters ampO, phaseO, approx) return hplus_fd
import pytest import lalsimulation as lalsim # Function to get the name of a function def get_name(f): return f.__name__ # Set of functions to test func_list = [ lalsim.SimInspiralGetSpinSupportFromApproximant, lalsim.SimInspiralGetSpinFreqFromApproximant, lalsim.SimInspiralApproximantAcceptTestGRParams ] # Loop over all implemented TD or FD approximants IMPLEMENTED = [ k for k in range(lalsim.NumApproximants) if lalsim.SimInspiralImplementedTDApproximants(k) or lalsim.SimInspiralImplementedFDApproximants(k) ] @pytest.mark.parametrize("func", func_list, ids=get_name) @pytest.mark.parametrize("k", IMPLEMENTED, ids=lalsim.GetStringFromApproximant) def test_wf_property_lists(k, func): func(k) if __name__ == '__main__': args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-wf_property_lists.xml"] sys.exit(pytest.main(args=[__file__] + args))
float(p['polarization']), float(p['delta_t'])) hp = TimeSeries(hp.data.data[:], delta_t=hp.deltaT, epoch=hp.epoch) hc = TimeSeries(hc.data.data[:], delta_t=hc.deltaT, epoch=hc.epoch) return hp, hc for approx_enum in xrange(0, lalsimulation.NumApproximants): if lalsimulation.SimInspiralImplementedTDApproximants(approx_enum): approx_name = lalsimulation.GetStringFromApproximant(approx_enum) _lalsim_enum[approx_name] = approx_enum _lalsim_td_approximants[approx_name] = _lalsim_td_waveform for approx_enum in xrange(0, lalsimulation.NumApproximants): if lalsimulation.SimInspiralImplementedFDApproximants(approx_enum): approx_name = lalsimulation.GetStringFromApproximant(approx_enum) _lalsim_enum[approx_name] = approx_enum _lalsim_fd_approximants[approx_name] = _lalsim_fd_waveform # sine-Gaussian burst for approx_enum in xrange(0, lalsimulation.NumApproximants): if lalsimulation.SimInspiralImplementedFDApproximants(approx_enum): approx_name = lalsimulation.GetStringFromApproximant(approx_enum) _lalsim_enum[approx_name] = approx_enum _lalsim_sgburst_approximants[approx_name] = _lalsim_sgburst_waveform cpu_sgburst = _lalsim_sgburst_approximants cpu_td = dict(_lalsim_td_approximants.items()) cpu_fd = _lalsim_fd_approximants
def _base_lal_cbc_fd_waveform( frequency_array, mass_1, mass_2, luminosity_distance, theta_jn, phase, a_1=0.0, a_2=0.0, tilt_1=0.0, tilt_2=0.0, phi_12=0.0, phi_jl=0.0, lambda_1=0.0, lambda_2=0.0, eccentricity=0.0, **waveform_kwargs): """ Generate a cbc waveform model using lalsimulation Parameters ========== frequency_array: array_like The frequencies at which we want to calculate the strain mass_1: float The mass of the heavier object in solar masses mass_2: float The mass of the lighter object in solar masses luminosity_distance: float The luminosity distance in megaparsec a_1: float Dimensionless primary spin magnitude tilt_1: float Primary tilt angle phi_12: float Azimuthal angle between the component spins a_2: float Dimensionless secondary spin magnitude tilt_2: float Secondary tilt angle phi_jl: float Azimuthal angle between the total and orbital angular momenta theta_jn: float Orbital inclination phase: float The phase at coalescence eccentricity: float Binary eccentricity lambda_1: float Tidal deformability of the more massive object lambda_2: float Tidal deformability of the less massive object kwargs: dict Optional keyword arguments Returns ======= dict: A dictionary with the plus and cross polarisation strain modes """ import lal import lalsimulation as lalsim waveform_approximant = waveform_kwargs['waveform_approximant'] reference_frequency = waveform_kwargs['reference_frequency'] minimum_frequency = waveform_kwargs['minimum_frequency'] maximum_frequency = waveform_kwargs['maximum_frequency'] catch_waveform_errors = waveform_kwargs['catch_waveform_errors'] pn_spin_order = waveform_kwargs['pn_spin_order'] pn_tidal_order = waveform_kwargs['pn_tidal_order'] pn_phase_order = waveform_kwargs['pn_phase_order'] pn_amplitude_order = waveform_kwargs['pn_amplitude_order'] waveform_dictionary = waveform_kwargs.get( 'lal_waveform_dictionary', lal.CreateDict() ) approximant = lalsim_GetApproximantFromString(waveform_approximant) if pn_amplitude_order != 0: start_frequency = lalsim.SimInspiralfLow2fStart( minimum_frequency, int(pn_amplitude_order), approximant) else: start_frequency = minimum_frequency delta_frequency = frequency_array[1] - frequency_array[0] frequency_bounds = ((frequency_array >= minimum_frequency) * (frequency_array <= maximum_frequency)) luminosity_distance = luminosity_distance * 1e6 * utils.parsec mass_1 = mass_1 * utils.solar_mass mass_2 = mass_2 * utils.solar_mass iota, spin_1x, spin_1y, spin_1z, spin_2x, spin_2y, spin_2z = bilby_to_lalsimulation_spins( theta_jn=theta_jn, phi_jl=phi_jl, tilt_1=tilt_1, tilt_2=tilt_2, phi_12=phi_12, a_1=a_1, a_2=a_2, mass_1=mass_1, mass_2=mass_2, reference_frequency=reference_frequency, phase=phase) longitude_ascending_nodes = 0.0 mean_per_ano = 0.0 lalsim.SimInspiralWaveformParamsInsertPNSpinOrder( waveform_dictionary, int(pn_spin_order)) lalsim.SimInspiralWaveformParamsInsertPNTidalOrder( waveform_dictionary, int(pn_tidal_order)) lalsim.SimInspiralWaveformParamsInsertPNPhaseOrder( waveform_dictionary, int(pn_phase_order)) lalsim.SimInspiralWaveformParamsInsertPNAmplitudeOrder( waveform_dictionary, int(pn_amplitude_order)) lalsim_SimInspiralWaveformParamsInsertTidalLambda1( waveform_dictionary, lambda_1) lalsim_SimInspiralWaveformParamsInsertTidalLambda2( waveform_dictionary, lambda_2) for key, value in waveform_kwargs.items(): func = getattr(lalsim, "SimInspiralWaveformParamsInsert" + key, None) if func is not None: func(waveform_dictionary, value) if waveform_kwargs.get('numerical_relativity_file', None) is not None: lalsim.SimInspiralWaveformParamsInsertNumRelData( waveform_dictionary, waveform_kwargs['numerical_relativity_file']) if ('mode_array' in waveform_kwargs) and waveform_kwargs['mode_array'] is not None: mode_array = waveform_kwargs['mode_array'] mode_array_lal = lalsim.SimInspiralCreateModeArray() for mode in mode_array: lalsim.SimInspiralModeArrayActivateMode(mode_array_lal, mode[0], mode[1]) lalsim.SimInspiralWaveformParamsInsertModeArray(waveform_dictionary, mode_array_lal) if lalsim.SimInspiralImplementedFDApproximants(approximant): wf_func = lalsim_SimInspiralChooseFDWaveform else: wf_func = lalsim_SimInspiralFD try: hplus, hcross = wf_func( mass_1, mass_2, spin_1x, spin_1y, spin_1z, spin_2x, spin_2y, spin_2z, luminosity_distance, iota, phase, longitude_ascending_nodes, eccentricity, mean_per_ano, delta_frequency, start_frequency, maximum_frequency, reference_frequency, waveform_dictionary, approximant) except Exception as e: if not catch_waveform_errors: raise else: EDOM = (e.args[0] == 'Internal function call failed: Input domain error') if EDOM: failed_parameters = dict(mass_1=mass_1, mass_2=mass_2, spin_1=(spin_1x, spin_2y, spin_1z), spin_2=(spin_2x, spin_2y, spin_2z), luminosity_distance=luminosity_distance, iota=iota, phase=phase, eccentricity=eccentricity, start_frequency=start_frequency) logger.warning("Evaluating the waveform failed with error: {}\n".format(e) + "The parameters were {}\n".format(failed_parameters) + "Likelihood will be set to -inf.") return None else: raise h_plus = np.zeros_like(frequency_array, dtype=complex) h_cross = np.zeros_like(frequency_array, dtype=complex) if len(hplus.data.data) > len(frequency_array): logger.debug("LALsim waveform longer than bilby's `frequency_array`" + "({} vs {}), ".format(len(hplus.data.data), len(frequency_array)) + "probably because padded with zeros up to the next power of two length." + " Truncating lalsim array.") h_plus = hplus.data.data[:len(h_plus)] h_cross = hcross.data.data[:len(h_cross)] else: h_plus[:len(hplus.data.data)] = hplus.data.data h_cross[:len(hcross.data.data)] = hcross.data.data h_plus *= frequency_bounds h_cross *= frequency_bounds if wf_func == lalsim_SimInspiralFD: dt = 1 / hplus.deltaF + (hplus.epoch.gpsSeconds + hplus.epoch.gpsNanoSeconds * 1e-9) time_shift = np.exp(-1j * 2 * np.pi * dt * frequency_array[frequency_bounds]) h_plus[frequency_bounds] *= time_shift h_cross[frequency_bounds] *= time_shift return dict(plus=h_plus, cross=h_cross)
base_dir ='' # all directories are provided as full path names if opts.choose_data_LI_seglen: cmd_event = "gracedb_legacy download " + opts.gracedb_id + " coinc.xml" os.system(cmd_event) event_dict = retrieve_event_from_coinc("coinc.xml") P=lalsimutils.ChooseWaveformParams() P.m1 = event_dict["m1"]*lal.MSUN_SI; P.m2=event_dict["m2"]*lal.MSUN_SI; P.s1z = event_dict["s1z"]; P.s2z = event_dict["s2z"] P.fmin = opts.fmin # fmin we will use internally T_wave = lalsimutils.estimateWaveformDuration(P) +2 # 2 second buffer on end; note that with next power of 2, will go up to 4s T_wave_round = lalsimutils.nextPow2( T_wave) # For frequency-domain approximants, I need another factor of 2! # We have an extra buffer if lalsim.SimInspiralImplementedFDApproximants(P.approx)==1: print( " FD approximant, needs extra buffer for RIFT at present ") T_wave_round *=2 print( " Assigning auto-selected segment length ", T_wave_round) opts.data_LI_seglen = T_wave_round # Problem with SEOBNRv3 starting frequencies mtot_msun = event_dict["m1"]+event_dict["m2"] if ('SEOB' in opts.approx) and mtot_msun > 90*(20./opts.fmin): fmin_template = int(14*(90/mtot_msun)) # should also decrease this due to lmax! print( " SEOB starting frequencies need to be reduced for this event; trying ", fmin_template) is_analysis_precessing =False if opts.approx == "SEOBNRv3" or opts.approx == "NRSur7dq2" or opts.approx == "NRSur7dq4" or (opts.approx == 'SEOBNv3_opt') or (opts.approx == 'IMRPhenomPv2') or (opts.approx =="SEOBNRv4P" ) or (opts.approx == "SEOBNRv4PHM") or ('SpinTaylor' in opts.approx):
def _base_lal_cbc_fd_waveform(frequency_array, mass_1, mass_2, luminosity_distance, theta_jn, phase, a_1=0.0, a_2=0.0, tilt_1=0.0, tilt_2=0.0, phi_12=0.0, phi_jl=0.0, lambda_1=0.0, lambda_2=0.0, eccentricity=0.0, **waveform_kwargs): """ Generate a cbc waveform model using lalsimulation Parameters ---------- frequency_array: array_like The frequencies at which we want to calculate the strain mass_1: float The mass of the heavier object in solar masses mass_2: float The mass of the lighter object in solar masses luminosity_distance: float The luminosity distance in megaparsec a_1: float Dimensionless primary spin magnitude tilt_1: float Primary tilt angle phi_12: float Azimuthal angle between the component spins a_2: float Dimensionless secondary spin magnitude tilt_2: float Secondary tilt angle phi_jl: float Azimuthal angle between the total and orbital angular momenta theta_jn: float Orbital inclination phase: float The phase at coalescence eccentricity: float Binary eccentricity lambda_1: float Tidal deformability of the more massive object lambda_2: float Tidal deformability of the less massive object kwargs: dict Optional keyword arguments Returns ------- dict: A dictionary with the plus and cross polarisation strain modes """ waveform_approximant = waveform_kwargs['waveform_approximant'] reference_frequency = waveform_kwargs['reference_frequency'] minimum_frequency = waveform_kwargs['minimum_frequency'] maximum_frequency = waveform_kwargs['maximum_frequency'] catch_waveform_errors = waveform_kwargs['catch_waveform_errors'] pn_spin_order = waveform_kwargs['pn_spin_order'] pn_tidal_order = waveform_kwargs['pn_tidal_order'] pn_phase_order = waveform_kwargs['pn_phase_order'] pn_amplitude_order = waveform_kwargs['pn_amplitude_order'] approximant = lalsim_GetApproximantFromString(waveform_approximant) if pn_amplitude_order != 0: start_frequency = lalsim.SimInspiralfLow2fStart( minimum_frequency, int(pn_amplitude_order), approximant) else: start_frequency = minimum_frequency delta_frequency = frequency_array[1] - frequency_array[0] frequency_bounds = ((frequency_array >= minimum_frequency) * (frequency_array <= maximum_frequency)) luminosity_distance = luminosity_distance * 1e6 * utils.parsec mass_1 = mass_1 * utils.solar_mass mass_2 = mass_2 * utils.solar_mass iota, spin_1x, spin_1y, spin_1z, spin_2x, spin_2y, spin_2z = bilby_to_lalsimulation_spins( theta_jn=theta_jn, phi_jl=phi_jl, tilt_1=tilt_1, tilt_2=tilt_2, phi_12=phi_12, a_1=a_1, a_2=a_2, mass_1=mass_1, mass_2=mass_2, reference_frequency=reference_frequency, phase=phase) longitude_ascending_nodes = 0.0 mean_per_ano = 0.0 waveform_dictionary = lal.CreateDict() lalsim.SimInspiralWaveformParamsInsertPNSpinOrder(waveform_dictionary, int(pn_spin_order)) lalsim.SimInspiralWaveformParamsInsertPNTidalOrder(waveform_dictionary, int(pn_tidal_order)) lalsim.SimInspiralWaveformParamsInsertPNPhaseOrder(waveform_dictionary, int(pn_phase_order)) lalsim.SimInspiralWaveformParamsInsertPNAmplitudeOrder( waveform_dictionary, int(pn_amplitude_order)) lalsim_SimInspiralWaveformParamsInsertTidalLambda1(waveform_dictionary, lambda_1) lalsim_SimInspiralWaveformParamsInsertTidalLambda2(waveform_dictionary, lambda_2) if 'modearray' in waveform_kwargs: modearray = waveform_kwargs['modearray'] mode_array = lalsim.SimInspiralCreateModeArray() for mode in modearray: lalsim.SimInspiralModeArrayActivateMode(mode_array, mode[0], mode[1]) lalsim.SimInspiralWaveformParamsInsertModeArray( waveform_dictionary, mode_array) if lalsim.SimInspiralImplementedFDApproximants(approximant): wf_func = lalsim_SimInspiralChooseFDWaveform else: wf_func = lalsim_SimInspiralFD try: hplus, hcross = wf_func(mass_1, mass_2, spin_1x, spin_1y, spin_1z, spin_2x, spin_2y, spin_2z, luminosity_distance, iota, phase, longitude_ascending_nodes, eccentricity, mean_per_ano, delta_frequency, start_frequency, maximum_frequency, reference_frequency, waveform_dictionary, approximant) except Exception as e: if not catch_waveform_errors: raise else: EDOM = (e.args[0] == 'Internal function call failed: Input domain error') if EDOM: failed_parameters = dict( mass_1=mass_1, mass_2=mass_2, spin_1=(spin_1x, spin_2y, spin_1z), spin_2=(spin_2x, spin_2y, spin_2z), luminosity_distance=luminosity_distance, iota=iota, phase=phase, eccentricity=eccentricity, start_frequency=start_frequency) logger.warning( "Evaluating the waveform failed with error: {}\n".format(e) + "The parameters were {}\n".format(failed_parameters) + "Likelihood will be set to -inf.") return None else: raise h_plus = np.zeros_like(frequency_array, dtype=np.complex) h_cross = np.zeros_like(frequency_array, dtype=np.complex) if len(hplus.data.data) > len(frequency_array): raise ValueError("Waveform longer than frequency array") h_plus[:len(hplus.data.data)] = hplus.data.data h_cross[:len(hcross.data.data)] = hcross.data.data h_plus *= frequency_bounds h_cross *= frequency_bounds return dict(plus=h_plus, cross=h_cross)