rubberband.py 文件源码

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

项目:PySAT 作者: USGS-Astrogeology 项目源码 文件源码
def _rubberband(bands, intensities, num_ranges):
    '''Basic rubberband method,
    from p.77 of "IR and Raman Spectroscopy" (OPUS manual)'''
    # create n ranges of equal size in the spectrum
    range_size = len(intensities) // num_ranges
    y = intensities[:range_size * num_ranges].reshape((num_ranges, range_size))
    # find the smallest intensity point in each range
    idx = np.arange(num_ranges) * range_size + np.argmin(y, axis=1)
    # add in the start and end points as well, to avoid weird edge effects
    if idx[0] != 0:
        idx = np.append(0, idx)
    if idx[-1] != len(intensities) - 1:
        idx = np.append(idx, len(intensities) - 1)
    baseline_pts = np.column_stack((bands[idx], intensities[idx]))
    # wrap a rubber band around the baseline points
    hull = ConvexHull(baseline_pts)
    hidx = idx[hull.vertices]
    # take only the bottom side of the hull
    left = np.argmin(bands[hidx])
    right = np.argmax(bands[hidx])
    mask = np.ones(len(hidx), dtype=bool)
    for i in range(len(hidx)):
        if i > right and (i < left or right > left):
            mask[i] = False
        elif i < left and i < right:
            mask[i] = False
    hidx = hidx[mask]
    hidx = hidx[np.argsort(bands[hidx])]
    # interpolate a baseline
    return np.interp(bands, bands[hidx], intensities[hidx])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号