Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

matplotlib - How to use find_peaks for spectrum (python)

I need to automatically find a specific peak to process hundreds of spectra quickly. I have refocused the search for the function on the area of the spectrum I am interested in, but this always gives a far from satisfying result. I tried with the different parameters: threshold, distance and prominence which seems to be the most adapted but it doesn't find the peaks.

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+"
 Spectre n° : "+str(counter))
    #plt.axis([70,350,2000,10000])
    i+=Nb_point
    counter+=1
    plt.show()


On some spectra, a peak appears, it is the one im interested in. Here is the result :

RBM spectra

what could I do to get a better result from the find_peaks function ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...