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.2-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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

thermal_comfort-1.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (523.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

thermal_comfort-1.1.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

thermal_comfort-1.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (523.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

thermal_comfort-1.1.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

thermal_comfort-1.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (523.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

thermal_comfort-1.1.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

thermal_comfort-1.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (523.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

thermal_comfort-1.1.2-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.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

thermal_comfort-1.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (523.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f224c0e101f5a381ed653613680e950f7e0c693af502f4fdb06350c9859b7f15
MD5 311a6994f819cd2beff699dad66f9206
BLAKE2b-256 4ee8f72358ec200aafd9c3debd90494c503445dc0edcd83675ff788c6cdf96ec

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 123fd7e0e339301ea3c035e69c9ae0fc012d9d98173ea449e48efc8ffd6b99b2
MD5 b3d99f5c922a891e9fc64a7a7e4adcea
BLAKE2b-256 0fd5bcaf443bf333b510747994fd87cc1bbfe6b816dd43fc3c3ca219c78e47e5

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 67380c52f7fc339cf4fdba208a658a24781475a959dcc2edcc253d0a3517f7d5
MD5 49c4e1e9eb4af73c2f014b8eaed2ed2d
BLAKE2b-256 f68ef3271f7a3d918ff50002ba9653682c90da0b97beb4244846ed625697a2bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 effcf782281e03dd7e5f75a2d43daf7af54c401b3a78c87af271b74018826497
MD5 16a8ed6f01909a87e2bbd131da137230
BLAKE2b-256 0e629f853a6d0bea0908510c465110072945238fb6f914b45cf0252020b98565

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90d94816921a3d03e6437056cbe80105fb19eff0eac92b9d48ce553210ec8d4f
MD5 b1ef63d386a2ebe81b005a3feb0a7c37
BLAKE2b-256 be46ef8e4f0a6c8fe4e2e3542f2a391e7cef40ee82b1aad9f6d44746a87d95cb

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e30b3be8e66334d93037ea4b64db42f2ac1a23a6e7088b0b34e97cd62687c963
MD5 e2d2184111d9369d0c7146b1f9775f84
BLAKE2b-256 347c9b9162bc513f1037b7aea8190884aaa24605720baafb496b2b3ff0969f47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b1520c4bfcef39a01fee29a070b6c3aed102dd5133ad98cab8f32d4bd629a326
MD5 a2c036fc62f3a1691194efb7ac60c790
BLAKE2b-256 3e56c3665404784a7f365cddcbd9f15d27e1ea6f587ad07656895625eb44ed57

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0b2112c2000f3d29032e2493a0e1a6a8579bfebfaf35d6b4cdd36df53c23309
MD5 6d9eb5960bf83a86b8da62600277a7a7
BLAKE2b-256 900fcc6438c3df01b808eab5620eee741ccb055fae364428183ba3da0af9a10c

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8567f0b26c817a50ea0a543399f392d4e7e979c12475f0cc5443fe4cea06578b
MD5 83d47266cdae9189b3643fe81deb2d08
BLAKE2b-256 24a0bab4fc530edffe60fafad7e691a06c1048ddea094438101ed01c67d67465

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2f60ddc111e0f4642805b7ab12f290e5f79f47fb3b5d391de16af71dc590c5f9
MD5 5c0da8486719f015cbf131b12aab353b
BLAKE2b-256 a76deae69f90d05cb0622bbefbce82f6c311ba0238ce248bcb95119ceb7edf01

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 777e597656dc3368a097d0b474288bf4e3d183ab853859421582c41943f3f93e
MD5 b963e5730777882aa904a21ac54df27f
BLAKE2b-256 31b3006af1dfaf7cdb3c065878f029c2c026f7b022546bb34098b319899e0fb0

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f4dd17cb45207521fcb612468eab3578ecfeeded9c3a896b096f36f311483744
MD5 79b0ca49f35972a214c54e4645dfd53c
BLAKE2b-256 57f59f38c5734b4a31414c153b4b327ac6ee8d99afd2e0431bd7ee83a1830a16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 37c9a3633a6244ba0a3d92cebb226e1eae09330c3378d7d7479600b4a19c05d4
MD5 58a4b16f36e74b22b39129dbd133e4f3
BLAKE2b-256 1bdeb0b193034f7bcf99a852e267231b3c01b4f624b1a22a4d95d2872cd19f3a

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4fa8532e52a19997edb1d72b9b0360820513924cf53b6bfecb49e24b0d16b0f
MD5 b0e0959f89edeceffb7d257a29b87ac6
BLAKE2b-256 1f07127b0f586ce50e08b944b01e26af9dcd4bd46d9cd32f63188d80f1d723fe

See more details on using hashes here.

File details

Details for the file thermal_comfort-1.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e94db53f9b686621dee8fc39c9cb32e58f610215e249d105c2e3cb50eaf2b056
MD5 c8064f33f974f81b7468c861c5b9b3f2
BLAKE2b-256 18063bee2fd9cbe37225ce12754867b1b8ad1cb10d85e32b834614c02fb14f59

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