Scipy find_peaks 函数无法识别 Carbon XPS 数据中的峰值

问题描述 投票:0回答:1

我有碳的 XPS 数据,如图所示,有一种隐藏的峰值(峰值 2),当边界有限时,它在 Excel 上更清晰,我尝试了不同的参数来查找峰值,但它一直忽略它。

Literature diagram

Data on excel

# Find peaks
peaks, _ = find_peaks(y_values, prominence=1, height=50)  # adjust parameters as needed

# Plot the data
plt.figure(figsize=(10, 5))
plt.plot(x_values, y_values)
plt.plot(x_values[peaks], y_values[peaks], 'r.')
plt.show()

Output

无论如何,是否可以通过查找峰值来找到第二个峰值,或者是否有其他功能我可以尝试,而无需自己将变量分配给确切的点。

这是我的数据:

import numpy as np
x_values = np.array([541.0, 540.898, 540.797, 540.695, 540.594, 540.492, 540.391, 540.289, 540.187, 540.086, 539.984, 539.883, 539.781, 539.68, 539.578, 539.477, 539.375, 539.273, 539.172, 539.07, 538.969, 538.867, 538.766, 538.664, 538.563, 538.461, 538.359, 538.258, 538.156, 538.055, 537.953, 537.852, 537.75, 537.648, 537.547, 537.445, 537.344, 537.242, 537.141, 537.039, 536.938, 536.836, 536.734, 536.633, 536.531, 536.43, 536.328, 536.227, 536.125, 536.023, 535.922, 535.82, 535.719, 535.617, 535.516, 535.414, 535.313, 535.211, 535.109, 535.008, 534.906, 534.805, 534.703, 534.602, 534.5, 534.399, 534.297, 534.195, 534.094, 533.992, 533.891, 533.789, 533.688, 533.586, 533.484, 533.383, 533.281, 533.18, 533.078, 532.977, 532.875, 532.774, 532.672, 532.57, 532.469, 532.367, 532.266, 532.164, 532.063, 531.961, 531.86, 531.758, 531.656, 531.555, 531.453, 531.352, 531.25, 531.149, 531.047, 530.945, 530.844, 530.742, 530.641, 530.539, 530.438, 530.336, 530.235, 530.133, 530.031, 529.93, 529.828, 529.727, 529.625, 529.524, 529.422, 529.32, 529.219, 529.117, 529.016, 528.914, 528.813, 528.711, 528.61, 528.508, 528.406, 528.305, 528.203, 528.102, 528.0, 527.899, 527.797, 527.696, 527.594, 527.492, 527.391, 527.289, 527.188, 527.086, 526.985, 526.883, 526.781, 526.68, 526.578, 526.477, 526.375, 526.274, 526.172, 526.071, 525.969, 525.867, 525.766, 525.664, 525.563, 525.461, 525.36, 525.258, 525.156, 525.055, 524.953, 524.852, 524.75, 524.649, 524.547, 524.446, 524.344, 524.242, 524.141, 524.039, 523.938, 523.836, 523.735, 523.633, 523.532, 523.43, 523.328, 523.227, 523.125, 523.024, 522.922, 522.821, 522.719, 522.617, 522.516, 522.414, 522.313, 522.211, 522.11, 522.008, 521.907, 521.805, 521.703, 521.602, 521.5, 521.399, 521.297, 521.196, 521.094, 520.993, 520.891, 520.789, 520.688, 520.586, 520.485, 520.383, 520.282, 520.18, 520.078, 519.977, 519.875, 519.774, 519.672, 519.571, 519.469, 519.368, 519.266, 519.164, 519.063, 518.961, 518.86, 518.758, 518.657, 518.555, 518.453, 518.352, 518.25, 518.149, 518.047, 517.946, 517.844, 517.743, 517.641, 517.539, 517.438, 517.336, 517.235, 517.133, 517.032, 516.93, 516.829, 516.727, 516.625, 516.524, 516.422, 516.321, 516.219, 516.118, 516.016, 515.914, 515.813, 515.711, 515.61, 515.508, 515.407, 515.305, 515.204, 515.102])
y_values = np.array([532.0, 578.798, 579.991, 547.426, 581.397, 563.409, 598.07, 559.236, 552.207, 502.015, 554.546, 510.321, 540.243, 511.492, 502.404, 493.493, 540.986, 538.38, 530.542, 516.08, 553.795, 558.839, 533.378, 520.071, 554.352, 561.609, 570.081, 517.388, 543.012, 518.682, 522.045, 546.661, 556.104, 511.879, 523.131, 489.059, 514.627, 520.0, 502.23, 526.207, 502.19, 491.942, 498.549, 527.537, 490.663, 482.826, 485.465, 503.979, 499.058, 472.742, 487.912, 477.8, 466.839, 465.0, 476.019, 473.521, 483.677, 466.872, 459.46, 430.675, 416.671, 433.923, 426.453, 474.383, 455.182, 434.755, 452.121, 437.514, 430.737, 428.071, 410.984, 379.671, 403.811, 422.721, 407.231, 399.294, 407.426, 399.137, 417.58, 412.837, 382.027, 392.78, 403.0, 415.768, 392.621, 370.039, 371.273, 366.143, 400.378, 362.198, 344.909, 351.058, 335.853, 334.388, 355.765, 354.027, 371.408, 360.517, 349.938, 345.645, 331.871, 338.086, 337.0, 335.766, 334.269, 355.657, 352.02, 341.049, 348.593, 342.312, 345.745, 368.031, 362.849, 348.895, 354.032, 344.715, 336.847, 334.548, 314.314, 315.488, 320.016, 346.263, 368.668, 336.551, 311.455, 312.043, 322.103, 333.515, 331.524, 332.91, 340.0, 333.211, 325.039, 309.234, 309.048, 321.855, 329.439, 344.541, 350.822, 354.946, 350.892, 361.817, 381.605, 379.48, 364.561, 390.936, 432.882, 453.498, 481.646, 510.265, 570.595, 660.56, 752.368, 848.6, 952.16, 1152.19, 1321.03, 1506.57, 1739.6, 1852.39, 2017.11, 2195.02, 2290.98, 2336.5, 2352.62, 2397.25, 2363.37, 2348.33, 2340.48, 2270.91, 2276.46, 2284.39, 2265.04, 2316.24, 2383.37, 2489.15, 2550.97, 2549.44, 2542.15, 2545.73, 2418.45, 2302.77, 2069.91, 1852.75, 1680.41, 1448.06, 1239.73, 1050.01, 896.686, 772.546, 638.703, 549.506, 489.718, 453.084, 421.465, 386.54, 349.766, 350.151, 343.386, 315.197, 340.307, 318.909, 297.553, 321.623, 300.8, 337.824, 301.359, 321.381, 311.462, 314.788, 293.208, 267.455, 300.159, 304.71, 295.175, 280.611, 286.373, 298.836, 287.963, 265.726, 268.168, 257.0, 259.117, 273.128, 275.484, 286.955, 293.079, 282.566, 260.004, 298.425, 265.043, 248.216, 262.677, 289.236, 282.451, 298.084, 287.216, 287.427, 254.092, 284.35, 274.11, 277.716, 309.908, 308.085, 308.532, 279.388, 288.504, 300.449, 284.729, 277.111, 317.859, 266.034, 268.168, 281.052, 286.978, 282.0])
python scipy
1个回答
0
投票

假设我们要拟合多峰模型,以便回归位置、高度和宽度等参数。

您有两个挑战需要解决:

  • 删除基线
  • 找到结论性的初步猜测

对于给定的数据集,可以回归三个峰值。

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats, optimize
from pybaselines import Baseline

我们删除基线:

fitter = Baseline(x_data=x)
background, parameters = fitter.rolling_ball(y)
yb = y - background

现在我们可以创建模型并拟合多个峰值:

def peak(x, x0, s, A):
    law = stats.norm(loc=x0, scale=s)
    return A * law.pdf(x) / law.pdf(x0)

def model(x, x0, s0, A0, x1, s1, A1, x2, s2, A2):
    return peak(x, x0, s0, A0) + peak(x, x1, s1, A1) + peak(x, x2, s2, A2)

popt, pcov = optimize.curve_fit(model, x, yb, p0=[522, 1, 2000, 523, 1, 2000, 524, 1, 2000])

并渲染完整的结果:

fig, axe = plt.subplots()
axe.plot(x, yb)
axe.plot(x, yhat)
for i in range(3):
    axe.plot(x, peak(x, *popt[i*3:(i+1)*3]), "--", color="gray")
    axe.axvline(popt[i*3], color="black")
axe.grid()

© www.soinside.com 2019 - 2024. All rights reserved.