Calculate 'feels like temperature' for weather models

This code uses the 'Joint Action Group for Temp Indices' (JAG TI) formula to calculate Wind Chill from temperature (tempC) and Wind speed (windkph). And also the 'apparent temperature' using the Steadman's Apparent temperature formula which requires wind speed in knots, the dew temperature and current temperature.
So as can be seen, you will need existing data feeds for the data to be computed which can be readily parsed from various sources. I obtain data from my own sensors, and combine it with windspeed data from a nearby airport (as I have nowhere suitable to accurately site a anemometer).
Once you have the Wind Chill factor and Apparent Temperature, a if-else statement determines when they are implemented.
This is based upon the Met Office model, which uses the 'Chill factor' below 10 degC, the 'Apparent Temperature' on temps above 20 degC, and a linear interpolation of both formulas in the mid range.

Paul

[{"id":"a147cd02.5eb83","type":"function","name":"Parse METAR","func":"var METARdata = msg.payload.response.data[0].METAR[0];\nvar windkt = METARdata.wind_speed_kt[0];\nvar windkph = (windkt*1.852);\nvar gusts = windkt; //if wind_gust_kt is not present, value defaults to wind_speed_kt\n   if (typeof METARdata.wind_gust_kt != \"undefined\") {\n\t   gusts = METARdata.wind_gust_kt[0];\n       }\nvar altim = METARdata.altim_in_hg[0];\nvar pressure = Math.round(altim * 33.8637526); //convert hg to mb\nvar dew = METARdata.dewpoint_c[0];\ndew = Math.round(dew);\nvar tempC = METARdata.temp_c[0];\nvar tempF = ((tempC*1.8)+32);\n\n//tempC=5;\n//dew = 15;\n//windkt=1;\n\n//August-Roche-Magnus approximation to calculate rh_hum\nvar constA = 17.625;\nvar constB = 243.04;\nvar rh_numer = 10000.0*Math.exp((constA*eval(dew))/(eval(dew)+constB));\nvar rh_denom = Math.exp((constA*eval(tempC))/(eval(tempC)+constB));\nvar rh_hum   = (rh_numer/rh_denom);\nvar humidityemon = Math.round(rh_hum);\nvar humidity = (humidityemon/100);\n\n//Wind Chill Index Calculations using the 'Joint Action Group for Temp Indices' (JAG TI) formula\nvar chill=(13.12+0.6215*tempC-11.37*Math.pow(windkph,0.16)+0.3965*tempC*Math.pow(windkph,0.16));\n\n//Calculate Apparent Temperature\n//firstly, Calculate Vapor pressure in kPa\nvar vaporp = ((6.11*Math.pow(10,(7.5*dew/(237.3 + dew))))/10);\n//apply Steadman's Apparent Temperature formula\nvar apptemp = -2.7+(1.04*tempC)+(2*vaporp)-(windkt*0.3343886);\n        \n//Calculation of 'feels like' temperature by using the 'chill factor' if\n//the temp is below 10degC, or 'apparent temp' if over 20degC, or if between\n//10 and 20degC using a linear interpolation of both.\nvar feels;\nif (tempC < 10.0) {\n\tfeels=chill;\n\t}\n\telse if (tempC > 20.0) {\n\tfeels=apptemp;\n\t}\n\t\telse {\n\t\tvar calcA=((tempC-10)/10);\n\t\tvar calcB=1-calcA;\n\t\tfeels=((apptemp*calcA)+(chill*calcB));\n\t\t}\n\t\t\tfeels=Math.round(feels*100);\n\t\t\nmsg.payload = ((windkt) + (\",\") + (gusts) + (\",\") + (humidityemon) + (\",\") + (pressure) + (\",\") + (feels));\nreturn msg;","outputs":1,"x":578,"y":440,"z":"3f1992f2.c0e66e","wires":[["c40dd6c1.3bf228","37138490.c8ec7c"]]}]
Paul-Reed

Flow Info

created 2 years, 8 months ago

Node Types

Core
  • function (x1)

Tags

  • weather
  • chill
  • temperature
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option