Finally added heat index
This commit is contained in:
parent
8975016273
commit
88d8db6a52
|
@ -18,6 +18,11 @@ sudo python3 /var/gopher/scripts/current_weather.py
|
|||
echo "╚══════════════╝▒ ╚══════════════╝▒ ╚══════════════╝▒ ╚══════════════╝▒"
|
||||
echo " ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
|
||||
echo ""
|
||||
echo "╔════════════════════════════════════════════════════════════════════╗"
|
||||
sudo python3 /var/gopher/scripts/heat_index.py
|
||||
echo "╚════════════════════════════════════════════════════════════════════╝▒"
|
||||
echo " ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
|
||||
echo ""
|
||||
echo "╔════════════════════════════════╗ ╔════════════════════════════════╗"
|
||||
sudo /var/gopher/scripts/hilow_rain.py /var/gopher$today
|
||||
echo "╚════════════════════════════════╝▒ ╚════════════════════════════════╝▒"
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
#!/usr/bin/python3
|
||||
from __future__ import division
|
||||
import bme280
|
||||
import smbus2
|
||||
from time import sleep
|
||||
import math
|
||||
|
||||
port = 1
|
||||
address = 0x76 # Adafruit BME280 address. Other BME280s may be different
|
||||
bus = smbus2.SMBus(port)
|
||||
|
||||
def truncate(n, decimals=0):
|
||||
multiplier = 10 ** decimals
|
||||
return int(n * multiplier) / multiplier
|
||||
|
||||
def heat_index(temperature, humidity):
|
||||
"""Calculate Heat Index (feels like temperature) based on NOAA equation.
|
||||
HI is useful only when the temperature is minimally 80 F with a relative
|
||||
humidity of >= 40%.
|
||||
Default unit for resulting Temp value is Fahrenheit and it will be used
|
||||
in case of casting to int/float. Use Temp properties to convert result to
|
||||
Celsius (Temp.c) or Kelvin (Temp.k).
|
||||
:param temperature: temperature value in Fahrenheit or Temp instance.
|
||||
:type temperature: int, float, Temp
|
||||
:param humidity: relative humidity in % (1-100)
|
||||
:type humidity: int, float
|
||||
:returns: Heat Index value
|
||||
:rtype: Temp
|
||||
"""
|
||||
|
||||
c1 = -42.379
|
||||
c2 = 2.04901523
|
||||
c3 = 10.14333127
|
||||
c4 = -0.22475541
|
||||
c5 = -6.83783e-3
|
||||
c6 = -5.481717e-2
|
||||
c7 = 1.22874e-3
|
||||
c8 = 8.5282e-4
|
||||
c9 = -1.99e-6
|
||||
|
||||
T = (temperature * 9 / 5. ) + 32
|
||||
|
||||
RH = humidity
|
||||
# print('temp, humidity:', T,',',RH)
|
||||
# try simplified formula first (used for HI < 80)
|
||||
HI = 0.5 * (T + 61. + (T - 68.) * 1.2 + RH * 0.094)
|
||||
# print('Heat Index 1:', HI)
|
||||
|
||||
if T >= 80:
|
||||
# use Rothfusz regression
|
||||
HI = math.fsum([
|
||||
c1,
|
||||
c2 * T,
|
||||
c3 * RH,
|
||||
c4 * T * RH,
|
||||
c5 * T*T,
|
||||
c6 * RH*RH,
|
||||
c7 * T*T* RH,
|
||||
c8 * T * RH*RH,
|
||||
c9 * T*T * RH*RH,
|
||||
])
|
||||
|
||||
HIc=(HI-32)*5/9
|
||||
# print('Heat Index 2:', HI)
|
||||
return HIc
|
||||
|
||||
bme280.load_calibration_params(bus,address)
|
||||
wxdata = bme280.sample(bus,address)
|
||||
humidity = wxdata.humidity
|
||||
temperature = wxdata.temperature
|
||||
temperature_f = (temperature * 1.8) + 32
|
||||
|
||||
if temperature_f >= 80.0:
|
||||
hi = heat_index(temperature, humidity)
|
||||
hi_f = (hi * 1.8) + 32
|
||||
else:
|
||||
hi = temperature
|
||||
hi_f = temperature_f
|
||||
|
||||
ce = truncate(hi, 2)
|
||||
fe = truncate(hi_f, 2)
|
||||
|
||||
print('║ Heat Index ║▒')
|
||||
print('║ ║▒')
|
||||
if int(fe) > 100:
|
||||
print('║ Feels like {0:.2f}°F / {1:.2f}°C ║▒'.format(hi_f, hi))
|
||||
elif int(ce) > 10 and int(fe) > 10:
|
||||
print('║ Feels like {0:.2f}°F / {1:.2f}°C ║▒'.format(hi_f, hi))
|
||||
elif int(ce) < 10 and int(fe) > 10:
|
||||
print('║ Feels like {0:.2f}°F / {1:.2f}°C ║▒'.format(hi_f, hi))
|
||||
else:
|
||||
print('║ Feels like {0:.2f}°F / {1:.2f}°C ║▒'.format(hi_f, hi))
|
Loading…
Reference in New Issue