Advertisement
GregLeblanc

Untitled

Apr 14th, 2025
449
0
362 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. # Define a generic gaussian function
  2. def gauss_lin(x, *params):
  3.     """
  4.    This defines a generic gaussiann function plus a linear background, with
  5.    an arbitrary number of peaks.  Pass the X values and a pointer to your
  6.    initial guesses.
  7.    Make sure that guesses are in the order of slope, intercept, amplitude,
  8.    mean, and sigma, and that you have a multiple of 2+3n guesses to pass in.  
  9.    
  10.    Parameters
  11.    ----------
  12.    x : independent variable
  13.    params : parameters for the Gaussian function
  14.        - slope: slope of the linear background
  15.        - intercept: y-intercept of the linear background
  16.        - amplitude: height of the peak
  17.        - mean: position of the center of the peak
  18.        - sigma: width of the peak
  19.        - (repeat for multiple peaks)
  20.    
  21.    Returns
  22.    -------
  23.    y : dependent variable
  24.    """
  25.     y = np.zeros_like(x)
  26.     slope = params[0]
  27.     intercept = params[1]
  28.     y += slope * x + intercept
  29.     for i in range(2, len(params), 3):
  30.         amplitude = params[i]
  31.         mean = params[i + 1]
  32.         sigma = params[i + 2]
  33.         y += amplitude * np.exp(-(( x - mean) ** 2) / (2 * sigma ** 2))
  34.     return y
  35. # End of gauss_lin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement