python - 如何将 find_peaks 用于频谱(python)
问题描述
我需要自动找到一个特定的峰来快速处理数百个光谱。我已经将函数的搜索重新集中在我感兴趣的光谱区域上,但这总是给出远非令人满意的结果。我尝试了不同的参数:阈值、距离和突出度,这似乎是最适合的,但没有找到峰值。
import numpy as np
import os
import matplotlib.pyplot as plt
import scipy.signal as sig
def N_spectres(path_file):
spectres = np.loadtxt(path_file, skiprows=1, usecols=(2,3))
N_spectre = 0
i=0
ref = spectres[0,0]
while i < len(spectres[:,0]) :
if spectres[i,0]==ref :
N_spectre +=1
i+=1
return N_spectre
##############################################################################
# Data declaration
##############################################################################
file_name = "F837 FeCl3 Rux3 SiO2 E14 MAP cata_532 nm.txt"
os.chdir("DataRenishaw")
correct = 0
#############################################################
file = np.loadtxt(file_name, usecols=(2,3))
N_spectra = N_spectres(file_name)
Nb_point = int(len(file[:,0])/N_spectra)
debut = Nb_point - 230
axes = plt.gca()
plt.show()
i=0
counter=1
while i < len(file[:,0]):
peaks, _= sig.find_peaks(file[i+debut:i+Nb_point-correct, 1], prominence = 100)
plt.plot(peaks, file[i+debut:i+Nb_point-correct, 1][peaks], "xr")
plt.plot(file[i+debut:i+Nb_point-correct, 0], file[i+debut:i+Nb_point-correct, 1])
axes.set_xlabel("Nombre d'onde (cm^-1)")
axes.set_ylabel("Intensité")
#plt.plot(file[i+debut:i+Nb_point, 0], file[i+debut:i+Nb_point, 1])
plt.title(file_name+"\n Spectre n° : "+str(counter))
#plt.axis([70,350,2000,10000])
i+=Nb_point
counter+=1
plt.show()
在某些光谱上,会出现一个峰,这是我感兴趣的峰。结果如下:
我该怎么做才能从 find_peaks 函数中获得更好的结果?
解决方案
推荐阅读
- ajax - Jquery Datatable 数据到 mvc 控制器
- excel - 当另一个值更改时增加 vlookup 单元格引用
- jenkins - 修复 jenkins svn 认证问题 ProxyException
- joomla - 防止注册带有加号 (+) 的电子邮件地址
- java - 如何使用另一个类的属性创建(getter)方法
- http-status-code-404 - 热创建 Artifactory 页面 404 定制?
- java - SIP 注册失败 - 超时 - 清单中包含的所有权限,但应用程序中未包含来自互联网权限的接收数据
- ios - 在 iPad 上使用全屏模式的 iOS 12 出现问题 - 网络钓鱼检测误报
- ibm-certificate-manager - 云证书管理器与 SSL 服务
- c# - 静态变量到线程 C#