peak_performance.models#

This is the core of PeakPerformance, where the model functions for peaks are defined.

This module contains functions for creating various kinds of peak models and to make initial guesses for their parameters.

class peak_performance.models.ModelType(value)#

Bases: str, Enum

Enum of default model types.

Methods

capitalize(/)

Return a capitalized version of the string.

casefold(/)

Return a version of the string suitable for caseless comparisons.

center(width[, fillchar])

Return a centered string of length width.

count(sub[, start[, end]])

Return the number of non-overlapping occurrences of substring sub in string S[start:end].

encode(/[, encoding, errors])

Encode the string using the codec registered for encoding.

endswith(suffix[, start[, end]])

Return True if S ends with the specified suffix, False otherwise.

expandtabs(/[, tabsize])

Return a copy where all tab characters are expanded using spaces.

find(sub[, start[, end]])

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

format(*args, **kwargs)

Return a formatted version of S, using substitutions from args and kwargs.

format_map(mapping)

Return a formatted version of S, using substitutions from mapping.

index(sub[, start[, end]])

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

isalnum(/)

Return True if the string is an alpha-numeric string, False otherwise.

isalpha(/)

Return True if the string is an alphabetic string, False otherwise.

isascii(/)

Return True if all characters in the string are ASCII, False otherwise.

isdecimal(/)

Return True if the string is a decimal string, False otherwise.

isdigit(/)

Return True if the string is a digit string, False otherwise.

isidentifier(/)

Return True if the string is a valid Python identifier, False otherwise.

islower(/)

Return True if the string is a lowercase string, False otherwise.

isnumeric(/)

Return True if the string is a numeric string, False otherwise.

isprintable(/)

Return True if the string is printable, False otherwise.

isspace(/)

Return True if the string is a whitespace string, False otherwise.

istitle(/)

Return True if the string is a title-cased string, False otherwise.

isupper(/)

Return True if the string is an uppercase string, False otherwise.

join(iterable, /)

Concatenate any number of strings.

ljust(width[, fillchar])

Return a left-justified string of length width.

lower(/)

Return a copy of the string converted to lowercase.

lstrip([chars])

Return a copy of the string with leading whitespace removed.

maketrans

partition(sep, /)

Partition the string into three parts using the given separator.

removeprefix(prefix, /)

Return a str with the given prefix string removed if present.

removesuffix(suffix, /)

Return a str with the given suffix string removed if present.

replace(old, new[, count])

Return a copy with all occurrences of substring old replaced by new.

rfind(sub[, start[, end]])

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

rindex(sub[, start[, end]])

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

rjust(width[, fillchar])

Return a right-justified string of length width.

rpartition(sep, /)

Partition the string into three parts using the given separator.

rsplit(/[, sep, maxsplit])

Return a list of the substrings in the string, using sep as the separator string.

rstrip([chars])

Return a copy of the string with trailing whitespace removed.

split(/[, sep, maxsplit])

Return a list of the substrings in the string, using sep as the separator string.

splitlines(/[, keepends])

Return a list of the lines in the string, breaking at line boundaries.

startswith(prefix[, start[, end]])

Return True if S starts with the specified prefix, False otherwise.

strip([chars])

Return a copy of the string with leading and trailing whitespace removed.

swapcase(/)

Convert uppercase characters to lowercase and lowercase characters to uppercase.

title(/)

Return a version of the string where each word is titlecased.

translate(table, /)

Replace each character in the string using the given translation table.

upper(/)

Return a copy of the string converted to uppercase.

zfill(width, /)

Pad a numeric string with zeros on the left, to fill a field of the given width.

DoubleNormal = 'double_normal'#

Superposition of two Normal peaks.

DoubleSkewNormal = 'double_skew_normal'#

Superposition of two SkewedNormal peaks.

Normal = 'normal'#

Shape of a Gaussian Normal PDF.

SkewNormal = 'skew_normal'#

Shape of a skewed Normal PDF.

peak_performance.models.baseline_intercept_prior_params(intercept_guess: float | int) Mapping[str, float]#

Centralized function for supplying parameters for the baseline intercept prior.

Returns:
parameter_dict

Dictionary containing mu and sigma for the normally distributed prior.

peak_performance.models.baseline_slope_prior_params(slope_guess: float | int) Mapping[str, float]#

Centralized function for supplying parameters for the baseline slope prior.

Returns:
parameter_dict

Dictionary containing mu and sigma for the normally distributed prior.

peak_performance.models.compute_log_likelihood(pmodel: Model, idata: InferenceData)#

Method to compute the element-wise loglikelihood of every posterior sample and add it to a given inference data object.

Parameters:
pmodel

PyMC model.

idata

Inference data object resulting from sampling.

Returns:
idata

Inference data object updated with element-wise loglikelihood of every posterior sample.

peak_performance.models.define_model_double_normal(time: ndarray, intensity: ndarray) Model#

Define a model for fitting two ordered normal distributions to the peak data (for when data contains two peaks or a double peak without baseline separation).

Parameters:
time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

Returns:
pmodel

PyMC model.

peak_performance.models.define_model_double_skew_normal(time: ndarray, intensity: ndarray) Model#

Define a model for fitting two ordered skew normal distributions to the peak data (for when data contains two peaks or a double peak without baseline separation).

Parameters:
time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

Returns:
pmodel

PyMC model.

peak_performance.models.define_model_normal(time: ndarray, intensity: ndarray) Model#

Define a model for fitting a normal distribution to the peak data.

Parameters:
time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

Returns:
pmodel

PyMC model.

peak_performance.models.define_model_skew(time: ndarray, intensity: ndarray) Model#

Define a model for fitting a skew normal distribution to the peak data.

Parameters:
time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

Returns:
pmodel

PyMC model.

peak_performance.models.delta_calculation(alpha)#

Calculate the delta term included in several subsequent formulae.

Parameters:
alpha

Skewness parameter of the skew normal distribution.

peak_performance.models.double_model_mean_prior(time)#

Function creating prior probability distributions for the mean retention times of a dual-peak.

Parameters:
time

NumPy array with the time values of the relevant timeframe.

Returns:
mean

Normally distributed prior for the ordered means of the multi-peak model.

diff

Difference between the group mean and peak-wise mean.

meanmean

Normally distributed prior for the group mean of the peak means.

peak_performance.models.double_normal_peak_shape(baseline, time: ndarray, mean, std, *, height)#

Model a peak shaped like a univariate ordered normal distribution.

Parameters:
baseline

Baseline of the data.

time

NumPy array with the time values of the relevant timeframe.

mean

Arithmetic mean of the normal distribution.

std

Standard deviation of the first and second peak.

height

Height of the first and second peak.

Returns:
y

Probability density function (PDF) of a univariate ordered normal distribution as the posterior.

peak_performance.models.double_skew_normal_peak_shape(baseline, time: ndarray, mean, std, alpha, *, area)#

Model a peak shaped like the a univariate ordered skew normal distribution.

Parameters:
baseline

Baseline of the data.

time

NumPy array with the time values of the relevant timeframe.

mean

Location parameter.

std

Scale parameter of the first and second peak.

alpha

Skewness parameter of the first and second peak.

area

Area of the first and second peak.

Returns:
y

Probability density function (PDF) of a univariate ordered normal distribution as the posterior.

peak_performance.models.guess_noise(intensity)#

Function for providing a guess for the noise width of a given signal based on the first and last 15 % of data points in a time series.

Parameters:
time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

peak_performance.models.height_calculation(area, loc, scale, alpha, mode_skew)#

Calculate the height of a skew normal distribution. The formula is the result of inserting time = mode_skew into the posterior.

Parameters:
area

Area of the peak described by the skew normal distribution (area between baseline and skew normal distribution).

loc

Location parameter of the skew normal distribution.

scale

Scale parameter of the skew normal distribution.

alpha

Skewness parameter of the skew normal distribution.

mode_skew

Mode of the skew normal distribution.

Returns:
mean

Arithmetic mean of a skew normal distribution.

peak_performance.models.initial_guesses(time: ndarray, intensity: ndarray)#

Provide initial guesses for priors.

Parameters:
time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

Returns:
baseline_fit.slopefloat or int

Guess for the slope of the linear baseline prior.

baseline_fit.interceptfloat or int

Guess for the intercept of the linear baseline prior.

noise_width_guessfloat or int

Guess for the width of the noise.

peak_performance.models.mean_skew_calculation(loc, scale, alpha)#

Calculate the arithmetic mean of a skew normal distribution with f(x | loc, scale, alpha).

Parameters:
loc

Location parameter of the skew normal distribution.

scale

Scale parameter of the skew normal distribution.

alpha

Skewness parameter of the skew normal distribution.

Returns:
mean

Arithmetic mean of a skew normal distribution.

peak_performance.models.mode_offset_calculation(mue_z, skewness, sigma_z, alpha)#

Calculate the offset between arithmetic mean and mode of a skew normal distribution.

peak_performance.models.mode_skew_calculation(loc, scale, mode_offset)#

Calculate a numerical approximation of the mode of a skew normal distribution.

peak_performance.models.model_comparison(compare_dict: Mapping[str, InferenceData], ic: str = 'loo') DataFrame#

Method to compare the models detailed in compare_dict based on the leave-one-out cross-validation (loo) or the widely-applicable information criterion (waic).

Parameters:
compare_dict

Dictionary with the model denominations as keys and their respective inference data objects as values.

ic

Choice of the information criterion with which models are ranked (“loo” or “waic”). Default is “loo”.

Returns:
df_comp

DataFrame containing the ranking of the given models.

peak_performance.models.mue_z_calculation(delta)#

Calculate the mue_z variable which is needed to compute a numerical approximation of the mode of a skew normal distribution.

peak_performance.models.multi_peak_means_prior(time)#

Function creating prior probability distributions for multi-peaks using a ZeroSumNormal distribution.

The number of peaks is determined from the “subpeak” model coordinates.

Parameters:
time

NumPy array with the time values of the relevant timeframe.

Returns:
mean

Normally distributed prior for the ordered means of the multi-peak model.

offset

Time offset between the group mean and peak-wise mean.

meanmean

Normally distributed prior for the group mean of the peak means.

peak_performance.models.normal_peak_shape(baseline, time: ndarray, mean, std, *, height)#

Model a peak shaped like a normal distribution.

Parameters:
baseline

Baseline of the data.

time

NumPy array with the time values of the relevant timeframe.

mean

Arithmetic mean of the normal distribution.

std

Standard deviation of the normal distribution.

height

Height of the normal distribution (starting from the baseline, thus not the total height).

Returns:
Probability density function (PDF) of the normally distributed posterior.
peak_performance.models.sigma_z_calculation(mue_z)#

Calculate the sigma_z variable which is needed to compute a numerical approximation of the mode of a skew normal distribution.

peak_performance.models.skew_normal_peak_shape(baseline, time, mean, std, alpha, *, area)#

Model a peak shaped like a skew normal distribution.

Parameters:
baseline

Baseline of the data.

time

NumPy array with the time values of the relevant timeframe.

intensity

NumPy array with the intensity values of the relevant timeframe.

mean

Location parameter, i.e. arithmetic mean.

std

Scale parameter, i.e. standard deviation.

alpha

Skewness parameter.

area

Peak area.

Returns:
y

Probability density function (PDF) of a univariate ordered normal distribution as the posterior.

peak_performance.models.skewness_calculation(delta)#

Calculate the skewness of a skew normal distribution.

peak_performance.models.std_skew_calculation(scale, alpha)#

Calculate the standard deviation of a skew normal distribution with f(x | loc, scale, alpha).

Parameters:
scale

Scale parameter of the skew normal distribution.

alpha

Skewness parameter of the skew normal distribution.

Returns:
std

Standard deviation of a skew normal distribution.