Exemplo n.º 1
0
def kepler_orbit(type='single'):
    """
    Kepler orbits ((p,t0,e,omega,K,v0) or (p,t0,e,omega,K1,v01,K2,v02))
    
    A single kepler orbit
    parameters are: [p, t0, e, omega, k, v0]
    
    A double kepler orbit
    parameters are: [p, t0, e, omega, k_1, v0_1, k_2, v0_2]
    Warning: This function uses 2d input and output!
    """
    if type == 'single':
        pnames = ['p','t0','e','omega','k','v0']
        function = lambda p, x: kepler.radial_velocity(p, times=x, itermax=8)
        function.__name__ = 'kepler_orbit_single'
    
        return Function(function=function, par_names=pnames)
        
    elif type == 'double':
        pnames = ['p','t0','e','omega','k1','v01','k2','v02' ]
        function = lambda p, x: [kepler.radial_velocity([p[0],p[1],p[2],p[3],p[4],p[5]], times=x[0], itermax=8),
                                 kepler.radial_velocity([p[0],p[1],p[2],p[3],p[6],p[7]], times=x[1], itermax=8)]
        def residuals(syn, data, weights=None, errors=None, **kwargs):
            return np.hstack( [( data[0] - syn[0] ) * weights[0],  ( data[1] - syn[1] ) * weights[1] ] )
        function.__name__ = 'kepler_orbit_double'
    
        return Function(function=function, par_names=pnames, resfunc=residuals)
Exemplo n.º 2
0
def binary(times, parameters, n1=None, itermax=8):
    """
    Simultaneous evaluation of two binary components.
    
    parameter fields must be C{'P','T0','e','omega','K1', 'K2'}.
    """
    if n1 is None:
        n1 = len(times) / 2
    if 'gamma' in parameters.dtype.names:
        RVfit = parameters['gamma'].sum()
    else:
        RVfit = 0
    RVfit = RVfit * np.ones(len(times))
    p1 = [
        parameters['P'], parameters['T0'], parameters['e'],
        parameters['omega'], parameters['K1'], 0
    ]
    p2 = [
        parameters['P'], parameters['T0'], parameters['e'],
        parameters['omega'], parameters['K2'], 0
    ]
    RVfit[:n1] += keplerorbit.radial_velocity(p1,
                                              times=times[:n1],
                                              itermax=itermax)
    RVfit[n1:] += keplerorbit.radial_velocity(p2,
                                              times=times[n1:],
                                              itermax=itermax)
    return RVfit
Exemplo n.º 3
0
def kepler_orbit(type='single'):
    """
    Kepler orbits ((p,t0,e,omega,K,v0) or (p,t0,e,omega,K1,v01,K2,v02))

    A single kepler orbit
    parameters are: [p, t0, e, omega, k, v0]

    A double kepler orbit
    parameters are: [p, t0, e, omega, k_1, v0_1, k_2, v0_2]
    Warning: This function uses 2d input and output!
    """
    if type == 'single':
        pnames = ['p', 't0', 'e', 'omega', 'k', 'v0']
        function = lambda p, x: kepler.radial_velocity(p, times=x, itermax=8)
        function.__name__ = 'kepler_orbit_single'

        return Function(function=function, par_names=pnames)

    elif type == 'double':
        pnames = ['p', 't0', 'e', 'omega', 'k1', 'v01', 'k2', 'v02']
        function = lambda p, x: [
            kepler.radial_velocity(
                [p[0], p[1], p[2], p[3], p[4], p[5]], times=x[0], itermax=8),
            kepler.radial_velocity(
                [p[0], p[1], p[2], p[3], p[6], p[7]], times=x[1], itermax=8)
        ]

        def residuals(syn, data, weights=None, errors=None, **kwargs):
            return np.hstack([(data[0] - syn[0]) * weights[0],
                              (data[1] - syn[1]) * weights[1]])

        function.__name__ = 'kepler_orbit_double'

        return Function(function=function, par_names=pnames, resfunc=residuals)
def kepler(times,parameters,itermax=8):
    """
    Construct a radial velocity curve due to Kepler orbit(s).

    Parameter fields: C{gamma, P, T0, e, omega, K}

    @param times: observation times
    @type times: numpy array
    @param parameters: record array containing periods ('P' in days),
    times of periastron ('T0' in days), eccentricities ('e'),
    longitudes of periastron ('omega' in radians), amplitude ('K' in km/s) and
    systemic velocity ('gamma' in km/s)
    phases ('phase'), frequency shifts ('D') and optionally constants ('const')
    @type parameters: record array
    @param itermax: maximum number of iterations for solving Kepler equation
    @type itermax: integer
    @return: radial velocity curve (same shape as C{times})
    @rtype: array
    """
    if 'gamma' in parameters.dtype.names:
        RVfit = parameters['gamma'].sum()
    else:
        RVfit = 0
    for pars in parameters:
        p = [pars['P'],pars['T0'],pars['e'],pars['omega'],pars['K'],0]
        RVfit += keplerorbit.radial_velocity(p,times=times,itermax=itermax)
    return RVfit
Exemplo n.º 5
0
def kepler(times,parameters,itermax=8):
    """
    Construct a radial velocity curve due to Kepler orbit(s).
    
    Parameter fields: C{gamma, P, T0, e, omega, K}
    
    @param times: observation times
    @type times: numpy array
    @param parameters: record array containing periods ('P' in days),
    times of periastron ('T0' in days), eccentricities ('e'),
    longitudes of periastron ('omega' in radians), amplitude ('K' in km/s) and
    systemic velocity ('gamma' in km/s)
    phases ('phase'), frequency shifts ('D') and optionally constants ('const')
    @type parameters: record array
    @param itermax: maximum number of iterations for solving Kepler equation
    @type itermax: integer
    @return: radial velocity curve (same shape as C{times})
    @rtype: array
    """
    if 'gamma' in parameters.dtype.names:
        RVfit = parameters['gamma'].sum()
    else:
        RVfit = 0
    for pars in parameters:
        p = [pars['P'],pars['T0'],pars['e'],pars['omega'],pars['K'],0]
        RVfit += keplerorbit.radial_velocity(p,times=times,itermax=itermax)
    return RVfit
Exemplo n.º 6
0
def binary(times,parameters,n1=None,itermax=8):
    """
    Simultaneous evaluation of two binary components.
    
    parameter fields must be C{'P','T0','e','omega','K1', 'K2'}.
    """
    if n1 is None:
        n1 = len(times)/2
    if 'gamma' in parameters.dtype.names:
        RVfit = parameters['gamma'].sum()
    else:
        RVfit = 0
    RVfit = RVfit*np.ones(len(times))
    p1 = [parameters['P'],parameters['T0'],parameters['e'],parameters['omega'],parameters['K1'],0]
    p2 = [parameters['P'],parameters['T0'],parameters['e'],parameters['omega'],parameters['K2'],0]
    RVfit[:n1] += keplerorbit.radial_velocity(p1,times=times[:n1],itermax=itermax)
    RVfit[n1:] += keplerorbit.radial_velocity(p2,times=times[n1:],itermax=itermax)
    return RVfit