Skip to main content

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.

  1. Run import natpy.
  2. 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'>

  1. 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 in natpy/default_values.py.

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

  1. See tests/convert_test.py for more examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NatPy-0.0.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

NatPy-0.0.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

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

Hashes for NatPy-0.0.3.tar.gz
Algorithm Hash digest
SHA256 b9e581a44137d74cf98c912f61104039ec33c373cc32f0250738249aa11388e0
MD5 48f55f0bf830d5bddb09daee34eeda75
BLAKE2b-256 916e25699c8c7dc8b3f3c28d9f45a7e549bebf3099c4349da09dff044a57ba9d

See more details on using hashes here.

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

Hashes for NatPy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 516e2ee7e181b4fefe49f8226d94a6d845aad80f498c2749af59681d18b0644f
MD5 0bfc413d231b85d3fb89e32aefcbe0bc
BLAKE2b-256 1b70765386b08f63833b3340ec4a4b77d01b8130af9923bc3db4cd0141fe6ce8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page