Skip to main content

Tools for working with common Passive House unit types

Project description

PH-Units:

A package for converting common Passive House unit types (IP | SI).

Usage:

The most basic usage is a simple conversion from one known unit to another:

>>> from ph_units.converter import convert
>>> # Convert 12.45 meters to feet...
>>> convert(12.45, "M", "FT") -> 40.85 # FT

The package also has a parser which can take simple text in the format: "{value} {unit}" and will split apart the text into a numeric part and a unit part:

>>> from ph_units.parser import parse_input
>>> val, unit = parse_input("0.17 BTU/HR-FT2-F")
>>> val  # 0.17
>>> unit # 'BTU/HR-FT2-F'

The results of the parser can then be fed into the converter

>>> from ph_units.converter import convert
>>> convert(val, "W/MK", unit) -> 0.098 # BTU/HR-FT2-F

Unit Types Supported:

  • area (M2, FT2)
  • density (KG/M3, LB/FT3)
  • emissions factors (G/KWH)
  • energy (Wh/M3, Wh/M2, kW/M2, kBtu/ft2, Btu/ft2)
  • envelope (U-Value, R-Value)
  • length (M, CM, MM, IN, FT)
  • moisture vapor resistance (MNS/G, PERM-IN)
  • power (kW, W, W/M2, W/ft2, W/cfm, Btu/h-ft2, Btu/h)
  • speed (m/d, m/s, m/h, ft/s, ft/d)
  • temperature (C, F)
  • volume flow (M3/HR, CFM)
  • volume (M2, FT3, LITER, GALLON)

Adding New Units:

The conversion factors used are stored as types in the ph_units.unit_types directory. Note that the types also allow for common 'alias' descriptions ie: 'feet' can be denoted as "FT", "ft." or even the symbol '

The Unit Type:

The package also includes a new Unit type which subclasses from float but also retains the unit-type information. This allows for easy conversion between units. For example:

>>> from ph_units.unit_type import Unit
>>> a_meter_value = Unit(1.0, "M")
>>> print(a_meter_value)
>>> "1.0 (M)"
>>> a_foot_value = a_meter_value.as_a("FT")
>>> print(a_foot_value)
>>> "3.281(FT)"

This Unit type supports basic mathematical operations like addition and subtraction, as well as unit-related operations like 'inversion'.

The Unit type also supports serialization and deserialization to and from JSON. Additionally, the Unit type can be used as a dataclass field type and should serialize properly when dataclass as_dict is called on the parent object.


Tests versions IronPython

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

PH-units-1.5.9.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

PH_units-1.5.9-py2.py3-none-any.whl (29.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file PH-units-1.5.9.tar.gz.

File metadata

  • Download URL: PH-units-1.5.9.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for PH-units-1.5.9.tar.gz
Algorithm Hash digest
SHA256 2b951dcc7af9c4bbdff278682816f3715f2cf88cbc2174cad00d8cd0dcfc773c
MD5 af90dc5ac2fd45ae4f4033031fd2a01d
BLAKE2b-256 bc608341f3a054f9d5396c485d116b1d224cd0ea22f6fa973439e48b3cedc960

See more details on using hashes here.

Provenance

File details

Details for the file PH_units-1.5.9-py2.py3-none-any.whl.

File metadata

  • Download URL: PH_units-1.5.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for PH_units-1.5.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5a91389f143b99d7d40e66eb3d4bffa995ae779dac1b01813fe5e11587daae7a
MD5 8e8f0146a1ea3971c6f2b5d1bfc7dfa2
BLAKE2b-256 d0e9e6e410e25e104ec492346eb49106abad4deefa7b2860fe3ec28ecdbd6006

See more details on using hashes here.

Provenance

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