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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8554712757cbb8c447e4d899bf863a4f329bc7b73b8d670b9b7e3cf0d370fc8f
MD5 ffb19d165a5363b3b11338742fec4372
BLAKE2b-256 a4f84d93a6d69030d594f5343a1dae6184c67f0a54a4ada173840847629407ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b3c8dff1127aeec99b1cc755422b2abd379e1a435ceaf09a6562bba49a844bf7
MD5 88be31bb373fa8043ee62246f4c70bd2
BLAKE2b-256 c949fdf3e10b77e2ac8edced0c59d5f2a82f7622ebaf82e4e87c9e90fa14d970

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 abec0b09e249931f33b586d8e327b6a3b15ec861b2f46a86f926e64635bafd14
MD5 441a9755853422453400b3918f5008b5
BLAKE2b-256 495851efd7bbf1804d9c5c2d619d3ce1dd8d05e715cb6714205cf0e15835cce7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 37b7528be28b50d06e64336e22e04a60d27f170248bdad04c991c1edea29f3cb
MD5 927822438c29d3fe3df078884fc54f5d
BLAKE2b-256 a862e0d68d08cbbd021209787467f66b78dc83e216bde20b8c908ba24219febd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d7187e68c1ade748137ddadc2decfc8c35a6a354090b7e16c47b255192148b6
MD5 2962c170fe137ca632fe52f59f377366
BLAKE2b-256 3523543d58e02b97ac102b3acb84996734a2fcfaaa964f346d3b1a9c57994f1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d6b22d773d653b470a401912babe35b3ef2674b6d457e70605fcffb726ea2f6b
MD5 71898786b2d86847c0ca4a5efac7b734
BLAKE2b-256 5120bde703a3388d3479bdaf748b0f8c6ca026b48a06c8ac78d8899c6322ea61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 469107722746dc8c4a192973fbc0239282603849bddbb4422ed1c8217fbe9166
MD5 a3aaf350b9b39f2c782092842c5dce4b
BLAKE2b-256 96152e2a3e2880eba742ea6575454cf6d3ff35c050a7829395d31f01169ff6dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c431d662219f845e61b57fe48e3f4c3a8df63bb1358429da10e3b2ad30ebe1e5
MD5 3b17123c78170b3390f1f8787eff1abd
BLAKE2b-256 aa56b066b1ca523f8499a8b42a1deb7bb5ae663a775a455f0ae6140ed7ec01ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2d70b2cc835d4e1893e0d77281fec144eb85d837a005f884d9acc10cc6bbfbf0
MD5 a9828188bbc3e4f84b697540f17de976
BLAKE2b-256 5c124f6f561c4f9a5d28388600c47563fde37e260f157841ea9b670e77c73fea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b065b7103223d44755e7c312686477276c65a865253c242d6a55d398bf1f986f
MD5 878bbd101ae53219374b3271df167fca
BLAKE2b-256 3448ca1675d179bce51acb7ff990c058a7f69b6ee8d8423d0d97d7ea030d6a72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4ce7c3d8d0250fe0ac57f40015efda47917a0c9109eac1787c22a76b8d4a10c3
MD5 bfb936859d51036a66716204f901ba12
BLAKE2b-256 e01eaad78a0b0d8897c2e5a7b77da75171d69d4de456db9cda8e6e65f4b746cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 57d58543910917df3e6fe99e9c7ce776c6c39e7463516bce053e1b32d04e82ed
MD5 8802e60d095e9b0aad2c98e0ab3dd204
BLAKE2b-256 f3832b65f1f267a508153bf2035706e00b0de2ab88346463dcaf968bd83c6ef4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 afb0e675a9fbb7db732bde6582501c1cf9bc452a5fbd1c9456a9802153820a8f
MD5 8ea0d22e4d49aae2e5af24a4333ae14a
BLAKE2b-256 ab1adc73638616c026040c53134be68ec91eb8b3d9cff054bbbff541d2786498

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 38f54c2d35f0ed8aaef4ac9e754f5fa9b63c83e887bb6d1b55a748e7b147af6a
MD5 5b36fce55636f3bc186750f1fe81d616
BLAKE2b-256 b9745d7e93f14e69969b032b8456c49677d6379d53853df14710b9335e330168

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.4-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8d953c5285c853629427cd1ac1ec8bf4d7399379e1c3efe1ca296e3a00295eb5
MD5 5d64f45310eb68d412b3104fe6cca445
BLAKE2b-256 56ac88145fe578089e049a939f2cf21de54a0dfbc7bce4a9b881c94ffc741246

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