fitmultipeak module

File : fitmultipeak.py Author : Rolf Verberg Description: Test program to fit a multipeak spectrum

create_data(peak_pars, trend_pars=None, num_peak=3, seed=1, scale=0.05, no_noise=False, num=1000)

Create the data to fit.

Parameters:
  • peak_pars (dict) – Peak parameters and their stdev.

  • trend_pars (dict, optional) – Treadline parameters, default to no trendline.

  • num_peak (int, optional) – Number of peaks, defaults to 3.

  • seed (int) – Random generator initial seed, default to 1.

  • scale (float, optional) – Stdev for y-coordinate noise, defaults to 0.05.

  • no_noise (bool, optional) – No noise is added if set, defaults to False.

  • num (int, optional) – Number of data points, defaults to 1000.

Returns:

The x and y coordinates and the nominal peak center positions.

Return type:

np.ndarray, np.ndarray, list[float]

fit(x, y, centers)

Fit a spectrum with a multipeak Gaussian function and optionally a quadratic trendline.

Parameters:
  • x (np.ndarray) – x-coordinates.

  • y (np.ndarray) – y-coordinates.

  • centers (list[float]) – Nominal peak center positions.

Returns:

The fit result.

Return type:

CHAP.utils.fit.Fit

main()

Main function.

ran_uni(set_seed=None)

Create a random number distributed in the range [-0.5, 0.5].

Parameters:

set_seed (int, optional) – Initialial seed for the random number generator if set.

Returns:

Random number distributed in [-0.5, 0.5] if set_seed is None.

Return type:

Union[None, float]