跳转到主要内容

HEP单位系统中的单位和常数

项目描述

Scikit-HEP PyPI version Conda-forge version Zenodo DOI

GitHub Actions Status: CI Code Coverage

hepunits 收集了HEP单位系统中常用到的单位和常数,这些单位和常数源自CLHEP项目最初定义的基本单位,这些单位与SI单位系统不同

名称

单位

长度

毫米

mm

时间

纳秒

ns

能量

兆电子伏特

MeV

正电子电荷

eplus

温度

开尔文

K

物质的量

摩尔

mol

光强度

坎德拉

cd

平面角

弧度

rad

立体角

球面度

sr

它主要基于国际单位制(SI

名称

单位

长度

m

时间

s

质量

千克

kg

电流

安培

A

温度

开尔文

K

物质的量

摩尔

mol

光强度

坎德拉

cd

但通过方便的定义来补充它,改变了基本长度和时间单位。

这种高能物理单位系统在许多软件库中都在使用,例如GEANT4和Gaudi。

请注意,现在许多单位是精确的,例如真空中的光速。该软件包与2020年粒子数据组审查中的值一致。

安装

像其他Python包一样安装 hepunits,通常

python -m pip install hepunits

该软件包还可在 conda-forge 上找到,并可通过

conda install -c conda-forge hepunits

入门

该软件包包含2个模块,constantsunits,其名称具有自解释性。尽管可以从顶层导入(from hepunits import ...),但最好还是显式地从每个模块中导入量。

hepunits.constants模块包含两种常数:物理常数和常用常数。

典型用法如下

>>> from hepunits.constants import c_light
>>> from hepunits.units import picosecond, micrometer
>>> tau_Bs = 1.5 * picosecond  # a particle lifetime, say the Bs meson's
>>> ctau_Bs = c_light * tau_Bs  # ctau of the particle, ~450 microns
>>> print(ctau_Bs)  # result in HEP units, so mm
0.449688687
>>> print(ctau_Bs / micrometer)  # result in micrometers
449.688687

hepunits.units模块的典型用法

>>> # add two quantities with length units and get the result in meters
>>> from hepunits import units as u
>>> (1 * u.meter + 5 * u.cm) / u.meter
1.05
>>> # the default result is, of course, in HEP units, so mm
>>> 1 * u.meter + 5 * u.cm
1050.0

更高级的用法

在处理数据时,用户不需要知道内部表示中使用了哪些单位(虽然这很重要,并且需要在“数据存储”中保持一致!)。

以下简单的规则就足够了——如下面的代码示例所示

  • “数据存储”中的有量纲量遵守高能物理单位系统。

  • 所有有量纲量的定义都通过乘以单位来表示量纲,如在mass_window = 500 * keV中。

  • 所有有量纲量的输出都通过除以单位转换为所需的单位,如在energy_resolution() / GeV中。

为了讨论,让我们考虑以下返回有量纲量的函数。下面的函数存储了一个在keV中定义的有量纲量(实际值用MeV表示,这是标准单位),调用者只需确保通过除以它(例如,GeV)显式地将其转换为所需的单位。

>>> from hepunits.units import keV, MeV, GeV
>>> mass_window = 1 * GeV  # define a 1 GeV mass window
>>> def energy_resolution():
...     # returns the energy resolution of 500 keV
...     return 500.0 * keV  # numerical value is 0.5
...
>>> energy_resolution() / GeV  # get the energy resolution in GeV
0.0005

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪一个,请了解更多关于安装软件包的信息。

源代码分发

hepunits-2.3.4.tar.gz (13.4 kB 查看哈希值)

上传时间 源代码

构建分发

hepunits-2.3.4-py3-none-any.whl (14.4 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面