qspec logo qspec logo

A physics toolbox for laser spectroscopy.

Static Badge Static Badge Static Badge

Static Badge Static Badge

© 2026 Patrick Müller. All rights reserved.

qspec. propagate  (  f ,  x ,  x_d=None ,  cov=None ,  unc_places=None ,  sample_size=1000000 ,  rtol=0.001 ,  atol=None ,  force_sym=False ,  full_output=False ,  show=False  )[source]

Propagate the uncertainties of the input values x through the function f using Monte-Carlo sampling.

If the resulting uncertainties are asymmetric, the value and the two uncertainties of the returned Observable are the median and the left- (~0.1587) and right-sided (~0.8413) 1-sigma percentiles relative to the median, respectively, and the parameters of a skew normal distribution are fitted to the sample and stored in the observable. If the uncertainties are symmetric, the observable is assumed to be normally distributed and its value and uncertainty are the mean and the standard deviation of the sample.

Parameters:
fCallable

The function to compute. f needs to be vectorized.

xIterable[scalar]

The input values. If x_d is None, the sample data is generated with Observable.rvs, which considers asymmetric uncertainties. If an element is not an Observable, its uncertainty is assumed to be 0.

x_darray_like | None

The uncertainties of the input values.

covscalar_nd | None

The covariance matrix of the input values. If not None, x is assumed to be distributed according to a multivariate normal distribution with covariance cov.

unc_placesint_like | None

The number of significant decimal places the result will be rounded to. If None, the result is not rounded.

sample_sizeint_like

The number of random variates used for the calculation. The default is 1,000,000.

rtolfloat

The relative tolerance, with respect to the median of the resulting sample, with which the left- and right-sided uncertainties can deviate before asymmetric uncertainties are used.

atolfloat | None

The absolute tolerance with which the left- and right-sided uncertainties can deviate, before asymmetric uncertainties are used. Overrides rtol.

force_symbool

Whether to force symmetric uncertainties. If so, a normal distribution is assumed.

full_outputbool

Whether to return the randomly generated data samples.

showbool

Whether to show a histogram and estimated pdfs of the computed sample data.

Returns:
(ob, x_samples, y_samples)Observable | tuple[Observable, ndarray, ndarray]

An Observable whose uncertainties result from the propagation of the uncertainties of the input values x by the function f. If full_output is True, the input samples and the output sample are returned as well.

Raises:
ValueError

If x and x_d have different sizes.