Skip to content

Commit

Permalink
Merge pull request #40 from ecmwf/develop
Browse files Browse the repository at this point in the history
release 2.1.1
  • Loading branch information
tlmquintino authored Dec 27, 2024
2 parents e0b7dbf + 0b760cc commit 8b9dcae
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 130 deletions.
7 changes: 6 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
ChangeLog
=========

Version 2.1.1
-------------

* Small bug fix in the UTCI computaiton

Version 2.1.0
-------------

* Fix computaiton of normal effective temperature
* Fix computation of normal effective temperature
* Fix documentation links to new repository URL

Version 2.0.0
Expand Down
10 changes: 9 additions & 1 deletion tests/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ def test_mean_radiant_temperature(self):
assert mrt == pytest.approx(270.85099123, abs=1e-6)

def test_utci(self):
# case 1
t2_k = np.array([309.0])
va = np.array([3])
mrt = np.array([310.0])
e_hPa = np.array([12])
utci = np.array([tmf.calculate_utci(t2_k, va, mrt, td_k=None, ehPa=e_hPa)])
assert utci == pytest.approx(307.7653007813098, abs=1e-5)
assert utci == pytest.approx(307.76473586, abs=1e-5)
# case 2
t2_k = np.array([tmf.celsius_to_kelvin(27.0)])
va = np.array([4])
mrt = np.array([tmf.celsius_to_kelvin(9.2)])
e_hPa = np.array([16.5])
utci = np.array([tmf.calculate_utci(t2_k, va, mrt, td_k=None, ehPa=e_hPa)])
assert tmf.kelvin_to_celsius(utci) == pytest.approx(18.93148565062157, abs=1e-5)

def test_wbgt_simple(self):
t2_k = np.array([tmf.celsius_to_kelvin(30.0)])
Expand Down
100 changes: 50 additions & 50 deletions tests/utci.csv
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
3.066522212727615511e+02
3.030800798387573991e+02
2.817822892871009799e+02
2.817861128169730023e+02
2.819055035623330809e+02
2.820843145092730992e+02
2.822544991669730621e+02
2.824349526752729389e+02
2.825192538801423439e+02
2.825538748847658326e+02
2.825907371565169797e+02
2.825242879214880531e+02
2.826026115672207766e+02
2.825903695416938604e+02
2.825686119579708588e+02
2.824956841798426126e+02
2.824348637207822890e+02
2.824035494901654033e+02
2.823213843713008373e+02
2.821970206521376667e+02
2.820885320761137791e+02
2.819656581875690904e+02
2.818555616959664576e+02
2.817461663478956098e+02
2.817759371144935585e+02
2.817185696310076537e+02
2.946498698424303484e+02
2.946533254779482718e+02
2.944946214658237409e+02
2.944897141383211761e+02
2.945103976688493503e+02
2.947898943915968175e+02
2.950985979339650953e+02
2.954969432846014001e+02
2.962806470001805224e+02
2.968935483653857546e+02
2.978520607117526993e+02
2.980357230206132613e+02
2.981480733775071030e+02
2.981944615486317502e+02
2.981428990611726704e+02
2.978010563977110223e+02
2.975932622364314284e+02
2.970409706830507162e+02
2.966390711592547405e+02
2.963166376189072366e+02
2.957028202850734147e+02
2.952145755314123790e+02
2.947429575753403697e+02
2.945757319227597577e+02
3.065924867914495735e+02
3.030486962010081697e+02
2.817818400755697326e+02
2.817856618292843223e+02
2.819050232573577546e+02
2.820837846167555654e+02
2.822539179874810316e+02
2.824343083744449245e+02
2.825185735961071032e+02
2.825531739197518846e+02
2.825900077002742705e+02
2.825235699893789274e+02
2.826019008014984593e+02
2.825896474642471503e+02
2.825678864506331820e+02
2.824949747697248199e+02
2.824341695440342619e+02
2.824028617643160146e+02
2.823207288911114574e+02
2.821964150665114630e+02
2.820879680652919319e+02
2.819651357102680436e+02
2.818550741200479592e+02
2.817457086535698636e+02
2.817755003847337321e+02
2.817181403313402370e+02
2.946498240390932324e+02
2.946532123794038398e+02
2.944943339649283303e+02
2.944894158911849900e+02
2.945101022936242430e+02
2.947897026881508395e+02
2.950984482962226707e+02
2.954968486598986033e+02
2.962806254056695252e+02
2.968932701327588575e+02
2.978505991675414180e+02
2.980338637485639310e+02
2.981460347491484981e+02
2.981924101442477308e+02
2.981408478888602644e+02
2.977996553891449025e+02
2.975920557990174302e+02
2.970403537173256723e+02
2.966386721881900144e+02
2.963162506735635020e+02
2.957026884027639539e+02
2.952145198944800768e+02
2.947429574736622726e+02
2.945757265589746225e+02
2 changes: 1 addition & 1 deletion thermofeel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

from .thermofeel import * # noqa

__version__ = "2.1.0"
__version__ = "2.1.1"
164 changes: 87 additions & 77 deletions thermofeel/thermofeel.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,17 @@ def calculate_mean_radiant_temperature(ssrd, ssr, dsrp, strd, fdir, strr, cossza
return mrt


def calculate_utci_polynomial(t2m, mrt, va, rh):
def calculate_utci_polynomial(t2m, mrt, va, wvp):
"""
Helper function to calculate the UTCI polynomial approximation
:param t2_k: (float array) is 2m temperature [K]
:param mrt: (float array) is mean radiant temperature [K]
:param va: (float array) is wind speed at 10 meters [m/s]
:param wvp: (float array) is water vapour pressure [kPa]
returns UTCI [K]
Reference: Brode et al. (2012)
https://doi.org/10.1007/s00484-011-0454-1
"""
e_mrt = np.subtract(mrt, t2m)

t2m2 = t2m * t2m
Expand All @@ -241,26 +251,26 @@ def calculate_utci_polynomial(t2m, mrt, va, rh):
e_mrt5 = e_mrt4 * e_mrt
e_mrt6 = e_mrt5 * e_mrt

rh2 = rh * rh
rh3 = rh2 * rh
rh4 = rh3 * rh
rh5 = rh4 * rh
rh6 = rh5 * rh
wvp2 = wvp * wvp
wvp3 = wvp2 * wvp
wvp4 = wvp3 * wvp
wvp5 = wvp4 * wvp
wvp6 = wvp5 * wvp

varh2 = va * rh2
va2_rh = va2 * rh
varh2 = va * wvp2
va2_rh = va2 * wvp
va2_e_mrt = va2 * e_mrt
e_mrt_rh = e_mrt * rh
e_mrt_rh2 = e_mrt * rh2
e_mrt2_rh = e_mrt2 * rh
e_mrt2_rh2 = e_mrt2 * rh2
e_mrt_rh3 = e_mrt * rh3
e_mrt_rh = e_mrt * wvp
e_mrt_rh2 = e_mrt * wvp2
e_mrt2_rh = e_mrt2 * wvp
e_mrt2_rh2 = e_mrt2 * wvp2
e_mrt_rh3 = e_mrt * wvp3
va_e_mrt = va * e_mrt
va_e_mrt2 = va * e_mrt2
va_rh = va * rh
va_rh = va * wvp
t2m_va = t2m * va
e_mrt3_rh = e_mrt3 * rh
e_mrt4_rh = e_mrt4 * rh
e_mrt3_rh = e_mrt3 * wvp
e_mrt4_rh = e_mrt4 * wvp

utci = (
t2m
Expand Down Expand Up @@ -315,7 +325,7 @@ def calculate_utci_polynomial(t2m, mrt, va, rh):
+ 8.15300114e-08 * va5 * e_mrt
+ 7.55043090e-04 * e_mrt2
+ -5.65095215e-05 * t2m * e_mrt2
+ -4.52166564e-07 * t2m * e_mrt2
+ -4.52166564e-07 * t2m2 * e_mrt2
+ 2.46688878e-08 * t2m3 * e_mrt2
+ 2.42674348e-10 * t2m4 * e_mrt2
+ 1.54547250e-04 * va_e_mrt2
Expand Down Expand Up @@ -348,12 +358,12 @@ def calculate_utci_polynomial(t2m, mrt, va, rh):
+ 4.03863260e-13 * t2m * e_mrt5
+ 1.95087203e-12 * va * e_mrt5
+ -4.73602469e-12 * e_mrt6
+ 5.12733497e00 * rh
+ -3.12788561e-01 * t2m * rh
+ -1.96701861e-02 * t2m2 * rh
+ 9.99690870e-04 * t2m3 * rh
+ 9.51738512e-06 * t2m4 * rh
+ -4.66426341e-07 * t2m5 * rh
+ 5.12733497e00 * wvp
+ -3.12788561e-01 * t2m * wvp
+ -1.96701861e-02 * t2m2 * wvp
+ 9.99690870e-04 * t2m3 * wvp
+ 9.51738512e-06 * t2m4 * wvp
+ -4.66426341e-07 * t2m5 * wvp
+ 5.48050612e-01 * va_rh
+ -3.30552823e-03 * t2m * va_rh
+ -1.64119440e-03 * t2m2 * va_rh
Expand All @@ -363,12 +373,12 @@ def calculate_utci_polynomial(t2m, mrt, va, rh):
+ 5.00845667e-03 * t2m * va2_rh
+ 1.00601257e-06 * t2m2 * va2_rh
+ -1.81748644e-06 * t2m3 * va2_rh
+ -1.25813502e-03 * va3 * rh
+ -1.79330391e-04 * t2m * va3 * rh
+ 2.34994441e-06 * t2m2 * va3 * rh
+ 1.29735808e-04 * va4 * rh
+ 1.29064870e-06 * t2m * va4 * rh
+ -2.28558686e-06 * va5 * rh
+ -1.25813502e-03 * va3 * wvp
+ -1.79330391e-04 * t2m * va3 * wvp
+ 2.34994441e-06 * t2m2 * va3 * wvp
+ 1.29735808e-04 * va4 * wvp
+ 1.29064870e-06 * t2m * va4 * wvp
+ -2.28558686e-06 * va5 * wvp
+ -3.69476348e-02 * e_mrt_rh
+ 1.62325322e-03 * t2m * e_mrt_rh
+ -3.14279680e-05 * t2m2 * e_mrt_rh
Expand Down Expand Up @@ -403,22 +413,22 @@ def calculate_utci_polynomial(t2m, mrt, va, rh):
+ 3.94367674e-08 * e_mrt4_rh
+ -1.18566247e-09 * t2m * e_mrt4_rh
+ 3.34678041e-10 * va * e_mrt4_rh
+ -1.15606447e-10 * e_mrt5 * rh
+ -2.80626406e00 * rh2
+ 5.48712484e-01 * t2m * rh2
+ -3.99428410e-03 * t2m2 * rh2
+ -9.54009191e-04 * t2m3 * rh2
+ 1.93090978e-05 * t2m4 * rh2
+ -1.15606447e-10 * e_mrt5 * wvp
+ -2.80626406e00 * wvp2
+ 5.48712484e-01 * t2m * wvp2
+ -3.99428410e-03 * t2m2 * wvp2
+ -9.54009191e-04 * t2m3 * wvp2
+ 1.93090978e-05 * t2m4 * wvp2
+ -3.08806365e-01 * varh2
+ 1.16952364e-02 * t2m * varh2
+ 4.95271903e-04 * t2m2 * varh2
+ -1.90710882e-05 * t2m3 * varh2
+ 2.10787756e-03 * va2 * rh2
+ -6.98445738e-04 * t2m * va2 * rh2
+ 2.30109073e-05 * t2m2 * va2 * rh2
+ 4.17856590e-04 * va3 * rh2
+ -1.27043871e-05 * t2m * va3 * rh2
+ -3.04620472e-06 * va4 * rh2
+ 2.10787756e-03 * va2 * wvp2
+ -6.98445738e-04 * t2m * va2 * wvp2
+ 2.30109073e-05 * t2m2 * va2 * wvp2
+ 4.17856590e-04 * va3 * wvp2
+ -1.27043871e-05 * t2m * va3 * wvp2
+ -3.04620472e-06 * va4 * wvp2
+ 5.14507424e-02 * e_mrt_rh2
+ -4.32510997e-03 * t2m * e_mrt_rh2
+ 8.99281156e-05 * t2m2 * e_mrt_rh2
Expand All @@ -435,45 +445,45 @@ def calculate_utci_polynomial(t2m, mrt, va, rh):
+ 7.68023384e-06 * va * e_mrt2_rh2
+ -5.47446896e-07 * t2m_va * e_mrt2_rh2
+ -3.59937910e-08 * va2 * e_mrt2_rh2
+ -4.36497725e-06 * e_mrt3 * rh2
+ 1.68737969e-07 * t2m * e_mrt3 * rh2
+ 2.67489271e-08 * va * e_mrt3 * rh2
+ 3.23926897e-09 * e_mrt4 * rh2
+ -3.53874123e-02 * rh3
+ -2.21201190e-01 * t2m * rh3
+ 1.55126038e-02 * t2m2 * rh3
+ -2.63917279e-04 * t2m3 * rh3
+ 4.53433455e-02 * va * rh3
+ -4.32943862e-03 * t2m_va * rh3
+ 1.45389826e-04 * t2m2 * va * rh3
+ 2.17508610e-04 * va2 * rh3
+ -6.66724702e-05 * t2m * va2 * rh3
+ 3.33217140e-05 * va3 * rh3
+ -4.36497725e-06 * e_mrt3 * wvp2
+ 1.68737969e-07 * t2m * e_mrt3 * wvp2
+ 2.67489271e-08 * va * e_mrt3 * wvp2
+ 3.23926897e-09 * e_mrt4 * wvp2
+ -3.53874123e-02 * wvp3
+ -2.21201190e-01 * t2m * wvp3
+ 1.55126038e-02 * t2m2 * wvp3
+ -2.63917279e-04 * t2m3 * wvp3
+ 4.53433455e-02 * va * wvp3
+ -4.32943862e-03 * t2m_va * wvp3
+ 1.45389826e-04 * t2m2 * va * wvp3
+ 2.17508610e-04 * va2 * wvp3
+ -6.66724702e-05 * t2m * va2 * wvp3
+ 3.33217140e-05 * va3 * wvp3
+ -2.26921615e-03 * e_mrt_rh3
+ 3.80261982e-04 * t2m * e_mrt_rh3
+ -5.45314314e-09 * t2m2 * e_mrt_rh3
+ -7.96355448e-04 * va * e_mrt_rh3
+ 2.53458034e-05 * t2m_va * e_mrt_rh3
+ -6.31223658e-06 * va2 * e_mrt_rh3
+ 3.02122035e-04 * e_mrt2 * rh3
+ -4.77403547e-06 * t2m * e_mrt2 * rh3
+ 1.73825715e-06 * va * e_mrt2 * rh3
+ -4.09087898e-07 * e_mrt3 * rh3
+ 6.14155345e-01 * rh4
+ -6.16755931e-02 * t2m * rh4
+ 1.33374846e-03 * t2m2 * rh4
+ 3.55375387e-03 * va * rh4
+ -5.13027851e-04 * t2m_va * rh4
+ 1.02449757e-04 * va2 * rh4
+ -1.48526421e-03 * e_mrt * rh4
+ -4.11469183e-05 * t2m * e_mrt * rh4
+ -6.80434415e-06 * va * e_mrt * rh4
+ -9.77675906e-06 * e_mrt2 * rh4
+ 8.82773108e-02 * rh5
+ -3.01859306e-03 * t2m * rh5
+ 1.04452989e-03 * va * rh5
+ 2.47090539e-04 * e_mrt * rh5
+ 1.48348065e-03 * rh6
+ 3.02122035e-04 * e_mrt2 * wvp3
+ -4.77403547e-06 * t2m * e_mrt2 * wvp3
+ 1.73825715e-06 * va * e_mrt2 * wvp3
+ -4.09087898e-07 * e_mrt3 * wvp3
+ 6.14155345e-01 * wvp4
+ -6.16755931e-02 * t2m * wvp4
+ 1.33374846e-03 * t2m2 * wvp4
+ 3.55375387e-03 * va * wvp4
+ -5.13027851e-04 * t2m_va * wvp4
+ 1.02449757e-04 * va2 * wvp4
+ -1.48526421e-03 * e_mrt * wvp4
+ -4.11469183e-05 * t2m * e_mrt * wvp4
+ -6.80434415e-06 * va * e_mrt * wvp4
+ -9.77675906e-06 * e_mrt2 * wvp4
+ 8.82773108e-02 * wvp5
+ -3.01859306e-03 * t2m * wvp5
+ 1.04452989e-03 * va * wvp5
+ 2.47090539e-04 * e_mrt * wvp5
+ 1.48348065e-03 * wvp6
)

return utci
Expand All @@ -493,19 +503,19 @@ def calculate_utci(t2_k, va, mrt, td_k=None, ehPa=None):
"""

if ehPa is not None:
kPa = ehPa / 10.0 # water vapour pressure in kPa
wvp = ehPa / 10.0 # water vapour pressure in kPa
else:
if td_k is not None:
rh_pc = calculate_relative_humidity_percent(t2_k, td_k)
ehPa = calculate_saturation_vapour_pressure(t2_k) * rh_pc / 100.0
kPa = ehPa / 10.0 # water vapour pressure in kPa
wvp = ehPa / 10.0 # water vapour pressure in kPa
else:
raise ValueError("Missing input ehPa or td_k")

t2_c = kelvin_to_celsius(t2_k) # polynomial approx. is in Celsius
mrt_c = kelvin_to_celsius(mrt) # polynomial approx. is in Celsius

utci = calculate_utci_polynomial(t2_c, mrt_c, va, kPa)
utci = calculate_utci_polynomial(t2_c, mrt_c, va, wvp)
utci_k = celsius_to_kelvin(utci)

return utci_k
Expand Down

0 comments on commit 8b9dcae

Please sign in to comment.