functions.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Orbit-Fitting 作者: jacob-i-skinner 项目源码 文件源码
def periodogram(x, rv, f, max_period):
    '''
    Computes a Lomb-Scargle Periodogram of the input RV data.
    This was adapted from Jake Vanderplas' article "Fast Lomb-Scargle Periodograms in Python."

    Parameters
    ----------
    x : list
        The times at which the data points were gathered.

    rv : list
        The values of the measurand at the corresponding time, x.

    f : float
        The number of samples to take over the interval.

    max_period : float
        The maximum of the interval of periods to check.

    Returns
    -------
    periods : array_like[len(f)]
        Equally spaced array of possible period values.

    powers : array_like[len(f)]
        The calculated Power values over the range of periods,
        these form the normalized Lomb-Scargle Periodogram.

    delta_x : float
        The smallest separation between two values in x.

    '''
    from scipy.signal import lombscargle

    # Sort the time data chronologically.
    x = np.sort(np.array(x))
    rv = np.array(rv)

    # Start delta_x very large
    delta_x = np.inf

    # Iteratively lower delta_x
    for i in range(0, len(x)-2):        
        if x[i+1]-x[i] < delta_x and x[i+1]-x[i] != 0:
            delta_x = x[i+1]-x[i]

    # Compute the periodogram
    periods = np.linspace(delta_x, max_period, num = f)
    ang_freqs = 2 * pi / periods
    powers = lombscargle(x, rv - rv.mean(), ang_freqs)
    powers *= 2 / (len(x) * rv.std() ** 2)

    return periods, powers, delta_x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号