0

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))
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    What exactly isn't working with the linked post? Did you try using the same input data in there and did it also return the wrong answer? – OneCricketeer Jun 26 '21 at 22:32
  • I used some data I have that is similar to the question and got the wrong answers that i put on the question. I used the linked post as base to my code, but I'm glad if there is another thing I could do to achieve a better response. – Yan Vinícius Jun 28 '21 at 12:59
  • So, what exactly did you change from the linked post? – OneCricketeer Jun 28 '21 at 13:52
  • The main change I did was to use 2 txt files to create my graphic. – Yan Vinícius Jul 02 '21 at 15:07

0 Answers0