Esempio n. 1
0
def test_secondary_eclipse():
    u1 = np.array([0.3, 0.2])
    lc1 = LimbDarkLightCurve(u1)

    u2 = np.array([0.4, 0.1])
    lc2 = LimbDarkLightCurve(u1)

    s = 0.3
    ror = 0.08
    f = ror**2 * s
    lc = SecondaryEclipseLightCurve(u1, u2, s)

    t = np.linspace(-6.435, 10.4934, 5000)
    orbit1 = KeplerianOrbit(period=1.543, t0=-0.123)
    orbit2 = KeplerianOrbit(
        period=orbit1.period,
        t0=orbit1.t0 + 0.5 * orbit1.period,
        r_star=ror,
        m_star=1.0,
    )

    y1 = lc1.get_light_curve(orbit=orbit1, r=ror, t=t).eval()
    y2 = lc2.get_light_curve(orbit=orbit2, r=1.0, t=t).eval()
    y = lc.get_light_curve(orbit=orbit1, r=ror, t=t).eval()
    y_expect = (y1 + f * y2) / (1 + f)

    assert np.allclose(y_expect, y, atol=5e-6)
Esempio n. 2
0
def test_estimate_minimum_mass(seed=9502):
    np.random.seed(seed)
    t = np.sort(np.random.uniform(0, 10, 500))
    period = 2.345
    t0 = 0.5
    orbit = KeplerianOrbit(period=period, t0=t0, m_planet=0.01, incl=0.8)
    y = orbit.get_radial_velocity(t).eval()
    m1 = (orbit.m_planet * orbit.sin_incl).eval()
    m2 = estimate_minimum_mass(period, t, y).to(u.M_sun).value
    m3 = estimate_minimum_mass(period, t, y, t0s=t0).to(u.M_sun).value
    assert np.abs((m1 - m2) / m1) < 0.01
    assert np.abs((m1 - m3) / m1) < 0.01
Esempio n. 3
0
def test_in_transit():
    t = np.linspace(-20, 20, 1000)
    m_planet = np.array([0.3, 0.5])
    m_star = 1.45
    orbit = KeplerianOrbit(
        m_star=m_star,
        r_star=1.5,
        t0=np.array([0.5, 17.4]),
        period=np.array([10.0, 5.3]),
        ecc=np.array([0.1, 0.8]),
        omega=np.array([0.5, 1.3]),
        m_planet=m_planet,
    )
    u = np.array([0.2, 0.3, 0.1, 0.5])
    r = np.array([0.1, 0.01])

    lc = LimbDarkLightCurve(u)
    model1 = lc.get_light_curve(r=r, orbit=orbit, t=t)
    model2 = lc.get_light_curve(r=r, orbit=orbit, t=t, use_in_transit=False)
    vals = theano.function([], [model1, model2])()
    utt.assert_allclose(*vals)

    model1 = lc.get_light_curve(r=r, orbit=orbit, t=t, texp=0.1)
    model2 = lc.get_light_curve(r=r,
                                orbit=orbit,
                                t=t,
                                texp=0.1,
                                use_in_transit=False)
    vals = theano.function([], [model1, model2])()
    utt.assert_allclose(*vals)
Esempio n. 4
0
def test_simple_light_curve_compare_kepler():
    t = np.linspace(0.0, 1, 1000)
    # We use a long period, because at short periods there is a big difference
    # between a circular orbit and an object moving on a straight line.
    period = 1000
    t0 = 0.5
    r = 0.01
    r_star = 1
    b = 1 - r / r_star * 3

    star = LimbDarkLightCurve(0.2, 0.3)
    orbit_keplerian = KeplerianOrbit(period=period,
                                     t0=t0,
                                     b=b,
                                     r_star=r_star,
                                     m_star=1)
    duration = (period / np.pi) * np.arcsin(
        ((r_star + r)**2 - (b * r_star)**2)**0.5 / orbit_keplerian.a).eval()

    lc_keplerian = star.get_light_curve(orbit=orbit_keplerian, r=r, t=t)
    orbit_simple1 = SimpleTransitOrbit(
        period=period,
        t0=t0,
        b=b,
        duration=duration,
        r_star=r_star,
        ror=r / r_star,
    )
    lc_simple1 = star.get_light_curve(orbit=orbit_simple1, r=r, t=t)

    # Should look similar to Keplerian orbit
    assert np.allclose(lc_keplerian.eval(), lc_simple1.eval(), rtol=0.001)
Esempio n. 5
0
def test_contact_bug():
    orbit = KeplerianOrbit(period=3.456, ecc=0.6, omega=-1.5)
    t = np.linspace(-0.1, 0.1, 1000)
    u = [0.3, 0.2]
    y1 = (LimbDarkLightCurve(u[0], u[1]).get_light_curve(orbit=orbit,
                                                         r=0.1,
                                                         t=t,
                                                         texp=0.02).eval())
    y2 = (LimbDarkLightCurve(u[0], u[1]).get_light_curve(
        orbit=orbit, r=0.1, t=t, texp=0.02, use_in_transit=False).eval())
    assert np.allclose(y1, y2)
Esempio n. 6
0
def test_mass_units():
    P_earth = 365.256
    Tper_earth = 2454115.5208333
    inclination_earth = np.radians(45.0)

    orbit1 = KeplerianOrbit(
        period=P_earth,
        t_periastron=Tper_earth,
        incl=inclination_earth,
        m_planet=units.with_unit(1.0, u.M_earth),
    )
    orbit2 = KeplerianOrbit(
        period=P_earth,
        t_periastron=Tper_earth,
        incl=inclination_earth,
        m_planet=1.0,
        m_planet_units=u.M_earth,
    )

    t = np.linspace(Tper_earth, Tper_earth + 1000, 1000)
    rv1 = orbit1.get_radial_velocity(t).eval()
    rv_diff = np.max(rv1) - np.min(rv1)
    assert rv_diff < 1.0, "with_unit"

    rv2 = orbit2.get_radial_velocity(t).eval()
    rv_diff = np.max(rv2) - np.min(rv2)
    assert rv_diff < 1.0, "m_planet_units"
    np.testing.assert_allclose(rv2, rv1)
Esempio n. 7
0
def rv_injection_worker(task):

    logK, logP, t0, sini, t_observed, gammadot_limit = task
    ecc = 0

    if use_exoplanet:
        # slow, and bringing a machine-gun to a knife-fight
        orbit = KeplerianOrbit(period=np.exp(logP),
                               b=0,
                               t0=t0,
                               r_star=RSTAR,
                               m_star=MSTAR)
        rv = orbit.get_radial_velocity(t_observed,
                                       K=np.exp(logK),
                                       output_units=u.m / u.s)
        _rv = rv.eval() * sini

    else:
        if ecc != 0:
            raise NotImplementedError
        # analytic solution for circular orbits (from radvel.kepler)

        per = np.exp(logP)
        tp = t0
        om = 0
        k = np.exp(logK)

        m = 2 * np.pi * (((t_observed - tp) / per) - np.floor(
            (t_observed - tp) / per))

        _rv = k * sini * np.cos(m + om)

    coef = polyfit(t_observed, _rv, 1)

    slope = coef[0]

    isdetectable = np.abs(slope) > gammadot_limit.to(u.m / u.s / u.day).value

    return slope, isdetectable
Esempio n. 8
0
def test_small_star():
    pytest.importorskip("batman.transitmodel")
    from batman.transitmodel import TransitModel, TransitParams

    u_star = [0.2, 0.1]
    r = 0.04221468

    m_star = 0.151
    r_star = 0.189
    period = 0.4626413
    t0 = 0.2
    b = 0.5
    ecc = 0.1
    omega = 0.1
    t = np.linspace(0, period, 500)

    r_pl = r * r_star

    orbit = KeplerianOrbit(
        r_star=r_star,
        m_star=m_star,
        period=period,
        t0=t0,
        b=b,
        ecc=ecc,
        omega=omega,
    )
    a = orbit.a.eval()
    incl = orbit.incl.eval()

    lc = LimbDarkLightCurve(u_star[0], u_star[1])

    model1 = lc.get_light_curve(r=r_pl, orbit=orbit, t=t)
    model2 = lc.get_light_curve(r=r_pl, orbit=orbit, t=t, use_in_transit=False)
    vals = theano.function([], [model1, model2])()
    assert np.allclose(*vals)

    params = TransitParams()
    params.t0 = t0
    params.per = period
    params.rp = r
    params.a = a / r_star
    params.inc = np.degrees(incl)
    params.ecc = ecc
    params.w = np.degrees(omega)
    params.u = u_star
    params.limb_dark = "quadratic"

    model = TransitModel(params, t)
    flux = model.light_curve(params)
    assert np.allclose(vals[0][:, 0], flux - 1)
Esempio n. 9
0
def test_variable_texp():
    t = np.linspace(-20, 20, 1000)
    m_planet = np.array([0.3, 0.5])
    m_star = 1.45
    orbit = KeplerianOrbit(
        m_star=m_star,
        r_star=1.5,
        t0=np.array([0.5, 17.4]),
        period=np.array([10.0, 5.3]),
        ecc=np.array([0.1, 0.8]),
        omega=np.array([0.5, 1.3]),
        m_planet=m_planet,
    )
    u = np.array([0.2, 0.3])
    r = np.array([0.1, 0.01])
    texp0 = 0.1

    lc = LimbDarkLightCurve(u[0], u[1])
    model1 = lc.get_light_curve(r=r,
                                orbit=orbit,
                                t=t,
                                texp=texp0,
                                use_in_transit=False)
    model2 = lc.get_light_curve(
        r=r,
        orbit=orbit,
        t=t,
        use_in_transit=False,
        texp=texp0 + np.zeros_like(t),
    )
    vals = theano.function([], [model1, model2])()
    assert np.allclose(*vals)

    model1 = lc.get_light_curve(r=r, orbit=orbit, t=t, texp=texp0)
    model2 = lc.get_light_curve(
        r=r,
        orbit=orbit,
        t=t,
        texp=texp0 + np.zeros_like(t),
        use_in_transit=False,
    )
    vals = theano.function([], [model1, model2])()
    assert np.allclose(*vals)