Skip to main content

Functions to calculate thermal comfort indices

Project description

ci wheels pre-commit

thermal-comfort

Installation

via pypi

pip install thermal-comfort

via https

pip install git+https://github.com/RUBclim/thermal-comfort

via ssh

pip install git+ssh://git@github.com/RUBclim/thermal-comfort

[!NOTE] For this to work, you will have to have git and gfortran installed

For every release, pre-compiled ABI-3 wheels are provided under releases

Run the tests

On version 3.12 for example...

tox -e py312

Documentation

Docs can be found here: https://rubclim.github.io/thermal-comfort/.

Quick start

The thermal-comfort package provides a limited set of commonly used functions. Which work for scalar values, but are mainly optimized for large array calculation of hundreds of thousands of values.

scalars

from thermal_comfort import utci_approx

utci_approx(ta=20.3, tmrt=50.9, v=2.7, rh=50.5)

arrays

1-dimensional arrays

import numpy as np
from thermal_comfort import utci_approx

utci_approx(
    ta=np.array([20.3, 28.5]),
    tmrt=np.array([50.9, 70.3]),
    v=np.array([2.7, 1.9]),
    rh=np.array([50.5, 70.3]),
)

n-dimensional arrays

The functions only accept 1-dimensional arrays, multi dimensional arrays must be reshaped before and after.

import numpy as np
from thermal_comfort import utci_approx

# 2D arrays e.g. a raster
ta = np.array([[20.3, 28.5], [20.3, 28.5]])
tmrt = np.array([[50.9, 70.3], [50.9, 70.3]])
v = np.array([[2.7, 1.9], [2.7, 1.9]])
rh = np.array([[50.5, 70.3], [50.5, 70.3]])
# retrieve the initial shape
orig_shape = ta.shape

# reshape the array to be 1-dimensional
ta = np.ravel(ta)
tmrt = np.ravel(tmrt)
v = np.ravel(v)
rh = np.ravel(rh)

# calculate the UTCI along the 1-dimensional array
utci = utci_approx( ta=ta, tmrt=tmrt, v=v, rh=rh)

# restore the original shape
utci = utci.reshape(orig_shape)

API

For a complete documentation look at the docs

Mean Radiant Temperature (MRT)

Calculate the mean radiant temperature based on DIN EN ISO 7726.

mean_radiant_temp(ta, tg, v, d = 0.15, e = 0.95)
  • ta: air temperature in °C
  • tg: black globe temperature in °C

UTCI

Calculate the Universal Thermal Climate Index (UTCI)

utci_approx(ta, tmrt, v, rh)
  • ta: Air temperature in °C
  • tmrt: Mean radiant temperature in °C
  • v: Wind speed in m/s
  • rh: Relative humidity in %

PET

Calculate the Physiological Equivalent Temperature (PET).

pet_static(ta, tmrt, v, rh, p)
  • ta: air temperature in °C
  • rh: relative humidity in %
  • v: wind speed in m/s
  • tmrt: mean radiant temperature in °C
  • p: atmospheric pressure in hPa

Heat Index

Calculate the heat index following Steadman R.G (1979) & Rothfusz L.P (1990).

heat_index(ta, rh)
  • ta: air temperature in °C
  • rh: relative humidity in %

Extended Heat Index

Calculate the heat index following Steadman R.G (1979) & Rothfusz L.P (1990), but extends the range following The National Weather Service Weather Predicion Center.

heat_index_extended(ta, rh)
  • ta: air temperature in °C
  • rh: relative humidity in %

Wet Bulb Temperature (TWB)

Calculate the wet bulb temperature following the Stull (2011) equation

wet_bulb_temp(ta, rh)
  • ta: air temperature in °C
  • rh: relative humidity in %

Saturation Vapor Pressure

Over water
sat_vap_press_water(ta)
  • ta: air temperature in °C
Over ice
sat_vap_press_ice(ta)
  • ta: air temperature in °C

Dew Point Temperature

dew_point(ta, rh)
  • ta: air temperature in °C
  • rh: relative humidity in %

Absolute Humidity

absolute_humidity(ta, rh)
  • ta: air temperature in °C
  • rh: relative humidity in %

Specific Humidity

specific_humidity(ta, rh)
  • ta: air temperature in °C
  • rh: relative humidity in %

Performance

The benchmark was ran using an array of 100,000 values and 4 threads (OMP_NUM_THREADS=4). See the benchmark directory for more details on the benchmarks.

The hardware used is:

  • 2x AMD EPYC 7702 64-Core Processor
  • ubuntu 22.04

using an array of length 100,000 the following results were found:

comparing to pythermalcomfort

Benchmark pythermalcomfort (bf9febd) thermal-comfort thermal-comfort (unsafe) thermal-comfort (Open MPI) thermal-comfort (unsafe & Open MPI)
tmrt scalar 21.0 us 20.3 us: 1.03x faster 2.21 us: 9.50x faster 23.3 us: 1.11x slower 4.38 us: 4.79x faster
tmrt array 11.9 ms 5.77 ms: 2.06x faster 11.3 ms: 1.05x faster 3.86 ms: 3.07x faster 1.29 ms: 9.17x faster
twb scalar 11.2 us 2.43 us: 4.59x faster 1.31 us: 8.52x faster 2.44 us: 4.57x faster 1.27 us: 8.80x faster
twb array 8.86 ms 2.54 ms: 3.49x faster 2.52 ms: 3.52x faster 2.63 ms: 3.37x faster 1.73 ms: 5.13x faster
heat index scalar 34.9 us 2.38 us: 14.67x faster 1.24 us: 28.10x faster 5.06 us: 6.89x faster 3.68 us: 9.47x faster
heat index array 4.06 ms 2.27 ms: 1.79x faster 2.44 ms: 1.66x faster 1.92 ms: 2.11x faster 859 us: 4.72x faster
utci scalar 59.5 us 22.7 us: 2.62x faster 2.23 us: 26.66x faster 26.0 us: 2.29x faster 4.45 us: 13.36x faster
utci array 37.1 ms 5.93 ms: 6.25x faster 11.4 ms: 3.25x faster 3.82 ms: 9.71x faster 1.24 ms: 29.84x faster
pet scalar 6.04 ms 5.86 us: 1031.44x faster 6.73 us: 897.57x faster 8.68 us: 696.14x faster 6.56 us: 922.14x faster
pet array 189 sec 284 ms: 665.14x faster 804 ms: 234.82x faster 117 ms: 1611.19x faster 113 ms: 1669.13x faster
Geometric mean (ref) 10.00x faster 13.83x faster 10.45x faster 23.64x faster

comparing to umep

Benchmark umep umep (njit) pythermalcomfort (bf9febd) thermal-comfort thermal-comfort (unsafe) thermal-comfort (Open MPI) thermal-comfort (unsafe & Open MPI)
utci scalar 44.5 us 6.56 us: 6.79x faster 59.5 us: 1.34x slower 22.7 us: 1.96x faster 2.23 us: 19.97x faster 26.0 us: 1.72x faster 4.45 us: 10.00x faster
utci array 6.87 sec 313 ms: 21.95x faster 37.1 ms: 185.23x faster 5.93 ms: 1157.28x faster 11.4 ms: 602.16x faster 3.82 ms: 1798.79x faster 1.24 ms: 5526.68x faster
pet scalar 388 us 3.17 us: 122.51x faster 6.04 ms: 15.56x slower 5.86 us: 66.29x faster 6.73 us: 57.69x faster 8.68 us: 44.74x faster 6.56 us: 59.26x faster
pet array 62.6 sec 1.33 sec: 48.25x faster 189 sec: 3.02x slower 284 ms: 220.43x faster 804 ms: 77.82x faster 117 ms: 533.95x faster 113 ms: 553.15x faster
Geometric mean (ref) 35.61x faster 2.07x faster 53.17x faster 88.52x faster 51.68x faster 148.51x faster

While njit already gives a huge performance boost, the difference between umep (njit) and thermal-comfort increases for larger arrays e.g. 1,000,000 values as shown here:

Benchmark umep (njit) thermal-comfort
utci scalar 6.53 us 22.9 us: 3.51x slower
utci array 3.09 sec 48.5 ms: 63.77x faster
pet scalar 3.15 us 5.84 us: 1.85x slower
pet array 13.3 sec 2.80 sec: 4.75x faster
Geometric mean (ref) 2.61x faster

[!CAUTION] If you're after the last bit of performance and don't care about input validation, you may use the underscored functions e.g. _utci_approx or _pet_static which fully avoid any computations in python. However, you will have to guarantee that all your arrays have the same length otherwise undefined behavior may happen. For performance reasons this package is not compiled using -fcheck=bounds compiler-flag.

Compilation

You can set the cmake flag -DUSE_OPENMP=1 to compile the package with OpenMP support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

thermal_comfort-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thermal_comfort-1.1.5-cp313-cp313-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

thermal_comfort-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thermal_comfort-1.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (528.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

thermal_comfort-1.1.5-cp312-cp312-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

thermal_comfort-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thermal_comfort-1.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (528.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

thermal_comfort-1.1.5-cp311-cp311-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

thermal_comfort-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thermal_comfort-1.1.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (528.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

thermal_comfort-1.1.5-cp310-cp310-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

thermal_comfort-1.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thermal_comfort-1.1.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (527.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

thermal_comfort-1.1.5-cp39-cp39-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

thermal_comfort-1.1.5-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thermal_comfort-1.1.5-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (527.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file thermal_comfort-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 43ed771492bf8b61d9ce78715e329c48785bf9390f97eff3282c8b22fc08b5a8
MD5 d90232f80117e2d3186120744bf31b1b
BLAKE2b-256 2022a5e43e3f24ee0467470eb2e672cf6c938b307476110889a00f9b74eb0844

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f351843f83358be4ab4dd5ad3fa2326a9ce1a9977fd0e075658638f3f31fec8
MD5 3b95f146732c788d492b11a99a84869e
BLAKE2b-256 2d42b4a0c48ae61cc603bfb192e3e0d551d744e5a158c69d7bbe77b029ac2c05

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9a498c90898e18bca45bd0dd575152cbdce0b7f8c7aa3b87f8302d6d60ce1457
MD5 ab1c76521ab6168ac3346bc27d2dd6ca
BLAKE2b-256 082282ad68af3d2d9f089c42139db20ef3458121e363224e45f8c142873152ad

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 331f1c2e1e8993ed9bf8ca46fccb67cc67c5db4a60b6543d2fff6add865cc135
MD5 67159c41cf119957626fa1389a1c7635
BLAKE2b-256 52647fc81d509b9ba3ce2b8b4218f3cde4a6ff41b28006a1599ac95b30124f4b

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 609c34b60ee8e81d4579da52719efeda039fb4bd7072ef641bb9287898c4a6e9
MD5 6e1a701033f6421a82a6beaa42f3a7a7
BLAKE2b-256 e4ea4889f087bdbdd25fb527604293f535fc2da30aae1fbe5f276b7e6231a90f

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 372873e387d95bd1160c32a76af0c5fa91411016e91cfe3b8c62ea3c00388686
MD5 f7b0373bc4aceeca14e6dd3a44c1c411
BLAKE2b-256 2520640ac7b41bb5c3a10548a3d65f854ab5fbfb17c554becda662646771f621

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6f3af0aa335dac4035ba9a957dac8343937cdb5ef42138b0a4f19dd8731ea081
MD5 d9b91afbb8de184bcf2cfe00eeaa8f1a
BLAKE2b-256 075f582a1a917f43a26a13a4548a2deff8a4b6652bceb620498589ea4cddbc8a

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 588c5ca2a9f8fa142298db94c4b44579e83146cfd47eb734c989052e6db4b48e
MD5 51e5b903878077009ce692c0aa4df4cf
BLAKE2b-256 1e2e0544f8044ecddaa6f529d5541980f2fa2db0a6c1baf3065ff151f1b85c7a

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ed3312494aab46d6be164128fb3596bcd771c7304b1d0e78fc860ed7c681bb7
MD5 1b63e38dcdbaf42908ca6d09364cba86
BLAKE2b-256 55d7856e076559564fb9864d15c5164fe4bc4acbcd7051c044639748774d73b9

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cb8c5e69b7d9303e72eca4137d90bc7e7d0f817970cd9edb5edc973a876e26ed
MD5 74b4cc704baf221787d9efed6ee9bc88
BLAKE2b-256 2c640fe0671efe0f96ce8e86a2f95ad70e6b13cf69bfbe61c0375fef50c72eab

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0c715cf5c269366ff9071181d1e10d61115c52b7a0caa1b3b87cdb1921027c6d
MD5 c320f7eece80e488cfea1378abf088ac
BLAKE2b-256 cfc40b939e26b76c9bf145cfa4f3865a1729522761021d00c1d190ab13e999fe

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9090dd69cf9f86a9222af5ba6ff4767026cb1f17b1ed9915fcd8b16fe7a21ff9
MD5 6d2e64cebe19c5c7664b6edf556498a5
BLAKE2b-256 6208ef189923bccaa3d0261bc8dbba38b0577db781df885c769a250614d14d21

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8a6b30bdcca7ba66e22a90f5d04ef6be839f6ae8574b68f47b3d5dde945576c2
MD5 34302d6ee2d9358eb90bd47c194a7192
BLAKE2b-256 2ddad70cf104a44986696d65ad0522b2597eec51b0a7e321b86e9273afc364a2

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8cfef5bdba2821c6cf57288fe143f9267863c150e006d47d6a059282039b605c
MD5 24e3a5cb333d0c7557aa7dc3caabc018
BLAKE2b-256 dd3544ce9d779d8527481632630f3aa74d2b6d630d8dd34465624f4addb5210f

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 24eaccee06b586f52378c6994329782d22bb9bcfa0fc3f7322a25a6471920033
MD5 4386611f90329df57100e9a1ba6dff38
BLAKE2b-256 fcea022d5054bc97e02d666c824ef52f6ed6f0879d0c2ba726ad1e8cf6234a9e

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.5-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.5-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f0d5f6cc00478cff175c100e431cd13dcc9eb6aaa011c30fef775bde3bbb9245
MD5 0dbfed9e542f6a81f7604463b8bf57ab
BLAKE2b-256 1599ef6786a14fbdc38a50d069afe6fcfe966ab2dba00c8a215ae6916271ce03

See more details on using hashes here.

Supported by

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