PyCUC: A lightweight Python package for creating custom unit conversions.
Project description
Python Custom Unit Converter (PyCUC)
Python Custom Unit Converter (PyCUC) is an open-source package designed to simplify unit conversions in Python. With PyCUC, you can effortlessly create custom conversion factors, convert between units, and streamline calculations in various fields, such as physics, engineering, and scientific computing.
Key Features:
-
Custom Conversion Factors: Define your own conversion factors for unique units.
-
Flexible Unit Conversions: Convert between units with ease, using a simple and intuitive methods.
-
Lightweight: Minimal dependencies and optimized for performance.
-
Easy to Use: Simple installation and straightforward usage.
Google Colab
You can use the following code to run PyCUC in Google Colab:
Installation
Install PyCUC with pip
import pycuc
# check version
print(pycuc.__version__)
Usage Example 1
- CHECK REFERENCES
print(pycuc.check_reference('pressure'))
- CREATE A CUSTOM UNIT CONVERTER
# ! pressure
my_cuc_1 = pycuc.create_cuc(1, 'MPa')
# convert to Pa
print(my_cuc_1.convert('Pa'))
print(my_cuc_1.convert('bar'))
print(my_cuc_1.convert('kPa'))
# ! temperature
my_cuc_2 = pycuc.create_cuc(358, 'K')
# convert to K
print(my_cuc_2.convert('C'))
print(my_cuc_2.convert('F'))
print(my_cuc_2.convert('R'))
- CONVERT FROM TO
# ! pressure
print(pycuc.convert_from_to(1, 'MPa', 'Pa'))
# ! temperature
print(pycuc.convert_from_to(358, 'K', 'C'))
print(pycuc.convert_from_to(25, 'C', 'K'))
- CONVERT FROM TO (short format)
# ! pressure
print(pycuc.to(125, 'MPa => Pa'))
# ! temperature
print(pycuc.to(360, 'K => C'))
print(pycuc.to(250, 'C => K'))
- DEFINE A NEW UNIT
# ! heat capacity unit: J/mol.K
my_cuc_3 = pycuc.create_cuc(25, 'J/mol.K')
# add custom
my_cuc_3.add_custom_unit('J/mol.K', 1)
my_cuc_3.add_custom_unit('kJ/mol.K', 1000)
# conversion
print(my_cuc_3.convert('J/mol.K'))
print(my_cuc_3.convert('kJ/mol.K'))
- CHECK REFERENCE
# ! pressure
print(my_cuc_3.check_reference('pressure'))
# ! temperature
print(my_cuc_3.check_reference('temperature'))
# ! custom
print(my_cuc_3.check_reference('custom'))
Usage Examples 2
- LOAD
CUSTOM UNITFROMYML FILES
# load unit yml file
unit_file = os.path.join(os.getcwd(), 'test', 'custom-unit.yml')
my_cuc = pycuc.go(reference_file=unit_file)
from_toMETHOD AS:
# ! pressure
print(my_cuc.from_to(1, 'MPa', 'Pa'))
toMETHOD AS:
# ! pressure
print(my_cuc.to(125, 'MPa => Pa'))
- CHECK REFERENCES:
# ! from yml file
print(my_cuc.check_reference('custom::CUSTOM'))
print(my_cuc.check_reference('custom::HEAT-CAPACITY'))
print(my_cuc.check_reference('custom::ENERGY'))
FAQ
For any question, contact me on LinkedIn
Authors
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 pycuc-1.3.0.tar.gz.
File metadata
- Download URL: pycuc-1.3.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b51054ae127b233a1cdbc57484a9c8212c184dc1c3ddb0455f93c9fd6fb7ca
|
|
| MD5 |
2ffdbb9729d21e1d8b54ea44def60c92
|
|
| BLAKE2b-256 |
11f3712a3952e55b9bab61ad0ea433f88e08e40bc4eeb7c0dd4109e3a12c5e97
|
File details
Details for the file PyCUC-1.3.0-py3-none-any.whl.
File metadata
- Download URL: PyCUC-1.3.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22a7e4b77bb366b31c606136ef3be0948178ae0f7328d617b5a91af8bda4b104
|
|
| MD5 |
0e40633b043ad04c856d01f121f25437
|
|
| BLAKE2b-256 |
226c6705d8d0f0d56d4b521378608b6f3c3b617dfb43398366355a42f97de01a
|