Skip to main content

physipy

Binder PyPI version

This python package allows you to manipulate physical quantities, basically considering in the association of a value (scalar, numpy.ndarray and more) and a physical unit (like meter or joule).

>>> from physipy.quickstart import nm, hp, c, J
>>> E_ph = hp * c / (500 * nm)
>>> print(E_ph)
3.9728916483435158e-19 kg*m**2/s**2
>>> E_ph.favunit = J
>>> print(E_ph)
3.9728916483435158e-19 J

For a quickstart, check the quickstart notebook on the homepage Get a live session at Binder

Installation

pip install physipy

Goals

  • Few LOC
  • Simple architecture, with only 2 classes (namely Dimension and Quantity)
  • High numpy compatibility
  • Human-readable syntax (fast syntax !)

Use case

  • Define scalar and arrays of physical quantities
  • Compute operation between them : add, sub, mul, div, pow, and so on
  • Display physical quantities in various “units”

Implementation approach

The implementation is pretty simple :

  • a Dimension object represents a physical dimension. For now, these dimension are based on the SI unit. It is basically a dictionary where the keys represent the base dimensions, and the values are the exponent these dimensions.
  • a Quantity object is simply the association of a value, scalar or array (or more!), and a Dimension object. Note that this Quantity classe does not sub-class numpy.ndarray (although Quantity objects are compatible with numpy's ufuncs). Most of the work is done by this class.
  • By default, a Quantity is displayed in term of SI untis. To express a Quantity in another unit, just set the "favunit", which stands for "favourite unit" of the Quantity : my_toe_length.favunit = mm.
  • Plenty of common units (ex : Watt) and constants (ex : speed of light) are packed in. Your physical quantities (my_toe_length), units (kg), and constants (kB) are all Quantity objects.

Numpy's support

See NEP35.

Known issues

numpy.full

import numpy as np
from physipy import m
np.full((3,3), 2*m)

About angles and units

See : https://www.bipm.org/en/CGPM/db/20/8/. Astropy's base units : https://docs.astropy.org/en/stable/units/standard_units.html#enabling-other-units

Alternative packages

There are plenty of python packages that handle physical quantities computation. Some of them are full packages while some are just plain python module. Here is a list of those I could find (approximately sorted by guessed-popularity) :

If you know another package that is not in this list yet, feel free to contribute ! Also, if you are interested in the subject of physical quantities packages in python, check this quantities-comparison repo and this talk. Also check this comparison table.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgment

Thumbs up to phicem and his pysics package, on which this package was highly inspired. Check it out !

Metadata

Release files for physipy 0.2.2

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

Source distribution (sdist)

Source distribution for physipy 0.2.2
File Size Uploaded
physipy-0.2.2.tar.gz 54.2 kB Details

Built distribution (wheel)

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

Total release size: 90.7 kB

Release files / physipy-0.2.2.tar.gz

Download URL physipy-0.2.2.tar.gz
Size 54.2 kB
Tags Source
SHA-256 checksum
How to use checksums
847bf963d372112ad0e6f42b6da6d9711d5b069b5a0d95b8e958fea9c5c67fb2
BLAKE2b-256 checksum
How to use checksums
6fba1fb30b069b10926f63abeb692abffa0ed79fa1fdbb0310cd470bb4cf2bdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.7.4

Release files / physipy-0.2.2-py3-none-any.whl

Download URL physipy-0.2.2-py3-none-any.whl
Size 36.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee18fe0040518b8ad95925116b898e9c316de1af91bacce1bfa31901c3f91c90
BLAKE2b-256 checksum
How to use checksums
a67f9b73bf3abe75159b16a8c02314af13d6753a01018d0bbddc8d09e2077b32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.7.4

Release history Release notifications | RSS feed

0.2.8

2 release files

0.2.6

2 release files

0.2.4

2 release files

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.0

2 release files

0.1.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