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.1-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.1-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.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (523.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

thermal_comfort-1.1.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4be607e864e9354cdef0791db818189af0f653257e3bc5ba033b301eb37d67c7
MD5 3442d80fdb881f1ce5be44c08da0b409
BLAKE2b-256 f34eaf8f383efe8749aaef7b5c849bd7132357a28f7938a226944cc69dd49004

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be8c39714f46a8dfea6f4ff50ea87427b3fda64430a148797a91ff7b86dd7da2
MD5 58492ad3bc77f953829abc54e5fec5f4
BLAKE2b-256 639e98c32f0d617aa07e12e83ec517711d6b163087b8396442d3230801d66d9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5e3b575ce20c8b8b402105d4c0931d7ec915005ba5fd050cb52fd288b3f896ad
MD5 b163e703c14aded31d38fe38cb7d8939
BLAKE2b-256 3fa75f17aa6ca7ebbc3054f4f70b1b1d2e2ecbfe52455d90349b8f1953b5c776

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 665cd11ccb1454145421823642992c0de0260c7136dfec9887f88614425d5758
MD5 74922e4cb950fe223775115e08273b0c
BLAKE2b-256 33e2e69237dc893d9c3ec46a1c3e05c8faafbc6be3b4d3547a89e58c0c45f2da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3aa4b83038f8090172883fa62a3e4c148e1fe1e3ddef52841afac17f1f015d1
MD5 1e982181e290cd04793732c5805008d1
BLAKE2b-256 c00703289039822d55189f7bd991f2415473315cb4223197945f19c657f80dcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0a0788d8d62a7e7bf31c8c2e36008e6530670665e2405ea3aac5c17f9aab2154
MD5 9f7e157ebad06cd53be916ac3a2d2994
BLAKE2b-256 4e3d5c6d5792a62e6a3f0fa200701905c2108fbd5c39a3aa4153a25061632798

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2ebe6e91461fa041f49f753c921a97b685712ce840493f6ac8c364bcc34009b7
MD5 b2f65137da37c2c6609b7708df8bbef9
BLAKE2b-256 cb138987c390b3ccbea9df3d9bf3d302665a3affb53c8b59c65590a61953bd92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c31b6dcc6dd372b31efa0054bd784f960d10ea29338bd5ee0dcb05c3008d0c2d
MD5 e3147f26fb38788070663a68ff3776a5
BLAKE2b-256 f6b9b02a582f3d27050350c4af42e53e39a7b2d1d585591c229a97e53946903c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3468cf75e779e5f79286f1e90d53f8914adf0a238ef97efa1f3ec89451491d8c
MD5 4c08f342bd102a72c0fe4e9c4f1f74ff
BLAKE2b-256 728cd0064d98c4db8664e19133f821b4490385102589a963a5e5aa3bb5800be9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 96f387d172b84265832f33a4f507da6d8fcf470707b2503191076d4bd025e136
MD5 6e02b69ab21d1d596c81b214e1062838
BLAKE2b-256 cb319226b2ffe8f7b9f18af979a95e3502bd6c29a7b0e16783d1f1731db8b8f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a82f4df34135384459c266d6b79972d6f5ca164be0d14a5a6113a4c4636e65e
MD5 4c3db14df55011a7bf318401099e7e50
BLAKE2b-256 aff35231c239d086cedaeb08884074e79be2218f961d96a06653fcb0d1bbc9a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1642647c0c72ffce6fb5e8692bef6bebf308b6b50faf321505f14d1cb7f068e0
MD5 a874e392be1dd9babdc180f2fa17611f
BLAKE2b-256 838a9486087df9072422f5ca500778b74ceccf2563d5ab57ad24a1e83af815d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e3b012b1684c27458c01f721ddcd5e998c1188c07e21c1ef59cadd259c6779d4
MD5 9a7b21e707044ab9cef806666b8cdc68
BLAKE2b-256 a0fe78dd749bb7d28dcc3e09f9bce1199196a8cc27810209e58a753336a2fc74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 afb42b34971e4d6ab4dad134dd8ef30d25f304208dac751c6a7755170c7af154
MD5 709f64a6052bf94f419a766e140976a5
BLAKE2b-256 3c1302e88e766f4c57bfe45b8093b324104bbea2d25d3726b513e2b8f5be277c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thermal_comfort-1.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 132d604492e2a63c5e7aaeb494b3b7a07a789efee1b96aff161ab327373c65e4
MD5 dfb9eec47c20cfa7708eaf4673a91031
BLAKE2b-256 75eee560fc89406b055fc2d2c6ee493ff91340ff5765994b876a245eea46c24e

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