Skip to main content

Pythonic interface for units, unit systems, and unit conversions.

Project description

PyAnsys PyPI Python GH-CI codecov MIT Black pre-commit.ci status

Overview

PyAnsys Units provides a Pythonic interface for units, unit systems, and unit conversions. Its features enable seamless setup and usage of physical quantities, enabling you to perform these tasks:

  • Instantiate physical quantities from a unit string, list of dimensions, or quantity map.

  • Perform unit conversions and arithmetic operations between quantity objects or real values.

  • Create custom units and unit systems.

Documentation and issues

Documentation for the latest stable release of PyAnsys Units is hosted at PyAnsys Units documentation.

In the upper right corner of the documentation’s title bar, there is an option for switching from viewing the documentation for the latest stable release to viewing the documentation for the development version or previously released versions.

On the PyAnsys Units Issues page, you can create issues to report bugs, and request new features. On the PyAnsys Units Discussions page or the Discussions page on the Ansys Developer portal, you can post questions, share ideas, and get community feedback.

To reach the project support team, email pyansys.core@ansys.com.

Installation

The ansys.units package supports Python 3.9 through Python 3.11 on Windows and Linux.

Install the latest release from PyPI with this command:

pip install ansys-units

If you plan on doing local development of PyAnsys Units with Git, install the latest release with these commands:

git clone https://github.com/ansys/pyansys-units.git
cd pyansys-units
pip install pip -U
pip install -e .

Getting started

Basic usage

Import the ansys.units package:

import ansys.units as ansunits

You can instantiate quantities with one of three methods:

# unit string

volume = ansunits.Quantity(value=1, units="m^3")

volume.value  # 1.0
volume.units  # "m^3"

# dimensions

acceleration = ansunits.Quantity(value=3, dimensions=[0, 1, -2])

acceleration.value  # 3.0
acceleration.units  # "m s^-2"

# quantity map

torque = ansunits.Quantity(5, quantity_map={"Torque": 1})

torque.value  # 5.0
torque.units  # "N m"

You can instantiate unit systems with one of two methods:

# custom unit systems

sys = ansunits.UnitSystem(
    name="sys",
    base_units=["slug", "ft", "s", "R", "radian", "slugmol", "cd", "A", "sr"],
)

# pre-defined unit systems

si = ansunits.UnitSystem(unit_sys="SI")

Examples

Perform arithmetic operations:

import ansys.units as ansunits

deg = ansunits.Quantity(90, "degree")
math.sin(deg)  # 1.0

v1 = ansunits.Quantity(10.0, "m s^-1")
v2 = ansunits.Quantity(5.0, "m s^-1")

v3 = v1 - v2
v3.value  # 5.0

vpow = v1**2
vpow.value  # 100.0
vpow.units  # "m^2 s^-2"

Directly convert values to another set of units:

import ansys.units as ansunits

fps = ansunits.Quantity(1, "lb ft^-1 s^-1")
fps.value  # 1

pas = fps.to("Pa s")
pas.value  # 1.4881639435695542
pas.units  # 'Pa s'

Use a custom unit system to perform conversions:

import ansys.units as ansunits

sys = ansunits.UnitSystem(
    name="sys",
    base_units=["slug", "ft", "s", "R", "radian", "slugmol", "cd", "A", "sr"],
)

v = ansunits.Quantity(10, "kg m s^2")
v2 = sys.convert(v)

v2.value  # 2.2480894309971045
v2.units  # 'slug ft s^2'

License

PyAnsys Units is licensed under the MIT license. For more information, see the LICENSE file.

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

ansys_units-0.2.dev0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

ansys_units-0.2.dev0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file ansys_units-0.2.dev0.tar.gz.

File metadata

  • Download URL: ansys_units-0.2.dev0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for ansys_units-0.2.dev0.tar.gz
Algorithm Hash digest
SHA256 3c96b801998f44c40d68b5cbc11a03cd7fc9db2c9e8b11a9da195367ad340ce9
MD5 60f46a0f4609bdd06d099a7becbc3234
BLAKE2b-256 34adeb2408528371ac65c2b8c2d0f4c206da769340bf137b491a61277db26c55

See more details on using hashes here.

File details

Details for the file ansys_units-0.2.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for ansys_units-0.2.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bf3d372bb6e2949d35956eadfacf91b8bd89b1571eb56cd7af763a71c811f55
MD5 9552ebf7dc95c55d5a6c92fbf5d02d82
BLAKE2b-256 44d6d84bc2383e737f6e966b7d0cf900ce8caa616b2d65b5b9d77fee72b22fbe

See more details on using hashes here.

Supported by

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