A library containing functions used for estimating uncertainties
Project description
uncertaintylib
uncertaintylib is a Python library for estimating and propagating uncertainties in engineering and scientific calculations. It is designed to work with any Python function whose inputs and outputs are flat dictionaries.
Key Principles
- Function-agnostic: You can pass any Python function to the library, as long as its inputs and outputs are flat dictionaries (no nested dicts or lists).
- Standard-inspired: Attempts to follow uncertainty propagation principles outlined in JCGM 100:2008 (Guide to the Expression of Uncertainty in Measurement).
Installation
Install from PyPI:
pip install uncertaintylib
Usage
The main interface is through functions in uncertaintylib.uncertainty_functions. You provide:
- A Python function (inputs: flat dict, outputs: flat dict)
- A dictionary containing 'mean' and 'standard_uncertainty' for each variable. These are provided as sub dictionaries.
- The standard uncertainty can also be given in relative terms (%), using the 'standard_uncertainty_percent' key
- If both 'standard_uncertainty' and 'standard_uncertainty_percent', the largest of the two will be used. This can be useful for variables where for example noise dominates the uncertainty in the lower region (such as zero stability of a coriolis massflow meter)
- 'min' and 'max' are only used in Monte Carlo calculations, to address the issue of non-physical distributions (for example distribution of mole-% of a component going below 0)
- 'distribution' is used mainly by Monte Carlo, but also in cases where some of the inputs are settings (for example 0 or 1), where you dont want to pertubate or calculate sensitivity coefficients for that spesific input variable. In this case 'distribution' can be set to 'none', which will ignore that parameter.
Example usage (standard uncertainty calculation):
from uncertaintylib import uncertainty_functions
inputs = {
'mean': {'Q': 370, 'rho': 54},
'standard_uncertainty': {'Q': 1, 'rho': 0.03},
'standard_uncertainty_percent': {'Q': 0.25, 'rho': 0.1},
'distribution': {'Q': 'normal', 'rho': 'normal'},
'min': {'Q': 0, 'rho': 0},
'max': {'Q': None, 'rho': None}
}
def calculate_massflow(inputs):
outputs = {}
outputs['MassFlow'] = inputs['Q']*inputs['rho']
return outputs
results = uncertainty_functions.calculate_uncertainty(
indata=inputs,
function=calculate_massflow
)
print(results)
Plotting Functionalities
uncertaintylib includes plotting utilities based on matplotlib, available in uncertaintylib.plot_functions. These functions help visualize uncertainty propagation and contributions:
- Monte Carlo Distribution Plots: Visualize the distribution of output properties from Monte Carlo simulations, including summary tables of mean and uncertainty.
- Uncertainty Contribution Plots: Show the percentage contribution of each input variable to the total expanded uncertainty of an output property.
All plots are generated using matplotlib and can be customized or saved using standard matplotlib methods. See the API docstrings in plot_functions.py for details.
Documentation & Examples
- See the
examples/folder for practical scripts demonstrating usage. - API documentation is available in the source code docstrings.
License
MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uncertaintylib-1.0.0.tar.gz.
File metadata
- Download URL: uncertaintylib-1.0.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
022ceb20b54032562969d41c6bc19d0f0f60c0585ed06ebeb09feb5e4383b208
|
|
| MD5 |
675f6d848aa4bd26ae810c4f22e4d940
|
|
| BLAKE2b-256 |
2a0290b75b784fc1f166f13e4371ec42c94a1dc47bacb885eec49fa6096a4671
|
File details
Details for the file uncertaintylib-1.0.0-py3-none-any.whl.
File metadata
- Download URL: uncertaintylib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd64634e64fd06328f405e6dcb83d246ce22b7cca09d1394d221695b6a4899db
|
|
| MD5 |
7fa30e31ebc5bf94099aecf3e7399393
|
|
| BLAKE2b-256 |
12f07a0a2ba1fc402dd020539bf24263a453e820550846fd6c2a3003f7c78a44
|