def _compute_waveform(self, df, f_final): approx = lalsim.GetApproximantFromString("IMRPhenomP") phi0 = 0 # what is phi0? lmbda1 = lmbda2 = 0 ampO = 3 phaseO = 7 # are these PN orders correct for PhenomP? hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( phi0, 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, 40.0, # reference frequency, want it to be fixed to a constant value always and forever 1e6 * PC_SI, # irrelevant parameter for banks/banksims self.iota, lmbda1, lmbda2, # irrelevant parameters for BBH None, None, # non-GR parameters ampO, phaseO, approx) # project onto detector return project_hplus_hcross(hplus_fd, hcross_fd, self.theta, self.phi, self.psi)
def get_hF2(indx, ifo): global opts P = P2_list[indx % nlines2].manual_copy() # looping if not (opts.fmin_template2 is None): P.fmin = opts.fmin_template2 if not (opts.fref is None): P.fref = opts.fref else: P.ref = P.fmin P.radec = True P.tref = P2_list[indx % nlines2].tref # copy, this is an allocated object P.deltaF = df P.deltaT = 1. / opts.srate P.detector = ifo P.approx = lalsim.GetApproximantFromString( opts.approx2) # override the XML. Can screw you up if P.approx == lalsim.IMRPhenomPv2: cosbeta = np.cos(P.extract_param('beta')) my_phase = np.pi - np.pi / 2 dt = 20 * ( P.m1 + P.m2 ) / lal.MSUN_SI * lalsimutils.MsunInSec # ad hoc factor .. there is apparently a timeshift of Pv2 relative to PD of about 20 M P.tref += dt phiJL_now = P.extract_param('phiJL') psi_now = P.psi P.assign_param('phiJL', phiJL_now - my_phase) # Estimate P.psi = psi_now # fix L alignment, not J P.phiref += my_phase P.phiref += np.pi / 2 if opts.verbose: P.print_params() hF = lalsimutils.non_herm_hoff(P) return hF
def hplus_of_f(m1, m2, s1, s2, f_min, f_max, delta_f): farr = numpy.linspace(0, f_max, f_max / delta_f + delta_f) spin1 = [0., 0., s1] spin2 = [0., 0., s2] hp, hc = lalsim.SimInspiralFD( m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, spin1[0], spin1[1], spin1[2], spin2[0], spin2[1], spin2[2], 1.0, # distance (m) 0.0, 0.0, # reference orbital phase (rad) 0.0, # longitude of ascending nodes (rad) 0.0, 0.0, # mean anomaly of periastron delta_f, f_min, f_max + delta_f, 100., # reference frequency (Hz) None, # LAL dictionary containing accessory parameters lalsim.GetApproximantFromString("IMRPhenomD")) assert hp.data.length > 0, "huh!? h+ has zero length!" return hp.data.data[:len(farr)]
def get_hF2_NR(indx, ifo): P_here = P2_list[indx % nlines2] wfP2.P.radec = True wfP2.P.m1 = P_here.m1 wfP2.P.m2 = P_here.m2 wfP2.P.dist = P_here.dist wfP2.P.incl = P_here.incl wfP2.P.theta = P_here.theta wfP2.P.phi = P_here.phi wfP2.P.tref = P_here.tref wfP2.P.psi = P_here.psi wfP2.P.phiref = P_here.phiref wfP2.P.fmin = opts.fmin wfP2.P.deltaF = df wfP2.P.deltaT = 1. / opts.srate wfP2.P.detector = ifo wfP2.P.approx = lalsim.GetApproximantFromString( opts.approx2) # override the XML. Can screw you up (ref spins) if opts.verbose: wfP2.P.print_params() hF = wfP2.non_herm_hoff() return hF
def spin_tidal_IMRPhenomD_FD(m1, m2, s1z, s2z, lambda1, lambda2, f_min, f_max, deltaF=1.0/128.0, delta_t=1.0/16384.0, distance=1.0, inclination=0.0, approximant='IMRPhenomD_NRTidal', verbose=True): # print m1, m2, s1z, s2z, lambda1, lambda2, f_min, delta_t, distance, inclination f_ref = 0. phiRef = 0. # Must have aligned spin s1x, s1y, s2x, s2y = 0., 0., 0., 0. # Eccentricity is not part of the model longAscNodes = 0. eccentricity = 0. meanPerAno = 0. lal_approx = LS.GetApproximantFromString(approximant) # Insert matter parameters lal_params = lal.CreateDict() LS.SimInspiralWaveformParamsInsertTidalLambda1(lal_params, lambda1) LS.SimInspiralWaveformParamsInsertTidalLambda2(lal_params, lambda2) # Evaluate FD waveform Hp, Hc = LS.SimInspiralFD( m1*lal.MSUN_SI, m2*lal.MSUN_SI, s1x, s1y, s1z, s2x, s2y, s2z, distance*lal.PC_SI, inclination, phiRef, longAscNodes, eccentricity, meanPerAno, deltaF, f_min, f_max, f_ref, lal_params, lal_approx) f = deltaF * np.arange(Hp.data.length) return f, Hp, Hc
def get_final_freq(approx, m1, m2, s1z, s2z): """ Returns the LALSimulation function which evaluates the final (highest) frequency for a given approximant using given template parameters. NOTE: TaylorTx and TaylorFx are currently all given an ISCO cutoff !! Parameters ---------- approx : string Name of the approximant e.g. 'EOBNRv2' m1 : float or numpy.array First component mass in solar masses m2 : float or numpy.array Second component mass in solar masses s1z : float or numpy.array First component dimensionless spin S_1/m_1^2 projected onto L s2z : float or numpy.array Second component dimensionless spin S_2/m_2^2 projected onto L Returns ------- f : float or numpy.array Frequency in Hz """ lalsim_approx = lalsimulation.GetApproximantFromString(approx) return _vec_get_final_freq(lalsim_approx, m1, m2, s1z, s2z)
def generateWfparameters(opts): '''Turn parameters specified by input file and/or command line options into parameter dictionary that can be used for waveform generation.''' optsDict = vars(opts) inputpar = copy.deepcopy(optsDict) inputpar['m1'] *= lal.MSUN_SI inputpar['m2'] *= lal.MSUN_SI inputpar['distance'] *= (1.e6 * lal.PC_SI) inputpar['approximant'] = lalsim.GetApproximantFromString( inputpar['approximant']) if (inputpar['sampleRate'] != defSampleRate): inputpar['deltaT'] = 1./inputpar['sampleRate'] optsDict['deltaT'] = inputpar['deltaT'] domain = optsDict['domain'] wfinputpar=[inputpar[name] for name in paramnames[domain]] LALpars=lal.CreateDict() if (inputpar['lambda1']): lalsim.SimInspiralWaveformParamsInsertTidalLambda1(LALpars,inputpar['lambda1']) if (inputpar['lambda2']): lalsim.SimInspiralWaveformParamsInsertTidalLambda2(LALpars,inputpar['lambda2']) if (inputpar['ampOrder']!=-1): lalsim.SimInspiralWaveformParamsInsertPNAmplitudeOrder(LALpars,inputpar['ampOrder']) if (inputpar['phaseOrder']!=-1): lalsim.SimInspiralWaveformParamsInsertPNPhaseOrder(LALpars,inputpar['phaseOrder']) wfinputpar.append(LALpars) wfinputpar.append(inputpar['approximant']) return domain, wfinputpar, optsDict
def tmplttime(f0, m1, m2, j1, j2, approx): dt = 1.0 / 16384.0 approximant = lalsim.GetApproximantFromString(approx) hp, hc = lalsim.SimInspiralChooseTDWaveform(phiRef=0, deltaT=dt, m1=m1, m2=m2, s1x=0, s1y=0, s1z=j1, s2x=0, s2y=0, s2z=j2, f_min=f0, f_ref=0, r=1, i=0, lambda1=0, lambda2=0, waveFlags=None, nonGRparams=None, amplitudeO=0, phaseO=0, approximant=approximant) h = numpy.array(hp.data.data, dtype=complex) h += 1j * numpy.array(hc.data.data, dtype=complex) try: n = list(abs(h)).index(0) except ValueError: n = len(h) return n * hp.deltaT
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 hfpc(f, Mc, eta, chi1x, chi1y, chi1z, chi2x, chi2y, chi2z, DL, tc, phic, iota, approximant, fRef=0., phiRef=0.): f_min = f[0] delta_f = f[1] - f[0] f_max = f[-1] + delta_f if not fRef: fRef = f_min m1, m2 = m1_m2_of_M_eta(M_of_Mc_eta(Mc, eta), eta) m1 *= Msun m2 *= Msun r = DL * Mpc approx = lalsim.GetApproximantFromString(approximant) hPlus, hCross = lalsim.SimInspiralChooseFDWaveform(m1=m1, m2=m2, S1x=chi1x, S1y=chi1y, S1z=chi1z, S2x=chi2x, S2y=chi2y, S2z=chi2z, distance=r, inclination=iota, phiRef=phiRef, longAscNodes=0., eccentricity=0., meanPerAno=0., deltaF=delta_f, f_min=f_min, f_max=f_max, f_ref=fRef, LALpars=None, approximant=approx) pf = exp(1j * (2 * f * pi * tc - phic)) i0 = int(round((f_min - hPlus.f0) / delta_f)) hfp = pf * hPlus.data.data[i0:i0 + len(f)] hfc = pf * hCross.data.data[i0:i0 + len(f)] return hfp, hfc
def gstlal_valid_approximant(appx_str): try: lalsim.GetApproximantFromString(str(appx_str)) except RuntimeError: raise ValueError("Approximant not supported by lalsimulation: %s" % appx_str) if appx_str not in gstlal_approximants: raise ValueError( "Approximant not currently supported by gstlal, but is supported by lalsimulation: %s. Please consider preparing a patch" % appx_str)
def overestimate_j_from_chi(chi): """ Overestimate final black hole spin """ return min( max( lalsim.SimIMREOBFinalMassSpin( 1, 1, [0, 0, chi], [0, 0, chi], lalsim.GetApproximantFromString('SEOBNRv2'))[2], abs(chi)), 0.998)
def test_approximant(name, i): a = lalsim.GetApproximantFromString(name) assert a == i, ( "The Approximant enum is modified in an non-backward-compatible way, " "Approximant {name} is {a} but it should be {i}; " "please append new approximants to the Approximants enum in LALSimInspiral.h, " "rather than reordering the list".format( i=i, a=a, name=name, ))
def _waveform(param): # FIXME: Need to be fixed when we take into account precession. m1, m2, a1z, a2z = param hp, _ = lalsimulation.SimInspiralChooseFDWaveform( m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, 0.0, 0.0, a1z, 0.0, 0.0, a2z, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, deltaF, flow, fhigh, flow, None, lalsimulation.GetApproximantFromString(approximant)) hp = hp.data.data[start_index::] if quadratic: return np.conj(hp) * hp else: return hp
def recalculate_waveform(conf): '''Reads single data set and returns both the reference waveform and the newly calculated waveform with the same parameters. Returns: [hpref, hcref, hpnew, hcnew] ''' approx = lalsim.GetApproximantFromString( conf.get('approximant', 'approximant')) domain = conf.get('approximant', 'domain') if domain == 'TD': hpref, hcref = [ np.array(map(float, (conf.get('waveform-data', l)).split())) for l in ['hp', 'hc'] ] if domain == 'FD': hpRref, hpIref, hcRref, hcIref = [ np.array(map(float, (conf.get('waveform-data', l)).split())) for l in ['hp_real', 'hp_imag', 'hc_real', 'hc_imag'] ] hpref = hpRref + 1j * hpIref hcref = hcRref + 1j * hcIref names = CheckReferenceWaveforms.paramnames[domain] parDict = dict([ (p, CheckReferenceWaveforms.paramtype[p](conf.get('parameters', p))) for p in conf.options('parameters') ]) parDict['m1'] *= lal.MSUN_SI parDict['m2'] *= lal.MSUN_SI parDict['distance'] *= (1.e6 * lal.PC_SI) params = [parDict[name] for name in names] LALpars = lal.CreateDict() try: tmp = parDict['lambda1'] except: tmp = 0. if (tmp): lalsim.SimInspiralWaveformParamsInsertTidalLambda1( LALpars, parDict['lambda1']) try: tmp = parDict['lambda2'] except: tmp = 0. if (tmp): lalsim.SimInspiralWaveformParamsInsertTidalLambda2( LALpars, parDict['lambda2']) params.append(LALpars) params.append(approx) hp, hc = waveformgenerator(domain, params) return [hpref, hcref, hp, hc]
def legacy_approximant_name(apx): """Convert the old style xml approximant name to a name and phase_order. Alex: I hate this function. Please delet this when we use Collin's new tables. """ apx = str(apx) try: order = sim.GetOrderFromString(apx) except: print("Warning: Could not read phase order from string, using default") order = -1 name = sim.GetStringFromApproximant(sim.GetApproximantFromString(apx)) return name, order
def _compute_waveform(self, df, f_final): """ The ROM is a frequency domain waveform, so easier. """ # get hptilde approx_enum = lalsim.GetApproximantFromString( 'SEOBNRv2_ROM_DoubleSpin') flags = lalsim.SimInspiralCreateWaveformFlags() htilde, _ = 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, 1, 8, approx_enum) return htilde
def _compute_waveform(self, df, f_final): phi0 = 0 # This is a reference phase, and not an intrinsic parameter LALpars = lal.CreateDict() approx = lalsim.GetApproximantFromString(self.approx_name) hplus_fd, hcross_fd = lalsim.SimInspiralChooseFDWaveform( self.m1 * MSUN_SI, self.m2 * MSUN_SI, 0., 0., self.spin1z, 0., 0., self.spin2z, 1.e6 * PC_SI, 0., phi0, 0., 0., 0., df, self.flow, f_final, self.flow, LALpars, approx) # Must set values greater than _get_f_final to 0 act_f_max = self._get_f_final() f_max_idx = int(act_f_max / df + 0.999) hplus_fd.data.data[f_max_idx:] = 0 return hplus_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_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): 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 generateWfparameters(opts): '''Turn parameters specified by input file and/or command line options into parameter dictionary that can be used for waveform generation.''' optsDict = vars(opts) inputpar = copy.deepcopy(optsDict) inputpar['m1'] *= lal.MSUN_SI inputpar['m2'] *= lal.MSUN_SI inputpar['distance'] *= (1.e6 * lal.PC_SI) inputpar['approximant'] = lalsim.GetApproximantFromString( inputpar['approximant']) inputpar.update({'nonGRparams': None, 'waveformFlags': None}) # nonGRparams and waveformsFlags currently not supported if (inputpar['sampleRate'] != defSampleRate): inputpar['deltaT'] = 1. / inputpar['sampleRate'] optsDict['deltaT'] = inputpar['deltaT'] return inputpar, optsDict
def get_approximant_and_orders_from_string(s): """Determine the approximant, amplitude order, and phase order for a string of the form "TaylorT4threePointFivePN". In this example, the waveform is "TaylorT4" and the phase order is 7 (twice 3.5). If the input contains the substring "restricted" or "Restricted", then the amplitude order is taken to be 0. Otherwise, the amplitude order is the same as the phase order.""" # SWIG-wrapped functions apparently do not understand Unicode, but # often the input argument will come from a Unicode XML file. s = str(s) approximant = lalsimulation.GetApproximantFromString(s) try: phase_order = lalsimulation.GetOrderFromString(s) except RuntimeError: phase_order = -1 if 'restricted' in s or 'Restricted' in s: amplitude_order = 0 else: amplitude_order = phase_order return approximant, amplitude_order, phase_order
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
def generate_waveform(m1, m2): mtot = (m1 + m2) * lal.MTSUN_SI f_min = 20.0 f_max = 2048.0 df = 1. / 32. f_rescaled_min = f_min * mtot f_rescaled_max = f_max * mtot df_rescaled = mtot * df hptilde, hctilde = lalsim.SimInspiralChooseFDWaveform( #where is its definition and documentation???? m1 * lalsim.lal.MSUN_SI, #m1 m2 * lalsim.lal.MSUN_SI, #m2 0., 0., .5, #spin vector 1 0., 0., 0., #spin vector 2 1. * 1e6 * lalsim.lal.PC_SI, #distance to source 0., #inclination 0., #phi ref 0., #longAscNodes 0., #eccentricity 0., #meanPerAno 1e-3, # frequency incremental step f_min, # lowest value of frequency f_max, # highest value of frequency f_min, #some reference value of frequency (??) lal.CreateDict(), #some lal dictionary # lalsim.GetApproximantFromString('IMRPHenomPv2') #approx method for the model lalsim.GetApproximantFromString('SEOBNRv4_ROM' ) #approx method for the model ) frequency = np.linspace(0.0, f_max, hptilde.data.length) rescaled_frequency = frequency * mtot print(mtot) return frequency, rescaled_frequency, hptilde.data.data + 1j * hctilde.data.data
def _compute_waveform(self, df, f_final): phi0 = 0 # This is a reference phase, and not an intrinsic parameter lmbda1 = lmbda2 = 0 # No tidal terms here ampO = 0 phaseO = 7 approx = lalsim.GetApproximantFromString(self.approx_name) wave_flags = lalsim.SimInspiralCreateWaveformFlags() lalsim.SimInspiralSetSpinOrder(wave_flags, 5) 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, 40.0, 1e6 * PC_SI, 0, lmbda1, lmbda2, # irrelevant parameters for BBH wave_flags, None, # non-GR parameters ampO, phaseO, approx) # Must set values greater than _get_f_final to 0 act_f_max = self._get_f_final() f_max_idx = int(act_f_max / df + 0.999) hplus_fd.data.data[f_max_idx:] = 0 return hplus_fd
def my_distance(P1, P2): global IP global opts P1.approx = P2.approx = lalsim.GetApproximantFromString(opts.approx) P1.fmin = P2.fmin = opts.fmin P1.deltaF = P2.deltaF = 1. / T_window # if opts.verbose: # print " ---> Inside distance function < " # P1.print_params() # P2.print_params() dist = 1e5 try: hF1 = lalsimutils.complex_hoff(P1) hF2 = lalsimutils.complex_hoff(P2) rho1 = IP.norm(hF1) rho2 = IP.norm(hF2) dist = 1 - np.abs(IP.ip(hF1, hF2) / rho1 / rho2) except: print(" Distance evaluation failure ") if np.isnan(dist): return 1e5 return dist
def get_hF1(indx, ifo): global opts P = P1_list[indx % nlines1].manual_copy() # looping if not (opts.fmin_template1 is None): P.fmin = opts.fmin_template1 if not (opts.fref is None): P.fref = opts.fref else: P.ref = P.fmin P.radec = True P.tref = P1_list[indx % nlines1].tref # copy, this is an allocated object P.deltaF = df P.deltaT = 1. / opts.srate P.detector = ifo P.approx = lalsim.GetApproximantFromString( opts.approx) # override the XML. Can screw you up (ref spins) # if P.approx == lalsim.IMRPhenomPv2: # phiJL_now = P.extract_param('phiJL') # P.assign_param('phiJL', phiJL_now-np.pi/2) # Estimate # P.fref = 100 if opts.verbose: P.print_params() hF = lalsimutils.non_herm_hoff(P) return hF
def lalsim_FD_waveform(m1, m2, s1x, s1y, s1z, s2x, s2y, s2z, theta_jn, phase, duration, dL, fmax, lambda_1=None, lambda_2=None, **kwarg): mass1 = m1 * lal.MSUN_SI mass2 = m2 * lal.MSUN_SI spin_1x = s1x spin_1y = s1y spin_1z = s1z spin_2x = s2x spin_2y = s2y spin_2z = s2z iota = theta_jn phaseC = phase # Phase is hard coded to be zero eccentricity = 0 longitude_ascending_nodes = 0 mean_per_ano = 0 waveform_arg = dict(minimum_freq=20.0, reference_frequency=20) waveform_arg.update(kwarg) dL = dL * lal.PC_SI * 1e6 # MPC --> Km approximant = lalsim.GetApproximantFromString( waveform_arg["waveform_approximant"]) flow = waveform_arg["minimum_freq"] delta_freq = 1.0 / duration maximum_frequency = fmax # 1024.0 # ISCO(m1, m2) fref = waveform_arg["reference_frequency"] waveform_dictionary = lal.CreateDict() if lambda_1 is not None: lalsim.SimInspiralWaveformParamsInsertTidalLambda1( waveform_dictionary, float(lambda_1)) if lambda_2 is not None: lalsim.SimInspiralWaveformParamsInsertTidalLambda2( waveform_dictionary, float(lambda_2)) hplus, hcross = lalsim.SimInspiralChooseFDWaveform( mass1, mass2, spin_1x, spin_1y, spin_1z, spin_2x, spin_2y, spin_2z, dL, iota, phaseC, longitude_ascending_nodes, eccentricity, mean_per_ano, delta_freq, flow, maximum_frequency, fref, waveform_dictionary, approximant, ) h_plus = hplus.data.data[:] h_cross = hcross.data.data[:] return {"plus": h_plus, "cross": h_cross}
def get_WF_and_snr(inj, PSD, sample_rate, instrument="H1", plot_dir=None): "Given an injection row, it computes the WF and the SNR" #https://git.ligo.org/lscsoft/gstlal/-/blob/precession_hm-0.2/gstlal-inspiral/bin/gstlal_inspiral_injection_snr #PSD should be a lal PSD obj assert instrument in ["H1", "L1", "V1"] injtime = inj.time_geocent sample_rate = 16384.0 approximant = lalsimulation.GetApproximantFromString(str(inj.waveform)) f_min = inj.f_lower h_plus, h_cross = lalsimulation.SimInspiralTD(m1=inj.mass1 * lal.MSUN_SI, m2=inj.mass2 * lal.MSUN_SI, S1x=inj.spin1x, S1y=inj.spin1y, S1z=inj.spin1z, S2x=inj.spin2x, S2y=inj.spin2y, S2z=inj.spin2z, distance=inj.distance * 1e6 * lal.PC_SI, inclination=inj.inclination, phiRef=inj.coa_phase, longAscNodes=0.0, eccentricity=0.0, meanPerAno=0.0, deltaT=1.0 / sample_rate, f_min=f_min, f_ref=0.0, LALparams=None, approximant=approximant) h_plus.epoch += injtime h_cross.epoch += injtime # Compute strain in the chosen detector. h = lalsimulation.SimDetectorStrainREAL8TimeSeries( h_plus, h_cross, inj.longitude, inj.latitude, inj.polarization, lalsimulation.DetectorPrefixToLALDetector(instrument)) #Compute the SNR if PSD is not None: snr = lalsimulation.MeasureSNR(h, PSD, options.flow, options.fmax) else: snr = 0. if isinstance(plot_dir, str): plt.figure() plt.title( "(m1, m2, s1 (x,y,z), s2 (x,y,z), d_L) =\n {0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} {6:.2f} {7:.2f} {8:.2f} " .format(inj.mass1, inj.mass2, inj.spin1x, inj.spin1y, inj.spin1z, inj.spin2x, inj.spin2y, inj.spin2z, inj.distance)) plt.plot( np.linspace(0, len(h_plus.data.data) / sample_rate, len(h_plus.data.data)), h_plus.data.data) plt.savefig(plot_dir + '/inj_{}.png'.format(injtime)) #plt.show() plt.close('all') return (h.data.data, snr)