Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fit_peaks(self, type, initial_guesses):
- """
- Fit the data to a specified function.
- Parameters:
- initial_guesses (tuple): Initial guesses for the fit parameters.
- Returns:
- tuple: Fitted parameters and covariance matrix.
- """
- parameters = getattr(self, f"{type}_parameters")
- x = getattr(self, f"{type}_channel")
- y = getattr(self, f"{type}_counts")
- # Fit the data to the specified function
- popt, pcov = curve_fit(gauss_lin,
- x,
- y,
- p0=initial_guesses)
- # print(f"Linear background is: y= {popt[0]:.2f}x + {popt[1]:.2f}")
- parameters = popt
- peak_amplitude = getattr(self, f"{type}_peak_amplitude")
- peak_mean = getattr(self, f"{type}_peak_mean")
- peak_sigma = getattr(self, f"{type}_peak_sigma")
- for i in range(2, len(popt), 3):
- peak_amplitude.append(popt[i])
- peak_mean.append(popt[i + 1])
- peak_sigma.append(popt[i + 2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement