NatPy
Convert the units of particle physics quantities
Packages needed:
- astropy
- numpy
Guided Tutorial
https://github.com/AndreScaffidi/Natpy_pyhep_2021
Basic Usage
Code levarages astropy.units.core.Unit and astropy.units.quantity.Quantity objects.
-
Run
import natpy. -
Access physical constants with symbol within
const:>>> import natpy as nat >>> nat.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'> >>> nat.const.hbar <class 'astropy.constants.codata2018.CODATA2018'> name='Reduced Planck constant' value=1.0545718176461565e-34 uncertainty=0.0 unit='J s' reference='CODATA 2018'> -
Access units with symbol. Combine with values or
numpyobjects to form quantities:>>> nat.m Unit("m") >>> nat.m / nat.s Unit("m / s") >>> 500 * nat.MeV <Quantity 500. MeV> -
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. The list of default bases may be found innatpy/default_values.py. The default sets c = ℏ = ε₀ = 1. -
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.>>> import natpy as nat # kg to keV >>> nat.convert(nat.kg, nat.keV) 5.6173581670146864e+32 # Electron mass >>> me = nat.convert(9.11e-31 * nat.kg, nat.keV) >>> me <Quantity 511.74132902 keV> # Energy of electron with momentum of 1 MeV >>> p = 1 * nat.MeV >>> E = np.sqrt(p**2 + me**2) # Convert to SI units >>> nat.convert(E, nat.J) <Quantity 1.79926309e-13 J>Note: Summing quantities of compatible units results in a quantity with the first terms units.
-
natpy.convert()may also be accessed as a method for unit or quantity objects.>>> import natpy as nat >>> nat.GeV.convert( nat.fm**(-1) ) 5.067730716156395 >>> (1 * nat.GeV).convert( nat.fm**(-1) ) <Quantity 5.06773072 1 / fm> -
Electromagnetic constants are defined in the SI system by default:
>>> nat.const.e <<class 'astropy.constants.codata2018.EMCODATA2018'> name='Electron charge' value=1.602176634e-19 uncertainty=0.0 unit='C' reference='CODATA 2018'>Values may be accessed in other systems as attributes of the
nat.const.cgssubmodule:>>> nat.const.cgs.e.gauss <<class 'astropy.constants.codata2018.EMCODATA2018'> name='Electron charge' value=4.803204712570263e-10 uncertainty=0.0 unit='Fr' reference='CODATA 2018'>The default system may be changed using
natpy.set_active_em_system(), with argumentssi,gauss,esuoremu:>>> nat.set_active_em_system('gauss') >>> nat.const.e <<class 'astropy.constants.codata2018.EMCODATA2018'> name='Electron charge' value=4.803204712570263e-10 uncertainty=0.0 unit='Fr' reference='CODATA 2018'> -
Dimensionless unscales quantities may be constructed using
natpy.dimensionless_unscaled, which is also bound tonatpy.dimensionless,natpy.unitlessandnatpy.one, for added usability. -
See
examples/conversion.pyfor more examples.
Metadata
Release files for NatPy 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| NatPy-0.1.4.tar.gz | 7.0 kB | Without provenance | Details for NatPy-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| NatPy-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for NatPy-0.1.4-py3-none-any.whl |
Total release size: 15.7 kB
Release files / NatPy-0.1.4.tar.gz
| Download URL | NatPy-0.1.4.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af9c36cd40e91c02ecb84c96da0bb8ab1f89610e103d4740b97eed70d2a0af80
|
|
BLAKE2b-256 checksum How to use checksums |
e569d2a7a87f2023187f34fd5a24519886377405af8619f37a09811a6d0a8818
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.13
|
Release files / NatPy-0.1.4-py3-none-any.whl
| Download URL | NatPy-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
898688835c3875fde6171b4b4453fd4847f5e214f941760c49ddebba33d3d68a
|
|
BLAKE2b-256 checksum How to use checksums |
8495f3ab7ebc39342cb9838fe39c0579ca355ac758ec6edc852d5765de995be2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.13
|
Security for NatPy 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.