Advertisement
GregLeblanc

Untitled

Apr 14th, 2025 (edited)
416
0
362 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1.  
  2.     def fit_peaks(self, type, initial_guesses):
  3.         """
  4.        Fit the data to a specified function.
  5.        
  6.        Parameters:
  7.        initial_guesses (tuple): Initial guesses for the fit parameters.
  8.        
  9.        Returns:
  10.        tuple: Fitted parameters and covariance matrix.
  11.        """
  12.         parameters = getattr(self, f"{type}_parameters")
  13.         x = getattr(self, f"{type}_channel")
  14.         y = getattr(self, f"{type}_counts")
  15.          
  16.         # Fit the data to the specified function
  17.         popt, pcov = curve_fit(gauss_lin,
  18.                                x,
  19.                                y,
  20.                                p0=initial_guesses)
  21.         # print(f"Linear background is: y= {popt[0]:.2f}x + {popt[1]:.2f}")
  22.        
  23.         parameters = popt
  24.  
  25.         peak_amplitude = getattr(self, f"{type}_peak_amplitude")
  26.         peak_mean = getattr(self, f"{type}_peak_mean")
  27.         peak_sigma = getattr(self, f"{type}_peak_sigma")
  28.  
  29.         for i in range(2, len(popt), 3):
  30.             peak_amplitude.append(popt[i])
  31.             peak_mean.append(popt[i + 1])
  32.             peak_sigma.append(popt[i + 2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement