Skip to main content

Functions to calculate thermal comfort indices

Project description

ci wheels pre-commit

thermal-comfort-omp

This version is compiled with OpenMPI support. For single core processing use thermal-comfort instead.

You can set the environment variable OMP_NUM_CORES=<number of cores> to control how many cores are used by the package. Using too many cores can lead to degraded performance.

Installation

via pypi

pip install thermal-comfort-omp

[!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_omp-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

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

thermal_comfort_omp-1.1.5-cp313-cp313-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

thermal_comfort_omp-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

thermal_comfort_omp-1.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (641.3 kB view details)

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

thermal_comfort_omp-1.1.5-cp312-cp312-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

thermal_comfort_omp-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

thermal_comfort_omp-1.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (641.3 kB view details)

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

thermal_comfort_omp-1.1.5-cp311-cp311-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

thermal_comfort_omp-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

thermal_comfort_omp-1.1.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (641.0 kB view details)

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

thermal_comfort_omp-1.1.5-cp310-cp310-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

thermal_comfort_omp-1.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

thermal_comfort_omp-1.1.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (639.7 kB view details)

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

thermal_comfort_omp-1.1.5-cp39-cp39-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

thermal_comfort_omp-1.1.5-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

thermal_comfort_omp-1.1.5-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (639.8 kB view details)

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

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 10f9ad6ca8243a4363f932eed8980ec0d882b722ba75af21698fd12fe0f027ae
MD5 f94a22f62d852655bcdeae49295d5ebf
BLAKE2b-256 4b016ff15099407349ee46125a3a5b99c4461e64118a9bce9c5854ee8cf1dfb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ce34caef149a919e457819c76d74d6eb868c837a1b9ffaa04c28b03dadc4c121
MD5 cea8955442ed143c2cdac6580aa1e09d
BLAKE2b-256 52d0aa63f5a443debb79730b7b55c56926fe31662d6517c3642040ab8ddad14a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fff19ff41e03e73fb8cde863789f0ad63caa57d72de06a1cb945d55315a4d98f
MD5 1fdbef0f490e89c5f2369195aebd3f53
BLAKE2b-256 b70549e66d7d32407c586f929f0ef28643f334faedca40baee42cb68dddbce4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 88e7cfa1e3f87cab003ba836d8d7d043d808c0f2709c544e116c45bf392eda8d
MD5 ab891f893c22f3d5332d9b3b5d8b13ca
BLAKE2b-256 4d430933fc84bfabf5b4dc6127e7085eb926f5a838e242322ff1255892f6cf81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9ddd1c97ee6aa1b50a9bbf57f4d4f6ed2d0dc80022c84f1ef18454742e2f4c1c
MD5 79988654da90368441b1c6a198b7a9aa
BLAKE2b-256 7af99d8d48788ba90946191b030a53207e32d65f1b6e9ed36cff5c85a4a15175

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cdfa2f95fec0882e02da2d3d5a4cea8609d8e6e2cf6128e0e12da3ca3107d6f9
MD5 ab919eb456431f71e366b3d68c3fb1bd
BLAKE2b-256 fc4765711440fd4bfdffceb0d2bd6d38b8de8ce5306831915797575d05065124

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5c008f87a72bfc3ce0d0f9031b8b6d58427b17f4ad3a55760aa31478d0b4b82f
MD5 8bfd8f169a5841417ce8cbb98b46fd65
BLAKE2b-256 9b070a817dd16eca2feb5e40c6473d996d4fb7a3d6108d92b5749556fd7a9892

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 02bb6363854af02261f3cfbc696a03a27ba6376d430f2ff0c2752bb33474f2b5
MD5 69fda33ce34d2462ca0f4d72a2a19644
BLAKE2b-256 5963d2772efad0707a1bf04bd377032a1eea57c37cd0b53f777e01ac25c04cea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26b953da22a3c6e6aa0e57c311cf51b52b552398f4bb16466137ec0528f8b2e0
MD5 768f2884245301473ec976fafac1ac36
BLAKE2b-256 4805954a80c9a19c07dc3f8c31593ff3c85bd3e504005257da8a0333c5561055

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0ecdbae997b8678e6192793f83f3e771d0ba3e67cd8e2dfdacb7b71fb643501f
MD5 bd55fc75453fc02d2e5c39a6458ab4ba
BLAKE2b-256 8456b0a94211d6b0474376f40c021592df8af36aae5f2c07a4bd9179e3060a34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5cea98db983d9647fb273e9ecfe102adcabf648875a652a4994dfe6c9eff7f28
MD5 a337ac8cc8d574e9bc3a962e05238ed7
BLAKE2b-256 3c13efb30ca20336cdb27f0d428e89aabe202007f261213a5e63ffb62f2c9137

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e1ddccf3533d4416132fd6f07536ee14d2d785d7e9807776c6ad087ac982da34
MD5 481e0eeb8bd5a28be30a38014ae78da9
BLAKE2b-256 9b6087056923d564765ca569e172b5a88b1ca0b7796d15e9963dc788e7876b1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 078ecc988875a13251425b750b0e6345497cc9c98f69a88c8058e262804e6838
MD5 544a3f2adf9eaed6f2bcc408bc60a5fd
BLAKE2b-256 e96dd7157bc5a05ef2992ff910a50658891369a7e710afef764b0c152f2dbfab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3c1fb41bd01c44286232e12d17b2b58cb42d2474f407e1bf03aee038395e39a9
MD5 c55f549e5c2102ec2fad2111d37c80ac
BLAKE2b-256 3ac8802a2c50a756d335ef8b485eaa147679d23a536589098febf967f80ed361

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5966891748ff3c4df66904489083151882aa495e8c662af488e1e5e247bd3f8c
MD5 d4c767b6c4e818412190af086d439002
BLAKE2b-256 b758da971c99e3e90641bbc6b074f99ef86264d1f1ff0ba75adc40c838e6d091

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort_omp-1.1.5-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 96a98056c6bdac11784f20b447d45caf3a3e587e021e767928c344402e7bbe98
MD5 dde5e5400c4c615eb7a1b0600c89f846
BLAKE2b-256 a9c1ebe24aef2c9a5736676e0e5a7e0390fbaebe12ae833a41364abec58f4ffc

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