Beispiel #1
0
def lambda_from_m(m):
    eos = lalsim.SimNeutronStarEOSByName("AP4")
    eos_fam = lalsim.CreateSimNeutronStarFamily(eos)
    if m < 10**15:
        m = m * lal.MSUN_SI
    k2 = lalsim.SimNeutronStarLoveNumberK2(m, eos_fam)
    r = lalsim.SimNeutronStarRadius(m, eos_fam)
    m = m * lal.G_SI / lal.C_SI**2
    lam = 2. / (3 * lal.G_SI) * k2 * r**5
    dimensionless_lam = lal.G_SI * lam * (1 / m)**5
    return dimensionless_lam
Beispiel #2
0
    def __init__(self, name):
        self.name = name
        self.eos = None
        self.eos_fam = None
        self.mMaxMsun = None

        eos = lalsim.SimNeutronStarEOSByName(name)
        fam = lalsim.CreateSimNeutronStarFamily(eos)
        mmass = lalsim.SimNeutronStarMaximumMass(fam) / lal.MSUN_SI
        self.eos = eos
        self.eos_fam = fam
        self.mMaxMsun = mmass
        return None
Beispiel #3
0
def get_lalsim_eos(eos_name):
    """
    EOS tables described by Ozel `here <https://arxiv.org/pdf/1603.02698.pdf>`_ and downloadable `here <http://xtreme.as.arizona.edu/NeutronStars/data/eos_tables.tar>`_. LALSim utilizes this tables, but needs some interfacing (i.e. conversion to SI units, and conversion from non monotonic to monotonic pressure density tables)
    """
    import os
    import lalsimulation
    import lal
    obs_max_mass = 2.01 - 0.04
    print("Checking %s" % eos_name)
    eos_fname = ""
    if os.path.exists(eos_name):
        # NOTE: Adapted from code by Monica Rizzo
        print("Loading from %s" % eos_name)
        bdens, press, edens = np.loadtxt(eos_name, unpack=True)
        press *= 7.42591549e-25
        edens *= 7.42591549e-25
        eos_name = os.path.basename(eos_name)
        eos_name = os.path.splitext(eos_name)[0].upper()

        if not np.all(np.diff(press) > 0):
            keep_idx = np.where(np.diff(press) > 0)[0] + 1
            keep_idx = np.concatenate(([0], keep_idx))
            press = press[keep_idx]
            edens = edens[keep_idx]
        assert np.all(np.diff(press) > 0)
        if not np.all(np.diff(edens) > 0):
            keep_idx = np.where(np.diff(edens) > 0)[0] + 1
            keep_idx = np.concatenate(([0], keep_idx))
            press = press[keep_idx]
            edens = edens[keep_idx]
        assert np.all(np.diff(edens) > 0)

        print("Dumping to %s" % eos_fname)
        eos_fname = "./." + eos_name + ".dat"
        np.savetxt(eos_fname, np.transpose((press, edens)), delimiter='\t')
        eos = lalsimulation.SimNeutronStarEOSFromFile(eos_fname)
        fam = lalsimulation.CreateSimNeutronStarFamily(eos)

    else:
        eos = lalsimulation.SimNeutronStarEOSByName(eos_name)
        fam = lalsimulation.CreateSimNeutronStarFamily(eos)

    mmass = lalsimulation.SimNeutronStarMaximumMass(fam) / lal.MSUN_SI
    print("Family %s, maximum mass: %1.2f" % (eos_name, mmass))
    if np.isnan(mmass) or mmass > 3. or mmass < obs_max_mass:
        return

    return eos, fam
def Lambdas(params):
    #Unpack params
    eosname = params['eosname']
    m1 = params['m1']
    m2 = params['m2']

    #Create EOS/Family structures
    eos = lalsim.SimNeutronStarEOSByName(eosname)
    fam = lalsim.CreateSimNeutronStarFamily(eos)
    r1 = lalsim.SimNeutronStarRadius(m1 * MSUN_SI, fam)
    r2 = lalsim.SimNeutronStarRadius(m2 * MSUN_SI, fam)
    k1 = lalsim.SimNeutronStarLoveNumberK2(m1 * MSUN_SI, fam)
    k2 = lalsim.SimNeutronStarLoveNumberK2(m2 * MSUN_SI, fam)
    c1 = m1 * MRSUN_SI / r1
    c2 = m2 * MRSUN_SI / r2
    Lambda1 = (2.0 / 3.0) * k1 / c1**5.
    Lambda2 = (2.0 / 3.0) * k2 / c2**5.

    return [Lambda1, Lambda2]
Beispiel #5
0
def make_tidal_waveform(approx='TaylorT4',
                        rate=4096,
                        Lambda1=None,
                        Lambda2=None,
                        mass1=1.4,
                        mass2=1.3,
                        inclination=0,
                        distance=100,
                        eccentricity=0,
                        meanPerAno=0,
                        phiRef=0,
                        f_min=30,
                        f_ref=0,
                        longAscNodes=0,
                        s1x=0,
                        s1y=0,
                        s1z=0,
                        s2x=0,
                        s2y=0,
                        s2z=0,
                        eos=None,
                        save=False):
    # Sanity check
    if (Lambda1 is None) and (Lambda2 is None) and (eos is None):
        # Assuming Lambdas to be zero is not provided
        print("Assuming tidal deformability is zero")
        print(
            "Use arguments Lambda1=, and Lambda2= to provide deformabilities")
        Lambda1 = 0.0
        Lambda2 = 0.0
    if eos:
        if Lambda1 or Lambda2:
            print(
                "Warning: Both eos and Lambda1 and/or Lambda2 has been provided"
            )
            print("Ignoring Lambdas in favor of the eos")
        e = lalsim.SimNeutronStarEOSByName(eos)
        fam = lalsim.CreateSimNeutronStarFamily(e)
        max_mass = lalsim.SimNeutronStarMaximumMass(fam) / lal.MSUN_SI
        assert mass1 < max_mass, "mass1 greater than maximum mass allowed for the neutron star"
        assert mass2 < max_mass, "mass2 greater than the maximum mass allowed for the neutron star"
        r1 = lalsim.SimNeutronStarRadius(mass1 * lal.MSUN_SI, fam)
        k1 = lalsim.SimNeutronStarLoveNumberK2(mass1 * lal.MSUN_SI, fam)

        r2 = lalsim.SimNeutronStarRadius(mass2 * lal.MSUN_SI, fam)
        k2 = lalsim.SimNeutronStarLoveNumberK2(mass2 * lal.MSUN_SI, fam)
        c2 = mass2 * lal.MRSUN_SI / r2
        c1 = mass1 * lal.MRSUN_SI / r1

        Lambda1 = (2 / 3) * k1 / (c1**5)
        Lambda2 = (2 / 3) * k2 / (c2**5)

    mass1 = mass1 * lal.MSUN_SI
    mass2 = mass2 * lal.MSUN_SI
    distance = distance * 1e6 * lal.PC_SI
    deltaT = 1.0 / rate
    approximant = lalsim.GetApproximantFromString(approx)
    lal_pars = lal.CreateDict()
    lalsim.SimInspiralWaveformParamsInsertTidalLambda1(lal_pars, Lambda1)
    lalsim.SimInspiralWaveformParamsInsertTidalLambda2(lal_pars, Lambda2)
    hp, hc = lalsim.SimInspiralChooseTDWaveform(mass1,
                                                mass2,
                                                s1x=s1x,
                                                s1y=s1y,
                                                s1z=s1z,
                                                s2x=s2x,
                                                s2y=s2y,
                                                s2z=s2z,
                                                distance=distance,
                                                inclination=inclination,
                                                phiRef=phiRef,
                                                longAscNodes=longAscNodes,
                                                eccentricity=eccentricity,
                                                meanPerAno=meanPerAno,
                                                deltaT=deltaT,
                                                f_min=f_min,
                                                f_ref=f_ref,
                                                params=lal_pars,
                                                approximant=approximant)
    if save:
        plus_data = hp.data.data
        cross_data = hc.data.data
        tstart_p = hp.epoch.gpsSeconds + hp.epoch.gpsNanoSeconds * 1e-9
        tstart_c = hc.epoch.gpsSeconds + hc.epoch.gpsNanoSeconds * 1e-9
        tp = np.arange(tstart_p, 0, hp.deltaT)
        tp = tp[:len(hp.data.data)]
        tc = np.arange(tstart_c, 0, hc.deltaT)
        tc = tc[:len(hc.data.data)]
        output_plus = np.vstack((tp, plus_data)).T
        output_cross = np.vstack((tc, cross_data)).T

        np.savetxt("plus_polarization_data.txt", output_plus, fmt="%f\t%e")
        np.savetxt("cross_polarization_data.txt", output_cross, fmt="%f\t%e")

    return (hp, hc)
Beispiel #6
0
    def __init__(self, sim, eos="WFF1"):
        # Load if from sim inspiral table
        if isinstance(sim, lsctables.SimInspiral):
            self.sim = sim

            # Set NS
            self.m_ns = sim.mass2
            self.s_ns_x = sim.spin2x
            self.s_ns_y = sim.spin2y
            self.s_ns_z = sim.spin2z

            # Set BH
            self.m_bh = sim.mass1
            self.s_bh_x = sim.spin1x
            self.s_bh_y = sim.spin1y
            self.s_bh_z = sim.spin1z

            self.s_bh = np.sqrt(self.s_bh_x**2 + self.s_bh_y**2 +
                                self.s_bh_z**2)
            self.s_bh_tilt = np.arccos(self.s_bh_z / self.s_bh)

        # Load if from LALInference posterior samples
        elif isinstance(sim, np.void):
            # Set NS
            self.m_ns = sim["m2"]

            # Set BH
            self.m_bh = sim["m1"]
            self.s_bh = sim["a1"]
            self.s_bh_tilt = sim["tilt1"]
            self.s_bh_z = self.s_bh * np.cos(self.s_bh_tilt)

        elif isinstance(sim, dict):

            # Set NS
            self.m_ns = sim['mass2']
            self.s_ns_x = sim['spin2x']
            self.s_ns_y = sim['spin2y']
            self.s_ns_z = sim['spin2z']

            # Set BH
            self.m_bh = sim['mass1']
            self.s_bh_x = sim['spin1x']
            self.s_bh_y = sim['spin1y']
            self.s_bh_z = sim['spin1z']

            self.s_bh = np.sqrt(self.s_bh_x**2 + self.s_bh_y**2 +
                                self.s_bh_z**2)
            self.s_bh_tilt = np.arccos(self.s_bh_z / self.s_bh)

        else:
            raise NotImplementedError(
                "Input of type {} not yet supported!".format(type(sim)))

        #print("BH = {:.2f}, NS = {:.2f}".format(self.m_bh, self.m_ns))

        if eos in list(lalsim.SimNeutronStarEOSNames):
            eos_obj = lalsim.SimNeutronStarEOSByName(eos)
            self.eos = lalsim.CreateSimNeutronStarFamily(eos_obj)

            # Get limiting NS masses and ensure valid input
            m_max = lalsim.SimNeutronStarMaximumMass(self.eos)
            self.m_max = m_max / lal.MSUN_SI
            assert (self.m_ns < self.m_max)
            m_min = lalsim.SimNeutronStarFamMinimumMass(self.eos)
            self.m_min = m_min / lal.MSUN_SI
            assert (self.m_ns > self.m_min)

            # Get NS radius
            self.r_ns = lalsim.SimNeutronStarRadius(self.m_ns * lal.MSUN_SI,
                                                    self.eos)

            # NS tidal deformability
            self.compactness = self.get_compactness()
            self.love = lalsim.SimNeutronStarLoveNumberK2(
                self.m_ns * lal.MSUN_SI, self.eos)
            self.lamb = 2. / 3. * self.love * self.compactness**-5

        else:
            eos_func, mr_func, self.m_max, self.m_min = choose_func(eos)
            assert (self.m_ns < self.m_max)
            assert (self.m_ns > self.m_min)
            self.lamb = eos_func(self.m_ns)
            self.r_ns = mr_func(self.m_ns) * 1e3
            self.compactness = self.get_compactness()