Skip to content

Instantly share code, notes, and snippets.

@ethaniel
Created November 26, 2021 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethaniel/c0160bc12feab27dbd442264b40687c1 to your computer and use it in GitHub Desktop.
Save ethaniel/c0160bc12feab27dbd442264b40687c1 to your computer and use it in GitHub Desktop.
PHP script for converting relative humidity to absolute humidity
<?php
// formulas courtesy of https://planetcalc.com/2167/
$pressure = 1000; // Pressure in hPa
$temperature = 25; // Temperature in Celsius
$humidity = 75; // Relative Humidity in %
$e = 2.71828;
$tp = ($pressure * 133.322)/100;
$et = 6.112 * pow($e,((17.62*$temperature)/(243.12+$temperature)));
$fp = 1.0016 + 3.15 * pow(10,-6) * $tp - 0.074/$tp;
$ept = $fp*$et;
$e = ($humidity/100)*$ept;
$Rv = 461.5;
$T = $temperature + 273.15;
$absolute = ($e*100/($Rv*$T)); // absolute humidity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment