Humidity Calculation Error and Fix v 1.59
Brought to you by:
iridium
From: James a. J. W. <kk...@nc...> - 2002-02-01 04:22:18
|
In using PHPWeather for an amateur-radio project I am working on, I came across a situation where the humidity was being incorrectly calculated. This afternoon, for the station PAPK (Anaktuvuk Pass, AK--I just picked it at random!), PHPWeather calculated a negative humidty value (it was somewhere in the -90% range). I did a little research and found another formula for calculating relative humidity from the temp and dew point and implemented it in my copy of phpweather. The result came out correct (it was the same as our National Weather Service had calculated on their web page), and was also correct for several other weather stations. Also, the code is probably more efficient as it is only doing 2 pow() calculations rather than 8. This is your original code: $decoded_metar['rel_humidity'] = number_format(100 * ( 610.710701 + 44.4293573 * $decoded_metar['dew_c'] + 1.41696846 * pow($decoded_metar['dew_c'], 2) + 0.0274759545 * pow($decoded_metar['dew_c'], 3) + 2.61145937E-4 * pow($decoded_metar['dew_c'], 4) + 2.85993708E-6 * pow($decoded_metar['dew_c'], 5) ) / ( 610.710701 + 44.4293573 * $decoded_metar['temp_c'] + 1.41696846 * pow($decoded_metar['temp_c'], 2) + 0.0274759545 * pow($decoded_metar['temp_c'], 3) + 2.61145937E-4 * pow($decoded_metar['temp_c'], 4) + 2.85993708E-6 * pow($decoded_metar['temp_c'], 5) ), 1); This is my new code: $decoded_metar['rel_humidity'] = number_format(100 * (6.11*(pow(10,(7.5*$decoded_metar['dew_c']/(237.7+$decoded_metar['dew_c']))))) / (6.11*(pow(10,(7.5*$decoded_metar['temp_c']/(237.7+$decoded_metar['temp_c']))))) ,1); The only thing I haven't done is to not calculate the RH if one or the other temp is missing (PAKP is currently not showing a dew point in the METAR). Also, for my purposes, I have removed the thousand's separator from the air pressure calculation. It was hampering a reformat of the data for my project. I hope this helps your efforts! Thanks, James Wiles kk...@nc... - White County, AR, USA |