Utility functions

This folder contains further functions that help with various tasks. These functions are split up into individual files, depending on their specific tasks.

Fitting functions

gaussian()

rimseval.utilities.fitting.gaussian(xdat: float | ndarray, coeffs: ndarray) float | ndarray

Return the value of a Gaussian for given parameters.

Parameters:
  • xdat – X value

  • coeffs – Coefficients, [mu, sigma, height]

Returns:

Value of the Gaussian.

residuals_gaussian()

rimseval.utilities.fitting.residuals_gaussian(coeffs: ndarray, ydat: ndarray, xdat: ndarray) ndarray

Calculate residuals and return them.

Parameters:
  • coeffs – Coefficients for model

  • ydat – Y data to compare with

  • xdat – X data for model fit

Returns:

Residual of the Gaussian.

Peirce’s rejection criterion

Functions to deal with Peirce’s rejection criterion. See Wikipedia and this PDF file for details.

peirce_criterion()

rimseval.utilities.peirce.peirce_criterion(n_tot: int, n: int, m: int = 1) float

Peirce’s criterion.

Returns the threshold error deviation for outlier identification using Peirce’s criterion based on Gould’s methodology. This routine is heavily copied from Wikipedia

Parameters:
  • n_tot – Total number of observations.

  • n – Number of outliers to be removed.

  • m – Number of model unknowns, defaults to 1.

Returns:

Error threshold R (Ross, 2003) / Square root of x**2 (Gould, 1955)

reject_outliers()

rimseval.utilities.peirce.reject_outliers(data: ndarray, m: int = 1) Tuple[float, float, ndarray, ndarray]

Apply Peirce’s criterion to reject outliers.

Algorithm implmeneted as given by Ross (2003).

Parameters:
  • data – All data points.

  • m – Number of model unknowns, defaults to 1.

Returns:

New average and standard deviation, Array with the outliers.

Utilities

Further utility routines that do not fit anywhere else.

rimseval.utilities.utils.not_index(ind: array, length: int) array

Reverse an index.

After filtering ions, e.g., using np.where, and keeping the indices of an array, this routine creates the opposite, i.e., an array of the indices that have not been filtered.

Parameters:
  • ind – Array of all the indexes.

  • length – Length of the original index to take out of.

Returns:

The reversed index.

Raises:

ValueError – Max index is larger than the total length, which should not be.

Example:
>>> a = np.arange(7)
>>> b = np.where(a < 4)[0]
>>> b
array([0, 1, 2, 3])
>>> not_index(b)
array([4, 5, 6])