simonrw / ttvfast-python

Python interface to the TTVFast library
GNU General Public License v2.0
15 stars 6 forks source link

Support astrocentric coordinates #9

Closed simonrw closed 7 years ago

simonrw commented 7 years ago

The code hard codes Jacobi coordinates (with input_flag=0). The code should support other valid values of this flag, so add this in.

Original report:

I was doing some testing with TTVFast today, and I realized that you have hard-coded ttvfast-python to use Jacobi coordinates (input_flag=0). I usually work in astrocentric coordinates, so I modified my own version of init.py to allow myself to set the input_flag to a non-zero value. You might want to make this change in the distributed version as well!

Example updated code, in __init__.py:

# -*- coding: utf-8 -*-

"Fast TTV computation"

__all__ = ['ttvfast']

from ._ttvfast import _ttvfast as _ttvfast_fn
from . import models

def ttvfast(planets, stellar_mass, time, dt, total, rv_times=None, input_flag = 0):
    '''
    Run the TTV fast function. See https://github.com/kdeck/TTVFast.
    Program arguments:
    * planets: list of `models.Planet` instances
    * stellar_mass: stellar mass (solar masses)
    * time: start point for integration (days)
    * dt: time step for the integration (days)
    * total: end point for integration (days)
    * rv_times: rv measurement times
    * input_flag: IC system [0=Jacobi, 1=astrocentric_elements, 2=astrocentric_cartesian]
    '''
    params = models.planets_to_params(stellar_mass, planets)
    n_plan = len(planets)

    len_rv = len(rv_times) if rv_times is not None else 0
    positions, rv = _ttvfast_fn(params, dt, time, total, n_plan, input_flag, len_rv, rv_times)
    return {'positions': positions, 'rv': rv}

__all__ = ['ttvfast']