continuum.py 文件源码

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

项目:PySAT 作者: USGS-Astrogeology 项目源码 文件源码
def continuum_correct(spectrum, nodes=None, method='linear'):
    """
    Apply a continuum correction to a given spectrum

    Parameters
    ==========
    spectrum : pd.Series
               A pandas series or Spectrum object

    nodes: list
           A list of the nodes between which piecewise continuum
           will be fit

    method : {'linear', 'regresison', 'cubic'}
             The type of regression to be fit, where 'linear' is a piecewise
             linear fit, 'regression' is an Ordinary Least Squares fit, and 
             'cubic' is a 2nd order polynomial fit.

    Returns
    =======
     : pd.Series
       The continuum corrected Spectrum

     : pd.Series
       The continuum line
    """

    x = spectrum.index
    y = spectrum
    if not nodes:
        nodes = [x[0], x[-1]]

    return_length = len(y)
    corrected = np.empty(return_length)
    continuum = np.empty(return_length)

    start = 0
    nlist = list(zip(nodes, nodes[1:]))
    for i, n in enumerate(nlist):
        # Define indices into sub-series
        ny = y[n[0]:n[1]]
        nx = ny.index
        if i == 0:
            stop = start + len(y[:n[1]])
            c = correction_methods[method](nx, ny, ex=y[:n[1]].index.values)
            ey = y[:n[1]]
        elif i == len(nlist) - 1:
            stop = start + len(y[n[0]:])
            c = correction_methods[method](nx, ny, ex=y[n[0]:].index.values)
            ey = y[n[0]:]
        else:
            stop = start + len(ny)
            c = correction_methods[method](nx, ny)
            ey = ny

        continuum[start:stop] = c
        corrected[start:stop] = ey / c

        start = stop

    return pd.Series(corrected, index=x), pd.Series(continuum, index=x)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号