Ejemplo n.º 1
0
def match_lines2(s, wvl, ref_line_list):
    """

    returns matched_indices, matched_fit_params, matched_distances

    matched_indices : indices of lines (from ref_line_list) that are
                      associated with line features in the given spectra

    matched_distances : distances in pixel

    """

    # find centroids of s
    from libs.find_peak import find_peaks
    sol_list = find_peaks(s, sigma=3)
    cent_list = np.array([sol[0] for sol in sol_list])

    # define transform from lambda to pixel
    wvl2pix = interp1d(wvl, np.arange(len(wvl)))

    ref_pix_list = wvl2pix(ref_line_list)


    # find nearest matches

    kdtree = spatial.KDTree(ref_pix_list.reshape([-1,1]))
    dists, indices = kdtree.query(cent_list.reshape([-1,1]))

    # filter out multiple hits. Only the nearest one remains.
    filtered_indices = []
    for k, l in itertools.groupby(zip(indices,
                                      sol_list, dists),
                                  operator.itemgetter(0)):
        l = list(l)
        i = np.argmin([l1[-1] for l1 in l])
        filtered_indices.append(l[i])

    matched_indices =  [s_[0] for s_ in filtered_indices]
    matched_fit_params = [s_[1] for s_ in filtered_indices]
    matched_distances = [s_[2] for s_ in filtered_indices]

    return matched_indices, matched_fit_params, matched_distances
Ejemplo n.º 2
0
def match_lines1_pix(s, ref_pix_list):
    """

    returns matched_indices, matched_fit_params, matched_distances

    matched_indices : indices of lines (from ref_line_list) that are
                      associated with line features in the given spectra

    matched_distances : distances in pixel

    """

    # find centroids of s
    from libs.find_peak import find_peaks
    sol_list = find_peaks(s, sigma=3)
    cent_list = np.array([sol[0] for sol in sol_list])

    cent_list, dists = match_lines1_pixel(cent_list, ref_pix_list)

    return cent_list, dists