A practical tool for calculations with physical units
Project description
Quantitas
概要
Quantitasは、煩雑な単位計算を手軽に実行するためのパッケージです。物理量に対して四則演算などの計算を行ったり、単位変換をしたりできます。また、本パッケージには、自然科学の分野でよく使われる単位や定数の多くがあらかじめ実装されており、ユーザーは自身で定義することなくこれらを使うことができます。
インストール
pip install quantitas
クイックスタート
木星の半径と質量から、木星表面の重力加速度を計算するサンプルコードです。
import quantitas as qt
from quantitas.units import * #Quantitasが収録する全ての単位をインポート
from quantitas import G, M_Jupiter, M_Earth #定数をインポート
r = 71492*km_
g = G*M_Jupiter/r**2
print(g)
#出力: 24.79160264727122 m⋅s^-2
単位を表す変数名には末尾にアンダースコア (_) が付きます。万有引力定数Gや木星質量M_Jupiterなど、よく使われる定数の多くはあらかじめ定義されています。
上のサンプルコードのように物理量はprint関数で表示することもできますが、物理量を出力するのに特化したqrint関数がおすすめです。
from quantitas import qrint
qrint(g)
#出力: 24.79160264727122 m⋅s^-2
qrint(g, [N_, kg_]) #単位を指定すると自動で変換されます
#出力: 24.79160264727122 N⋅kg^-1
qrint([M_Jupiter, M_Earth]) #複数の物理量もまとめて出力できます
#出力: 1.8985138610303162e+27 kg 5.972168401180649e+24 kg
単位はユーザーが定義することもできます。give_symbol関数を使うことで物理量に文字列の記号を与えることができます。
kph_ = qt.give_symbol(km_/h_, "kph") #キロメートル毎時
qrint(340*m_/s_, kph_)
#出力: 1224.0 kph
もっと詳しく
本パッケージには上で紹介しきれなかった機能や仕様がたくさんあります。Quantitasについてもっと知りたいと思った方は以下をご参照ください。
License
This project is licensed under the MIT License, see the LICENSE.txt file for details.
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 quantitas-1.2.0b1.tar.gz.
File metadata
- Download URL: quantitas-1.2.0b1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68384e72e2b70e6666f4e5e775592650b6edfa8d72ccd4e1a77e7f9a97a621c7
|
|
| MD5 |
239253b2981253aa1d79bd9e0092aaba
|
|
| BLAKE2b-256 |
d850b937812562c50d12b9ee22353828d5f7f19185233df7060733998cfdad01
|
File details
Details for the file quantitas-1.2.0b1-py3-none-any.whl.
File metadata
- Download URL: quantitas-1.2.0b1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23a7ee63496dae6c41de7a42f00770210b7ac27a5254e94d068392c23d0f9347
|
|
| MD5 |
a838b544fc710025f2f45dfe3b06b7c0
|
|
| BLAKE2b-256 |
3dd92f966b78a98a451b85255ba61f44be1bc2d0034e65827bb6ccf2af8474dc
|