Skip to main content

MetroloPy

tools for dealing with physical quantities: uncertainty propagation and unit conversion


MetroloPy requires Python 3.10 or later and depends on NumPy, SciPy, pandas, matplotlib and ipython. It looks best in a Jupyter Notebook.

Install MetroloPy with pip install metrolopy or conda install -c conda-forge metrolopy. Alternatively, add it to your project, e.g. uv or pixi.

Physical quantities can then be represented in Python as gummy objects with an uncertainty and (or) a unit:

>>> import metrolopy as uc
>>> a = uc.gummy(1.2345,u=0.0234,unit='cm')
>>> a
1.234(23) cm

>>> b = uc.gummy(3.034,u=0.174,unit='mm')
>>> f = uc.gummy(uc.UniformDist(center=0.9345,half_width=0.096),unit='N')
>>> p = f/(a*b)
>>> p
2.50(21) N/cm2

>>> p.unit = 'kPa'
>>> p.uunit = '%'
>>> p
25.0 kPa ± 8.5%

MetroloPy can do much more including Monte-Carlo uncertainty propagation, generating uncertainty budget tables, and curve fitting. It can also handle expanded uncertainties, degrees of freedom, correlated quantities, and complex valued quantities. Also gummys work with many numpy functions with no wrapping.

See:

new in version 1.1.0

  • The continuous and discrete distributions defined in scipy.stats can now be used directly used with gummys.

  • The DistFit class for fitting distributions and the DoF class for descibing quantities drawn from the same underlying distribution have been added.

  • The legacy numpy.random.RandomState random number generator has been replaced with the newer numpy.random.Generator for Monte-Carlo uncertainty propagation. The scipy.optimize.leastsq function has been replaced with the newer scipy.optimize.least_squares function as the solver for nonlinear least squares fitting. And the depreciated scipy.odr package has been replaced with odrpack for orthogonal distance regression.

  • A class properties has been added to gummy to control the separator between the digit groupings when displaying long numbers.

  • Lazy loading for gummy module components has been implemented and added lazy_loader as a dependancy.

  • Fixed issues that affected the gummy.apply and gummy.napply method when broadcasing over arguments and and applying functions that have array like return values.

  • Fixed an number of bugs in the fitting module, bugs affecting some built-in distributions and incorrect derviatives for arccos and arccosh.

new in version 1.0.0

  • The calculation of effective degrees of freedom has been improved. In previous versions, in a multi-step calculation, the effective degree of freedom were calculated at each step based on the degrees of freedom calculated for the previous step (using a modified Welch-Satterthwaite approximation). Now effective degrees of freedom are always calculated directly from the independent variables using the standard Welch-Satterthwaite approximation.

  • CODATA 2022 values instead of 2018 values are used in the Constants module.

  • The significance value in budget table has been redefined from (sensitivity coefficient * standard uncertainty/combined uncertainty) to the square of that value so that the significance values in a budget sum to one.

  • Units can now be raised to a fractional power and many other bug fixes.

new in version 0.6.0

  • A constant library has been added with physical constants that can be accessed by name or alias with the constant function. The search_constants function with no argument gives a listing of all built-in constants. Each constant definition includes any correlations with other constants.

  • The Quantity class has been added to represent a general numerical value multiplied by a unit and the unit function has been added to retrieve Unit instances from the unit library by name or alias. Unit instances can now be multiplied and divided by other Unit instances to produce composite units, can be multiplied and divided by numbers to produce Quantity instances or multiply or divide Quantity instances. The gummy class is now a subclass of Quantity with a nummy value rather than a subclass of nummy. A QuantityArray class has been introduced to represent an array of values all with the same unit. Multiplying a Unit instance by a list, tuple, or numpy array produces a QuantityArray instance.

  • The immy class has been introduced as an ummy valued counterpart of the jummy class for representing complex values with uncertainties. immy and jummy values can now be displayed in a polar representation in addition to a cartesian representation. immy and jummy .r and .phi properties have been added to access the magnitude and argument of the values as a complement to the .real and .imag properties.

Metadata

Release files for metrolopy 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metrolopy 1.1.1
File Size Uploaded
metrolopy-1.1.1.tar.gz 189.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for metrolopy 1.1.1
File Interpreter ABI Platform
metrolopy-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 407.9 kB

Release files / metrolopy-1.1.1.tar.gz

Download URL metrolopy-1.1.1.tar.gz
Size 189.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f40427004e6cd09823129f8b0d64a4a952f249d9f93744a01022eb4a816ac517
BLAKE2b-256 checksum
How to use checksums
357d3d6e20adeaacf8571f22ffbe4e73fed6c047c15ece80f2b78039b1c983a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / metrolopy-1.1.1-py3-none-any.whl

Download URL metrolopy-1.1.1-py3-none-any.whl
Size 218.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c453439df91fdba62f42d3363e488d7835010ba419261de3336b7db0f96452f
BLAKE2b-256 checksum
How to use checksums
0331ee63519c0cb3720b70ec5fa80696ac277c444a8e961167b24322c3698cab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page