Convert the units of particle physics quantities.
Project description
NatPy
Convert the units of particle physics quantities
Packages needed:
- astropy
- numpy
Basic Usage
Code levarages astropy.units.core.Unit and astropy.units.quantity.Quantity objects.
- Run
import natpy. - Access physical constants with symbol:
>>> natpy.const.c
<class 'astropy.constants.codata2018.CODATA2018'> name='Speed of light in vacuum' value=299792458.0 uncertainty=0.0 unit='m / s' reference='CODATA 2018'>
>>> natpy.const.hbar
<class 'astropy.constants.codata2018.CODATA2018'> name='Reduced Planck constant' value=1.0545718176461565e-34 uncertainty=0.0 unit='J s' reference='CODATA 2018'>
-
Specify base of natural units with
natpy.set_active_units(). Pass a string corresponding to a list of default natural units, or a list of physical constants to set your own. List of default bases found innatpy/default_values.py. -
Run
natpy.convert()to convert between units, including necessary factors of natural units. Pass just unit objects to obtain conversion factors. Pass quantity objects to perform conversions. E.g.
# kg to keV
>>> natpy.convert(u.kg, u.keV)
5.6173581670146864e+32
# Electron mass
>>> me = natpy.convert(9.11e-31 * u.kg, u.keV)
>>> me
<Quantity 511.74132902 keV>
# Energy of electron with momentum of 1 MeV
>>> p = 1 * u.MeV
>>> E = np.sqrt(p**2 + me**2)
# Convert to SI units
>>> natpy.convert(E,u.J)
<Quantity 1.79926309e-13 J>
Note: Summing quanties requires conventionally equivalent units.
- See
tests/convert_test.pyfor more examples.
Project details
Release history Release notifications | RSS feed
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 NatPy-0.0.3.tar.gz.
File metadata
- Download URL: NatPy-0.0.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9e581a44137d74cf98c912f61104039ec33c373cc32f0250738249aa11388e0
|
|
| MD5 |
48f55f0bf830d5bddb09daee34eeda75
|
|
| BLAKE2b-256 |
916e25699c8c7dc8b3f3c28d9f45a7e549bebf3099c4349da09dff044a57ba9d
|
File details
Details for the file NatPy-0.0.3-py3-none-any.whl.
File metadata
- Download URL: NatPy-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
516e2ee7e181b4fefe49f8226d94a6d845aad80f498c2749af59681d18b0644f
|
|
| MD5 |
0bfc413d231b85d3fb89e32aefcbe0bc
|
|
| BLAKE2b-256 |
1b70765386b08f63833b3340ec4a4b77d01b8130af9923bc3db4cd0141fe6ce8
|