Пример #1
0
def test_center_of_mass():
    t = np.linspace(0, 100, 1000)
    m_planet = np.array([0.5, 0.1])
    m_star = 1.45
    orbit = KeplerianOrbit(
        m_star=m_star,
        r_star=1.0,
        t0=np.array([0.5, 17.4]),
        period=np.array([100.0, 37.3]),
        ecc=np.array([0.1, 0.8]),
        omega=np.array([0.5, 1.3]),
        Omega=np.array([0.0, 1.0]),
        incl=np.array([0.25 * np.pi, 0.3 * np.pi]),
        m_planet=m_planet,
    )

    planet_coords = theano.function([], orbit.get_planet_position(t))()
    star_coords = theano.function([], orbit.get_star_position(t))()

    com = np.sum(
        (m_planet[None, :] * np.array(planet_coords) +
         m_star * np.array(star_coords)) / (m_star + m_planet)[None, :],
        axis=0,
    )
    assert np.allclose(com, 0.0)
Пример #2
0
def test_flip_circular():
    t = np.linspace(0, 100, 1000)
    m_planet = 0.1
    m_star = 1.3
    orbit1 = KeplerianOrbit(
        m_star=m_star,
        r_star=1.1,
        t0=0.5,
        period=100.0,
        Omega=1.0,
        incl=0.25 * np.pi,
        m_planet=m_planet,
    )
    orbit2 = orbit1._flip(0.7)

    x1, y1, z1 = theano.function([], orbit1.get_star_position(t))()
    x2, y2, z2 = theano.function([], orbit2.get_planet_position(t))()
    assert np.allclose(x1, x2, atol=1e-5)
    assert np.allclose(y1, y2, atol=1e-5)
    assert np.allclose(z1, z2, atol=1e-5)

    x1, y1, z1 = theano.function([], orbit1.get_planet_position(t))()
    x2, y2, z2 = theano.function([], orbit2.get_star_position(t))()
    assert np.allclose(x1, x2, atol=1e-5)
    assert np.allclose(y1, y2, atol=1e-5)
    assert np.allclose(z1, z2, atol=1e-5)
Пример #3
0
def test_velocity():
    t_tensor = tt.dvector()
    t = np.linspace(0, 100, 1000)
    m_planet = 0.1
    m_star = 1.3
    orbit = KeplerianOrbit(
        m_star=m_star,
        r_star=1.0,
        t0=0.5,
        period=100.0,
        ecc=0.1,
        omega=0.5,
        Omega=1.0,
        incl=0.25 * np.pi,
        m_planet=m_planet,
    )

    star_pos = orbit.get_star_position(t_tensor)
    star_vel = theano.function([], orbit.get_star_velocity(t))()
    star_vel_expect = np.empty_like(star_vel)
    for i in range(3):
        g = theano.grad(tt.sum(star_pos[i]), t_tensor)
        star_vel_expect[i] = theano.function([t_tensor], g)(t)
    assert np.allclose(star_vel, star_vel_expect)

    planet_pos = orbit.get_planet_position(t_tensor)
    planet_vel = theano.function([], orbit.get_planet_velocity(t))()
    planet_vel_expect = np.empty_like(planet_vel)
    for i in range(3):
        g = theano.grad(tt.sum(planet_pos[i]), t_tensor)
        planet_vel_expect[i] = theano.function([t_tensor], g)(t)
    assert np.allclose(planet_vel, planet_vel_expect)

    pos = orbit.get_relative_position(t_tensor)
    vel = np.array(theano.function([], orbit.get_relative_velocity(t))())
    vel_expect = np.empty_like(vel)
    for i in range(3):
        g = theano.grad(tt.sum(pos[i]), t_tensor)
        vel_expect[i] = theano.function([t_tensor], g)(t)
    assert np.allclose(vel, vel_expect)
Пример #4
0
def test_light_delay_shape_two_planets_single_t():
    orbit = KeplerianOrbit(period=[1.0, 2.0])
    x, y, z = orbit.get_planet_position([1.0], light_delay=False)
    xr, yr, zr = orbit.get_planet_position([1.0], light_delay=True)
    assert np.array_equal(x.shape.eval(), xr.shape.eval())
Пример #5
0
def test_light_delay_shape_scalar_t():
    orbit = KeplerianOrbit(period=1.0)
    x, y, z = orbit.get_planet_position(1.0, light_delay=False)
    xr, yr, zr = orbit.get_planet_position(1.0, light_delay=True)
    assert np.array_equal(x.shape.eval(), xr.shape.eval())
Пример #6
0
def test_light_delay_shape_two_planets_vector_t():
    orbit = KeplerianOrbit(period=[1.0, 2.0])
    t = np.linspace(0, 10, 50)
    x, y, z = orbit.get_planet_position(t, light_delay=False)
    xr, yr, zr = orbit.get_planet_position(t, light_delay=True)
    assert np.array_equal(x.shape.eval(), xr.shape.eval())
Пример #7
0
def test_light_delay():
    # Instantiate the orbit
    m_star = tt.scalar()
    period = tt.scalar()
    ecc = tt.scalar()
    omega = tt.scalar()
    Omega = tt.scalar()
    incl = tt.scalar()
    m_planet = tt.scalar()
    t = tt.scalar()
    orbit = KeplerianOrbit(
        m_star=m_star,
        r_star=1.0,
        t0=0.0,
        period=period,
        ecc=ecc,
        omega=omega,
        Omega=Omega,
        incl=incl,
        m_planet=m_planet,
    )

    # True position
    get_position = theano.function(
        [t, m_star, period, ecc, omega, Omega, incl, m_planet],
        orbit.get_planet_position([t], light_delay=False),
    )

    # Retarded position
    get_retarded_position = theano.function(
        [t, m_star, period, ecc, omega, Omega, incl, m_planet],
        orbit.get_planet_position([t], light_delay=True),
    )

    # Retarded position (numerical)
    def get_exact_retarded_position(t, *args):
        def loss(params):
            (ti, ) = params
            xr, yr, zr = get_position(ti, *args)
            delay = (zr * u.Rsun / c).to(u.day).value
            return (ti - delay - t)**2

        tr = minimize(loss, t).x[0]
        return get_position(tr, *args)

    # Compare for 100 different orbits
    np.random.seed(13)
    for i in range(100):
        m_star = 0.1 + np.random.random() * 1.9
        period = np.random.random() * 500
        ecc = np.random.random()
        omega = np.random.random() * 2 * np.pi
        Omega = np.random.random() * 2 * np.pi
        incl = np.random.random() * 0.5 * np.pi
        m_planet = np.random.random()
        t = np.random.random() * period
        args = (m_star, period, ecc, omega, Omega, incl, m_planet)
        assert np.allclose(
            np.reshape(get_retarded_position(t, *args), (-1, )),
            np.reshape(get_exact_retarded_position(t, *args), (-1, )),
        )