Skip to content

Instantly share code, notes, and snippets.

@jfcarr
Created March 28, 2016 18:25
Show Gist options
  • Save jfcarr/e68593c92c878257550d to your computer and use it in GitHub Desktop.
Save jfcarr/e68593c92c878257550d to your computer and use it in GitHub Desktop.
"Feels Like" (temperature) Calculation in Python
# I use a Python script to pull current weather conditions from the NOAA web service API. The NOAA web
# service does not return a windchill value for all locations, but given temperature, relative humidity,
# and wind speed you can calculate a “feels like” temperature as follows.
# This code assumes units of Fahrenheit, MPH, and Relative Humidity by percentage. In this example, a
# temperature of 35F, wind speed of 10mph, and relative humidity of 72% yields a "feels like" value of 27.4F
import math
vTemperature = float(35)
vWindSpeed = float(10)
vRelativeHumidity = float(72)
# Try Wind Chill first
if vTemperature <= 50 and vWindSpeed >= 3:
vFeelsLike = 35.74 + (0.6215*vTemperature) - 35.75*(vWindSpeed**0.16) + ((0.4275*vTemperature)*(vWindSpeed**0.16))
else:
vFeelsLike = vTemperature
# Replace it with the Heat Index, if necessary
if vFeelsLike == vTemperature and vTemperature >= 80:
vFeelsLike = 0.5 * (vTemperature + 61.0 + ((vTemperature-68.0)*1.2) + (vRelativeHumidity*0.094))
if vFeelsLike >= 80:
vFeelsLike = -42.379 + 2.04901523*vTemperature + 10.14333127*vRelativeHumidity - .22475541*vTemperature*vRelativeHumidity - .00683783*vTemperature*vTemperature - .05481717*vRelativeHumidity*vRelativeHumidity + .00122874*vTemperature*vTemperature*vRelativeHumidity + .00085282*vTemperature*vRelativeHumidity*vRelativeHumidity - .00000199*vTemperature*vTemperature*vRelativeHumidity*vRelativeHumidity
if vRelativeHumidity < 13 and vTemperature >= 80 and vTemperature <= 112:
vFeelsLike = vFeelsLike - ((13-vRelativeHumidity)/4)*math.sqrt((17-math.fabs(vTemperature-95.))/17)
if vRelativeHumidity > 85 and vTemperature >= 80 and vTemperature <= 87:
vFeelsLike = vFeelsLike + ((vRelativeHumidity-85)/10) * ((87-vTemperature)/5)
print "Feels like: " + '%0.1f' % (vFeelsLike) + "F"
# Feels like: 27.4F
@zstorms
Copy link

zstorms commented Jun 6, 2022

Hello -

I like the way you have this setup to calculate a wind chill or Heat Index, depending on the conditions. I'd like to use this code to create a feature for my load forecasting models. Do you mind if I ask a few questions?

Thank you.

@jfcarr
Copy link
Author

jfcarr commented Jun 6, 2022

I don't mind at all, but I don't know how much help I'll be: I neglected to document where I found the algorithms. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment