Thread: SV: Humidity Calculation Error and Fix v 1.59
Brought to you by:
iridium
From: Funder, J. O. <jh...@NA...> - 2002-02-01 07:29:57
|
Hi, For your information, the official formular looks like this: 1779,75 (Td - Tt) RH = ANTILOG ( -------------------------- + 2 ) (237,3 + Td) ( 237.3 + Tt) where Tt = temperature and Td = dewpoint (of course) This is how my code looks like in Fortran 77 (for what it's worth) TAELLER = (DEWPOINT-TEMPERATURE)*1779.75 NAEVNER = (237.3+DEWPOINT)*(237.3+TEMPERATURE) LOG10_VAL = ((TAELLER/NAEVNER)+2) BASE = 10 CONSTANT = LOG(BASE) R_HUMIDITY = EXP(LOG10_VAL * CONSTANT) It should be very easy to convert that to php. best regards Johnny Funder Danish Civil Aviation Administration Software development division. -----Oprindelig meddelelse----- Fra: James and Jan Wiles [mailto:kk...@nc...] Sendt: 1. februar 2002 07:21 Til: php...@li... Emne: Humidity Calculation Error and Fix v 1.59 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 _______________________________________________ PHPWeather-devel mailing list PHP...@li... https://lists.sourceforge.net/lists/listinfo/phpweather-devel |
From: Martin G. <gim...@gi...> - 2002-02-03 10:04:19
|
"Funder, Johnny OTP" <jh...@NA...> writes: > Hi, > > For your information, the official formular looks like this: > > 1779,75 (Td - Tt) > RH = ANTILOG ( -------------------------- + 2 ) > (237,3 + Td) ( 237.3 + Tt) > > where Tt = temperature and Td = dewpoint (of course) > > This is how my code looks like in Fortran 77 (for what it's worth) > > > TAELLER = (DEWPOINT-TEMPERATURE)*1779.75 > NAEVNER = (237.3+DEWPOINT)*(237.3+TEMPERATURE) > LOG10_VAL = ((TAELLER/NAEVNER)+2) > BASE = 10 > CONSTANT = LOG(BASE) > R_HUMIDITY = EXP(LOG10_VAL * CONSTANT) > > It should be very easy to convert that to php. Very nice - I'll update the tarballs accordingly, just as soon at I hear about my attempts at implementing extract and str_replace in PHP3-friendly code. By the way: I've been thinking about putting the old-but-working code into CVS at Sourceforge. It seams that people are using v 1.59 and are happy about it, so we should make it easy for ourselves to fix things in that source-tree as well. Is there anybody here who has experience with branches in CVS? I've only used CVS for PHP Weather, but I think that we should do a branch here, so that we could have the stable and unstable code in CVS at the same time. I know that we could also just make a directory called 'old' or something like that, but it doesn't sound like the correct way to do things with CVS. -- Martin Geisler My GnuPG Key: 0xF7F6B57B See my homepage at http://www.gimpster.com/ for: PHP Weather => Shows the current weather on your webpage. PHP Shell => A telnet-connection (almost :-) in a PHP page. |