Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created October 2, 2023 18:10
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 zaneclaes/0633af217a6512b32dcc846de70e08b1 to your computer and use it in GitHub Desktop.
Save zaneclaes/0633af217a6512b32dcc846de70e08b1 to your computer and use it in GitHub Desktop.
Heat Index Calculator
// Returns a Celcius temperature that transforms the input temperature based on the relative humidity
function calculateHeatIndex(airTempC, relativeHumidity){
relativeHumidity = Math.min(100, Math.max(0, relativeHumidity));
var hitemp = 61.0+((airTempC-68.0)*1.2)+(relativeHumidity*0.094);
var hifinal = 0.5*(airTempC+hitemp);
if(hifinal > 79.0){
var hi = -42.379+2.04901523*airTempC+10.14333127*relativeHumidity-0.22475541*airTempC*relativeHumidity-6.83783*(Math.pow(10, -3))*(Math.pow(airTempC, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(relativeHumidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(airTempC, 2))*relativeHumidity+8.5282*(Math.pow(10, -4))*airTempC*(Math.pow(relativeHumidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(airTempC, 2))*(Math.pow(relativeHumidity,2));
if((relativeHumidity <= 13) && (airTempC >= 80.0) && (airTempC <= 112.0)) {
var adj1 = (13.0-relativeHumidity)/4.0;
var adj2 = Math.sqrt((17.0-Math.abs(airTempC-95.0))/17.0);
var adj = adj1 * adj2;
var hi = hi - adj;
}
else if ((relativeHumidity > 85.0) && (airTempC >= 80.0) && (airTempC <= 87.0)) {
var adj1 = (relativeHumidity-85.0)/10.0;
var adj2 = (87.0-airTempC)/5.0;
var adj = adj1 * adj2;
var hi = hi + adj;
}
}
else{
var hi = hifinal;
}
twoplaces_rh = hi.toFixed(1);
celsius_temp_rh = (hi - 32) * .556;
return celsius_temp_rh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment