Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define a generic gaussian function
- def gauss_lin(x, *params):
- """
- This defines a generic gaussiann function plus a linear background, with
- an arbitrary number of peaks. Pass the X values and a pointer to your
- initial guesses.
- Make sure that guesses are in the order of slope, intercept, amplitude,
- mean, and sigma, and that you have a multiple of 2+3n guesses to pass in.
- Parameters
- ----------
- x : independent variable
- params : parameters for the Gaussian function
- - slope: slope of the linear background
- - intercept: y-intercept of the linear background
- - amplitude: height of the peak
- - mean: position of the center of the peak
- - sigma: width of the peak
- - (repeat for multiple peaks)
- Returns
- -------
- y : dependent variable
- """
- y = np.zeros_like(x)
- slope = params[0]
- intercept = params[1]
- y += slope * x + intercept
- for i in range(2, len(params), 3):
- amplitude = params[i]
- mean = params[i + 1]
- sigma = params[i + 2]
- y += amplitude * np.exp(-(( x - mean) ** 2) / (2 * sigma ** 2))
- return y
- # End of gauss_lin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement