{"id":95,"date":"2011-01-17T21:17:54","date_gmt":"2011-01-18T04:17:54","guid":{"rendered":"http:\/\/logicalchaos.org\/blog\/?p=95"},"modified":"2013-04-21T21:43:22","modified_gmt":"2013-04-22T03:43:22","slug":"calculating-wind-chill-with-rrdtool","status":"publish","type":"post","link":"http:\/\/logicalchaos.org\/blog\/2011\/01\/calculating-wind-chill-with-rrdtool\/","title":{"rendered":"Calculating wind chill with RRDTool"},"content":{"rendered":"<p>In the process of switching over my <a href=\"http:\/\/www.gnuplot.info\/\">Gnuplot<\/a> <a href=\"http:\/\/www.logicalchaos.org\/weather\/gnuplot\/minute.html\">graphs<\/a> to <a href=\"http:\/\/www.mrtg.org\/rrdtool\/\">RRD<\/a>, I needed to re-do the SQL function I used for calculating <a href=\"http:\/\/en.wikipedia.org\/wiki\/Wind_chill\">wind chill<\/a> into RPN notation.  Quite straight forward in sql:<br \/>\n<!--more--><br \/>\n[code lang=&#8221;sql&#8221;]\u0010<br \/>\nCREATE OR REPLACE FUNCTION apparent_temp( float, float, float )<br \/>\nRETURNS float AS &#8216;<br \/>\nDECLARE<br \/>\ntempf  ALIAS FOR $1;<br \/>\nrelh   ALIAS FOR $2;<br \/>\nspeed  ALIAS FOR $3;<br \/>\naptemp  float;<br \/>\nBEGIN<br \/>\nIF tempf &gt;= 80 AND relh &gt;= 40 THEN<br \/>\naptemp = -42.379 + 2.04901523*tempf + 10.14333127*relh<br \/>\n&#8211; 0.22475541*tempf*relh &#8211; 0.00683783*(tempf^2)<br \/>\n&#8211; 0.05481717*(relh^2) + 0.00122874*(tempf^2)*relh<br \/>\n+ .00085282*tempf*(relh^2) &#8211; 0.00000199*(tempf^2)*(relh^2);<br \/>\nELSIF speed &gt;= 3 AND tempf &lt;= 50 THEN<br \/>\naptemp =   35.74 + .6215*tempf &#8211; 35.75*(speed^.16)<br \/>\n+ .4275*tempf*(speed^.16);<br \/>\nELSE<br \/>\naptemp = tempf;<br \/>\nEND IF;<br \/>\nRETURN aptemp;<br \/>\nEND;<br \/>\n&#8216; LANGUAGE plpgsql IMMUTABLE STRICT;<br \/>\n[\/code]<br \/>\nCould not find anything quickly in Google for doing this in RRD, so I had to think on my own.  The calculation is not quite as obvious in RRD RPN notation, but doable.  It&#8217;s complicated by not having the power function in RRD:<br \/>\n<code><span style=\"font-size: x-small;\">DEF:ot=weather.rrd:outsidetemp:AVERAGE<br \/>\nDEF:ws=weather.rrd:windspeedaverage1:AVERAGE<br \/>\nCDEF:chill=ot,50,GE,ot,ws,3,LE,ot,35.74,.6215,ot,*,+,ws,LOG,.16,*,EXP,DUP,ot,*,.4275,*,EXC,35.75,*,-,+,IF,IF<\/span><\/code><br \/>\n<a rel=\"attachment wp-att-106\" href=\"http:\/\/logicalchaos.org\/blog\/2011\/01\/calculating-wind-chill-with-rrdtool\/outsidetemp_24hours-2\/\"><img loading=\"lazy\" class=\"alignright size-medium wp-image-106\" title=\"Temperature with wind chill\" src=\"http:\/\/logicalchaos.org\/blog\/wp-content\/uploads\/2011\/01\/outsidetemp_24hours1-300x98.png\" alt=\"\" width=\"300\" height=\"98\" srcset=\"http:\/\/logicalchaos.org\/blog\/wp-content\/uploads\/2011\/01\/outsidetemp_24hours1-300x98.png 300w, http:\/\/logicalchaos.org\/blog\/wp-content\/uploads\/2011\/01\/outsidetemp_24hours1.png 881w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<em><strong>ot<\/strong><\/em> &#8211; outside temperature in fahrenheit<br \/>\n<em><strong>ws<\/strong><\/em> &#8211; windspeed in miles per hour<br \/>\nThis calculation will present the current temperature if the temperature is &gt; 50 degrees fahrenheit or the windspeed &lt; 3 mph.<\/p>\n<p>Heat index comes next.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to calculate wind chill using wind speed and temperature in rrd. <a href=\"http:\/\/logicalchaos.org\/blog\/2011\/01\/calculating-wind-chill-with-rrdtool\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[9,10,11],"_links":{"self":[{"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/posts\/95"}],"collection":[{"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":18,"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":107,"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions\/107"}],"wp:attachment":[{"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/logicalchaos.org\/blog\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}