Exemplo n.º 1
0
def test_extract_peaks():
    x = np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2])
    y = np.array([1., 8., 1., 9., 8., 9., 1., 1., 5., 1., 1., 4., 1.])
    px, py = extract_peaks(x, y, threshold_fraction = 0.5, delta = 0.25)
    assert_array_equal(px, [0.3, 0.8])
    assert_array_equal(py, [9.0, 5.0])

    px, py = extract_peaks(x, y, threshold_fraction = 0.5, delta = 0.01)
    assert_array_equal(px, [0.1, 0.3, 0.5, 0.8])
    assert_array_equal(py, [8.0, 9.0, 9.0, 5.0])

    px, py = extract_peaks(x, y, threshold_fraction = 0.2, delta = 0.01)
    assert_array_equal(px, [0.1, 0.3, 0.5, 0.8, 1.1])
    assert_array_equal(py, [8.0, 9.0, 9.0, 5.0, 4.0])
Exemplo n.º 2
0
def label_spectrum_single(
        row,
        known_emission_lines,
        peak_threshold_fraction,
        label_peaks_strategy,
        filter_elements_fraction,
        delta):

    xs, ys = row_to_spectrum(row)
    px, py = extract_peaks(xs, ys,
        threshold_fraction = peak_threshold_fraction,
        delta = delta)
    filtered_elements = filter_elements(px, known_emission_lines,
        drop_if_below_fraction = filter_elements_fraction,
        delta = delta,
        group_by = ["elt", "ex"])
    e_to_p, p_to_e, unlabeled = label_peaks(
        px,
        known_emission_lines,
        delta = delta,
        strategy = label_peaks_strategy)

    labeled_peaks = json.dumps(p_to_e)
    extra_columns = pd.Series([labeled_peaks], index = ['labeled_peaks'])
    return row.append(extra_columns)