# Find peaks method for finding elusive peaks

I'm currently utilizing the find_peaks function to identify peaks within this spectrum. However, despite consulting similar queries on Stack Overflow, my attempts to incorporate features such as prominence and width have been unsuccessful. One peak in particular, labeled as "missing peak" in the image , remains elusive.

Why I know that is a peak? because i know the spectra, and that that energy correspond to the second level of emission of Niquel that has a peak in 7.48 and other in 8.26. Could anyone suggest a method that might prove effective for identifying such peaks within this type of spectrum?

This is my current code

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
a = -0.0188026396003431
b = 0.039549044037714
shape = np.shape(Data)
if shape == (2048, 1):
dim = 0
else:
dim = 1

inf=[]
sup=[]
energy_spectrum=[]
# Sample function definition for plot_energy_spectrum
def plot_energy_spectrum(Data, a, b,i,ax=None):
maxim = np.max(Data)
maxim=1
workingarray = np.squeeze(Data)
x = a + b * np.linspace(0, 885, 885)
ax.plot(x, workingarray[:885] / maxim,label=elements[i],color='black', marker='o')

peaks, _ = find_peaks(workingarray / maxim, height=50,prominence=7,width=0.0756)

peak_values = workingarray[peaks] / maxim
peak_indices = peaks
print( peak_values)
ax.scatter(a + b * peak_indices, peak_values,color='black', marker='o', s=20)

for i in range(len(peak_indices)):
ax.annotate(f"{a + b * peak_indices[i]:.2f} KeV", (a + b * peak_indices[i], peak_values[i]),
textcoords="offset points", xytext=(0, 10), ha='center')

inf.append(x[peak_indices[0] - 5])
sup.append(x[peak_indices[-1] + 5])
ax.set_xlabel('Energy (KeV)')
ax.set_ylabel('Normalized data')
ax.legend()
ax.set_title('Calibrated plot')

# print(a + b * peak_indices, sep='\n')
# print(*peak_values, sep='\n')
energy_spectrum.append(a + b * peak_indices)
#print(peak_indices, sep='\n')

if dim == 0:
fig, ax = plt.subplots()
plot_energy_spectrum(Data[:, 0],a, b,i,ax=ax)
ax.set_xlim(inf[0], sup[0])
#ax.set_xlim([8.64-3*0.0704,8.64+3*0.0704])
plt.show()
else:

fig, ax = plt.subplots()
for i in range(Data.shape[1]):
plot_energy_spectrum(Data[:, i], a, b,i,ax=ax)  # Pass the ax object to plot_energy_spectrum
ax.set_xlim([np.min(inf),np.max(sup)])
plt.show()

print(min(energy_spectrum))


And this is the code that I use to prepare the data in order to be analysed, so feel free to use it to open the spectrum data

import os
drive.mount('/content/drive')

# Function to read numeric data from a file
with open(file_path, 'r', encoding='latin1') as f:
data = []
live_time = None
real_time = None
for line in f:
if 'LIVE_TIME' in line:
live_time = line.strip()
elif 'REAL_TIME' in line:
real_time = line.strip()
elif all(char.isdigit() or char in ".-+e" for char in line.strip()):
row = [float(x) for x in line.split()]
data.extend(row)
return np.array(data), live_time, real_time

file_path = '/content/drive/MyDrive/ProjetoXRF_Manuel/April2024/Amostra4.mca'