I'im developing a python system where I need to calculate the graphic FWHM where the user says the txt files for X and Y axis (I save the axis in 2 lists xList and yList2). I ran two graphics and the results i got were: 30.918nm (correct value: 34.786 nm) and 76.601nm (correct value: 74.710nm). I'm using this solution: FWHM calculation using python. My code is:
import numpy as np
def lin_interp(x, y, i, half):
return x[i] + (x[i+1] - x[i]) * ((half - y[i]) / (y[i+1] - y[i]))
class FWHM:
def __init__(self, xList, yList2):
self.xList = xList
self.yList2 = yList2
#pega os valores máximo e mínimo do eixo Y e divide por 2
y_min = (min(yList2))
y_max = (max(yList2))
med_y = ((y_max-y_min)/2)
#cálculo para descobrir os pontos (x1 e x2) que estão à meia altura
signs = np.sign(np.add(yList2, -med_y))
zero_crossings = (signs[0:-2] != signs[1:-1])
zero_crossings_i = np.where(zero_crossings)[0]
x1 = lin_interp(xList, yList2, zero_crossings_i[1], med_y)
x2 = lin_interp(xList, yList2, zero_crossings_i[0], med_y)
#printa os pontos do eixo X e o FWHM
print(x1, x2, abs(x1-x2))