SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
heat_index.cpp
Go to the documentation of this file.
1#include "heat_index.h"
2
3#include <cmath>
4
5namespace sensesp {
6
7// heat index temperature
8
10 : Transform<std::tuple<float, float>, float>() {}
11
12void HeatIndexTemperature::set(const std::tuple<float, float>& input) {
13 // The following equation approximate the heat index
14 // using both Steadman's and Rothfusz equations
15 // See https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3801457/
16 // Algorithm 1 (table 1) (algorithm in figure 3)
17
18 float const temp_fahrenheit =
19 1.8 * (std::get<0>(input) - 273.15) +
20 32; // dry-bulb temperature in degrees fahrenheit
21 float const relative_humidity =
22 std::get<1>(input) * 100; // relative humidity in percent
23
24 // step 1: if temperature is less than 40°F then heat index temperature is
25 // dry bulb temperature.
26 float heat_index_temperature;
27
28 if (temp_fahrenheit <= 40) {
29 heat_index_temperature = temp_fahrenheit;
30 } else {
31 // step 2: use algorithm to calculate heat index and us it if the result
32 // is less than 79°F;
33 heat_index_temperature =
34 -10.3 + 1.1 * temp_fahrenheit + 0.047 * relative_humidity;
35 if (heat_index_temperature > 79) {
36 // step 3: calculate heat index temperature for other temperatures
37 // Coefficients for temperature in Fahrenheit
38 const float c1 = -42.379;
39 const float c2 = 2.04901523;
40 const float c3 = 10.14333127;
41 const float c4 = -0.22475541;
42 const float c5 = -0.00683783;
43 const float c6 = -0.05481717;
44 const float c7 = 0.00122874;
45 const float c8 = 0.00085282;
46 const float c9 = -0.00000199;
47
48 // equation for heat index
49 heat_index_temperature =
50 c1 + c2 * temp_fahrenheit + c3 * relative_humidity +
51 c4 * temp_fahrenheit * relative_humidity +
52 c5 * pow(temp_fahrenheit, 2) + c6 * pow(relative_humidity, 2) +
53 c7 * pow(temp_fahrenheit, 2) * relative_humidity +
54 c8 * temp_fahrenheit * pow(relative_humidity, 2) +
55 c9 * pow(temp_fahrenheit, 2) * pow(relative_humidity, 2);
56
57 // step 4: if humidity =< 13% and temp between 80°F and 112°F then
58 // correct heat index temperature
59 if (relative_humidity <= 13 && 80 <= temp_fahrenheit &&
60 temp_fahrenheit <= 112) {
61 heat_index_temperature = heat_index_temperature -
62 ((13 - relative_humidity) / 4) *
63 sqrt(17 - abs(temp_fahrenheit - 95) / 17);
64 }
65
66 // step 5: if humidity => 85% and temp between 80°C and 87°C then
67 // correct heat index temperature
68 else if (relative_humidity > 85 && 80 <= temp_fahrenheit &&
69 temp_fahrenheit <= 87) {
70 heat_index_temperature =
71 heat_index_temperature +
72 0.02 * (relative_humidity - 85) * (87 - temp_fahrenheit);
73 }
74 }
75 }
76
77 this->emit((heat_index_temperature - 32) / 1.8 +
78 273.15); // Fahrenheit to Kelvin
79}
80
81// heat index effect (warning levels)
82
84
85void HeatIndexEffect::set(const float& input) {
86 const float heat_index_temperature =
87 input - 273.15; // celsius = kelvin - 273.15
88 String heat_index_effect = "";
89 if (heat_index_temperature > 54) {
90 heat_index_effect = "Extreme danger";
91 } else if (heat_index_temperature > 41) {
92 heat_index_effect = "Danger";
93 } else if (heat_index_temperature > 32) {
94 heat_index_effect = "Extreme Caution";
95 } else if (heat_index_temperature > 27) {
96 heat_index_effect = "Caution";
97 }
98
99 this->emit(heat_index_effect);
100}
101
102} // namespace sensesp
virtual void set(const float &input) override
virtual void set(const std::tuple< float, float > &input) override
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:68
void emit(const T &new_value)