All Projects → KenKundert → Quantiphy

KenKundert / Quantiphy

Licence: gpl-3.0
Physical quantities

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Quantiphy

measured
Type-safe, intuitive units of measure
Stars: ✭ 81 (+145.45%)
Mutual labels:  units
elm-units
Simple, safe and convenient unit types and conversions for Elm
Stars: ✭ 80 (+142.42%)
Mutual labels:  units
Js Quantities
JavaScript library for quantity calculation and unit conversion
Stars: ✭ 335 (+915.15%)
Mutual labels:  units
UnitfulAstro.jl
An extension of Unitful.jl for astronomers.
Stars: ✭ 18 (-45.45%)
Mutual labels:  units
unlib
a light-weight, header-only, dependency-free, C++14 library for ISO units
Stars: ✭ 28 (-15.15%)
Mutual labels:  units
php-unit-conversion
A library providing full PSR-4 compatible unit conversions
Stars: ✭ 47 (+42.42%)
Mutual labels:  units
Unchained
A fully type safe, compile time only units library.
Stars: ✭ 70 (+112.12%)
Mutual labels:  units
Unitsnet
Makes life working with units of measurement just a little bit better.
Stars: ✭ 641 (+1842.42%)
Mutual labels:  units
purescript-quantities
Physical quantities and units
Stars: ✭ 44 (+33.33%)
Mutual labels:  units
Length.js
📏 JavaScript library for length units conversion.
Stars: ✭ 292 (+784.85%)
Mutual labels:  units
DustryX
More more content for you
Stars: ✭ 24 (-27.27%)
Mutual labels:  units
number-format
Wrapper above number_format and unit convertor.
Stars: ✭ 18 (-45.45%)
Mutual labels:  units
Jsr354 Api
JSR 354 - Money and Currency API
Stars: ✭ 262 (+693.94%)
Mutual labels:  units
physikal
Mirror of Gitlab Repository
Stars: ✭ 33 (+0%)
Mutual labels:  units
Units
A compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.
Stars: ✭ 365 (+1006.06%)
Mutual labels:  units
prettysize-rs
Pretty-print file sizes and more
Stars: ✭ 29 (-12.12%)
Mutual labels:  units
desktop
Extendable calculator for the 21st Century ⚡
Stars: ✭ 85 (+157.58%)
Mutual labels:  units
Units Converter
A simple utility library to measure and convert between units
Stars: ✭ 31 (-6.06%)
Mutual labels:  units
Convert Units
An elegant way to convert quantities between different units.
Stars: ✭ 480 (+1354.55%)
Mutual labels:  units
Unitful.jl
Physical quantities with arbitrary units
Stars: ✭ 279 (+745.45%)
Mutual labels:  units

QuantiPhy — Physical Quantities

.. image:: https://img.shields.io/travis/KenKundert/quantiphy/master.svg :target: https://travis-ci.org/KenKundert/quantiphy

.. image:: https://img.shields.io/coveralls/KenKundert/quantiphy.svg :target: https://coveralls.io/r/KenKundert/quantiphy

.. image:: https://img.shields.io/pypi/v/quantiphy.svg :target: https://pypi.python.org/pypi/quantiphy

.. image:: https://img.shields.io/pypi/pyversions/quantiphy.svg :target: https://pypi.python.org/pypi/quantiphy/

.. IGNORE: pypi statistics are broken and unlikely to be fixed .. image:: https://img.shields.io/pypi/dm/quantiphy.svg :target: https://pypi.python.org/pypi/quantiphy/

| Author: Ken Kundert | Version: 2.13.1 | Released: 2021-02-17 |

What?

QuantiPhy is a Python library that offers support for physical quantities.
A quantity is the pairing of a number and a unit of measure that indicates the amount of some measurable thing. QuantiPhy provides quantity objects that keep the units with the number, making it easy to share them as single object.
They subclass float and so can be used anywhere a real number is appropriate.

Why?

QuantiPhy naturally supports SI scale factors, which are widely used in science and engineering. SI scale factors make it possible to cleanly represent both very large and very small quantities in a form that is both easy to read and write. While generally better for humans, no general programming language provides direct support for reading or writing quantities with SI scale factors, making it difficult to write software that communicates effectively with humans.
QuantiPhy addresses this deficiency, making it natural and simple to both input and output physical quantities.

Features

  • Flexibly reads amounts with units and SI scale factors.
  • Quantities subclass the float class and so can be used as conventional numbers.
  • Generally includes the units when printing or converting to strings and by default employs SI scale factors.
  • Flexible unit conversion and scaling is supported to make it easy to convert to or from any required form.
  • Provides a small but extensible collection of physical constants.
  • Supports the binary scale factors (Ki, Mi, etc.) along with the normal SI scale factors (k, M, etc.).

Alternatives

There are a considerable number of Python packages dedicated to units and quantities (alternatives <https://kdavies4.github.io/natu/seealso.html>_).
However, as a rule, they focus on the units rather than the scale factors. In particular, they build a system of units that you are expected to use throughout your calculations. These packages demand a high level of commitment from their users and in turn provide unit consistency and built-in unit conversions. In contrast, QuantiPhy treats units basically as documentation. They are simply strings that are attached to quantities largely so they can be presented to the user when the values are printed. As such, QuantiPhy is a light-weight package that demands little from the user. It is used when inputting and outputting values, and then only when it provides value. As a result, it provides a simplicity in use that cannot be matched by the other packages.

Quick Start

You can find the documentation on ReadTheDocs <https://quantiphy.readthedocs.io>_. Install with::

pip3 install --user quantiphy

Requires Python 3.5 or newer. If you using an earlier version of Python, install version 2.10 of QuantiPhy.

You can find the full documentation here <https://quantiphy.readthedocs.io>_.

You use Quantity to convert numbers and units in various forms to quantities:

.. code-block:: python

from quantiphy import Quantity

Tclk = Quantity(10e-9, 's') print(Tclk) 10 ns

Fhy = Quantity('1420.405751786 MHz') print(Fhy) 1.4204 GHz

Rsense = Quantity('1e-4Ω') print(Rsense) 100 uΩ

cost = Quantity('$11_200_000') print(cost) $11.2M

Tboil = Quantity('212 °F', scale='°C') print(Tboil) 100 °C

Once you have a quantity, there are a variety of ways of accessing aspects of the quantity:

.. code-block:: python

Tclk.real 1e-08

float(Fhy) 1420405751.786

2*cost 22400000.0

Rsense.units 'Ω'

str(Tboil) '100 °C'

You can use the render method to flexibly convert the quantity to a string:

.. code-block:: python

Tclk.render() '10 ns'

Tclk.render(show_units=False) '10n'

Tclk.render(form='eng', show_units=False) '10e-9'

Fhy.render(prec=8) '1.42040575 GHz'

Tboil.render(scale='°F') '212 °F'

You can use the string format method or the new format strings to flexibly incorporate quantity values into strings:

.. code-block:: python

f'{Fhy}' '1.4204 GHz'

f'{Fhy:.6}' '1.420406 GHz'

f'«{Fhy:<15.6}»' '«1.420406 GHz »'

f'«{Fhy:>15.6}»' '« 1.420406 GHz»'

f'Boiling point of water: {Tboil:s}' 'Boiling point of water: 100 °C'

f'Boiling point of water: {Tboil:s°F}' 'Boiling point of water: 212 °F'

QuantiPhy has many more features and capabilities. For more information, view the documentation <https://quantiphy.readthedocs.io>_.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].