Utilities

Unit conversion classes

This module provides some pythonic classes to define measures. At the moment only these mesures are supported

  • Temperature
  • Pressure
  • Enthalpy
  • Length
  • Mass flow
  • Mass flow rate

thermopy.units

class thermopy.units.Enthalpy(data)

Bases: float

Class that models an enthalpy measure with conversion utilities

Supported units are

  • Joule per kg (default)
  • Kilojoule per kg (kJkg)
  • Kilocalorie per kg (kcalkg)
  • BTU per pound (Btulb)
>>> h = Enthalpy(1000)
>>> h.kJkg
1.0
>>> h.kcalkg
0.23900573613766729
>>> h.Btulb
0.42992261392949266
Btulb
kJkg
kcalkg
unit(units='si')
class thermopy.units.Length(data)

Bases: float

Class that models a length measure with conversion utilities

Supported units are

  • meter (default)
  • millimeter (mm)
  • inch (inch)
  • foot (ft)
>>> l = Length(1).unit('inch')
>>> l.mm
25.399999999999999
>>> l.ft
0.083333333333333343
>>> l
0.025399999999999999
ft
inch
mm
unit(units='m')
class thermopy.units.Massflow(data)

Bases: float

Class that models a mass flow measure with conversion utilities

Supported units are

  • kg per second (default)
  • kg per hour (kgh)
  • pounds per second (lbs)
  • pounds per hour (lbh)
kgh
lbh
lbs
unit(units='kgs')
class thermopy.units.Massflowrate(data)

Bases: float

Class that models a mass flow measure with conversion utilities

Supported units are

  • \frac{kg}{s\ m^2} (default)
  • \frac{lb}{s\ ft^2} (Btu)
Btu
unit(units='default')
class thermopy.units.Pressure(data)

Bases: float

Class that models a Pressure measure with conversion utilities

Suported units are

  • Pascal (Pa)
  • Mega Pascal (MPa)
  • Bar (bar)
  • Pound per square inch (psi)
  • Atmosphere (atm)
  • Millimeters of water column (mmwc)
  • Torricelli (torr)

Normal instantiation is pressure in Pa. How much is an athmosphere?

>>> p = Pressure(1.0).unit('atm')
>>> p
101325.0
>>> p.torr
760.0
>>> p.mmwc
10285.839999999998
>>> p.psi
14.69594877551345
MPa
atm
bar
mmwc
psi
torr
unit(units='Pa')
class thermopy.units.Temperature(data)

Bases: float

Class that models a temperature measure with conversion utilities

Supported units are

  • Kelvin
  • Celsius
  • Fahrenheit

Normal instantiation is a temperature in Kelvin

>>> T = Temperature(100)
>>> T
100.0

But you can instantiate and specify if unit is Celsius or Fahrenheit

>>> T = Temperature(100).unit('F')
>>> T
310.92777777777775

Unit conversion is as easy as it gets.

>>> T.C
37.777777777777771
>>> T.F
99.999999999999986

You can compute with temperatures because inherits from the float built-in

>>> T1 = Temperature(200)
>>> T2 = Temperature(0).unit('C')
>>> T1+T2
473.14999999999998

If you don’t want to use the class’ attribute you can use the function getattr to get a value using the unit code.

>>> getattr(T,'C')
37.777777777777771
C
F
unit(units='K')
thermopy.units.test_doctest()